diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 7e7bb5f61a324..c228bc2cf6b8c 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -60,7 +60,7 @@ use syntax::attr; use syntax::ast; use syntax::ast::*; use syntax::errors; -use syntax::ext::hygiene::Mark; +use syntax::ext::hygiene::ExpnId; use syntax::print::pprust; use syntax::source_map::{respan, ExpnInfo, ExpnKind, DesugaringKind, Spanned}; use syntax::std_inject; @@ -437,7 +437,7 @@ impl<'a> LoweringContext<'a> { owner, id, DefPathData::Misc, - Mark::root(), + ExpnId::root(), tree.prefix.span, ); self.lctx.allocate_hir_id_counter(id); @@ -875,7 +875,7 @@ impl<'a> LoweringContext<'a> { span: Span, allow_internal_unstable: Option>, ) -> Span { - span.fresh_expansion(Mark::root(), ExpnInfo { + span.fresh_expansion(ExpnId::root(), ExpnInfo { def_site: span, allow_internal_unstable, ..ExpnInfo::default(ExpnKind::Desugaring(reason), span, self.sess.edition()) @@ -968,7 +968,7 @@ impl<'a> LoweringContext<'a> { parent_index, node_id, DefPathData::LifetimeNs(str_name), - Mark::root(), + ExpnId::root(), span, ); @@ -1462,7 +1462,7 @@ impl<'a> LoweringContext<'a> { parent_def_index, impl_trait_node_id, DefPathData::ImplTrait, - Mark::root(), + ExpnId::root(), DUMMY_SP ); @@ -1921,7 +1921,7 @@ impl<'a> LoweringContext<'a> { self.parent, def_node_id, DefPathData::LifetimeNs(name.ident().as_interned_str()), - Mark::root(), + ExpnId::root(), lifetime.span); let (name, kind) = match name { diff --git a/src/librustc/hir/map/def_collector.rs b/src/librustc/hir/map/def_collector.rs index 6b93bd96a2718..d02aab54127a6 100644 --- a/src/librustc/hir/map/def_collector.rs +++ b/src/librustc/hir/map/def_collector.rs @@ -2,7 +2,7 @@ use crate::hir::map::definitions::*; use crate::hir::def_id::DefIndex; use syntax::ast::*; -use syntax::ext::hygiene::Mark; +use syntax::ext::hygiene::ExpnId; use syntax::visit; use syntax::symbol::{kw, sym}; use syntax::parse::token::{self, Token}; @@ -12,11 +12,11 @@ use syntax_pos::Span; pub struct DefCollector<'a> { definitions: &'a mut Definitions, parent_def: DefIndex, - expansion: Mark, + expansion: ExpnId, } impl<'a> DefCollector<'a> { - pub fn new(definitions: &'a mut Definitions, expansion: Mark) -> Self { + pub fn new(definitions: &'a mut Definitions, expansion: ExpnId) -> Self { let parent_def = definitions.invocation_parent(expansion); DefCollector { definitions, parent_def, expansion } } @@ -75,7 +75,7 @@ impl<'a> DefCollector<'a> { } fn visit_macro_invoc(&mut self, id: NodeId) { - self.definitions.set_invocation_parent(id.placeholder_to_mark(), self.parent_def); + self.definitions.set_invocation_parent(id.placeholder_to_expn_id(), self.parent_def); } } diff --git a/src/librustc/hir/map/definitions.rs b/src/librustc/hir/map/definitions.rs index 9188a78e489ef..8ee8c6d0e8983 100644 --- a/src/librustc/hir/map/definitions.rs +++ b/src/librustc/hir/map/definitions.rs @@ -15,7 +15,7 @@ use std::borrow::Borrow; use std::fmt::Write; use std::hash::Hash; use syntax::ast; -use syntax::ext::hygiene::Mark; +use syntax::ext::hygiene::ExpnId; use syntax::symbol::{Symbol, sym, InternedString}; use syntax_pos::{Span, DUMMY_SP}; use crate::util::nodemap::NodeMap; @@ -93,16 +93,16 @@ pub struct Definitions { node_to_def_index: NodeMap, def_index_to_node: Vec, pub(super) node_to_hir_id: IndexVec, - /// If `Mark` is an ID of some macro expansion, + /// If `ExpnId` is an ID of some macro expansion, /// then `DefId` is the normal module (`mod`) in which the expanded macro was defined. - parent_modules_of_macro_defs: FxHashMap, - /// Item with a given `DefIndex` was defined during macro expansion with ID `Mark`. - expansions_that_defined: FxHashMap, + parent_modules_of_macro_defs: FxHashMap, + /// Item with a given `DefIndex` was defined during macro expansion with ID `ExpnId`. + expansions_that_defined: FxHashMap, next_disambiguator: FxHashMap<(DefIndex, DefPathData), u32>, def_index_to_span: FxHashMap, - /// When collecting definitions from an AST fragment produced by a macro invocation `Mark` + /// When collecting definitions from an AST fragment produced by a macro invocation `ExpnId` /// we know what parent node that fragment should be attached to thanks to this table. - invocation_parents: FxHashMap, + invocation_parents: FxHashMap, } /// A unique identifier that we can use to lookup a definition @@ -437,7 +437,7 @@ impl Definitions { assert!(self.def_index_to_node.is_empty()); self.def_index_to_node.push(ast::CRATE_NODE_ID); self.node_to_def_index.insert(ast::CRATE_NODE_ID, root_index); - self.set_invocation_parent(Mark::root(), root_index); + self.set_invocation_parent(ExpnId::root(), root_index); // Allocate some other DefIndices that always must exist. GlobalMetaDataKind::allocate_def_indices(self); @@ -450,7 +450,7 @@ impl Definitions { parent: DefIndex, node_id: ast::NodeId, data: DefPathData, - expansion: Mark, + expn_id: ExpnId, span: Span) -> DefIndex { debug!("create_def_with_parent(parent={:?}, node_id={:?}, data={:?})", @@ -498,8 +498,8 @@ impl Definitions { self.node_to_def_index.insert(node_id, index); } - if expansion != Mark::root() { - self.expansions_that_defined.insert(index, expansion); + if expn_id != ExpnId::root() { + self.expansions_that_defined.insert(index, expn_id); } // The span is added if it isn't dummy @@ -519,23 +519,23 @@ impl Definitions { self.node_to_hir_id = mapping; } - pub fn expansion_that_defined(&self, index: DefIndex) -> Mark { - self.expansions_that_defined.get(&index).cloned().unwrap_or(Mark::root()) + pub fn expansion_that_defined(&self, index: DefIndex) -> ExpnId { + self.expansions_that_defined.get(&index).cloned().unwrap_or(ExpnId::root()) } - pub fn parent_module_of_macro_def(&self, mark: Mark) -> DefId { - self.parent_modules_of_macro_defs[&mark] + pub fn parent_module_of_macro_def(&self, expn_id: ExpnId) -> DefId { + self.parent_modules_of_macro_defs[&expn_id] } - pub fn add_parent_module_of_macro_def(&mut self, mark: Mark, module: DefId) { - self.parent_modules_of_macro_defs.insert(mark, module); + pub fn add_parent_module_of_macro_def(&mut self, expn_id: ExpnId, module: DefId) { + self.parent_modules_of_macro_defs.insert(expn_id, module); } - pub fn invocation_parent(&self, invoc_id: Mark) -> DefIndex { + pub fn invocation_parent(&self, invoc_id: ExpnId) -> DefIndex { self.invocation_parents[&invoc_id] } - pub fn set_invocation_parent(&mut self, invoc_id: Mark, parent: DefIndex) { + pub fn set_invocation_parent(&mut self, invoc_id: ExpnId, parent: DefIndex) { let old_parent = self.invocation_parents.insert(invoc_id, parent); assert!(old_parent.is_none(), "parent def-index is reset for an invocation"); } @@ -624,7 +624,7 @@ macro_rules! define_global_metadata_kind { CRATE_DEF_INDEX, ast::DUMMY_NODE_ID, DefPathData::GlobalMetaData(instance.name().as_interned_str()), - Mark::root(), + ExpnId::root(), DUMMY_SP ); diff --git a/src/librustc/ich/hcx.rs b/src/librustc/ich/hcx.rs index 4ef4d70ee1dcd..ae7d82c2020ac 100644 --- a/src/librustc/ich/hcx.rs +++ b/src/librustc/ich/hcx.rs @@ -359,21 +359,21 @@ impl<'a> HashStable> for Span { // times, we cache a stable hash of it and hash that instead of // recursing every time. thread_local! { - static CACHE: RefCell> = Default::default(); + static CACHE: RefCell> = Default::default(); } let sub_hash: u64 = CACHE.with(|cache| { - let mark = span.ctxt.outer(); + let expn_id = span.ctxt.outer_expn(); - if let Some(&sub_hash) = cache.borrow().get(&mark) { + if let Some(&sub_hash) = cache.borrow().get(&expn_id) { return sub_hash; } let mut hasher = StableHasher::new(); - mark.expn_info().hash_stable(hcx, &mut hasher); + expn_id.expn_info().hash_stable(hcx, &mut hasher); let sub_hash: Fingerprint = hasher.finish(); let sub_hash = sub_hash.to_smaller_hash(); - cache.borrow_mut().insert(mark, sub_hash); + cache.borrow_mut().insert(expn_id, sub_hash); sub_hash }); diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 6701c20b0a366..538afa6054ff9 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -44,7 +44,7 @@ use std::{mem, ptr}; use std::ops::Range; use syntax::ast::{self, Name, Ident, NodeId}; use syntax::attr; -use syntax::ext::hygiene::Mark; +use syntax::ext::hygiene::ExpnId; use syntax::symbol::{kw, sym, Symbol, LocalInternedString, InternedString}; use syntax_pos::Span; @@ -3071,10 +3071,10 @@ impl<'tcx> TyCtxt<'tcx> { self.expansion_that_defined(def_parent_def_id)) } - fn expansion_that_defined(self, scope: DefId) -> Mark { + fn expansion_that_defined(self, scope: DefId) -> ExpnId { match scope.krate { LOCAL_CRATE => self.hir().definitions().expansion_that_defined(scope.index), - _ => Mark::root(), + _ => ExpnId::root(), } } diff --git a/src/librustc/ty/query/on_disk_cache.rs b/src/librustc/ty/query/on_disk_cache.rs index a508d9846bce3..a25c1e34cf154 100644 --- a/src/librustc/ty/query/on_disk_cache.rs +++ b/src/librustc/ty/query/on_disk_cache.rs @@ -23,7 +23,7 @@ use std::mem; use syntax::ast::NodeId; use syntax::source_map::{SourceMap, StableSourceFileId}; use syntax_pos::{BytePos, Span, DUMMY_SP, SourceFile}; -use syntax_pos::hygiene::{Mark, SyntaxContext, ExpnInfo}; +use syntax_pos::hygiene::{ExpnId, SyntaxContext, ExpnInfo}; const TAG_FILE_FOOTER: u128 = 0xC0FFEE_C0FFEE_C0FFEE_C0FFEE_C0FFEE; @@ -588,13 +588,13 @@ impl<'a, 'tcx> SpecializedDecoder for CacheDecoder<'a, 'tcx> { let expn_info_tag = u8::decode(self)?; - // FIXME(mw): This method does not restore `MarkData::parent` or + // FIXME(mw): This method does not restore `InternalExpnData::parent` or // `SyntaxContextData::prev_ctxt` or `SyntaxContextData::opaque`. These things // don't seem to be used after HIR lowering, so everything should be fine // as long as incremental compilation does not kick in before that. let location = || Span::new(lo, hi, SyntaxContext::empty()); let recover_from_expn_info = |this: &Self, expn_info, pos| { - let span = location().fresh_expansion(Mark::root(), expn_info); + let span = location().fresh_expansion(ExpnId::root(), expn_info); this.synthetic_expansion_infos.borrow_mut().insert(pos, span.ctxt()); span }; @@ -725,7 +725,7 @@ struct CacheEncoder<'a, 'tcx, E: ty_codec::TyEncoder> { encoder: &'a mut E, type_shorthands: FxHashMap, usize>, predicate_shorthands: FxHashMap, usize>, - expn_info_shorthands: FxHashMap, + expn_info_shorthands: FxHashMap, interpret_allocs: FxHashMap, interpret_allocs_inverse: Vec, source_map: CachingSourceMapView<'tcx>, @@ -819,15 +819,15 @@ where if span_data.ctxt == SyntaxContext::empty() { TAG_NO_EXPANSION_INFO.encode(self) } else { - let (mark, expn_info) = span_data.ctxt.outer_and_expn_info(); + let (expn_id, expn_info) = span_data.ctxt.outer_expn_with_info(); if let Some(expn_info) = expn_info { - if let Some(pos) = self.expn_info_shorthands.get(&mark).cloned() { + if let Some(pos) = self.expn_info_shorthands.get(&expn_id).cloned() { TAG_EXPANSION_INFO_SHORTHAND.encode(self)?; pos.encode(self) } else { TAG_EXPANSION_INFO_INLINE.encode(self)?; let pos = AbsoluteBytePos::new(self.position()); - self.expn_info_shorthands.insert(mark, pos); + self.expn_info_shorthands.insert(expn_id, pos); expn_info.encode(self) } } else { diff --git a/src/librustc_allocator/expand.rs b/src/librustc_allocator/expand.rs index 9803ee99f1a47..87373364c4d9e 100644 --- a/src/librustc_allocator/expand.rs +++ b/src/librustc_allocator/expand.rs @@ -14,7 +14,7 @@ use syntax::{ base::{ExtCtxt, MacroKind, Resolver}, build::AstBuilder, expand::ExpansionConfig, - hygiene::Mark, + hygiene::ExpnId, }, mut_visit::{self, MutVisitor}, parse::ParseSess, @@ -85,7 +85,7 @@ impl MutVisitor for ExpandAllocatorDirectives<'_> { self.found = true; // Create a new expansion for the generated allocator code. - let span = item.span.fresh_expansion(Mark::root(), ExpnInfo::allow_unstable( + let span = item.span.fresh_expansion(ExpnId::root(), ExpnInfo::allow_unstable( ExpnKind::Macro(MacroKind::Attr, sym::global_allocator), item.span, self.sess.edition, [sym::rustc_attrs][..].into(), )); diff --git a/src/librustc_codegen_llvm/asm.rs b/src/librustc_codegen_llvm/asm.rs index bb92225c50ea0..9763d523a2ac4 100644 --- a/src/librustc_codegen_llvm/asm.rs +++ b/src/librustc_codegen_llvm/asm.rs @@ -102,7 +102,7 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> { let kind = llvm::LLVMGetMDKindIDInContext(self.llcx, key.as_ptr() as *const c_char, key.len() as c_uint); - let val: &'ll Value = self.const_i32(ia.ctxt.outer().as_u32() as i32); + let val: &'ll Value = self.const_i32(ia.ctxt.outer_expn().as_u32() as i32); llvm::LLVMSetMetadata(r, kind, llvm::LLVMMDNodeInContext(self.llcx, &val, 1)); diff --git a/src/librustc_codegen_ssa/back/write.rs b/src/librustc_codegen_ssa/back/write.rs index 7bb2cc7c08977..c9e4663fdbddf 100644 --- a/src/librustc_codegen_ssa/back/write.rs +++ b/src/librustc_codegen_ssa/back/write.rs @@ -26,7 +26,7 @@ use rustc_errors::{Handler, Level, DiagnosticBuilder, FatalError, DiagnosticId}; use rustc_errors::emitter::{Emitter}; use rustc_target::spec::MergeFunctions; use syntax::attr; -use syntax::ext::hygiene::Mark; +use syntax::ext::hygiene::ExpnId; use syntax_pos::MultiSpan; use syntax_pos::symbol::{Symbol, sym}; use jobserver::{Client, Acquired}; @@ -1775,7 +1775,7 @@ impl SharedEmitterMain { } } Ok(SharedEmitterMessage::InlineAsmError(cookie, msg)) => { - match Mark::from_u32(cookie).expn_info() { + match ExpnId::from_u32(cookie).expn_info() { Some(ei) => sess.span_err(ei.call_site, &msg), None => sess.err(&msg), } diff --git a/src/librustc_interface/passes.rs b/src/librustc_interface/passes.rs index bb11657d0c40c..6bf56bf851553 100644 --- a/src/librustc_interface/passes.rs +++ b/src/librustc_interface/passes.rs @@ -572,7 +572,7 @@ pub fn lower_to_hir( // Discard hygiene data, which isn't required after lowering to HIR. if !sess.opts.debugging_opts.keep_hygiene_data { - syntax::ext::hygiene::clear_markings(); + syntax::ext::hygiene::clear_syntax_context_map(); } Ok(hir_forest) diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index 6a5f62aec1537..8e76dbb882e3b 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -31,7 +31,7 @@ use syntax::ast::{self, Ident}; use syntax::source_map; use syntax::symbol::{Symbol, sym}; use syntax::ext::base::{MacroKind, SyntaxExtension}; -use syntax::ext::hygiene::Mark; +use syntax::ext::hygiene::ExpnId; use syntax_pos::{self, Span, BytePos, Pos, DUMMY_SP, NO_EXPANSION}; use log::debug; @@ -458,7 +458,7 @@ crate fn proc_macro_def_path_table(crate_root: &CrateRoot<'_>, crate_root, ast::DUMMY_NODE_ID, DefPathData::MacroNs(name.as_interned_str()), - Mark::root(), + ExpnId::root(), DUMMY_SP); debug!("definition for {:?} is {:?}", name, def_index); assert_eq!(def_index, DefIndex::from_proc_macro_index(index)); diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index 4554980071272..ee11228654b6f 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -30,7 +30,7 @@ use syntax::attr; use syntax::ast::{self, Block, ForeignItem, ForeignItemKind, Item, ItemKind, NodeId}; use syntax::ast::{MetaItemKind, StmtKind, TraitItem, TraitItemKind, Variant}; use syntax::ext::base::SyntaxExtension; -use syntax::ext::hygiene::Mark; +use syntax::ext::hygiene::ExpnId; use syntax::ext::tt::macro_rules; use syntax::feature_gate::is_builtin_attr; use syntax::parse::token::{self, Token}; @@ -45,7 +45,7 @@ use log::debug; type Res = def::Res; -impl<'a> ToNameBinding<'a> for (Module<'a>, ty::Visibility, Span, Mark) { +impl<'a> ToNameBinding<'a> for (Module<'a>, ty::Visibility, Span, ExpnId) { fn to_name_binding(self, arenas: &'a ResolverArenas<'a>) -> &'a NameBinding<'a> { arenas.alloc_name_binding(NameBinding { kind: NameBindingKind::Module(self.0), @@ -57,7 +57,7 @@ impl<'a> ToNameBinding<'a> for (Module<'a>, ty::Visibility, Span, Mark) { } } -impl<'a> ToNameBinding<'a> for (Res, ty::Visibility, Span, Mark) { +impl<'a> ToNameBinding<'a> for (Res, ty::Visibility, Span, ExpnId) { fn to_name_binding(self, arenas: &'a ResolverArenas<'a>) -> &'a NameBinding<'a> { arenas.alloc_name_binding(NameBinding { kind: NameBindingKind::Res(self.0, false), @@ -71,7 +71,7 @@ impl<'a> ToNameBinding<'a> for (Res, ty::Visibility, Span, Mark) { pub(crate) struct IsMacroExport; -impl<'a> ToNameBinding<'a> for (Res, ty::Visibility, Span, Mark, IsMacroExport) { +impl<'a> ToNameBinding<'a> for (Res, ty::Visibility, Span, ExpnId, IsMacroExport) { fn to_name_binding(self, arenas: &'a ResolverArenas<'a>) -> &'a NameBinding<'a> { arenas.alloc_name_binding(NameBinding { kind: NameBindingKind::Res(self.0, true), @@ -397,7 +397,7 @@ impl<'a> Resolver<'a> { let imported_binding = self.import(binding, directive); if ptr::eq(self.current_module, self.graph_root) { if let Some(entry) = self.extern_prelude.get(&ident.modern()) { - if expansion != Mark::root() && orig_name.is_some() && + if expansion != ExpnId::root() && orig_name.is_some() && entry.extern_crate_item.is_none() { self.session.span_err(item.span, "macro-expanded `extern crate` items \ cannot shadow names passed with \ @@ -571,13 +571,13 @@ impl<'a> Resolver<'a> { variant: &Variant, parent: Module<'a>, vis: ty::Visibility, - expansion: Mark) { + expn_id: ExpnId) { let ident = variant.node.ident; // Define a name in the type namespace. let def_id = self.definitions.local_def_id(variant.node.id); let res = Res::Def(DefKind::Variant, def_id); - self.define(parent, ident, TypeNS, (res, vis, variant.span, expansion)); + self.define(parent, ident, TypeNS, (res, vis, variant.span, expn_id)); // If the variant is marked as non_exhaustive then lower the visibility to within the // crate. @@ -596,11 +596,11 @@ impl<'a> Resolver<'a> { let ctor_def_id = self.definitions.local_def_id(ctor_node_id); let ctor_kind = CtorKind::from_ast(&variant.node.data); let ctor_res = Res::Def(DefKind::Ctor(CtorOf::Variant, ctor_kind), ctor_def_id); - self.define(parent, ident, ValueNS, (ctor_res, ctor_vis, variant.span, expansion)); + self.define(parent, ident, ValueNS, (ctor_res, ctor_vis, variant.span, expn_id)); } /// Constructs the reduced graph for one foreign item. - fn build_reduced_graph_for_foreign_item(&mut self, item: &ForeignItem, expansion: Mark) { + fn build_reduced_graph_for_foreign_item(&mut self, item: &ForeignItem, expn_id: ExpnId) { let (res, ns) = match item.node { ForeignItemKind::Fn(..) => { (Res::Def(DefKind::Fn, self.definitions.local_def_id(item.id)), ValueNS) @@ -615,16 +615,16 @@ impl<'a> Resolver<'a> { }; let parent = self.current_module; let vis = self.resolve_visibility(&item.vis); - self.define(parent, item.ident, ns, (res, vis, item.span, expansion)); + self.define(parent, item.ident, ns, (res, vis, item.span, expn_id)); } - fn build_reduced_graph_for_block(&mut self, block: &Block, expansion: Mark) { + fn build_reduced_graph_for_block(&mut self, block: &Block, expn_id: ExpnId) { let parent = self.current_module; if self.block_needs_anonymous_module(block) { let module = self.new_module(parent, ModuleKind::Block(block.id), parent.normal_ancestor_id, - expansion, + expn_id, block.span); self.block_map.insert(block.id, module); self.current_module = module; // Descend into the block. @@ -642,7 +642,7 @@ impl<'a> Resolver<'a> { // but metadata cannot encode gensyms currently, so we create it here. // This is only a guess, two equivalent idents may incorrectly get different gensyms here. let ident = ident.gensym_if_underscore(); - let expansion = Mark::root(); // FIXME(jseyfried) intercrate hygiene + let expansion = ExpnId::root(); // FIXME(jseyfried) intercrate hygiene match res { Res::Def(kind @ DefKind::Mod, def_id) | Res::Def(kind @ DefKind::Enum, def_id) => { @@ -734,14 +734,15 @@ impl<'a> Resolver<'a> { }; let kind = ModuleKind::Def(DefKind::Mod, def_id, name.as_symbol()); - let module = - self.arenas.alloc_module(ModuleData::new(parent, kind, def_id, Mark::root(), DUMMY_SP)); + let module = self.arenas.alloc_module(ModuleData::new( + parent, kind, def_id, ExpnId::root(), DUMMY_SP + )); self.extern_module_map.insert((def_id, macros_only), module); module } - pub fn macro_def_scope(&mut self, expansion: Mark) -> Module<'a> { - let def_id = match self.macro_defs.get(&expansion) { + pub fn macro_def_scope(&mut self, expn_id: ExpnId) -> Module<'a> { + let def_id = match self.macro_defs.get(&expn_id) { Some(def_id) => *def_id, None => return self.graph_root, }; @@ -858,7 +859,7 @@ impl<'a> Resolver<'a> { used: Cell::new(false), }); - let allow_shadowing = parent_scope.expansion == Mark::root(); + let allow_shadowing = parent_scope.expansion == ExpnId::root(); if let Some(span) = import_all { let directive = macro_use_directive(span); self.potentially_unused_imports.push(directive); @@ -918,12 +919,12 @@ impl<'a> Resolver<'a> { pub struct BuildReducedGraphVisitor<'a, 'b> { pub resolver: &'a mut Resolver<'b>, pub current_legacy_scope: LegacyScope<'b>, - pub expansion: Mark, + pub expansion: ExpnId, } impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> { fn visit_invoc(&mut self, id: ast::NodeId) -> &'b InvocationData<'b> { - let invoc_id = id.placeholder_to_mark(); + let invoc_id = id.placeholder_to_expn_id(); self.resolver.current_module.unresolved_invocations.borrow_mut().insert(invoc_id); diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index ba8cfdcf53548..d718d3f78f4e2 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -39,7 +39,7 @@ use rustc_metadata::creader::CrateLoader; use rustc_metadata::cstore::CStore; use syntax::source_map::SourceMap; -use syntax::ext::hygiene::{Mark, Transparency, SyntaxContext}; +use syntax::ext::hygiene::{ExpnId, Transparency, SyntaxContext}; use syntax::ast::{self, Name, NodeId, Ident, FloatTy, IntTy, UintTy}; use syntax::ext::base::SyntaxExtension; use syntax::ext::base::MacroKind; @@ -141,7 +141,7 @@ enum ScopeSet { #[derive(Clone, Debug)] pub struct ParentScope<'a> { module: Module<'a>, - expansion: Mark, + expansion: ExpnId, legacy: LegacyScope<'a>, derives: Vec, } @@ -1178,7 +1178,7 @@ pub struct ModuleData<'a> { builtin_attrs: RefCell)>>, // Macro invocations that can expand into items in this module. - unresolved_invocations: RefCell>, + unresolved_invocations: RefCell>, no_implicit_prelude: bool, @@ -1196,7 +1196,7 @@ pub struct ModuleData<'a> { /// Span of the module itself. Used for error reporting. span: Span, - expansion: Mark, + expansion: ExpnId, } type Module<'a> = &'a ModuleData<'a>; @@ -1205,7 +1205,7 @@ impl<'a> ModuleData<'a> { fn new(parent: Option>, kind: ModuleKind, normal_ancestor_id: DefId, - expansion: Mark, + expansion: ExpnId, span: Span) -> Self { ModuleData { parent, @@ -1304,7 +1304,7 @@ impl<'a> fmt::Debug for ModuleData<'a> { pub struct NameBinding<'a> { kind: NameBindingKind<'a>, ambiguity: Option<(&'a NameBinding<'a>, AmbiguityKind)>, - expansion: Mark, + expansion: ExpnId, span: Span, vis: ty::Visibility, } @@ -1513,7 +1513,7 @@ impl<'a> NameBinding<'a> { // in some later round and screw up our previously found resolution. // See more detailed explanation in // https://github.com/rust-lang/rust/pull/53778#issuecomment-419224049 - fn may_appear_after(&self, invoc_parent_expansion: Mark, binding: &NameBinding<'_>) -> bool { + fn may_appear_after(&self, invoc_parent_expansion: ExpnId, binding: &NameBinding<'_>) -> bool { // self > max(invoc, binding) => !(self <= invoc || self <= binding) // Expansions are partially ordered, so "may appear after" is an inversion of // "certainly appears before or simultaneously" and includes unordered cases. @@ -1686,13 +1686,13 @@ pub struct Resolver<'a> { dummy_ext_bang: Lrc, dummy_ext_derive: Lrc, non_macro_attrs: [Lrc; 2], - macro_defs: FxHashMap, + macro_defs: FxHashMap, local_macro_def_scopes: FxHashMap>, unused_macros: NodeMap, proc_macro_stubs: NodeSet, - /// Maps the `Mark` of an expansion to its containing module or block. - invocations: FxHashMap>, + /// Maps the `ExpnId` of an expansion to its containing module or block. + invocations: FxHashMap>, /// Avoid duplicated errors for "name already defined". name_already_seen: FxHashMap, @@ -1918,7 +1918,7 @@ impl<'a> Resolver<'a> { ); let graph_root = arenas.alloc_module(ModuleData { no_implicit_prelude: attr::contains_name(&krate.attrs, sym::no_implicit_prelude), - ..ModuleData::new(None, root_module_kind, root_def_id, Mark::root(), krate.span) + ..ModuleData::new(None, root_module_kind, root_def_id, ExpnId::root(), krate.span) }); let mut module_map = FxHashMap::default(); module_map.insert(DefId::local(CRATE_DEF_INDEX), graph_root); @@ -1941,11 +1941,11 @@ impl<'a> Resolver<'a> { } let mut invocations = FxHashMap::default(); - invocations.insert(Mark::root(), + invocations.insert(ExpnId::root(), arenas.alloc_invocation_data(InvocationData::root(graph_root))); let mut macro_defs = FxHashMap::default(); - macro_defs.insert(Mark::root(), root_def_id); + macro_defs.insert(ExpnId::root(), root_def_id); let features = session.features_untracked(); let non_macro_attr = @@ -2014,7 +2014,7 @@ impl<'a> Resolver<'a> { dummy_binding: arenas.alloc_name_binding(NameBinding { kind: NameBindingKind::Res(Res::Err, false), ambiguity: None, - expansion: Mark::root(), + expansion: ExpnId::root(), span: DUMMY_SP, vis: ty::Visibility::Public, }), @@ -2070,7 +2070,7 @@ impl<'a> Resolver<'a> { fn macro_def(&self, mut ctxt: SyntaxContext) -> DefId { loop { - match self.macro_defs.get(&ctxt.outer()) { + match self.macro_defs.get(&ctxt.outer_expn()) { Some(&def_id) => return def_id, None => ctxt.remove_mark(), }; @@ -2095,10 +2095,10 @@ impl<'a> Resolver<'a> { parent: Module<'a>, kind: ModuleKind, normal_ancestor_id: DefId, - expansion: Mark, + expn_id: ExpnId, span: Span, ) -> Module<'a> { - let module = ModuleData::new(Some(parent), kind, normal_ancestor_id, expansion, span); + let module = ModuleData::new(Some(parent), kind, normal_ancestor_id, expn_id, span); self.arenas.alloc_module(module) } @@ -2243,7 +2243,7 @@ impl<'a> Resolver<'a> { } Scope::CrateRoot => match ns { TypeNS => { - ident.span.adjust(Mark::root()); + ident.span.adjust(ExpnId::root()); Scope::ExternPrelude } ValueNS | MacroNS => break, @@ -2253,7 +2253,7 @@ impl<'a> Resolver<'a> { match self.hygienic_lexical_parent(module, &mut ident.span) { Some(parent_module) => Scope::Module(parent_module), None => { - ident.span.adjust(Mark::root()); + ident.span.adjust(ExpnId::root()); match ns { TypeNS => Scope::ExternPrelude, ValueNS => Scope::StdLibPrelude, @@ -2399,7 +2399,7 @@ impl<'a> Resolver<'a> { } if !module.no_implicit_prelude { - ident.span.adjust(Mark::root()); + ident.span.adjust(ExpnId::root()); if ns == TypeNS { if let Some(binding) = self.extern_prelude_get(ident, !record_used) { return Some(LexicalScopeBinding::Item(binding)); @@ -2407,7 +2407,7 @@ impl<'a> Resolver<'a> { } if ns == TypeNS && KNOWN_TOOLS.contains(&ident.name) { let binding = (Res::ToolMod, ty::Visibility::Public, - DUMMY_SP, Mark::root()).to_name_binding(self.arenas); + DUMMY_SP, ExpnId::root()).to_name_binding(self.arenas); return Some(LexicalScopeBinding::Item(binding)); } if let Some(prelude) = self.prelude { @@ -2428,7 +2428,7 @@ impl<'a> Resolver<'a> { fn hygienic_lexical_parent(&mut self, module: Module<'a>, span: &mut Span) -> Option> { - if !module.expansion.outer_is_descendant_of(span.ctxt()) { + if !module.expansion.outer_expn_is_descendant_of(span.ctxt()) { return Some(self.macro_def_scope(span.remove_mark())); } @@ -2464,7 +2464,7 @@ impl<'a> Resolver<'a> { module.expansion.is_descendant_of(parent.expansion) { // The macro is a proc macro derive if module.expansion.looks_like_proc_macro_derive() { - if parent.expansion.outer_is_descendant_of(span.ctxt()) { + if parent.expansion.outer_expn_is_descendant_of(span.ctxt()) { *poisoned = Some(node_id); return module.parent; } @@ -2506,7 +2506,7 @@ impl<'a> Resolver<'a> { } } ModuleOrUniformRoot::ExternPrelude => { - ident.span.modernize_and_adjust(Mark::root()); + ident.span.modernize_and_adjust(ExpnId::root()); } ModuleOrUniformRoot::CrateRootAndExternPrelude | ModuleOrUniformRoot::CurrentScope => { @@ -2552,7 +2552,7 @@ impl<'a> Resolver<'a> { result } else { ctxt = ctxt.modern(); - ctxt.adjust(Mark::root()) + ctxt.adjust(ExpnId::root()) }; let module = match mark { Some(def) => self.macro_def_scope(def), @@ -5063,7 +5063,7 @@ impl<'a> Resolver<'a> { }; let crate_root = self.get_module(DefId { krate: crate_id, index: CRATE_DEF_INDEX }); self.populate_module_if_necessary(&crate_root); - Some((crate_root, ty::Visibility::Public, DUMMY_SP, Mark::root()) + Some((crate_root, ty::Visibility::Public, DUMMY_SP, ExpnId::root()) .to_name_binding(self.arenas)) } }) diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index 34e85e1cf1011..3760cabcd898a 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -16,7 +16,7 @@ use syntax::attr::{self, StabilityLevel}; use syntax::ext::base::{self, Indeterminate}; use syntax::ext::base::{MacroKind, SyntaxExtension}; use syntax::ext::expand::{AstFragment, Invocation, InvocationKind}; -use syntax::ext::hygiene::{self, Mark, ExpnInfo, ExpnKind}; +use syntax::ext::hygiene::{self, ExpnId, ExpnInfo, ExpnKind}; use syntax::ext::tt::macro_rules; use syntax::feature_gate::{emit_feature_err, is_builtin_attr_name}; use syntax::feature_gate::GateIssue; @@ -135,19 +135,19 @@ impl<'a> base::Resolver for Resolver<'a> { self.session.next_node_id() } - fn get_module_scope(&mut self, id: ast::NodeId) -> Mark { - let span = DUMMY_SP.fresh_expansion(Mark::root(), ExpnInfo::default( + fn get_module_scope(&mut self, id: ast::NodeId) -> ExpnId { + let span = DUMMY_SP.fresh_expansion(ExpnId::root(), ExpnInfo::default( ExpnKind::Macro(MacroKind::Attr, sym::test_case), DUMMY_SP, self.session.edition() )); - let mark = span.ctxt().outer(); + let expn_id = span.ctxt().outer_expn(); let module = self.module_map[&self.definitions.local_def_id(id)]; - self.definitions.set_invocation_parent(mark, module.def_id().unwrap().index); - self.invocations.insert(mark, self.arenas.alloc_invocation_data(InvocationData { + self.definitions.set_invocation_parent(expn_id, module.def_id().unwrap().index); + self.invocations.insert(expn_id, self.arenas.alloc_invocation_data(InvocationData { module, parent_legacy_scope: LegacyScope::Empty, output_legacy_scope: Cell::new(None), })); - mark + expn_id } fn resolve_dollar_crates(&mut self) { @@ -160,15 +160,15 @@ impl<'a> base::Resolver for Resolver<'a> { }); } - fn visit_ast_fragment_with_placeholders(&mut self, mark: Mark, fragment: &AstFragment, - derives: &[Mark]) { - fragment.visit_with(&mut DefCollector::new(&mut self.definitions, mark)); + fn visit_ast_fragment_with_placeholders(&mut self, expn_id: ExpnId, fragment: &AstFragment, + derives: &[ExpnId]) { + fragment.visit_with(&mut DefCollector::new(&mut self.definitions, expn_id)); - let invocation = self.invocations[&mark]; + let invocation = self.invocations[&expn_id]; self.current_module = invocation.module; - self.current_module.unresolved_invocations.borrow_mut().remove(&mark); + self.current_module.unresolved_invocations.borrow_mut().remove(&expn_id); self.current_module.unresolved_invocations.borrow_mut().extend(derives); - let parent_def = self.definitions.invocation_parent(mark); + let parent_def = self.definitions.invocation_parent(expn_id); for &derive_invoc_id in derives { self.definitions.set_invocation_parent(derive_invoc_id, parent_def); } @@ -176,7 +176,7 @@ impl<'a> base::Resolver for Resolver<'a> { let mut visitor = BuildReducedGraphVisitor { resolver: self, current_legacy_scope: invocation.parent_legacy_scope, - expansion: mark, + expansion: expn_id, }; fragment.visit_with(&mut visitor); invocation.output_legacy_scope.set(Some(visitor.current_legacy_scope)); @@ -194,7 +194,7 @@ impl<'a> base::Resolver for Resolver<'a> { ambiguity: None, span: DUMMY_SP, vis: ty::Visibility::Public, - expansion: Mark::root(), + expansion: ExpnId::root(), }); if self.builtin_macros.insert(ident.name, binding).is_some() { self.session.span_err(ident.span, @@ -206,7 +206,7 @@ impl<'a> base::Resolver for Resolver<'a> { ImportResolver { resolver: self }.resolve_imports() } - fn resolve_macro_invocation(&mut self, invoc: &Invocation, invoc_id: Mark, force: bool) + fn resolve_macro_invocation(&mut self, invoc: &Invocation, invoc_id: ExpnId, force: bool) -> Result>, Indeterminate> { let (path, kind, derives_in_scope, after_derive) = match invoc.kind { InvocationKind::Attr { ref attr, ref derives, after_derive, .. } => @@ -223,16 +223,16 @@ impl<'a> base::Resolver for Resolver<'a> { let (ext, res) = self.smart_resolve_macro_path(path, kind, &parent_scope, force)?; let span = invoc.span(); - invoc.expansion_data.mark.set_expn_info(ext.expn_info(span, fast_print_path(path))); + invoc.expansion_data.id.set_expn_info(ext.expn_info(span, fast_print_path(path))); if let Res::Def(_, def_id) = res { if after_derive { self.session.span_err(span, "macro attributes must be placed before `#[derive]`"); } - self.macro_defs.insert(invoc.expansion_data.mark, def_id); + self.macro_defs.insert(invoc.expansion_data.id, def_id); let normal_module_def_id = - self.macro_def_scope(invoc.expansion_data.mark).normal_ancestor_id; - self.definitions.add_parent_module_of_macro_def(invoc.expansion_data.mark, + self.macro_def_scope(invoc.expansion_data.id).normal_ancestor_id; + self.definitions.add_parent_module_of_macro_def(invoc.expansion_data.id, normal_module_def_id); } @@ -250,10 +250,10 @@ impl<'a> base::Resolver for Resolver<'a> { impl<'a> Resolver<'a> { pub fn dummy_parent_scope(&self) -> ParentScope<'a> { - self.invoc_parent_scope(Mark::root(), Vec::new()) + self.invoc_parent_scope(ExpnId::root(), Vec::new()) } - fn invoc_parent_scope(&self, invoc_id: Mark, derives: Vec) -> ParentScope<'a> { + fn invoc_parent_scope(&self, invoc_id: ExpnId, derives: Vec) -> ParentScope<'a> { let invoc = self.invocations[&invoc_id]; ParentScope { module: invoc.module.nearest_item_scope(), @@ -460,7 +460,7 @@ impl<'a> Resolver<'a> { &parent_scope, true, force) { Ok((Some(ext), _)) => if ext.helper_attrs.contains(&ident.name) { let binding = (Res::NonMacroAttr(NonMacroAttrKind::DeriveHelper), - ty::Visibility::Public, derive.span, Mark::root()) + ty::Visibility::Public, derive.span, ExpnId::root()) .to_name_binding(this.arenas); result = Ok((binding, Flags::empty())); break; @@ -541,7 +541,7 @@ impl<'a> Resolver<'a> { } Scope::BuiltinAttrs => if is_builtin_attr_name(ident.name) { let binding = (Res::NonMacroAttr(NonMacroAttrKind::Builtin), - ty::Visibility::Public, DUMMY_SP, Mark::root()) + ty::Visibility::Public, DUMMY_SP, ExpnId::root()) .to_name_binding(this.arenas); Ok((binding, Flags::PRELUDE)) } else { @@ -550,7 +550,7 @@ impl<'a> Resolver<'a> { Scope::LegacyPluginHelpers => if this.session.plugin_attributes.borrow().iter() .any(|(name, _)| ident.name == *name) { let binding = (Res::NonMacroAttr(NonMacroAttrKind::LegacyPluginHelper), - ty::Visibility::Public, DUMMY_SP, Mark::root()) + ty::Visibility::Public, DUMMY_SP, ExpnId::root()) .to_name_binding(this.arenas); Ok((binding, Flags::PRELUDE)) } else { @@ -563,7 +563,7 @@ impl<'a> Resolver<'a> { )), } Scope::ToolPrelude => if KNOWN_TOOLS.contains(&ident.name) { - let binding = (Res::ToolMod, ty::Visibility::Public, DUMMY_SP, Mark::root()) + let binding = (Res::ToolMod, ty::Visibility::Public, DUMMY_SP, ExpnId::root()) .to_name_binding(this.arenas); Ok((binding, Flags::PRELUDE)) } else { @@ -588,7 +588,7 @@ impl<'a> Resolver<'a> { .get(&ident.name).cloned() { Some(prim_ty) => { let binding = (Res::PrimTy(prim_ty), ty::Visibility::Public, - DUMMY_SP, Mark::root()).to_name_binding(this.arenas); + DUMMY_SP, ExpnId::root()).to_name_binding(this.arenas); Ok((binding, Flags::PRELUDE)) } None => Err(Determinacy::Determined) @@ -688,7 +688,7 @@ impl<'a> Resolver<'a> { // the last segment, so we are certainly working with a single-segment attribute here.) assert!(ns == MacroNS); let binding = (Res::NonMacroAttr(NonMacroAttrKind::Custom), - ty::Visibility::Public, orig_ident.span, Mark::root()) + ty::Visibility::Public, orig_ident.span, ExpnId::root()) .to_name_binding(self.arenas); Ok(binding) } else { @@ -846,7 +846,7 @@ impl<'a> Resolver<'a> { pub fn define_macro(&mut self, item: &ast::Item, - expansion: Mark, + expansion: ExpnId, current_legacy_scope: &mut LegacyScope<'a>) { let (ext, ident, span, is_legacy) = match &item.node { ItemKind::MacroDef(def) => { diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 14622fd9f91fa..1960c06e86e4c 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -28,7 +28,7 @@ use rustc::util::nodemap::FxHashSet; use rustc::{bug, span_bug}; use syntax::ast::{self, Ident, Name, NodeId, CRATE_NODE_ID}; -use syntax::ext::hygiene::Mark; +use syntax::ext::hygiene::ExpnId; use syntax::symbol::kw; use syntax::util::lev_distance::find_best_match_for_name; use syntax::{struct_span_err, unwrap_or}; @@ -221,7 +221,7 @@ impl<'a> Resolver<'a> { ident.name == kw::DollarCrate { let module = self.resolve_crate_root(ident); let binding = (module, ty::Visibility::Public, - module.span, Mark::root()) + module.span, ExpnId::root()) .to_name_binding(self.arenas); return Ok(binding); } else if ident.name == kw::Super || @@ -246,7 +246,7 @@ impl<'a> Resolver<'a> { .map_err(|_| (Determined, Weak::No))?; // This happens when there is a cycle of imports. if let Some(binding) = resolution.binding { - if !restricted_shadowing && binding.expansion != Mark::root() { + if !restricted_shadowing && binding.expansion != ExpnId::root() { if let NameBindingKind::Res(_, true) = binding.kind { self.macro_expanded_macro_export_errors.insert((path_span, binding.span)); } @@ -286,7 +286,7 @@ impl<'a> Resolver<'a> { if let Some(shadowed_glob) = resolution.shadowed_glob { // Forbid expanded shadowing to avoid time travel. if restricted_shadowing && - binding.expansion != Mark::root() && + binding.expansion != ExpnId::root() && binding.res() != shadowed_glob.res() { self.ambiguity_errors.push(AmbiguityError { kind: AmbiguityKind::GlobVsExpanded, @@ -525,7 +525,7 @@ impl<'a> Resolver<'a> { (binding, old_binding) }; if glob_binding.res() != nonglob_binding.res() && - ns == MacroNS && nonglob_binding.expansion != Mark::root() { + ns == MacroNS && nonglob_binding.expansion != ExpnId::root() { resolution.binding = Some(this.ambiguity(AmbiguityKind::GlobVsExpanded, nonglob_binding, glob_binding)); } else { @@ -1248,7 +1248,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> { target: Ident, ) { // Skip if the import was produced by a macro. - if directive.parent_scope.expansion != Mark::root() { + if directive.parent_scope.expansion != ExpnId::root() { return; } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 6cfc1b77e03fe..b9b43c89346c7 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -5,7 +5,7 @@ pub use UnsafeSource::*; pub use crate::symbol::{Ident, Symbol as Name}; pub use crate::util::parser::ExprPrecedence; -use crate::ext::hygiene::{Mark, SyntaxContext}; +use crate::ext::hygiene::{ExpnId, SyntaxContext}; use crate::parse::token::{self, DelimToken}; use crate::print::pprust; use crate::ptr::P; @@ -251,12 +251,12 @@ mod node_id_inner { pub use node_id_inner::NodeId; impl NodeId { - pub fn placeholder_from_mark(mark: Mark) -> Self { - NodeId::from_u32(mark.as_u32()) + pub fn placeholder_from_expn_id(expn_id: ExpnId) -> Self { + NodeId::from_u32(expn_id.as_u32()) } - pub fn placeholder_to_mark(self) -> Mark { - Mark::from_u32(self.as_u32()) + pub fn placeholder_to_expn_id(self) -> ExpnId { + ExpnId::from_u32(self.as_u32()) } } diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 37d5885db60c3..926c9e88efe15 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -3,7 +3,7 @@ use crate::attr::{HasAttrs, Stability, Deprecation}; use crate::source_map::{SourceMap, Spanned, respan}; use crate::edition::Edition; use crate::ext::expand::{self, AstFragment, Invocation}; -use crate::ext::hygiene::{Mark, SyntaxContext, Transparency}; +use crate::ext::hygiene::{ExpnId, SyntaxContext, Transparency}; use crate::mut_visit::{self, MutVisitor}; use crate::parse::{self, parser, DirectoryOwnership}; use crate::parse::token; @@ -682,16 +682,16 @@ pub struct Indeterminate; pub trait Resolver { fn next_node_id(&mut self) -> ast::NodeId; - fn get_module_scope(&mut self, id: ast::NodeId) -> Mark; + fn get_module_scope(&mut self, id: ast::NodeId) -> ExpnId; fn resolve_dollar_crates(&mut self); - fn visit_ast_fragment_with_placeholders(&mut self, mark: Mark, fragment: &AstFragment, - derives: &[Mark]); + fn visit_ast_fragment_with_placeholders(&mut self, expn_id: ExpnId, fragment: &AstFragment, + derives: &[ExpnId]); fn add_builtin(&mut self, ident: ast::Ident, ext: Lrc); fn resolve_imports(&mut self); - fn resolve_macro_invocation(&mut self, invoc: &Invocation, invoc_id: Mark, force: bool) + fn resolve_macro_invocation(&mut self, invoc: &Invocation, invoc_id: ExpnId, force: bool) -> Result>, Indeterminate>; fn check_unused_macros(&self); @@ -705,7 +705,7 @@ pub struct ModuleData { #[derive(Clone)] pub struct ExpansionData { - pub mark: Mark, + pub id: ExpnId, pub depth: usize, pub module: Rc, pub directory_ownership: DirectoryOwnership, @@ -735,7 +735,7 @@ impl<'a> ExtCtxt<'a> { root_path: PathBuf::new(), resolver, current_expansion: ExpansionData { - mark: Mark::root(), + id: ExpnId::root(), depth: 0, module: Rc::new(ModuleData { mod_path: Vec::new(), directory: PathBuf::new() }), directory_ownership: DirectoryOwnership::Owned { relative: None }, @@ -763,13 +763,13 @@ impl<'a> ExtCtxt<'a> { pub fn parse_sess(&self) -> &'a parse::ParseSess { self.parse_sess } pub fn cfg(&self) -> &ast::CrateConfig { &self.parse_sess.config } pub fn call_site(&self) -> Span { - match self.current_expansion.mark.expn_info() { + match self.current_expansion.id.expn_info() { Some(expn_info) => expn_info.call_site, None => DUMMY_SP, } } pub fn backtrace(&self) -> SyntaxContext { - SyntaxContext::empty().apply_mark(self.current_expansion.mark) + SyntaxContext::empty().apply_mark(self.current_expansion.id) } /// Returns span for the macro which originally caused the current expansion to happen. @@ -877,7 +877,7 @@ impl<'a> ExtCtxt<'a> { ast::Ident::from_str(st) } pub fn std_path(&self, components: &[Symbol]) -> Vec { - let def_site = DUMMY_SP.apply_mark(self.current_expansion.mark); + let def_site = DUMMY_SP.apply_mark(self.current_expansion.id); iter::once(Ident::new(kw::DollarCrate, def_site)) .chain(components.iter().map(|&s| Ident::with_empty_ctxt(s))) .collect() @@ -900,7 +900,7 @@ pub fn expr_to_spanned_string<'a>( err_msg: &str, ) -> Result, Option>> { // Update `expr.span`'s ctxt now in case expr is an `include!` macro invocation. - expr.span = expr.span.apply_mark(cx.current_expansion.mark); + expr.span = expr.span.apply_mark(cx.current_expansion.id); // we want to be able to handle e.g., `concat!("foo", "bar")` cx.expander().visit_expr(&mut expr); diff --git a/src/libsyntax/ext/derive.rs b/src/libsyntax/ext/derive.rs index 1c15deab37377..ff9ad46deecc0 100644 --- a/src/libsyntax/ext/derive.rs +++ b/src/libsyntax/ext/derive.rs @@ -54,7 +54,7 @@ pub fn add_derived_markers(cx: &mut ExtCtxt<'_>, span: Span, traits: &[ast::P names.insert(unwrap_or!(path.segments.get(0), continue).ident.name); } - let span = span.fresh_expansion(cx.current_expansion.mark, ExpnInfo::allow_unstable( + let span = span.fresh_expansion(cx.current_expansion.id, ExpnInfo::allow_unstable( ExpnKind::Macro(MacroKind::Derive, Symbol::intern(&pretty_name)), span, cx.parse_sess.edition, cx.allow_derive_markers.clone(), )); diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 7f4b9904cab82..ae72f1fd108ed 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -5,7 +5,7 @@ use crate::source_map::{dummy_spanned, respan}; use crate::config::StripUnconfigured; use crate::ext::base::*; use crate::ext::derive::{add_derived_markers, collect_derives}; -use crate::ext::hygiene::{Mark, SyntaxContext, ExpnInfo, ExpnKind}; +use crate::ext::hygiene::{ExpnId, SyntaxContext, ExpnInfo, ExpnKind}; use crate::ext::placeholders::{placeholder, PlaceholderExpander}; use crate::feature_gate::{self, Features, GateIssue, is_builtin_attr, emit_feature_err}; use crate::mut_visit::*; @@ -304,7 +304,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { // Unresolved macros produce dummy outputs as a recovery measure. invocations.reverse(); let mut expanded_fragments = Vec::new(); - let mut derives: FxHashMap> = FxHashMap::default(); + let mut derives: FxHashMap> = FxHashMap::default(); let mut undetermined_invocations = Vec::new(); let (mut progress, mut force) = (false, !self.monotonic); loop { @@ -319,7 +319,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { }; let scope = - if self.monotonic { invoc.expansion_data.mark } else { orig_expansion_data.mark }; + if self.monotonic { invoc.expansion_data.id } else { orig_expansion_data.id }; let ext = match self.cx.resolver.resolve_macro_invocation(&invoc, scope, force) { Ok(ext) => ext, Err(Indeterminate) => { @@ -329,9 +329,9 @@ impl<'a, 'b> MacroExpander<'a, 'b> { }; progress = true; - let ExpansionData { depth, mark, .. } = invoc.expansion_data; + let ExpansionData { depth, id: expn_id, .. } = invoc.expansion_data; self.cx.current_expansion = invoc.expansion_data.clone(); - self.cx.current_expansion.mark = scope; + self.cx.current_expansion.id = scope; // FIXME(jseyfried): Refactor out the following logic let (expanded_fragment, new_invocations) = if let Some(ext) = ext { @@ -362,13 +362,13 @@ impl<'a, 'b> MacroExpander<'a, 'b> { item.visit_attrs(|attrs| attrs.retain(|a| a.path != sym::derive)); let mut item_with_markers = item.clone(); add_derived_markers(&mut self.cx, item.span(), &traits, &mut item_with_markers); - let derives = derives.entry(invoc.expansion_data.mark).or_default(); + let derives = derives.entry(invoc.expansion_data.id).or_default(); derives.reserve(traits.len()); invocations.reserve(traits.len()); for path in traits { - let mark = Mark::fresh(self.cx.current_expansion.mark, None); - derives.push(mark); + let expn_id = ExpnId::fresh(self.cx.current_expansion.id, None); + derives.push(expn_id); invocations.push(Invocation { kind: InvocationKind::Derive { path, @@ -377,7 +377,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { }, fragment_kind: invoc.fragment_kind, expansion_data: ExpansionData { - mark, + id: expn_id, ..invoc.expansion_data.clone() }, }); @@ -392,7 +392,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { if expanded_fragments.len() < depth { expanded_fragments.push(Vec::new()); } - expanded_fragments[depth - 1].push((mark, expanded_fragment)); + expanded_fragments[depth - 1].push((expn_id, expanded_fragment)); if !self.cx.ecfg.single_step { invocations.extend(new_invocations.into_iter().rev()); } @@ -405,7 +405,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { while let Some(expanded_fragments) = expanded_fragments.pop() { for (mark, expanded_fragment) in expanded_fragments.into_iter().rev() { let derives = derives.remove(&mark).unwrap_or_else(Vec::new); - placeholder_expander.add(NodeId::placeholder_from_mark(mark), + placeholder_expander.add(NodeId::placeholder_from_expn_id(mark), expanded_fragment, derives); } } @@ -423,7 +423,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { /// them with "placeholders" - dummy macro invocations with specially crafted `NodeId`s. /// Then call into resolver that builds a skeleton ("reduced graph") of the fragment and /// prepares data for resolving paths of macro invocations. - fn collect_invocations(&mut self, mut fragment: AstFragment, derives: &[Mark]) + fn collect_invocations(&mut self, mut fragment: AstFragment, derives: &[ExpnId]) -> (AstFragment, Vec) { // Resolve `$crate`s in the fragment for pretty-printing. self.cx.resolver.resolve_dollar_crates(); @@ -444,7 +444,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { if self.monotonic { self.cx.resolver.visit_ast_fragment_with_placeholders( - self.cx.current_expansion.mark, &fragment, derives); + self.cx.current_expansion.id, &fragment, derives); } (fragment, invocations) @@ -493,7 +493,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { } if self.cx.current_expansion.depth > self.cx.ecfg.recursion_limit { - let info = self.cx.current_expansion.mark.expn_info().unwrap(); + let info = self.cx.current_expansion.id.expn_info().unwrap(); let suggested_limit = self.cx.ecfg.recursion_limit * 2; let mut err = self.cx.struct_span_err(info.call_site, &format!("recursion limit reached while expanding the macro `{}`", @@ -822,17 +822,17 @@ impl<'a, 'b> InvocationCollector<'a, 'b> { )), _ => None, }; - let mark = Mark::fresh(self.cx.current_expansion.mark, expn_info); + let expn_id = ExpnId::fresh(self.cx.current_expansion.id, expn_info); self.invocations.push(Invocation { kind, fragment_kind, expansion_data: ExpansionData { - mark, + id: expn_id, depth: self.cx.current_expansion.depth + 1, ..self.cx.current_expansion.clone() }, }); - placeholder(fragment_kind, NodeId::placeholder_from_mark(mark)) + placeholder(fragment_kind, NodeId::placeholder_from_expn_id(expn_id)) } fn collect_bang(&mut self, mac: ast::Mac, span: Span, kind: AstFragmentKind) -> AstFragment { @@ -1402,7 +1402,7 @@ impl<'feat> ExpansionConfig<'feat> { // A Marker adds the given mark to the syntax context. #[derive(Debug)] -pub struct Marker(pub Mark); +pub struct Marker(pub ExpnId); impl MutVisitor for Marker { fn visit_span(&mut self, span: &mut Span) { diff --git a/src/libsyntax/ext/placeholders.rs b/src/libsyntax/ext/placeholders.rs index b2b8bfb09b45e..17d8bf3ab175f 100644 --- a/src/libsyntax/ext/placeholders.rs +++ b/src/libsyntax/ext/placeholders.rs @@ -2,7 +2,7 @@ use crate::ast::{self, NodeId}; use crate::source_map::{DUMMY_SP, dummy_spanned}; use crate::ext::base::ExtCtxt; use crate::ext::expand::{AstFragment, AstFragmentKind}; -use crate::ext::hygiene::Mark; +use crate::ext::hygiene::ExpnId; use crate::tokenstream::TokenStream; use crate::mut_visit::*; use crate::ptr::P; @@ -84,11 +84,11 @@ impl<'a, 'b> PlaceholderExpander<'a, 'b> { } } - pub fn add(&mut self, id: ast::NodeId, mut fragment: AstFragment, derives: Vec) { + pub fn add(&mut self, id: ast::NodeId, mut fragment: AstFragment, derives: Vec) { fragment.mut_visit_with(self); if let AstFragment::Items(mut items) = fragment { for derive in derives { - match self.remove(NodeId::placeholder_from_mark(derive)) { + match self.remove(NodeId::placeholder_from_expn_id(derive)) { AstFragment::Items(derived_items) => items.extend(derived_items), _ => unreachable!(), } diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index e04fd2ddc05bc..845dac557e821 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -219,7 +219,7 @@ pub fn transcribe( if let NtTT(ref tt) = **nt { result.push(tt.clone().into()); } else { - sp = sp.apply_mark(cx.current_expansion.mark); + sp = sp.apply_mark(cx.current_expansion.id); let token = TokenTree::token(token::Interpolated(nt.clone()), sp); result.push(token.into()); } @@ -234,8 +234,8 @@ pub fn transcribe( // If we aren't able to match the meta-var, we push it back into the result but // with modified syntax context. (I believe this supports nested macros). let ident = - Ident::new(ident.name, ident.span.apply_mark(cx.current_expansion.mark)); - sp = sp.apply_mark(cx.current_expansion.mark); + Ident::new(ident.name, ident.span.apply_mark(cx.current_expansion.id)); + sp = sp.apply_mark(cx.current_expansion.id); result.push(TokenTree::token(token::Dollar, sp).into()); result.push(TokenTree::Token(Token::from_ast_ident(ident)).into()); } @@ -247,7 +247,7 @@ pub fn transcribe( // jump back out of the Delimited, pop the result_stack and add the new results back to // the previous results (from outside the Delimited). quoted::TokenTree::Delimited(mut span, delimited) => { - span = span.apply_mark(cx.current_expansion.mark); + span = span.apply_mark(cx.current_expansion.id); stack.push(Frame::Delimited { forest: delimited, idx: 0, span }); result_stack.push(mem::take(&mut result)); } @@ -255,7 +255,7 @@ pub fn transcribe( // Nothing much to do here. Just push the token to the result, being careful to // preserve syntax context. quoted::TokenTree::Token(token) => { - let mut marker = Marker(cx.current_expansion.mark); + let mut marker = Marker(cx.current_expansion.id); let mut tt = TokenTree::Token(token); noop_visit_tt(&mut tt, &mut marker); result.push(tt.into()); diff --git a/src/libsyntax/std_inject.rs b/src/libsyntax/std_inject.rs index d86b76f71eca7..3fba81c0b6911 100644 --- a/src/libsyntax/std_inject.rs +++ b/src/libsyntax/std_inject.rs @@ -1,7 +1,7 @@ use crate::ast; use crate::attr; use crate::edition::Edition; -use crate::ext::hygiene::{Mark, MacroKind}; +use crate::ext::hygiene::{ExpnId, MacroKind}; use crate::symbol::{Ident, Symbol, kw, sym}; use crate::source_map::{ExpnInfo, ExpnKind, dummy_spanned, respan}; use crate::ptr::P; @@ -75,7 +75,7 @@ pub fn maybe_inject_crates_ref( INJECTED_CRATE_NAME.with(|opt_name| opt_name.set(Some(name))); - let span = DUMMY_SP.fresh_expansion(Mark::root(), ExpnInfo::allow_unstable( + let span = DUMMY_SP.fresh_expansion(ExpnId::root(), ExpnInfo::allow_unstable( ExpnKind::Macro(MacroKind::Attr, sym::std_inject), DUMMY_SP, edition, [sym::prelude_import][..].into(), )); diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index 799d64a996237..d82cdce2ce92b 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -21,7 +21,7 @@ use crate::entry::{self, EntryPointType}; use crate::ext::base::{ExtCtxt, Resolver}; use crate::ext::build::AstBuilder; use crate::ext::expand::ExpansionConfig; -use crate::ext::hygiene::{self, Mark, SyntaxContext, MacroKind}; +use crate::ext::hygiene::{self, ExpnId, SyntaxContext, MacroKind}; use crate::mut_visit::{*, ExpectOne}; use crate::feature_gate::Features; use crate::util::map_in_place::MapInPlace; @@ -232,7 +232,7 @@ fn mk_reexport_mod(cx: &mut TestCtxt<'_>, let name = Ident::from_str("__test_reexports").gensym(); let parent = if parent == ast::DUMMY_NODE_ID { ast::CRATE_NODE_ID } else { parent }; - cx.ext_cx.current_expansion.mark = cx.ext_cx.resolver.get_module_scope(parent); + cx.ext_cx.current_expansion.id = cx.ext_cx.resolver.get_module_scope(parent); let it = cx.ext_cx.monotonic_expander().flat_map_item(P(ast::Item { ident: name, attrs: Vec::new(), @@ -303,7 +303,7 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P { // #![main] // test::test_main_static(&[..tests]); // } - let sp = DUMMY_SP.fresh_expansion(Mark::root(), ExpnInfo::allow_unstable( + let sp = DUMMY_SP.fresh_expansion(ExpnId::root(), ExpnInfo::allow_unstable( ExpnKind::Macro(MacroKind::Attr, sym::test_case), DUMMY_SP, cx.ext_cx.parse_sess.edition, [sym::main, sym::test, sym::rustc_attrs][..].into(), )); diff --git a/src/libsyntax/tokenstream.rs b/src/libsyntax/tokenstream.rs index b32049b1da8c3..88142344d79e0 100644 --- a/src/libsyntax/tokenstream.rs +++ b/src/libsyntax/tokenstream.rs @@ -19,7 +19,7 @@ use crate::parse::Directory; use crate::parse::token::{self, DelimToken, Token, TokenKind}; use crate::print::pprust; -use syntax_pos::{BytePos, Mark, Span, DUMMY_SP}; +use syntax_pos::{BytePos, ExpnId, Span, DUMMY_SP}; #[cfg(target_arch = "x86_64")] use rustc_data_structures::static_assert_size; use rustc_data_structures::sync::Lrc; @@ -545,10 +545,10 @@ impl DelimSpan { self.open.with_hi(self.close.hi()) } - pub fn apply_mark(self, mark: Mark) -> Self { + pub fn apply_mark(self, expn_id: ExpnId) -> Self { DelimSpan { - open: self.open.apply_mark(mark), - close: self.close.apply_mark(mark), + open: self.open.apply_mark(expn_id), + close: self.close.apply_mark(expn_id), } } } diff --git a/src/libsyntax_ext/assert.rs b/src/libsyntax_ext/assert.rs index 637614a18bcc3..235565314f5e2 100644 --- a/src/libsyntax_ext/assert.rs +++ b/src/libsyntax_ext/assert.rs @@ -25,7 +25,7 @@ pub fn expand_assert<'cx>( } }; - let sp = sp.apply_mark(cx.current_expansion.mark); + let sp = sp.apply_mark(cx.current_expansion.id); let panic_call = Mac_ { path: Path::from_ident(Ident::new(sym::panic, sp)), tts: custom_message.unwrap_or_else(|| { diff --git a/src/libsyntax_ext/cfg.rs b/src/libsyntax_ext/cfg.rs index e952515bfe0eb..2b64f558be0a0 100644 --- a/src/libsyntax_ext/cfg.rs +++ b/src/libsyntax_ext/cfg.rs @@ -17,7 +17,7 @@ pub fn expand_cfg( sp: Span, tts: &[tokenstream::TokenTree], ) -> Box { - let sp = sp.apply_mark(cx.current_expansion.mark); + let sp = sp.apply_mark(cx.current_expansion.id); match parse_cfg(cx, sp, tts) { Ok(cfg) => { diff --git a/src/libsyntax_ext/concat.rs b/src/libsyntax_ext/concat.rs index 68d5178372eba..dbc985fd8599a 100644 --- a/src/libsyntax_ext/concat.rs +++ b/src/libsyntax_ext/concat.rs @@ -60,6 +60,6 @@ pub fn expand_syntax_ext( } else if has_errors { return base::DummyResult::expr(sp); } - let sp = sp.apply_mark(cx.current_expansion.mark); + let sp = sp.apply_mark(cx.current_expansion.id); base::MacEager::expr(cx.expr_str(sp, Symbol::intern(&accumulator))) } diff --git a/src/libsyntax_ext/concat_idents.rs b/src/libsyntax_ext/concat_idents.rs index df9191416038d..8184fc442676d 100644 --- a/src/libsyntax_ext/concat_idents.rs +++ b/src/libsyntax_ext/concat_idents.rs @@ -39,7 +39,7 @@ pub fn expand_syntax_ext<'cx>(cx: &'cx mut ExtCtxt<'_>, } } - let ident = ast::Ident::new(Symbol::intern(&res_str), sp.apply_mark(cx.current_expansion.mark)); + let ident = ast::Ident::new(Symbol::intern(&res_str), sp.apply_mark(cx.current_expansion.id)); struct ConcatIdentsResult { ident: ast::Ident } diff --git a/src/libsyntax_ext/deriving/generic/ty.rs b/src/libsyntax_ext/deriving/generic/ty.rs index 02b02e9b83695..fef1b4eebcf96 100644 --- a/src/libsyntax_ext/deriving/generic/ty.rs +++ b/src/libsyntax_ext/deriving/generic/ty.rs @@ -85,7 +85,7 @@ impl<'a> Path<'a> { PathKind::Global => cx.path_all(span, true, idents, params, Vec::new()), PathKind::Local => cx.path_all(span, false, idents, params, Vec::new()), PathKind::Std => { - let def_site = DUMMY_SP.apply_mark(cx.current_expansion.mark); + let def_site = DUMMY_SP.apply_mark(cx.current_expansion.id); idents.insert(0, Ident::new(kw::DollarCrate, def_site)); cx.path_all(span, false, idents, params, Vec::new()) } diff --git a/src/libsyntax_ext/env.rs b/src/libsyntax_ext/env.rs index b7f2ecf0f9137..03c60e3f11f03 100644 --- a/src/libsyntax_ext/env.rs +++ b/src/libsyntax_ext/env.rs @@ -21,7 +21,7 @@ pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt<'_>, Some(v) => v, }; - let sp = sp.apply_mark(cx.current_expansion.mark); + let sp = sp.apply_mark(cx.current_expansion.id); let e = match env::var(&*var.as_str()) { Err(..) => { let lt = cx.lifetime(sp, Ident::with_empty_ctxt(kw::StaticLifetime)); diff --git a/src/libsyntax_ext/format.rs b/src/libsyntax_ext/format.rs index c3dbd48cc6e4e..2f0d995098510 100644 --- a/src/libsyntax_ext/format.rs +++ b/src/libsyntax_ext/format.rs @@ -575,7 +575,7 @@ impl<'a, 'b> Context<'a, 'b> { for (i, e) in self.args.into_iter().enumerate() { let name = names_pos[i]; let span = - DUMMY_SP.with_ctxt(e.span.ctxt().apply_mark(self.ecx.current_expansion.mark)); + DUMMY_SP.with_ctxt(e.span.ctxt().apply_mark(self.ecx.current_expansion.id)); pats.push(self.ecx.pat_ident(span, name)); for ref arg_ty in self.arg_unique_types[i].iter() { locals.push(Context::format_arg(self.ecx, self.macsp, e.span, arg_ty, name)); @@ -652,7 +652,7 @@ impl<'a, 'b> Context<'a, 'b> { ty: &ArgumentType, arg: ast::Ident) -> P { - sp = sp.apply_mark(ecx.current_expansion.mark); + sp = sp.apply_mark(ecx.current_expansion.id); let arg = ecx.expr_ident(sp, arg); let trait_ = match *ty { Placeholder(ref tyname) => { @@ -691,7 +691,7 @@ fn expand_format_args_impl<'cx>( tts: &[tokenstream::TokenTree], nl: bool, ) -> Box { - sp = sp.apply_mark(ecx.current_expansion.mark); + sp = sp.apply_mark(ecx.current_expansion.id); match parse_args(ecx, sp, tts) { Ok((efmt, args, names)) => { MacEager::expr(expand_preparsed_format_args(ecx, sp, efmt, args, names, nl)) @@ -734,7 +734,7 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt<'_>, let arg_unique_types: Vec<_> = (0..args.len()).map(|_| Vec::new()).collect(); let mut macsp = ecx.call_site(); - macsp = macsp.apply_mark(ecx.current_expansion.mark); + macsp = macsp.apply_mark(ecx.current_expansion.id); let msg = "format argument must be a string literal"; let fmt_sp = efmt.span; diff --git a/src/libsyntax_ext/proc_macro_decls.rs b/src/libsyntax_ext/proc_macro_decls.rs index 2f78644dff2aa..08c40dde56c85 100644 --- a/src/libsyntax_ext/proc_macro_decls.rs +++ b/src/libsyntax_ext/proc_macro_decls.rs @@ -8,7 +8,7 @@ use syntax::source_map::{ExpnInfo, ExpnKind, respan}; use syntax::ext::base::{ExtCtxt, MacroKind}; use syntax::ext::build::AstBuilder; use syntax::ext::expand::ExpansionConfig; -use syntax::ext::hygiene::Mark; +use syntax::ext::hygiene::ExpnId; use syntax::mut_visit::MutVisitor; use syntax::parse::ParseSess; use syntax::ptr::P; @@ -346,7 +346,7 @@ fn mk_decls( custom_attrs: &[ProcMacroDef], custom_macros: &[ProcMacroDef], ) -> P { - let span = DUMMY_SP.fresh_expansion(Mark::root(), ExpnInfo::allow_unstable( + let span = DUMMY_SP.fresh_expansion(ExpnId::root(), ExpnInfo::allow_unstable( ExpnKind::Macro(MacroKind::Attr, sym::proc_macro), DUMMY_SP, cx.parse_sess.edition, [sym::rustc_attrs, sym::proc_macro_internals][..].into(), )); diff --git a/src/libsyntax_ext/proc_macro_server.rs b/src/libsyntax_ext/proc_macro_server.rs index e502735452735..e94d79a140da8 100644 --- a/src/libsyntax_ext/proc_macro_server.rs +++ b/src/libsyntax_ext/proc_macro_server.rs @@ -364,11 +364,11 @@ pub(crate) struct Rustc<'a> { impl<'a> Rustc<'a> { pub fn new(cx: &'a ExtCtxt<'_>) -> Self { // No way to determine def location for a proc macro right now, so use call location. - let location = cx.current_expansion.mark.expn_info().unwrap().call_site; + let location = cx.current_expansion.id.expn_info().unwrap().call_site; let to_span = |transparency| { location.with_ctxt( SyntaxContext::empty() - .apply_mark_with_transparency(cx.current_expansion.mark, transparency), + .apply_mark_with_transparency(cx.current_expansion.id, transparency), ) }; Rustc { diff --git a/src/libsyntax_ext/test.rs b/src/libsyntax_ext/test.rs index 4386fe8cfa2d6..f8755a1d1d791 100644 --- a/src/libsyntax_ext/test.rs +++ b/src/libsyntax_ext/test.rs @@ -59,7 +59,7 @@ pub fn expand_test_or_bench( return vec![Annotatable::Item(item)]; } - let ctxt = SyntaxContext::empty().apply_mark(cx.current_expansion.mark); + let ctxt = SyntaxContext::empty().apply_mark(cx.current_expansion.id); let (sp, attr_sp) = (item.span.with_ctxt(ctxt), attr_sp.with_ctxt(ctxt)); // Gensym "test" so we can extern crate without conflicting with any local names diff --git a/src/libsyntax_ext/test_case.rs b/src/libsyntax_ext/test_case.rs index af2cf42e04bb9..355f2428e0806 100644 --- a/src/libsyntax_ext/test_case.rs +++ b/src/libsyntax_ext/test_case.rs @@ -25,7 +25,7 @@ pub fn expand( ) -> Vec { if !ecx.ecfg.should_test { return vec![]; } - let sp = attr_sp.with_ctxt(SyntaxContext::empty().apply_mark(ecx.current_expansion.mark)); + let sp = attr_sp.with_ctxt(SyntaxContext::empty().apply_mark(ecx.current_expansion.id)); let mut item = anno_item.expect_item(); item = item.map(|mut item| { item.vis = respan(item.vis.span, ast::VisibilityKind::Public); diff --git a/src/libsyntax_pos/hygiene.rs b/src/libsyntax_pos/hygiene.rs index 5df1443923090..944b1da36d038 100644 --- a/src/libsyntax_pos/hygiene.rs +++ b/src/libsyntax_pos/hygiene.rs @@ -11,14 +11,14 @@ // ensuring that multiple HygieneData accesses are combined into a single // `HygieneData::with`. // -// This explains why `HygieneData`, `SyntaxContext` and `Mark` have interfaces +// This explains why `HygieneData`, `SyntaxContext` and `ExpnId` have interfaces // with a certain amount of redundancy in them. For example, // `SyntaxContext::outer_expn_info` combines `SyntaxContext::outer` and -// `Mark::expn_info` so that two `HygieneData` accesses can be performed within +// `ExpnId::expn_info` so that two `HygieneData` accesses can be performed within // a single `HygieneData::with` call. // // It also explains why many functions appear in `HygieneData` and again in -// `SyntaxContext` or `Mark`. For example, `HygieneData::outer` and +// `SyntaxContext` or `ExpnId`. For example, `HygieneData::outer` and // `SyntaxContext::outer` do the same thing, but the former is for use within a // `HygieneData::with` call while the latter is for use outside such a call. // When modifying this file it is important to understand this distinction, @@ -35,33 +35,34 @@ use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::sync::Lrc; use std::fmt; -/// A SyntaxContext represents a chain of macro expansions (represented by marks). +/// A `SyntaxContext` represents a chain of pairs `(ExpnId, Transparency)` named "marks". #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct SyntaxContext(u32); #[derive(Debug)] struct SyntaxContextData { - outer_mark: Mark, - transparency: Transparency, - prev_ctxt: SyntaxContext, - /// This context, but with all transparent and semi-transparent marks filtered away. + outer_expn: ExpnId, + outer_transparency: Transparency, + parent: SyntaxContext, + /// This context, but with all transparent and semi-transparent expansions filtered away. opaque: SyntaxContext, - /// This context, but with all transparent marks filtered away. + /// This context, but with all transparent expansions filtered away. opaque_and_semitransparent: SyntaxContext, /// Name of the crate to which `$crate` with this context would resolve. dollar_crate_name: Symbol, } -/// A mark is a unique ID associated with a macro expansion. +/// A unique ID associated with a macro invocation and expansion. #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] -pub struct Mark(u32); +pub struct ExpnId(u32); +// FIXME: Find a way to merge this with `ExpnInfo`. #[derive(Debug)] -struct MarkData { - parent: Mark, - /// Each mark should have an associated expansion info, but sometimes there's a delay between - /// creation of a mark and obtaining its info (e.g. macros are collected first and then - /// resolved later), so we use an `Option` here. +struct InternalExpnData { + parent: ExpnId, + /// Each expansion should have an associated expansion info, but sometimes there's a delay + /// between creation of an expansion ID and obtaining its info (e.g. macros are collected + /// first and then resolved later), so we use an `Option` here. expn_info: Option, } @@ -84,15 +85,15 @@ pub enum Transparency { Opaque, } -impl Mark { - pub fn fresh(parent: Mark, expn_info: Option) -> Self { - HygieneData::with(|data| data.fresh_mark(parent, expn_info)) +impl ExpnId { + pub fn fresh(parent: ExpnId, expn_info: Option) -> Self { + HygieneData::with(|data| data.fresh_expn(parent, expn_info)) } - /// The mark of the theoretical expansion that generates freshly parsed, unexpanded AST. + /// The ID of the theoretical expansion that generates freshly parsed, unexpanded AST. #[inline] pub fn root() -> Self { - Mark(0) + ExpnId(0) } #[inline] @@ -101,13 +102,13 @@ impl Mark { } #[inline] - pub fn from_u32(raw: u32) -> Mark { - Mark(raw) + pub fn from_u32(raw: u32) -> ExpnId { + ExpnId(raw) } #[inline] - pub fn parent(self) -> Mark { - HygieneData::with(|data| data.marks[self.0 as usize].parent) + pub fn parent(self) -> ExpnId { + HygieneData::with(|data| data.parent_expn(self)) } #[inline] @@ -118,20 +119,20 @@ impl Mark { #[inline] pub fn set_expn_info(self, info: ExpnInfo) { HygieneData::with(|data| { - let old_info = &mut data.marks[self.0 as usize].expn_info; - assert!(old_info.is_none(), "expansion info is reset for a mark"); + let old_info = &mut data.expn_data[self.0 as usize].expn_info; + assert!(old_info.is_none(), "expansion info is reset for an expansion ID"); *old_info = Some(info); }) } - pub fn is_descendant_of(self, ancestor: Mark) -> bool { + pub fn is_descendant_of(self, ancestor: ExpnId) -> bool { HygieneData::with(|data| data.is_descendant_of(self, ancestor)) } - /// `mark.outer_is_descendant_of(ctxt)` is equivalent to but faster than - /// `mark.is_descendant_of(ctxt.outer())`. - pub fn outer_is_descendant_of(self, ctxt: SyntaxContext) -> bool { - HygieneData::with(|data| data.is_descendant_of(self, data.outer(ctxt))) + /// `expn_id.outer_expn_is_descendant_of(ctxt)` is equivalent to but faster than + /// `expn_id.is_descendant_of(ctxt.outer_expn())`. + pub fn outer_expn_is_descendant_of(self, ctxt: SyntaxContext) -> bool { + HygieneData::with(|data| data.is_descendant_of(self, data.outer_expn(ctxt))) } // Used for enabling some compatibility fallback in resolve. @@ -152,27 +153,27 @@ impl Mark { #[derive(Debug)] crate struct HygieneData { - marks: Vec, - syntax_contexts: Vec, - markings: FxHashMap<(SyntaxContext, Mark, Transparency), SyntaxContext>, + expn_data: Vec, + syntax_context_data: Vec, + syntax_context_map: FxHashMap<(SyntaxContext, ExpnId, Transparency), SyntaxContext>, } impl HygieneData { crate fn new(edition: Edition) -> Self { HygieneData { - marks: vec![MarkData { - parent: Mark::root(), + expn_data: vec![InternalExpnData { + parent: ExpnId::root(), expn_info: Some(ExpnInfo::default(ExpnKind::Root, DUMMY_SP, edition)), }], - syntax_contexts: vec![SyntaxContextData { - outer_mark: Mark::root(), - transparency: Transparency::Opaque, - prev_ctxt: SyntaxContext(0), + syntax_context_data: vec![SyntaxContextData { + outer_expn: ExpnId::root(), + outer_transparency: Transparency::Opaque, + parent: SyntaxContext(0), opaque: SyntaxContext(0), opaque_and_semitransparent: SyntaxContext(0), dollar_crate_name: kw::DollarCrate, }], - markings: FxHashMap::default(), + syntax_context_map: FxHashMap::default(), } } @@ -180,15 +181,19 @@ impl HygieneData { GLOBALS.with(|globals| f(&mut *globals.hygiene_data.borrow_mut())) } - fn fresh_mark(&mut self, parent: Mark, expn_info: Option) -> Mark { - self.marks.push(MarkData { parent, expn_info }); - Mark(self.marks.len() as u32 - 1) + fn fresh_expn(&mut self, parent: ExpnId, expn_info: Option) -> ExpnId { + self.expn_data.push(InternalExpnData { parent, expn_info }); + ExpnId(self.expn_data.len() as u32 - 1) } - fn expn_info(&self, mark: Mark) -> Option<&ExpnInfo> { - if mark != Mark::root() { - Some(self.marks[mark.0 as usize].expn_info.as_ref() - .expect("no expansion info for a mark")) + fn parent_expn(&self, expn_id: ExpnId) -> ExpnId { + self.expn_data[expn_id.0 as usize].parent + } + + fn expn_info(&self, expn_id: ExpnId) -> Option<&ExpnInfo> { + if expn_id != ExpnId::root() { + Some(self.expn_data[expn_id.0 as usize].expn_info.as_ref() + .expect("no expansion info for an expansion ID")) } else { // FIXME: Some code relies on `expn_info().is_none()` meaning "no expansion". // Introduce a method for checking for "no expansion" instead and always return @@ -197,56 +202,53 @@ impl HygieneData { } } - fn is_descendant_of(&self, mut mark: Mark, ancestor: Mark) -> bool { - while mark != ancestor { - if mark == Mark::root() { + fn is_descendant_of(&self, mut expn_id: ExpnId, ancestor: ExpnId) -> bool { + while expn_id != ancestor { + if expn_id == ExpnId::root() { return false; } - mark = self.marks[mark.0 as usize].parent; + expn_id = self.parent_expn(expn_id); } true } - fn default_transparency(&self, mark: Mark) -> Transparency { - self.expn_info(mark).map_or( + fn default_transparency(&self, expn_id: ExpnId) -> Transparency { + self.expn_info(expn_id).map_or( Transparency::SemiTransparent, |einfo| einfo.default_transparency ) } fn modern(&self, ctxt: SyntaxContext) -> SyntaxContext { - self.syntax_contexts[ctxt.0 as usize].opaque + self.syntax_context_data[ctxt.0 as usize].opaque } fn modern_and_legacy(&self, ctxt: SyntaxContext) -> SyntaxContext { - self.syntax_contexts[ctxt.0 as usize].opaque_and_semitransparent + self.syntax_context_data[ctxt.0 as usize].opaque_and_semitransparent } - fn outer(&self, ctxt: SyntaxContext) -> Mark { - self.syntax_contexts[ctxt.0 as usize].outer_mark + fn outer_expn(&self, ctxt: SyntaxContext) -> ExpnId { + self.syntax_context_data[ctxt.0 as usize].outer_expn } - fn transparency(&self, ctxt: SyntaxContext) -> Transparency { - self.syntax_contexts[ctxt.0 as usize].transparency + fn outer_transparency(&self, ctxt: SyntaxContext) -> Transparency { + self.syntax_context_data[ctxt.0 as usize].outer_transparency } - fn prev_ctxt(&self, ctxt: SyntaxContext) -> SyntaxContext { - self.syntax_contexts[ctxt.0 as usize].prev_ctxt + fn parent_ctxt(&self, ctxt: SyntaxContext) -> SyntaxContext { + self.syntax_context_data[ctxt.0 as usize].parent } - fn remove_mark(&self, ctxt: &mut SyntaxContext) -> Mark { - let outer_mark = self.syntax_contexts[ctxt.0 as usize].outer_mark; - *ctxt = self.prev_ctxt(*ctxt); - outer_mark + fn remove_mark(&self, ctxt: &mut SyntaxContext) -> ExpnId { + let outer_expn = self.outer_expn(*ctxt); + *ctxt = self.parent_ctxt(*ctxt); + outer_expn } - fn marks(&self, mut ctxt: SyntaxContext) -> Vec<(Mark, Transparency)> { + fn marks(&self, mut ctxt: SyntaxContext) -> Vec<(ExpnId, Transparency)> { let mut marks = Vec::new(); while ctxt != SyntaxContext::empty() { - let outer_mark = self.outer(ctxt); - let transparency = self.transparency(ctxt); - let prev_ctxt = self.prev_ctxt(ctxt); - marks.push((outer_mark, transparency)); - ctxt = prev_ctxt; + marks.push((self.outer_expn(ctxt), self.outer_transparency(ctxt))); + ctxt = self.parent_ctxt(ctxt); } marks.reverse(); marks @@ -254,7 +256,7 @@ impl HygieneData { fn walk_chain(&self, mut span: Span, to: SyntaxContext) -> Span { while span.ctxt() != crate::NO_EXPANSION && span.ctxt() != to { - if let Some(info) = self.expn_info(self.outer(span.ctxt())) { + if let Some(info) = self.expn_info(self.outer_expn(span.ctxt())) { span = info.call_site; } else { break; @@ -263,28 +265,28 @@ impl HygieneData { span } - fn adjust(&self, ctxt: &mut SyntaxContext, expansion: Mark) -> Option { + fn adjust(&self, ctxt: &mut SyntaxContext, expn_id: ExpnId) -> Option { let mut scope = None; - while !self.is_descendant_of(expansion, self.outer(*ctxt)) { + while !self.is_descendant_of(expn_id, self.outer_expn(*ctxt)) { scope = Some(self.remove_mark(ctxt)); } scope } - fn apply_mark(&mut self, ctxt: SyntaxContext, mark: Mark) -> SyntaxContext { - assert_ne!(mark, Mark::root()); - self.apply_mark_with_transparency(ctxt, mark, self.default_transparency(mark)) + fn apply_mark(&mut self, ctxt: SyntaxContext, expn_id: ExpnId) -> SyntaxContext { + assert_ne!(expn_id, ExpnId::root()); + self.apply_mark_with_transparency(ctxt, expn_id, self.default_transparency(expn_id)) } - fn apply_mark_with_transparency(&mut self, ctxt: SyntaxContext, mark: Mark, + fn apply_mark_with_transparency(&mut self, ctxt: SyntaxContext, expn_id: ExpnId, transparency: Transparency) -> SyntaxContext { - assert_ne!(mark, Mark::root()); + assert_ne!(expn_id, ExpnId::root()); if transparency == Transparency::Opaque { - return self.apply_mark_internal(ctxt, mark, transparency); + return self.apply_mark_internal(ctxt, expn_id, transparency); } let call_site_ctxt = - self.expn_info(mark).map_or(SyntaxContext::empty(), |info| info.call_site.ctxt()); + self.expn_info(expn_id).map_or(SyntaxContext::empty(), |info| info.call_site.ctxt()); let mut call_site_ctxt = if transparency == Transparency::SemiTransparent { self.modern(call_site_ctxt) } else { @@ -292,10 +294,10 @@ impl HygieneData { }; if call_site_ctxt == SyntaxContext::empty() { - return self.apply_mark_internal(ctxt, mark, transparency); + return self.apply_mark_internal(ctxt, expn_id, transparency); } - // Otherwise, `mark` is a macros 1.0 definition and the call site is in a + // Otherwise, `expn_id` is a macros 1.0 definition and the call site is in a // macros 2.0 expansion, i.e., a macros 1.0 invocation is in a macros 2.0 definition. // // In this case, the tokens from the macros 1.0 definition inherit the hygiene @@ -304,27 +306,29 @@ impl HygieneData { // so that the macros 2.0 definition remains hygienic. // // See the example at `test/run-pass/hygiene/legacy_interaction.rs`. - for (mark, transparency) in self.marks(ctxt) { - call_site_ctxt = self.apply_mark_internal(call_site_ctxt, mark, transparency); + for (expn_id, transparency) in self.marks(ctxt) { + call_site_ctxt = self.apply_mark_internal(call_site_ctxt, expn_id, transparency); } - self.apply_mark_internal(call_site_ctxt, mark, transparency) + self.apply_mark_internal(call_site_ctxt, expn_id, transparency) } - fn apply_mark_internal(&mut self, ctxt: SyntaxContext, mark: Mark, transparency: Transparency) - -> SyntaxContext { - let syntax_contexts = &mut self.syntax_contexts; - let mut opaque = syntax_contexts[ctxt.0 as usize].opaque; + fn apply_mark_internal( + &mut self, ctxt: SyntaxContext, expn_id: ExpnId, transparency: Transparency + ) -> SyntaxContext { + let syntax_context_data = &mut self.syntax_context_data; + let mut opaque = syntax_context_data[ctxt.0 as usize].opaque; let mut opaque_and_semitransparent = - syntax_contexts[ctxt.0 as usize].opaque_and_semitransparent; + syntax_context_data[ctxt.0 as usize].opaque_and_semitransparent; if transparency >= Transparency::Opaque { - let prev_ctxt = opaque; - opaque = *self.markings.entry((prev_ctxt, mark, transparency)).or_insert_with(|| { - let new_opaque = SyntaxContext(syntax_contexts.len() as u32); - syntax_contexts.push(SyntaxContextData { - outer_mark: mark, - transparency, - prev_ctxt, + let parent = opaque; + opaque = *self.syntax_context_map.entry((parent, expn_id, transparency)) + .or_insert_with(|| { + let new_opaque = SyntaxContext(syntax_context_data.len() as u32); + syntax_context_data.push(SyntaxContextData { + outer_expn: expn_id, + outer_transparency: transparency, + parent, opaque: new_opaque, opaque_and_semitransparent: new_opaque, dollar_crate_name: kw::DollarCrate, @@ -334,15 +338,16 @@ impl HygieneData { } if transparency >= Transparency::SemiTransparent { - let prev_ctxt = opaque_and_semitransparent; + let parent = opaque_and_semitransparent; opaque_and_semitransparent = - *self.markings.entry((prev_ctxt, mark, transparency)).or_insert_with(|| { + *self.syntax_context_map.entry((parent, expn_id, transparency)) + .or_insert_with(|| { let new_opaque_and_semitransparent = - SyntaxContext(syntax_contexts.len() as u32); - syntax_contexts.push(SyntaxContextData { - outer_mark: mark, - transparency, - prev_ctxt, + SyntaxContext(syntax_context_data.len() as u32); + syntax_context_data.push(SyntaxContextData { + outer_expn: expn_id, + outer_transparency: transparency, + parent, opaque, opaque_and_semitransparent: new_opaque_and_semitransparent, dollar_crate_name: kw::DollarCrate, @@ -351,14 +356,14 @@ impl HygieneData { }); } - let prev_ctxt = ctxt; - *self.markings.entry((prev_ctxt, mark, transparency)).or_insert_with(|| { + let parent = ctxt; + *self.syntax_context_map.entry((parent, expn_id, transparency)).or_insert_with(|| { let new_opaque_and_semitransparent_and_transparent = - SyntaxContext(syntax_contexts.len() as u32); - syntax_contexts.push(SyntaxContextData { - outer_mark: mark, - transparency, - prev_ctxt, + SyntaxContext(syntax_context_data.len() as u32); + syntax_context_data.push(SyntaxContextData { + outer_expn: expn_id, + outer_transparency: transparency, + parent, opaque, opaque_and_semitransparent, dollar_crate_name: kw::DollarCrate, @@ -368,8 +373,8 @@ impl HygieneData { } } -pub fn clear_markings() { - HygieneData::with(|data| data.markings = FxHashMap::default()); +pub fn clear_syntax_context_map() { + HygieneData::with(|data| data.syntax_context_map = FxHashMap::default()); } pub fn walk_chain(span: Span, to: SyntaxContext) -> Span { @@ -379,8 +384,8 @@ pub fn walk_chain(span: Span, to: SyntaxContext) -> Span { pub fn update_dollar_crate_names(mut get_name: impl FnMut(SyntaxContext) -> Symbol) { // The new contexts that need updating are at the end of the list and have `$crate` as a name. let (len, to_update) = HygieneData::with(|data| ( - data.syntax_contexts.len(), - data.syntax_contexts.iter().rev() + data.syntax_context_data.len(), + data.syntax_context_data.iter().rev() .take_while(|scdata| scdata.dollar_crate_name == kw::DollarCrate).count() )); // The callback must be called from outside of the `HygieneData` lock, @@ -389,7 +394,7 @@ pub fn update_dollar_crate_names(mut get_name: impl FnMut(SyntaxContext) -> Symb let names: Vec<_> = range_to_update.clone().map(|idx| get_name(SyntaxContext::from_u32(idx as u32))).collect(); HygieneData::with(|data| range_to_update.zip(names.into_iter()).for_each(|(idx, name)| { - data.syntax_contexts[idx].dollar_crate_name = name; + data.syntax_context_data[idx].dollar_crate_name = name; })) } @@ -409,15 +414,15 @@ impl SyntaxContext { SyntaxContext(raw) } - /// Extend a syntax context with a given mark and default transparency for that mark. - pub fn apply_mark(self, mark: Mark) -> SyntaxContext { - HygieneData::with(|data| data.apply_mark(self, mark)) + /// Extend a syntax context with a given expansion and default transparency for that expansion. + pub fn apply_mark(self, expn_id: ExpnId) -> SyntaxContext { + HygieneData::with(|data| data.apply_mark(self, expn_id)) } - /// Extend a syntax context with a given mark and transparency - pub fn apply_mark_with_transparency(self, mark: Mark, transparency: Transparency) + /// Extend a syntax context with a given expansion and transparency. + pub fn apply_mark_with_transparency(self, expn_id: ExpnId, transparency: Transparency) -> SyntaxContext { - HygieneData::with(|data| data.apply_mark_with_transparency(self, mark, transparency)) + HygieneData::with(|data| data.apply_mark_with_transparency(self, expn_id, transparency)) } /// Pulls a single mark off of the syntax context. This effectively moves the @@ -436,11 +441,11 @@ impl SyntaxContext { /// of g (call it g1), calling remove_mark will result in the SyntaxContext for the /// invocation of f that created g1. /// Returns the mark that was removed. - pub fn remove_mark(&mut self) -> Mark { + pub fn remove_mark(&mut self) -> ExpnId { HygieneData::with(|data| data.remove_mark(self)) } - pub fn marks(self) -> Vec<(Mark, Transparency)> { + pub fn marks(self) -> Vec<(ExpnId, Transparency)> { HygieneData::with(|data| data.marks(self)) } @@ -452,13 +457,13 @@ impl SyntaxContext { /// m!(f); /// macro m($f:ident) { /// mod bar { - /// pub fn f() {} // `f`'s `SyntaxContext` has a single `Mark` from `m`. + /// pub fn f() {} // `f`'s `SyntaxContext` has a single `ExpnId` from `m`. /// pub fn $f() {} // `$f`'s `SyntaxContext` is empty. /// } - /// foo::f(); // `f`'s `SyntaxContext` has a single `Mark` from `m` + /// foo::f(); // `f`'s `SyntaxContext` has a single `ExpnId` from `m` /// //^ Since `mod foo` is outside this expansion, `adjust` removes the mark from `f`, /// //| and it resolves to `::foo::f`. - /// bar::f(); // `f`'s `SyntaxContext` has a single `Mark` from `m` + /// bar::f(); // `f`'s `SyntaxContext` has a single `ExpnId` from `m` /// //^ Since `mod bar` not outside this expansion, `adjust` does not change `f`, /// //| and it resolves to `::bar::f`. /// bar::$f(); // `f`'s `SyntaxContext` is empty. @@ -468,15 +473,15 @@ impl SyntaxContext { /// ``` /// This returns the expansion whose definition scope we use to privacy check the resolution, /// or `None` if we privacy check as usual (i.e., not w.r.t. a macro definition scope). - pub fn adjust(&mut self, expansion: Mark) -> Option { - HygieneData::with(|data| data.adjust(self, expansion)) + pub fn adjust(&mut self, expn_id: ExpnId) -> Option { + HygieneData::with(|data| data.adjust(self, expn_id)) } /// Like `SyntaxContext::adjust`, but also modernizes `self`. - pub fn modernize_and_adjust(&mut self, expansion: Mark) -> Option { + pub fn modernize_and_adjust(&mut self, expn_id: ExpnId) -> Option { HygieneData::with(|data| { *self = data.modern(*self); - data.adjust(self, expansion) + data.adjust(self, expn_id) }) } @@ -488,7 +493,7 @@ impl SyntaxContext { /// m!(f); /// macro m($i:ident) { /// mod foo { - /// pub fn f() {} // `f`'s `SyntaxContext` has a single `Mark` from `m`. + /// pub fn f() {} // `f`'s `SyntaxContext` has a single `ExpnId` from `m`. /// pub fn $i() {} // `$i`'s `SyntaxContext` is empty. /// } /// n(f); @@ -505,17 +510,17 @@ impl SyntaxContext { /// ``` /// This returns `None` if the context cannot be glob-adjusted. /// Otherwise, it returns the scope to use when privacy checking (see `adjust` for details). - pub fn glob_adjust(&mut self, expansion: Mark, glob_span: Span) -> Option> { + pub fn glob_adjust(&mut self, expn_id: ExpnId, glob_span: Span) -> Option> { HygieneData::with(|data| { let mut scope = None; let mut glob_ctxt = data.modern(glob_span.ctxt()); - while !data.is_descendant_of(expansion, data.outer(glob_ctxt)) { + while !data.is_descendant_of(expn_id, data.outer_expn(glob_ctxt)) { scope = Some(data.remove_mark(&mut glob_ctxt)); if data.remove_mark(self) != scope.unwrap() { return None; } } - if data.adjust(self, expansion).is_some() { + if data.adjust(self, expn_id).is_some() { return None; } Some(scope) @@ -529,16 +534,16 @@ impl SyntaxContext { /// assert!(self.glob_adjust(expansion, glob_ctxt) == Some(privacy_checking_scope)); /// } /// ``` - pub fn reverse_glob_adjust(&mut self, expansion: Mark, glob_span: Span) - -> Option> { + pub fn reverse_glob_adjust(&mut self, expn_id: ExpnId, glob_span: Span) + -> Option> { HygieneData::with(|data| { - if data.adjust(self, expansion).is_some() { + if data.adjust(self, expn_id).is_some() { return None; } let mut glob_ctxt = data.modern(glob_span.ctxt()); let mut marks = Vec::new(); - while !data.is_descendant_of(expansion, data.outer(glob_ctxt)) { + while !data.is_descendant_of(expn_id, data.outer_expn(glob_ctxt)) { marks.push(data.remove_mark(&mut glob_ctxt)); } @@ -550,10 +555,10 @@ impl SyntaxContext { }) } - pub fn hygienic_eq(self, other: SyntaxContext, mark: Mark) -> bool { + pub fn hygienic_eq(self, other: SyntaxContext, expn_id: ExpnId) -> bool { HygieneData::with(|data| { let mut self_modern = data.modern(self); - data.adjust(&mut self_modern, mark); + data.adjust(&mut self_modern, expn_id); self_modern == data.modern(other) }) } @@ -569,29 +574,29 @@ impl SyntaxContext { } #[inline] - pub fn outer(self) -> Mark { - HygieneData::with(|data| data.outer(self)) + pub fn outer_expn(self) -> ExpnId { + HygieneData::with(|data| data.outer_expn(self)) } /// `ctxt.outer_expn_info()` is equivalent to but faster than - /// `ctxt.outer().expn_info()`. + /// `ctxt.outer_expn().expn_info()`. #[inline] pub fn outer_expn_info(self) -> Option { - HygieneData::with(|data| data.expn_info(data.outer(self)).cloned()) + HygieneData::with(|data| data.expn_info(data.outer_expn(self)).cloned()) } - /// `ctxt.outer_and_expn_info()` is equivalent to but faster than - /// `{ let outer = ctxt.outer(); (outer, outer.expn_info()) }`. + /// `ctxt.outer_expn_with_info()` is equivalent to but faster than + /// `{ let outer = ctxt.outer_expn(); (outer, outer.expn_info()) }`. #[inline] - pub fn outer_and_expn_info(self) -> (Mark, Option) { + pub fn outer_expn_with_info(self) -> (ExpnId, Option) { HygieneData::with(|data| { - let outer = data.outer(self); + let outer = data.outer_expn(self); (outer, data.expn_info(outer).cloned()) }) } pub fn dollar_crate_name(self) -> Symbol { - HygieneData::with(|data| data.syntax_contexts[self.0 as usize].dollar_crate_name) + HygieneData::with(|data| data.syntax_context_data[self.0 as usize].dollar_crate_name) } } @@ -607,10 +612,10 @@ impl Span { /// other compiler-generated code to set per-span properties like allowed unstable features. /// The returned span belongs to the created expansion and has the new properties, /// but its location is inherited from the current span. - pub fn fresh_expansion(self, parent: Mark, expn_info: ExpnInfo) -> Span { + pub fn fresh_expansion(self, parent: ExpnId, expn_info: ExpnInfo) -> Span { HygieneData::with(|data| { - let mark = data.fresh_mark(parent, Some(expn_info)); - self.with_ctxt(data.apply_mark(SyntaxContext::empty(), mark)) + let expn_id = data.fresh_expn(parent, Some(expn_info)); + self.with_ctxt(data.apply_mark(SyntaxContext::empty(), expn_id)) }) } } @@ -638,7 +643,7 @@ pub struct ExpnInfo { /// The span of the macro definition (possibly dummy). /// This span serves only informational purpose and is not used for resolution. pub def_site: Span, - /// Transparency used by `apply_mark` for mark with this expansion info by default. + /// Transparency used by `apply_mark` for the expansion with this expansion info by default. pub default_transparency: Transparency, /// List of #[unstable]/feature-gated features that the macro is allowed to use /// internally without forcing the whole crate to opt-in @@ -681,7 +686,7 @@ impl ExpnInfo { /// Expansion kind. #[derive(Clone, Debug, RustcEncodable, RustcDecodable)] pub enum ExpnKind { - /// No expansion, aka root expansion. Only `Mark::root()` has this kind. + /// No expansion, aka root expansion. Only `ExpnId::root()` has this kind. Root, /// Expansion produced by a macro. /// FIXME: Some code injected by the compiler before HIR lowering also gets this kind. diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index 5ccfe5f0b8b1a..b9a062c0765f0 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -27,7 +27,7 @@ extern crate serialize as rustc_serialize; // used by deriving pub mod edition; use edition::Edition; pub mod hygiene; -pub use hygiene::{Mark, SyntaxContext, ExpnInfo, ExpnKind, MacroKind, DesugaringKind}; +pub use hygiene::{ExpnId, SyntaxContext, ExpnInfo, ExpnKind, MacroKind, DesugaringKind}; mod span_encoding; pub use span_encoding::{Span, DUMMY_SP}; @@ -516,13 +516,13 @@ impl Span { } #[inline] - pub fn apply_mark(self, mark: Mark) -> Span { + pub fn apply_mark(self, mark: ExpnId) -> Span { let span = self.data(); span.with_ctxt(span.ctxt.apply_mark(mark)) } #[inline] - pub fn remove_mark(&mut self) -> Mark { + pub fn remove_mark(&mut self) -> ExpnId { let mut span = self.data(); let mark = span.ctxt.remove_mark(); *self = Span::new(span.lo, span.hi, span.ctxt); @@ -530,34 +530,34 @@ impl Span { } #[inline] - pub fn adjust(&mut self, expansion: Mark) -> Option { + pub fn adjust(&mut self, expn_id: ExpnId) -> Option { let mut span = self.data(); - let mark = span.ctxt.adjust(expansion); + let mark = span.ctxt.adjust(expn_id); *self = Span::new(span.lo, span.hi, span.ctxt); mark } #[inline] - pub fn modernize_and_adjust(&mut self, expansion: Mark) -> Option { + pub fn modernize_and_adjust(&mut self, expn_id: ExpnId) -> Option { let mut span = self.data(); - let mark = span.ctxt.modernize_and_adjust(expansion); + let mark = span.ctxt.modernize_and_adjust(expn_id); *self = Span::new(span.lo, span.hi, span.ctxt); mark } #[inline] - pub fn glob_adjust(&mut self, expansion: Mark, glob_span: Span) -> Option> { + pub fn glob_adjust(&mut self, expn_id: ExpnId, glob_span: Span) -> Option> { let mut span = self.data(); - let mark = span.ctxt.glob_adjust(expansion, glob_span); + let mark = span.ctxt.glob_adjust(expn_id, glob_span); *self = Span::new(span.lo, span.hi, span.ctxt); mark } #[inline] - pub fn reverse_glob_adjust(&mut self, expansion: Mark, glob_span: Span) - -> Option> { + pub fn reverse_glob_adjust(&mut self, expn_id: ExpnId, glob_span: Span) + -> Option> { let mut span = self.data(); - let mark = span.ctxt.reverse_glob_adjust(expansion, glob_span); + let mark = span.ctxt.reverse_glob_adjust(expn_id, glob_span); *self = Span::new(span.lo, span.hi, span.ctxt); mark }