Skip to content

Commit da3ad47

Browse files
committed
Merge ExpnId and SyntaxContext.
1 parent 074a3c4 commit da3ad47

File tree

45 files changed

+454
-701
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+454
-701
lines changed

src/librustc/hir/lowering.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ use std::mem;
5757
use syntax::attr;
5858
use syntax::ast::*;
5959
use syntax::errors;
60+
use syntax::ext::hygiene::{Mark, SyntaxContext};
6061
use syntax::ptr::P;
6162
use syntax::codemap::{self, respan, Spanned};
6263
use syntax::std_inject;
@@ -392,14 +393,16 @@ impl<'a> LoweringContext<'a> {
392393
}
393394

394395
fn allow_internal_unstable(&self, reason: &'static str, mut span: Span) -> Span {
395-
span.expn_id = self.sess.codemap().record_expansion(codemap::ExpnInfo {
396+
let mark = Mark::fresh();
397+
mark.set_expn_info(codemap::ExpnInfo {
396398
call_site: span,
397399
callee: codemap::NameAndSpan {
398400
format: codemap::CompilerDesugaring(Symbol::intern(reason)),
399401
span: Some(span),
400402
allow_internal_unstable: true,
401403
},
402404
});
405+
span.ctxt = SyntaxContext::empty().apply_mark(mark);
403406
span
404407
}
405408

@@ -1998,7 +2001,7 @@ impl<'a> LoweringContext<'a> {
19982001
volatile: asm.volatile,
19992002
alignstack: asm.alignstack,
20002003
dialect: asm.dialect,
2001-
expn_id: asm.expn_id,
2004+
ctxt: asm.ctxt,
20022005
};
20032006
let outputs =
20042007
asm.outputs.iter().map(|out| self.lower_expr(&out.expr)).collect();

src/librustc/hir/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ use hir::def::Def;
3333
use hir::def_id::{DefId, DefIndex, CRATE_DEF_INDEX};
3434
use util::nodemap::{NodeMap, FxHashSet};
3535

36-
use syntax_pos::{Span, ExpnId, DUMMY_SP};
36+
use syntax_pos::{Span, DUMMY_SP};
3737
use syntax::codemap::{self, Spanned};
3838
use syntax::abi::Abi;
3939
use syntax::ast::{Ident, Name, NodeId, DUMMY_NODE_ID, AsmDialect};
4040
use syntax::ast::{Attribute, Lit, StrStyle, FloatTy, IntTy, UintTy, MetaItem};
41+
use syntax::ext::hygiene::SyntaxContext;
4142
use syntax::ptr::P;
4243
use syntax::symbol::{Symbol, keywords};
4344
use syntax::tokenstream::TokenStream;
@@ -1363,7 +1364,7 @@ pub struct InlineAsm {
13631364
pub volatile: bool,
13641365
pub alignstack: bool,
13651366
pub dialect: AsmDialect,
1366-
pub expn_id: ExpnId,
1367+
pub ctxt: SyntaxContext,
13671368
}
13681369

13691370
/// represents an argument in a function header

src/librustc/ich/caching_codemap_view.rs

-4
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ impl<'tcx> CachingCodemapView<'tcx> {
4747
}
4848
}
4949

50-
pub fn codemap(&self) -> &'tcx CodeMap {
51-
self.codemap
52-
}
53-
5450
pub fn byte_pos_to_line_and_col(&mut self,
5551
pos: BytePos)
5652
-> Option<(Rc<FileMap>, usize, BytePos)> {

src/librustc/middle/region.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ impl CodeExtent {
236236
// (This is the special case aluded to in the
237237
// doc-comment for this method)
238238
let stmt_span = blk.stmts[r.first_statement_index as usize].span;
239-
Some(Span { lo: stmt_span.hi, hi: blk.span.hi, expn_id: stmt_span.expn_id })
239+
Some(Span { lo: stmt_span.hi, hi: blk.span.hi, ctxt: stmt_span.ctxt })
240240
}
241241
}
242242
}

src/librustc/middle/stability.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
467467
}
468468

469469
pub fn check_stability(self, def_id: DefId, id: NodeId, span: Span) {
470-
if self.sess.codemap().span_allows_unstable(span) {
470+
if span.allows_unstable() {
471471
debug!("stability: \
472472
skipping span={:?} since it is internal", span);
473473
return;

src/librustc_driver/driver.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ pub fn phase_2_configure_and_expand<F>(sess: &Session,
582582

583583
krate = time(time_passes, "crate injection", || {
584584
let alt_std_name = sess.opts.alt_std_name.clone();
585-
syntax::std_inject::maybe_inject_crates_ref(&sess.parse_sess, krate, alt_std_name)
585+
syntax::std_inject::maybe_inject_crates_ref(krate, alt_std_name)
586586
});
587587

588588
let mut addl_plugins = Some(addl_plugins);
@@ -800,7 +800,7 @@ pub fn phase_2_configure_and_expand<F>(sess: &Session,
800800

801801
// Discard hygiene data, which isn't required after lowering to HIR.
802802
if !keep_hygiene_data(sess) {
803-
syntax::ext::hygiene::reset_hygiene_data();
803+
syntax::ext::hygiene::clear_markings();
804804
}
805805

806806
Ok(ExpansionResult {

src/librustc_errors/emitter.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use self::Destination::*;
1212

13-
use syntax_pos::{COMMAND_LINE_SP, DUMMY_SP, FileMap, Span, MultiSpan, CharPos};
13+
use syntax_pos::{DUMMY_SP, FileMap, Span, MultiSpan, CharPos};
1414

1515
use {Level, CodeSuggestion, DiagnosticBuilder, SubDiagnostic, CodeMapper};
1616
use RenderSpan::*;
@@ -151,7 +151,7 @@ impl EmitterWriter {
151151

152152
if let Some(ref cm) = self.cm {
153153
for span_label in msp.span_labels() {
154-
if span_label.span == DUMMY_SP || span_label.span == COMMAND_LINE_SP {
154+
if span_label.span == DUMMY_SP {
155155
continue;
156156
}
157157
let lo = cm.lookup_char_pos(span_label.span.lo);
@@ -615,15 +615,15 @@ impl EmitterWriter {
615615
let mut max = 0;
616616
if let Some(ref cm) = self.cm {
617617
for primary_span in msp.primary_spans() {
618-
if primary_span != &DUMMY_SP && primary_span != &COMMAND_LINE_SP {
618+
if primary_span != &DUMMY_SP {
619619
let hi = cm.lookup_char_pos(primary_span.hi);
620620
if hi.line > max {
621621
max = hi.line;
622622
}
623623
}
624624
}
625625
for span_label in msp.span_labels() {
626-
if span_label.span != DUMMY_SP && span_label.span != COMMAND_LINE_SP {
626+
if span_label.span != DUMMY_SP {
627627
let hi = cm.lookup_char_pos(span_label.span.hi);
628628
if hi.line > max {
629629
max = hi.line;
@@ -659,20 +659,20 @@ impl EmitterWriter {
659659

660660
// First, find all the spans in <*macros> and point instead at their use site
661661
for sp in span.primary_spans() {
662-
if (*sp == COMMAND_LINE_SP) || (*sp == DUMMY_SP) {
662+
if *sp == DUMMY_SP {
663663
continue;
664664
}
665665
if cm.span_to_filename(sp.clone()).contains("macros>") {
666-
let v = cm.macro_backtrace(sp.clone());
666+
let v = sp.macro_backtrace();
667667
if let Some(use_site) = v.last() {
668668
before_after.push((sp.clone(), use_site.call_site.clone()));
669669
}
670670
}
671-
for trace in cm.macro_backtrace(sp.clone()).iter().rev() {
671+
for trace in sp.macro_backtrace().iter().rev() {
672672
// Only show macro locations that are local
673673
// and display them like a span_note
674674
if let Some(def_site) = trace.def_site_span {
675-
if (def_site == COMMAND_LINE_SP) || (def_site == DUMMY_SP) {
675+
if def_site == DUMMY_SP {
676676
continue;
677677
}
678678
// Check to make sure we're not in any <*macros>
@@ -689,11 +689,11 @@ impl EmitterWriter {
689689
span.push_span_label(label_span, label_text);
690690
}
691691
for sp_label in span.span_labels() {
692-
if (sp_label.span == COMMAND_LINE_SP) || (sp_label.span == DUMMY_SP) {
692+
if sp_label.span == DUMMY_SP {
693693
continue;
694694
}
695695
if cm.span_to_filename(sp_label.span.clone()).contains("macros>") {
696-
let v = cm.macro_backtrace(sp_label.span.clone());
696+
let v = sp_label.span.macro_backtrace();
697697
if let Some(use_site) = v.last() {
698698
before_after.push((sp_label.span.clone(), use_site.call_site.clone()));
699699
}
@@ -848,7 +848,7 @@ impl EmitterWriter {
848848
// Make sure our primary file comes first
849849
let primary_lo = if let (Some(ref cm), Some(ref primary_span)) =
850850
(self.cm.as_ref(), msp.primary_span().as_ref()) {
851-
if primary_span != &&DUMMY_SP && primary_span != &&COMMAND_LINE_SP {
851+
if primary_span != &&DUMMY_SP {
852852
cm.lookup_char_pos(primary_span.lo)
853853
} else {
854854
emit_to_destination(&buffer.render(), level, &mut self.dst)?;

src/librustc_errors/lib.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ pub mod styled_buffer;
4848
mod lock;
4949

5050
use syntax_pos::{BytePos, Loc, FileLinesResult, FileName, MultiSpan, Span, NO_EXPANSION};
51-
use syntax_pos::MacroBacktrace;
5251

5352
#[derive(Clone, Debug, PartialEq, RustcEncodable, RustcDecodable)]
5453
pub enum RenderSpan {
@@ -75,7 +74,6 @@ pub trait CodeMapper {
7574
fn span_to_lines(&self, sp: Span) -> FileLinesResult;
7675
fn span_to_string(&self, sp: Span) -> String;
7776
fn span_to_filename(&self, sp: Span) -> FileName;
78-
fn macro_backtrace(&self, span: Span) -> Vec<MacroBacktrace>;
7977
fn merge_spans(&self, sp_lhs: Span, sp_rhs: Span) -> Option<Span>;
8078
}
8179

@@ -120,7 +118,7 @@ impl CodeSuggestion {
120118
let bounding_span = Span {
121119
lo: lo,
122120
hi: hi,
123-
expn_id: NO_EXPANSION,
121+
ctxt: NO_EXPANSION,
124122
};
125123
let lines = cm.span_to_lines(bounding_span).unwrap();
126124
assert!(!lines.lines.is_empty());

src/librustc_incremental/calculate_svh/svh_visitor.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ use self::SawTraitOrImplItemComponent::*;
1717
use syntax::abi::Abi;
1818
use syntax::ast::{self, Name, NodeId};
1919
use syntax::attr;
20+
use syntax::ext::hygiene::SyntaxContext;
2021
use syntax::parse::token;
2122
use syntax::symbol::InternedString;
22-
use syntax_pos::{Span, NO_EXPANSION, COMMAND_LINE_EXPN, BytePos};
23+
use syntax_pos::{Span, BytePos};
2324
use syntax::tokenstream;
2425
use rustc::hir;
2526
use rustc::hir::*;
@@ -92,10 +93,10 @@ impl<'a, 'hash, 'tcx> StrictVersionHashVisitor<'a, 'hash, 'tcx> {
9293
span.hi
9394
};
9495

95-
let expn_kind = match span.expn_id {
96-
NO_EXPANSION => SawSpanExpnKind::NoExpansion,
97-
COMMAND_LINE_EXPN => SawSpanExpnKind::CommandLine,
98-
_ => SawSpanExpnKind::SomeExpansion,
96+
let expn_kind = if span.ctxt == SyntaxContext::empty() {
97+
SawSpanExpnKind::NoExpansion
98+
} else {
99+
SawSpanExpnKind::SomeExpansion
99100
};
100101

101102
let loc1 = self.codemap.byte_pos_to_line_and_col(span.lo);
@@ -121,8 +122,7 @@ impl<'a, 'hash, 'tcx> StrictVersionHashVisitor<'a, 'hash, 'tcx> {
121122
saw.hash(self.st);
122123

123124
if expn_kind == SawSpanExpnKind::SomeExpansion {
124-
let call_site = self.codemap.codemap().source_callsite(span);
125-
self.hash_span(call_site);
125+
self.hash_span(span.source_callsite());
126126
}
127127
}
128128

@@ -483,7 +483,6 @@ fn saw_impl_item(ii: &ImplItemKind) -> SawTraitOrImplItemComponent {
483483
#[derive(Clone, Copy, Hash, Eq, PartialEq)]
484484
enum SawSpanExpnKind {
485485
NoExpansion,
486-
CommandLine,
487486
SomeExpansion,
488487
}
489488

@@ -501,7 +500,7 @@ impl<'a> Hash for StableInlineAsm<'a> {
501500
volatile,
502501
alignstack,
503502
dialect,
504-
expn_id: _, // This is used for error reporting
503+
ctxt: _, // This is used for error reporting
505504
} = *self.0;
506505

507506
asm.as_str().hash(state);

src/librustc_mir/transform/qualify_consts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ impl<'a, 'tcx> Qualifier<'a, 'tcx, 'tcx> {
223223
}
224224

225225
// This comes from a macro that has #[allow_internal_unstable].
226-
if self.tcx.sess.codemap().span_allows_unstable(self.span) {
226+
if self.span.allows_unstable() {
227227
return;
228228
}
229229

@@ -810,7 +810,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
810810
self.def_id.is_local() &&
811811

812812
// this doesn't come from a macro that has #[allow_internal_unstable]
813-
!self.tcx.sess.codemap().span_allows_unstable(self.span)
813+
!self.span.allows_unstable()
814814
{
815815
let mut err = self.tcx.sess.struct_span_err(self.span,
816816
"const fns are an unstable feature");

src/librustc_plugin/load.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use std::env;
2020
use std::mem;
2121
use std::path::PathBuf;
2222
use syntax::ast;
23-
use syntax_pos::{Span, COMMAND_LINE_SP};
23+
use syntax_pos::{Span, DUMMY_SP};
2424

2525
/// Pointer to a registrar function.
2626
pub type PluginRegistrarFun =
@@ -81,7 +81,7 @@ pub fn load_plugins(sess: &Session,
8181

8282
if let Some(plugins) = addl_plugins {
8383
for plugin in plugins {
84-
loader.load_plugin(COMMAND_LINE_SP, &plugin, vec![]);
84+
loader.load_plugin(DUMMY_SP, &plugin, vec![]);
8585
}
8686
}
8787

src/librustc_save_analysis/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -689,9 +689,8 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
689689
// Note we take care to use the source callsite/callee, to handle
690690
// nested expansions and ensure we only generate data for source-visible
691691
// macro uses.
692-
let callsite = self.tcx.sess.codemap().source_callsite(span);
693-
let callee = self.tcx.sess.codemap().source_callee(span);
694-
let callee = option_try!(callee);
692+
let callsite = span.source_callsite();
693+
let callee = option_try!(span.source_callee());
695694
let callee_span = option_try!(callee.span);
696695

697696
// Ignore attribute macros, their spans are usually mangled
@@ -950,5 +949,5 @@ fn escape(s: String) -> String {
950949
// Helper function to determine if a span came from a
951950
// macro expansion or syntax extension.
952951
pub fn generated_code(span: Span) -> bool {
953-
span.expn_id != NO_EXPANSION || span == DUMMY_SP
952+
span.ctxt != NO_EXPANSION || span == DUMMY_SP
954953
}

src/librustc_save_analysis/span_utils.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,7 @@ impl<'a> SpanUtils<'a> {
462462

463463
// Otherwise, a generated span is deemed invalid if it is not a sub-span of the root
464464
// callsite. This filters out macro internal variables and most malformed spans.
465-
let span = self.sess.codemap().source_callsite(parent);
466-
!(span.contains(parent))
465+
!parent.source_callsite().contains(parent)
467466
}
468467
}
469468

src/librustc_trans/asm.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,14 @@ pub fn trans_inline_asm<'a, 'tcx>(
111111
bcx.store(v, val, None);
112112
}
113113

114-
// Store expn_id in a metadata node so we can map LLVM errors
114+
// Store mark in a metadata node so we can map LLVM errors
115115
// back to source locations. See #17552.
116116
unsafe {
117117
let key = "srcloc";
118118
let kind = llvm::LLVMGetMDKindIDInContext(bcx.ccx.llcx(),
119119
key.as_ptr() as *const c_char, key.len() as c_uint);
120120

121-
let val: llvm::ValueRef = C_i32(bcx.ccx, ia.expn_id.into_u32() as i32);
121+
let val: llvm::ValueRef = C_i32(bcx.ccx, ia.ctxt.outer().as_u32() as i32);
122122

123123
llvm::LLVMSetMetadata(r, kind,
124124
llvm::LLVMMDNodeInContext(bcx.ccx.llcx(), &val, 1));

src/librustc_trans/back/write.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -371,14 +371,14 @@ struct HandlerFreeVars<'a> {
371371
unsafe extern "C" fn report_inline_asm<'a, 'b>(cgcx: &'a CodegenContext<'a>,
372372
msg: &'b str,
373373
cookie: c_uint) {
374-
use syntax_pos::ExpnId;
374+
use syntax::ext::hygiene::Mark;
375375

376376
match cgcx.lto_ctxt {
377377
Some((sess, _)) => {
378-
sess.codemap().with_expn_info(ExpnId::from_u32(cookie), |info| match info {
378+
match Mark::from_u32(cookie).expn_info() {
379379
Some(ei) => sess.span_err(ei.call_site, msg),
380380
None => sess.err(msg),
381-
});
381+
};
382382
}
383383

384384
None => {

0 commit comments

Comments
 (0)