Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libsyntax: Rename Mark into ExpnId #62705

Merged
merged 3 commits into from
Jul 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -968,7 +968,7 @@ impl<'a> LoweringContext<'a> {
parent_index,
node_id,
DefPathData::LifetimeNs(str_name),
Mark::root(),
ExpnId::root(),
span,
);

Expand Down Expand Up @@ -1462,7 +1462,7 @@ impl<'a> LoweringContext<'a> {
parent_def_index,
impl_trait_node_id,
DefPathData::ImplTrait,
Mark::root(),
ExpnId::root(),
DUMMY_SP
);

Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/hir/map/def_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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 }
}
Expand Down Expand Up @@ -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);
}
}

Expand Down
40 changes: 20 additions & 20 deletions src/librustc/hir/map/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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={:?})",
Expand Down Expand Up @@ -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
Expand All @@ -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");
}
Expand Down Expand Up @@ -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
);

Expand Down
10 changes: 5 additions & 5 deletions src/librustc/ich/hcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,21 +359,21 @@ 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| {
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
});

Expand Down
6 changes: 3 additions & 3 deletions src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

Expand Down
14 changes: 7 additions & 7 deletions src/librustc/ty/query/on_disk_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -588,13 +588,13 @@ impl<'a, 'tcx> SpecializedDecoder<Span> 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
};
Expand Down Expand Up @@ -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>,
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_allocator/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use syntax::{
base::{ExtCtxt, MacroKind, Resolver},
build::AstBuilder,
expand::ExpansionConfig,
hygiene::Mark,
hygiene::ExpnId,
},
mut_visit::{self, MutVisitor},
parse::ParseSess,
Expand Down Expand Up @@ -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(),
));
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_codegen_ssa/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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),
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_interface/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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));
Expand Down
Loading