libsyntax: Remove Mark into ExpnId

This commit is contained in:
Vadim Petrochenkov 2019-07-16 01:04:05 +03:00
parent f9477a77c5
commit 31e10aec83
23 changed files with 183 additions and 182 deletions

View File

@ -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<Lrc<[Symbol]>>,
) -> 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 {

View File

@ -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 }
}

View File

@ -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<DefIndex>,
def_index_to_node: Vec<ast::NodeId>,
pub(super) node_to_hir_id: IndexVec<ast::NodeId, hir::HirId>,
/// 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<Mark, DefId>,
/// Item with a given `DefIndex` was defined during macro expansion with ID `Mark`.
expansions_that_defined: FxHashMap<DefIndex, Mark>,
parent_modules_of_macro_defs: FxHashMap<ExpnId, DefId>,
/// Item with a given `DefIndex` was defined during macro expansion with ID `ExpnId`.
expansions_that_defined: FxHashMap<DefIndex, ExpnId>,
next_disambiguator: FxHashMap<(DefIndex, DefPathData), u32>,
def_index_to_span: FxHashMap<DefIndex, Span>,
/// 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<Mark, DefIndex>,
invocation_parents: FxHashMap<ExpnId, DefIndex>,
}
/// 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,
expansion: ExpnId,
span: Span)
-> DefIndex {
debug!("create_def_with_parent(parent={:?}, node_id={:?}, data={:?})",
@ -498,7 +498,7 @@ impl Definitions {
self.node_to_def_index.insert(node_id, index);
}
if expansion != Mark::root() {
if expansion != ExpnId::root() {
self.expansions_that_defined.insert(index, expansion);
}
@ -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 {
pub fn parent_module_of_macro_def(&self, mark: ExpnId) -> DefId {
self.parent_modules_of_macro_defs[&mark]
}
pub fn add_parent_module_of_macro_def(&mut self, mark: Mark, module: DefId) {
pub fn add_parent_module_of_macro_def(&mut self, mark: ExpnId, module: DefId) {
self.parent_modules_of_macro_defs.insert(mark, 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
);

View File

@ -359,7 +359,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for Span {
// times, we cache a stable hash of it and hash that instead of
// recursing every time.
thread_local! {
static CACHE: RefCell<FxHashMap<hygiene::Mark, u64>> = Default::default();
static CACHE: RefCell<FxHashMap<hygiene::ExpnId, u64>> = Default::default();
}
let sub_hash: u64 = CACHE.with(|cache| {

View File

@ -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(),
}
}

View File

@ -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;
@ -594,7 +594,7 @@ impl<'a, 'tcx> SpecializedDecoder<Span> for CacheDecoder<'a, 'tcx> {
// 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<Ty<'tcx>, usize>,
predicate_shorthands: FxHashMap<ty::Predicate<'tcx>, usize>,
expn_info_shorthands: FxHashMap<Mark, AbsoluteBytePos>,
expn_info_shorthands: FxHashMap<ExpnId, AbsoluteBytePos>,
interpret_allocs: FxHashMap<interpret::AllocId, usize>,
interpret_allocs_inverse: Vec<interpret::AllocId>,
source_map: CachingSourceMapView<'tcx>,

View File

@ -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(),
));

View File

@ -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),
}

View File

@ -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));

View File

@ -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<NodeId>;
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,7 +571,7 @@ impl<'a> Resolver<'a> {
variant: &Variant,
parent: Module<'a>,
vis: ty::Visibility,
expansion: Mark) {
expansion: ExpnId) {
let ident = variant.node.ident;
// Define a name in the type namespace.
@ -600,7 +600,7 @@ impl<'a> Resolver<'a> {
}
/// 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, expansion: ExpnId) {
let (res, ns) = match item.node {
ForeignItemKind::Fn(..) => {
(Res::Def(DefKind::Fn, self.definitions.local_def_id(item.id)), ValueNS)
@ -618,7 +618,7 @@ impl<'a> Resolver<'a> {
self.define(parent, item.ident, ns, (res, vis, item.span, expansion));
}
fn build_reduced_graph_for_block(&mut self, block: &Block, expansion: Mark) {
fn build_reduced_graph_for_block(&mut self, block: &Block, expansion: ExpnId) {
let parent = self.current_module;
if self.block_needs_anonymous_module(block) {
let module = self.new_module(parent,
@ -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,13 +734,14 @@ 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> {
pub fn macro_def_scope(&mut self, expansion: ExpnId) -> Module<'a> {
let def_id = match self.macro_defs.get(&expansion) {
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,7 +919,7 @@ 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> {

View File

@ -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<ast::Path>,
}
@ -1178,7 +1178,7 @@ pub struct ModuleData<'a> {
builtin_attrs: RefCell<Vec<(Ident, ParentScope<'a>)>>,
// Macro invocations that can expand into items in this module.
unresolved_invocations: RefCell<FxHashSet<Mark>>,
unresolved_invocations: RefCell<FxHashSet<ExpnId>>,
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<Module<'a>>,
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<SyntaxExtension>,
dummy_ext_derive: Lrc<SyntaxExtension>,
non_macro_attrs: [Lrc<SyntaxExtension>; 2],
macro_defs: FxHashMap<Mark, DefId>,
macro_defs: FxHashMap<ExpnId, DefId>,
local_macro_def_scopes: FxHashMap<NodeId, Module<'a>>,
unused_macros: NodeMap<Span>,
proc_macro_stubs: NodeSet,
/// Maps the `Mark` of an expansion to its containing module or block.
invocations: FxHashMap<Mark, &'a InvocationData<'a>>,
/// Maps the `ExpnId` of an expansion to its containing module or block.
invocations: FxHashMap<ExpnId, &'a InvocationData<'a>>,
/// Avoid duplicated errors for "name already defined".
name_already_seen: FxHashMap<Name, Span>,
@ -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,
}),
@ -2095,7 +2095,7 @@ impl<'a> Resolver<'a> {
parent: Module<'a>,
kind: ModuleKind,
normal_ancestor_id: DefId,
expansion: Mark,
expansion: ExpnId,
span: Span,
) -> Module<'a> {
let module = ModuleData::new(Some(parent), kind, normal_ancestor_id, expansion, span);
@ -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 {
@ -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))
}
})

View File

@ -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,8 +135,8 @@ 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();
@ -160,8 +160,8 @@ impl<'a> base::Resolver for Resolver<'a> {
});
}
fn visit_ast_fragment_with_placeholders(&mut self, mark: Mark, fragment: &AstFragment,
derives: &[Mark]) {
fn visit_ast_fragment_with_placeholders(&mut self, mark: ExpnId, fragment: &AstFragment,
derives: &[ExpnId]) {
fragment.visit_with(&mut DefCollector::new(&mut self.definitions, mark));
let invocation = self.invocations[&mark];
@ -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<Option<Lrc<SyntaxExtension>>, Indeterminate> {
let (path, kind, derives_in_scope, after_derive) = match invoc.kind {
InvocationKind::Attr { ref attr, ref derives, after_derive, .. } =>
@ -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<ast::Path>) -> ParentScope<'a> {
fn invoc_parent_scope(&self, invoc_id: ExpnId, derives: Vec<ast::Path>) -> 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) => {

View File

@ -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;
}

View File

@ -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 {
pub fn placeholder_from_mark(mark: ExpnId) -> Self {
NodeId::from_u32(mark.as_u32())
}
pub fn placeholder_to_mark(self) -> Mark {
Mark::from_u32(self.as_u32())
pub fn placeholder_to_mark(self) -> ExpnId {
ExpnId::from_u32(self.as_u32())
}
}

View File

@ -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, mark: ExpnId, fragment: &AstFragment,
derives: &[ExpnId]);
fn add_builtin(&mut self, ident: ast::Ident, ext: Lrc<SyntaxExtension>);
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<Option<Lrc<SyntaxExtension>>, Indeterminate>;
fn check_unused_macros(&self);
@ -705,7 +705,7 @@ pub struct ModuleData {
#[derive(Clone)]
pub struct ExpansionData {
pub mark: Mark,
pub mark: ExpnId,
pub depth: usize,
pub module: Rc<ModuleData>,
pub directory_ownership: DirectoryOwnership,
@ -735,7 +735,7 @@ impl<'a> ExtCtxt<'a> {
root_path: PathBuf::new(),
resolver,
current_expansion: ExpansionData {
mark: Mark::root(),
mark: ExpnId::root(),
depth: 0,
module: Rc::new(ModuleData { mod_path: Vec::new(), directory: PathBuf::new() }),
directory_ownership: DirectoryOwnership::Owned { relative: None },

View File

@ -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<Mark, Vec<_>> = FxHashMap::default();
let mut derives: FxHashMap<ExpnId, Vec<_>> = FxHashMap::default();
let mut undetermined_invocations = Vec::new();
let (mut progress, mut force) = (false, !self.monotonic);
loop {
@ -367,7 +367,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
derives.reserve(traits.len());
invocations.reserve(traits.len());
for path in traits {
let mark = Mark::fresh(self.cx.current_expansion.mark, None);
let mark = ExpnId::fresh(self.cx.current_expansion.mark, None);
derives.push(mark);
invocations.push(Invocation {
kind: InvocationKind::Derive {
@ -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<Invocation>) {
// Resolve `$crate`s in the fragment for pretty-printing.
self.cx.resolver.resolve_dollar_crates();
@ -822,7 +822,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
)),
_ => None,
};
let mark = Mark::fresh(self.cx.current_expansion.mark, expn_info);
let mark = ExpnId::fresh(self.cx.current_expansion.mark, expn_info);
self.invocations.push(Invocation {
kind,
fragment_kind,
@ -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) {

View File

@ -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,7 +84,7 @@ impl<'a, 'b> PlaceholderExpander<'a, 'b> {
}
}
pub fn add(&mut self, id: ast::NodeId, mut fragment: AstFragment, derives: Vec<Mark>) {
pub fn add(&mut self, id: ast::NodeId, mut fragment: AstFragment, derives: Vec<ExpnId>) {
fragment.mut_visit_with(self);
if let AstFragment::Items(mut items) = fragment {
for derive in derives {

View File

@ -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(),
));

View File

@ -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;
@ -303,7 +303,7 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
// #![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(),
));

View File

@ -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,7 +545,7 @@ impl DelimSpan {
self.open.with_hi(self.close.hi())
}
pub fn apply_mark(self, mark: Mark) -> Self {
pub fn apply_mark(self, mark: ExpnId) -> Self {
DelimSpan {
open: self.open.apply_mark(mark),
close: self.close.apply_mark(mark),

View File

@ -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<ast::Item> {
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(),
));

View File

@ -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,
@ -41,7 +41,7 @@ pub struct SyntaxContext(u32);
#[derive(Debug)]
struct SyntaxContextData {
outer_mark: Mark,
outer_mark: ExpnId,
transparency: Transparency,
prev_ctxt: SyntaxContext,
/// This context, but with all transparent and semi-transparent marks filtered away.
@ -54,11 +54,11 @@ struct SyntaxContextData {
/// A mark is a unique ID associated with a macro expansion.
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
pub struct Mark(u32);
pub struct ExpnId(u32);
#[derive(Debug)]
struct MarkData {
parent: Mark,
parent: ExpnId,
/// 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.
@ -84,15 +84,15 @@ pub enum Transparency {
Opaque,
}
impl Mark {
pub fn fresh(parent: Mark, expn_info: Option<ExpnInfo>) -> Self {
impl ExpnId {
pub fn fresh(parent: ExpnId, expn_info: Option<ExpnInfo>) -> Self {
HygieneData::with(|data| data.fresh_mark(parent, expn_info))
}
/// The mark of the theoretical expansion that generates freshly parsed, unexpanded AST.
#[inline]
pub fn root() -> Self {
Mark(0)
ExpnId(0)
}
#[inline]
@ -101,12 +101,12 @@ 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 {
pub fn parent(self) -> ExpnId {
HygieneData::with(|data| data.marks[self.0 as usize].parent)
}
@ -124,7 +124,7 @@ impl Mark {
})
}
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))
}
@ -154,18 +154,18 @@ impl Mark {
crate struct HygieneData {
marks: Vec<MarkData>,
syntax_contexts: Vec<SyntaxContextData>,
markings: FxHashMap<(SyntaxContext, Mark, Transparency), SyntaxContext>,
markings: FxHashMap<(SyntaxContext, ExpnId, Transparency), SyntaxContext>,
}
impl HygieneData {
crate fn new(edition: Edition) -> Self {
HygieneData {
marks: vec![MarkData {
parent: Mark::root(),
parent: ExpnId::root(),
expn_info: Some(ExpnInfo::default(ExpnKind::Root, DUMMY_SP, edition)),
}],
syntax_contexts: vec![SyntaxContextData {
outer_mark: Mark::root(),
outer_mark: ExpnId::root(),
transparency: Transparency::Opaque,
prev_ctxt: SyntaxContext(0),
opaque: SyntaxContext(0),
@ -180,13 +180,13 @@ impl HygieneData {
GLOBALS.with(|globals| f(&mut *globals.hygiene_data.borrow_mut()))
}
fn fresh_mark(&mut self, parent: Mark, expn_info: Option<ExpnInfo>) -> Mark {
fn fresh_mark(&mut self, parent: ExpnId, expn_info: Option<ExpnInfo>) -> ExpnId {
self.marks.push(MarkData { parent, expn_info });
Mark(self.marks.len() as u32 - 1)
ExpnId(self.marks.len() as u32 - 1)
}
fn expn_info(&self, mark: Mark) -> Option<&ExpnInfo> {
if mark != Mark::root() {
fn expn_info(&self, mark: ExpnId) -> Option<&ExpnInfo> {
if mark != ExpnId::root() {
Some(self.marks[mark.0 as usize].expn_info.as_ref()
.expect("no expansion info for a mark"))
} else {
@ -197,9 +197,9 @@ impl HygieneData {
}
}
fn is_descendant_of(&self, mut mark: Mark, ancestor: Mark) -> bool {
fn is_descendant_of(&self, mut mark: ExpnId, ancestor: ExpnId) -> bool {
while mark != ancestor {
if mark == Mark::root() {
if mark == ExpnId::root() {
return false;
}
mark = self.marks[mark.0 as usize].parent;
@ -207,7 +207,7 @@ impl HygieneData {
true
}
fn default_transparency(&self, mark: Mark) -> Transparency {
fn default_transparency(&self, mark: ExpnId) -> Transparency {
self.expn_info(mark).map_or(
Transparency::SemiTransparent, |einfo| einfo.default_transparency
)
@ -221,7 +221,7 @@ impl HygieneData {
self.syntax_contexts[ctxt.0 as usize].opaque_and_semitransparent
}
fn outer(&self, ctxt: SyntaxContext) -> Mark {
fn outer(&self, ctxt: SyntaxContext) -> ExpnId {
self.syntax_contexts[ctxt.0 as usize].outer_mark
}
@ -233,13 +233,13 @@ impl HygieneData {
self.syntax_contexts[ctxt.0 as usize].prev_ctxt
}
fn remove_mark(&self, ctxt: &mut SyntaxContext) -> Mark {
fn remove_mark(&self, ctxt: &mut SyntaxContext) -> ExpnId {
let outer_mark = self.syntax_contexts[ctxt.0 as usize].outer_mark;
*ctxt = self.prev_ctxt(*ctxt);
outer_mark
}
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);
@ -263,7 +263,7 @@ impl HygieneData {
span
}
fn adjust(&self, ctxt: &mut SyntaxContext, expansion: Mark) -> Option<Mark> {
fn adjust(&self, ctxt: &mut SyntaxContext, expansion: ExpnId) -> Option<ExpnId> {
let mut scope = None;
while !self.is_descendant_of(expansion, self.outer(*ctxt)) {
scope = Some(self.remove_mark(ctxt));
@ -271,14 +271,14 @@ impl HygieneData {
scope
}
fn apply_mark(&mut self, ctxt: SyntaxContext, mark: Mark) -> SyntaxContext {
assert_ne!(mark, Mark::root());
fn apply_mark(&mut self, ctxt: SyntaxContext, mark: ExpnId) -> SyntaxContext {
assert_ne!(mark, ExpnId::root());
self.apply_mark_with_transparency(ctxt, mark, self.default_transparency(mark))
}
fn apply_mark_with_transparency(&mut self, ctxt: SyntaxContext, mark: Mark,
fn apply_mark_with_transparency(&mut self, ctxt: SyntaxContext, mark: ExpnId,
transparency: Transparency) -> SyntaxContext {
assert_ne!(mark, Mark::root());
assert_ne!(mark, ExpnId::root());
if transparency == Transparency::Opaque {
return self.apply_mark_internal(ctxt, mark, transparency);
}
@ -310,7 +310,7 @@ impl HygieneData {
self.apply_mark_internal(call_site_ctxt, mark, transparency)
}
fn apply_mark_internal(&mut self, ctxt: SyntaxContext, mark: Mark, transparency: Transparency)
fn apply_mark_internal(&mut self, ctxt: SyntaxContext, mark: ExpnId, transparency: Transparency)
-> SyntaxContext {
let syntax_contexts = &mut self.syntax_contexts;
let mut opaque = syntax_contexts[ctxt.0 as usize].opaque;
@ -410,12 +410,12 @@ impl SyntaxContext {
}
/// Extend a syntax context with a given mark and default transparency for that mark.
pub fn apply_mark(self, mark: Mark) -> SyntaxContext {
pub fn apply_mark(self, mark: ExpnId) -> SyntaxContext {
HygieneData::with(|data| data.apply_mark(self, mark))
}
/// Extend a syntax context with a given mark and transparency
pub fn apply_mark_with_transparency(self, mark: Mark, transparency: Transparency)
pub fn apply_mark_with_transparency(self, mark: ExpnId, transparency: Transparency)
-> SyntaxContext {
HygieneData::with(|data| data.apply_mark_with_transparency(self, mark, transparency))
}
@ -436,11 +436,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 +452,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,12 +468,12 @@ 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<Mark> {
pub fn adjust(&mut self, expansion: ExpnId) -> Option<ExpnId> {
HygieneData::with(|data| data.adjust(self, expansion))
}
/// Like `SyntaxContext::adjust`, but also modernizes `self`.
pub fn modernize_and_adjust(&mut self, expansion: Mark) -> Option<Mark> {
pub fn modernize_and_adjust(&mut self, expansion: ExpnId) -> Option<ExpnId> {
HygieneData::with(|data| {
*self = data.modern(*self);
data.adjust(self, expansion)
@ -488,7 +488,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,7 +505,7 @@ 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<Option<Mark>> {
pub fn glob_adjust(&mut self, expansion: ExpnId, glob_span: Span) -> Option<Option<ExpnId>> {
HygieneData::with(|data| {
let mut scope = None;
let mut glob_ctxt = data.modern(glob_span.ctxt());
@ -529,8 +529,8 @@ 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<Option<Mark>> {
pub fn reverse_glob_adjust(&mut self, expansion: ExpnId, glob_span: Span)
-> Option<Option<ExpnId>> {
HygieneData::with(|data| {
if data.adjust(self, expansion).is_some() {
return None;
@ -550,7 +550,7 @@ impl SyntaxContext {
})
}
pub fn hygienic_eq(self, other: SyntaxContext, mark: Mark) -> bool {
pub fn hygienic_eq(self, other: SyntaxContext, mark: ExpnId) -> bool {
HygieneData::with(|data| {
let mut self_modern = data.modern(self);
data.adjust(&mut self_modern, mark);
@ -569,7 +569,7 @@ impl SyntaxContext {
}
#[inline]
pub fn outer(self) -> Mark {
pub fn outer(self) -> ExpnId {
HygieneData::with(|data| data.outer(self))
}
@ -583,7 +583,7 @@ impl SyntaxContext {
/// `ctxt.outer_and_expn_info()` is equivalent to but faster than
/// `{ let outer = ctxt.outer(); (outer, outer.expn_info()) }`.
#[inline]
pub fn outer_and_expn_info(self) -> (Mark, Option<ExpnInfo>) {
pub fn outer_and_expn_info(self) -> (ExpnId, Option<ExpnInfo>) {
HygieneData::with(|data| {
let outer = data.outer(self);
(outer, data.expn_info(outer).cloned())
@ -607,7 +607,7 @@ 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))
@ -681,7 +681,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.

View File

@ -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,7 +530,7 @@ impl Span {
}
#[inline]
pub fn adjust(&mut self, expansion: Mark) -> Option<Mark> {
pub fn adjust(&mut self, expansion: ExpnId) -> Option<ExpnId> {
let mut span = self.data();
let mark = span.ctxt.adjust(expansion);
*self = Span::new(span.lo, span.hi, span.ctxt);
@ -538,7 +538,7 @@ impl Span {
}
#[inline]
pub fn modernize_and_adjust(&mut self, expansion: Mark) -> Option<Mark> {
pub fn modernize_and_adjust(&mut self, expansion: ExpnId) -> Option<ExpnId> {
let mut span = self.data();
let mark = span.ctxt.modernize_and_adjust(expansion);
*self = Span::new(span.lo, span.hi, span.ctxt);
@ -546,7 +546,7 @@ impl Span {
}
#[inline]
pub fn glob_adjust(&mut self, expansion: Mark, glob_span: Span) -> Option<Option<Mark>> {
pub fn glob_adjust(&mut self, expansion: ExpnId, glob_span: Span) -> Option<Option<ExpnId>> {
let mut span = self.data();
let mark = span.ctxt.glob_adjust(expansion, glob_span);
*self = Span::new(span.lo, span.hi, span.ctxt);
@ -554,8 +554,8 @@ impl Span {
}
#[inline]
pub fn reverse_glob_adjust(&mut self, expansion: Mark, glob_span: Span)
-> Option<Option<Mark>> {
pub fn reverse_glob_adjust(&mut self, expansion: ExpnId, glob_span: Span)
-> Option<Option<ExpnId>> {
let mut span = self.data();
let mark = span.ctxt.reverse_glob_adjust(expansion, glob_span);
*self = Span::new(span.lo, span.hi, span.ctxt);