Skip to content

Commit 5c26b52

Browse files
committed
Auto merge of #62705 - petrochenkov:oh-bye-mark, r=matthewjasper
libsyntax: Rename `Mark` into `ExpnId` "`Mark`" is an ID that identifies both a macro invocation (`foo!()`), and expansion process, and expansion result of that macro invocation. The problem is that it's pretty hard to infer that from its name. This PR renames it into `ExpnId` reflecting its meaning in most contexts. (The contexts where it's meaning is closer to "macro invocation ID" are rarer.) I've kept "mark" in the names of functions that add or remove marks to/from syntactic contexts, those marks are not just expansion IDs, but something more complex.
2 parents e3cebcb + 8f30d26 commit 5c26b52

37 files changed

+378
-372
lines changed

src/librustc/hir/lowering.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ use syntax::attr;
6060
use syntax::ast;
6161
use syntax::ast::*;
6262
use syntax::errors;
63-
use syntax::ext::hygiene::Mark;
63+
use syntax::ext::hygiene::ExpnId;
6464
use syntax::print::pprust;
6565
use syntax::source_map::{respan, ExpnInfo, ExpnKind, DesugaringKind, Spanned};
6666
use syntax::std_inject;
@@ -437,7 +437,7 @@ impl<'a> LoweringContext<'a> {
437437
owner,
438438
id,
439439
DefPathData::Misc,
440-
Mark::root(),
440+
ExpnId::root(),
441441
tree.prefix.span,
442442
);
443443
self.lctx.allocate_hir_id_counter(id);
@@ -875,7 +875,7 @@ impl<'a> LoweringContext<'a> {
875875
span: Span,
876876
allow_internal_unstable: Option<Lrc<[Symbol]>>,
877877
) -> Span {
878-
span.fresh_expansion(Mark::root(), ExpnInfo {
878+
span.fresh_expansion(ExpnId::root(), ExpnInfo {
879879
def_site: span,
880880
allow_internal_unstable,
881881
..ExpnInfo::default(ExpnKind::Desugaring(reason), span, self.sess.edition())
@@ -968,7 +968,7 @@ impl<'a> LoweringContext<'a> {
968968
parent_index,
969969
node_id,
970970
DefPathData::LifetimeNs(str_name),
971-
Mark::root(),
971+
ExpnId::root(),
972972
span,
973973
);
974974

@@ -1462,7 +1462,7 @@ impl<'a> LoweringContext<'a> {
14621462
parent_def_index,
14631463
impl_trait_node_id,
14641464
DefPathData::ImplTrait,
1465-
Mark::root(),
1465+
ExpnId::root(),
14661466
DUMMY_SP
14671467
);
14681468

@@ -1921,7 +1921,7 @@ impl<'a> LoweringContext<'a> {
19211921
self.parent,
19221922
def_node_id,
19231923
DefPathData::LifetimeNs(name.ident().as_interned_str()),
1924-
Mark::root(),
1924+
ExpnId::root(),
19251925
lifetime.span);
19261926

19271927
let (name, kind) = match name {

src/librustc/hir/map/def_collector.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::hir::map::definitions::*;
22
use crate::hir::def_id::DefIndex;
33

44
use syntax::ast::*;
5-
use syntax::ext::hygiene::Mark;
5+
use syntax::ext::hygiene::ExpnId;
66
use syntax::visit;
77
use syntax::symbol::{kw, sym};
88
use syntax::parse::token::{self, Token};
@@ -12,11 +12,11 @@ use syntax_pos::Span;
1212
pub struct DefCollector<'a> {
1313
definitions: &'a mut Definitions,
1414
parent_def: DefIndex,
15-
expansion: Mark,
15+
expansion: ExpnId,
1616
}
1717

1818
impl<'a> DefCollector<'a> {
19-
pub fn new(definitions: &'a mut Definitions, expansion: Mark) -> Self {
19+
pub fn new(definitions: &'a mut Definitions, expansion: ExpnId) -> Self {
2020
let parent_def = definitions.invocation_parent(expansion);
2121
DefCollector { definitions, parent_def, expansion }
2222
}
@@ -75,7 +75,7 @@ impl<'a> DefCollector<'a> {
7575
}
7676

7777
fn visit_macro_invoc(&mut self, id: NodeId) {
78-
self.definitions.set_invocation_parent(id.placeholder_to_mark(), self.parent_def);
78+
self.definitions.set_invocation_parent(id.placeholder_to_expn_id(), self.parent_def);
7979
}
8080
}
8181

src/librustc/hir/map/definitions.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::borrow::Borrow;
1515
use std::fmt::Write;
1616
use std::hash::Hash;
1717
use syntax::ast;
18-
use syntax::ext::hygiene::Mark;
18+
use syntax::ext::hygiene::ExpnId;
1919
use syntax::symbol::{Symbol, sym, InternedString};
2020
use syntax_pos::{Span, DUMMY_SP};
2121
use crate::util::nodemap::NodeMap;
@@ -93,16 +93,16 @@ pub struct Definitions {
9393
node_to_def_index: NodeMap<DefIndex>,
9494
def_index_to_node: Vec<ast::NodeId>,
9595
pub(super) node_to_hir_id: IndexVec<ast::NodeId, hir::HirId>,
96-
/// If `Mark` is an ID of some macro expansion,
96+
/// If `ExpnId` is an ID of some macro expansion,
9797
/// then `DefId` is the normal module (`mod`) in which the expanded macro was defined.
98-
parent_modules_of_macro_defs: FxHashMap<Mark, DefId>,
99-
/// Item with a given `DefIndex` was defined during macro expansion with ID `Mark`.
100-
expansions_that_defined: FxHashMap<DefIndex, Mark>,
98+
parent_modules_of_macro_defs: FxHashMap<ExpnId, DefId>,
99+
/// Item with a given `DefIndex` was defined during macro expansion with ID `ExpnId`.
100+
expansions_that_defined: FxHashMap<DefIndex, ExpnId>,
101101
next_disambiguator: FxHashMap<(DefIndex, DefPathData), u32>,
102102
def_index_to_span: FxHashMap<DefIndex, Span>,
103-
/// When collecting definitions from an AST fragment produced by a macro invocation `Mark`
103+
/// When collecting definitions from an AST fragment produced by a macro invocation `ExpnId`
104104
/// we know what parent node that fragment should be attached to thanks to this table.
105-
invocation_parents: FxHashMap<Mark, DefIndex>,
105+
invocation_parents: FxHashMap<ExpnId, DefIndex>,
106106
}
107107

108108
/// A unique identifier that we can use to lookup a definition
@@ -437,7 +437,7 @@ impl Definitions {
437437
assert!(self.def_index_to_node.is_empty());
438438
self.def_index_to_node.push(ast::CRATE_NODE_ID);
439439
self.node_to_def_index.insert(ast::CRATE_NODE_ID, root_index);
440-
self.set_invocation_parent(Mark::root(), root_index);
440+
self.set_invocation_parent(ExpnId::root(), root_index);
441441

442442
// Allocate some other DefIndices that always must exist.
443443
GlobalMetaDataKind::allocate_def_indices(self);
@@ -450,7 +450,7 @@ impl Definitions {
450450
parent: DefIndex,
451451
node_id: ast::NodeId,
452452
data: DefPathData,
453-
expansion: Mark,
453+
expn_id: ExpnId,
454454
span: Span)
455455
-> DefIndex {
456456
debug!("create_def_with_parent(parent={:?}, node_id={:?}, data={:?})",
@@ -498,8 +498,8 @@ impl Definitions {
498498
self.node_to_def_index.insert(node_id, index);
499499
}
500500

501-
if expansion != Mark::root() {
502-
self.expansions_that_defined.insert(index, expansion);
501+
if expn_id != ExpnId::root() {
502+
self.expansions_that_defined.insert(index, expn_id);
503503
}
504504

505505
// The span is added if it isn't dummy
@@ -519,23 +519,23 @@ impl Definitions {
519519
self.node_to_hir_id = mapping;
520520
}
521521

522-
pub fn expansion_that_defined(&self, index: DefIndex) -> Mark {
523-
self.expansions_that_defined.get(&index).cloned().unwrap_or(Mark::root())
522+
pub fn expansion_that_defined(&self, index: DefIndex) -> ExpnId {
523+
self.expansions_that_defined.get(&index).cloned().unwrap_or(ExpnId::root())
524524
}
525525

526-
pub fn parent_module_of_macro_def(&self, mark: Mark) -> DefId {
527-
self.parent_modules_of_macro_defs[&mark]
526+
pub fn parent_module_of_macro_def(&self, expn_id: ExpnId) -> DefId {
527+
self.parent_modules_of_macro_defs[&expn_id]
528528
}
529529

530-
pub fn add_parent_module_of_macro_def(&mut self, mark: Mark, module: DefId) {
531-
self.parent_modules_of_macro_defs.insert(mark, module);
530+
pub fn add_parent_module_of_macro_def(&mut self, expn_id: ExpnId, module: DefId) {
531+
self.parent_modules_of_macro_defs.insert(expn_id, module);
532532
}
533533

534-
pub fn invocation_parent(&self, invoc_id: Mark) -> DefIndex {
534+
pub fn invocation_parent(&self, invoc_id: ExpnId) -> DefIndex {
535535
self.invocation_parents[&invoc_id]
536536
}
537537

538-
pub fn set_invocation_parent(&mut self, invoc_id: Mark, parent: DefIndex) {
538+
pub fn set_invocation_parent(&mut self, invoc_id: ExpnId, parent: DefIndex) {
539539
let old_parent = self.invocation_parents.insert(invoc_id, parent);
540540
assert!(old_parent.is_none(), "parent def-index is reset for an invocation");
541541
}
@@ -624,7 +624,7 @@ macro_rules! define_global_metadata_kind {
624624
CRATE_DEF_INDEX,
625625
ast::DUMMY_NODE_ID,
626626
DefPathData::GlobalMetaData(instance.name().as_interned_str()),
627-
Mark::root(),
627+
ExpnId::root(),
628628
DUMMY_SP
629629
);
630630

src/librustc/ich/hcx.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -359,21 +359,21 @@ impl<'a> HashStable<StableHashingContext<'a>> for Span {
359359
// times, we cache a stable hash of it and hash that instead of
360360
// recursing every time.
361361
thread_local! {
362-
static CACHE: RefCell<FxHashMap<hygiene::Mark, u64>> = Default::default();
362+
static CACHE: RefCell<FxHashMap<hygiene::ExpnId, u64>> = Default::default();
363363
}
364364

365365
let sub_hash: u64 = CACHE.with(|cache| {
366-
let mark = span.ctxt.outer();
366+
let expn_id = span.ctxt.outer_expn();
367367

368-
if let Some(&sub_hash) = cache.borrow().get(&mark) {
368+
if let Some(&sub_hash) = cache.borrow().get(&expn_id) {
369369
return sub_hash;
370370
}
371371

372372
let mut hasher = StableHasher::new();
373-
mark.expn_info().hash_stable(hcx, &mut hasher);
373+
expn_id.expn_info().hash_stable(hcx, &mut hasher);
374374
let sub_hash: Fingerprint = hasher.finish();
375375
let sub_hash = sub_hash.to_smaller_hash();
376-
cache.borrow_mut().insert(mark, sub_hash);
376+
cache.borrow_mut().insert(expn_id, sub_hash);
377377
sub_hash
378378
});
379379

src/librustc/ty/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use std::{mem, ptr};
4444
use std::ops::Range;
4545
use syntax::ast::{self, Name, Ident, NodeId};
4646
use syntax::attr;
47-
use syntax::ext::hygiene::Mark;
47+
use syntax::ext::hygiene::ExpnId;
4848
use syntax::symbol::{kw, sym, Symbol, LocalInternedString, InternedString};
4949
use syntax_pos::Span;
5050

@@ -3071,10 +3071,10 @@ impl<'tcx> TyCtxt<'tcx> {
30713071
self.expansion_that_defined(def_parent_def_id))
30723072
}
30733073

3074-
fn expansion_that_defined(self, scope: DefId) -> Mark {
3074+
fn expansion_that_defined(self, scope: DefId) -> ExpnId {
30753075
match scope.krate {
30763076
LOCAL_CRATE => self.hir().definitions().expansion_that_defined(scope.index),
3077-
_ => Mark::root(),
3077+
_ => ExpnId::root(),
30783078
}
30793079
}
30803080

src/librustc/ty/query/on_disk_cache.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use std::mem;
2323
use syntax::ast::NodeId;
2424
use syntax::source_map::{SourceMap, StableSourceFileId};
2525
use syntax_pos::{BytePos, Span, DUMMY_SP, SourceFile};
26-
use syntax_pos::hygiene::{Mark, SyntaxContext, ExpnInfo};
26+
use syntax_pos::hygiene::{ExpnId, SyntaxContext, ExpnInfo};
2727

2828
const TAG_FILE_FOOTER: u128 = 0xC0FFEE_C0FFEE_C0FFEE_C0FFEE_C0FFEE;
2929

@@ -588,13 +588,13 @@ impl<'a, 'tcx> SpecializedDecoder<Span> for CacheDecoder<'a, 'tcx> {
588588

589589
let expn_info_tag = u8::decode(self)?;
590590

591-
// FIXME(mw): This method does not restore `MarkData::parent` or
591+
// FIXME(mw): This method does not restore `InternalExpnData::parent` or
592592
// `SyntaxContextData::prev_ctxt` or `SyntaxContextData::opaque`. These things
593593
// don't seem to be used after HIR lowering, so everything should be fine
594594
// as long as incremental compilation does not kick in before that.
595595
let location = || Span::new(lo, hi, SyntaxContext::empty());
596596
let recover_from_expn_info = |this: &Self, expn_info, pos| {
597-
let span = location().fresh_expansion(Mark::root(), expn_info);
597+
let span = location().fresh_expansion(ExpnId::root(), expn_info);
598598
this.synthetic_expansion_infos.borrow_mut().insert(pos, span.ctxt());
599599
span
600600
};
@@ -725,7 +725,7 @@ struct CacheEncoder<'a, 'tcx, E: ty_codec::TyEncoder> {
725725
encoder: &'a mut E,
726726
type_shorthands: FxHashMap<Ty<'tcx>, usize>,
727727
predicate_shorthands: FxHashMap<ty::Predicate<'tcx>, usize>,
728-
expn_info_shorthands: FxHashMap<Mark, AbsoluteBytePos>,
728+
expn_info_shorthands: FxHashMap<ExpnId, AbsoluteBytePos>,
729729
interpret_allocs: FxHashMap<interpret::AllocId, usize>,
730730
interpret_allocs_inverse: Vec<interpret::AllocId>,
731731
source_map: CachingSourceMapView<'tcx>,
@@ -819,15 +819,15 @@ where
819819
if span_data.ctxt == SyntaxContext::empty() {
820820
TAG_NO_EXPANSION_INFO.encode(self)
821821
} else {
822-
let (mark, expn_info) = span_data.ctxt.outer_and_expn_info();
822+
let (expn_id, expn_info) = span_data.ctxt.outer_expn_with_info();
823823
if let Some(expn_info) = expn_info {
824-
if let Some(pos) = self.expn_info_shorthands.get(&mark).cloned() {
824+
if let Some(pos) = self.expn_info_shorthands.get(&expn_id).cloned() {
825825
TAG_EXPANSION_INFO_SHORTHAND.encode(self)?;
826826
pos.encode(self)
827827
} else {
828828
TAG_EXPANSION_INFO_INLINE.encode(self)?;
829829
let pos = AbsoluteBytePos::new(self.position());
830-
self.expn_info_shorthands.insert(mark, pos);
830+
self.expn_info_shorthands.insert(expn_id, pos);
831831
expn_info.encode(self)
832832
}
833833
} else {

src/librustc_allocator/expand.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use syntax::{
1414
base::{ExtCtxt, MacroKind, Resolver},
1515
build::AstBuilder,
1616
expand::ExpansionConfig,
17-
hygiene::Mark,
17+
hygiene::ExpnId,
1818
},
1919
mut_visit::{self, MutVisitor},
2020
parse::ParseSess,
@@ -85,7 +85,7 @@ impl MutVisitor for ExpandAllocatorDirectives<'_> {
8585
self.found = true;
8686

8787
// Create a new expansion for the generated allocator code.
88-
let span = item.span.fresh_expansion(Mark::root(), ExpnInfo::allow_unstable(
88+
let span = item.span.fresh_expansion(ExpnId::root(), ExpnInfo::allow_unstable(
8989
ExpnKind::Macro(MacroKind::Attr, sym::global_allocator), item.span, self.sess.edition,
9090
[sym::rustc_attrs][..].into(),
9191
));

src/librustc_codegen_llvm/asm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
102102
let kind = llvm::LLVMGetMDKindIDInContext(self.llcx,
103103
key.as_ptr() as *const c_char, key.len() as c_uint);
104104

105-
let val: &'ll Value = self.const_i32(ia.ctxt.outer().as_u32() as i32);
105+
let val: &'ll Value = self.const_i32(ia.ctxt.outer_expn().as_u32() as i32);
106106

107107
llvm::LLVMSetMetadata(r, kind,
108108
llvm::LLVMMDNodeInContext(self.llcx, &val, 1));

src/librustc_codegen_ssa/back/write.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use rustc_errors::{Handler, Level, DiagnosticBuilder, FatalError, DiagnosticId};
2626
use rustc_errors::emitter::{Emitter};
2727
use rustc_target::spec::MergeFunctions;
2828
use syntax::attr;
29-
use syntax::ext::hygiene::Mark;
29+
use syntax::ext::hygiene::ExpnId;
3030
use syntax_pos::MultiSpan;
3131
use syntax_pos::symbol::{Symbol, sym};
3232
use jobserver::{Client, Acquired};
@@ -1775,7 +1775,7 @@ impl SharedEmitterMain {
17751775
}
17761776
}
17771777
Ok(SharedEmitterMessage::InlineAsmError(cookie, msg)) => {
1778-
match Mark::from_u32(cookie).expn_info() {
1778+
match ExpnId::from_u32(cookie).expn_info() {
17791779
Some(ei) => sess.span_err(ei.call_site, &msg),
17801780
None => sess.err(&msg),
17811781
}

src/librustc_interface/passes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ pub fn lower_to_hir(
572572

573573
// Discard hygiene data, which isn't required after lowering to HIR.
574574
if !sess.opts.debugging_opts.keep_hygiene_data {
575-
syntax::ext::hygiene::clear_markings();
575+
syntax::ext::hygiene::clear_syntax_context_map();
576576
}
577577

578578
Ok(hir_forest)

src/librustc_metadata/decoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use syntax::ast::{self, Ident};
3131
use syntax::source_map;
3232
use syntax::symbol::{Symbol, sym};
3333
use syntax::ext::base::{MacroKind, SyntaxExtension};
34-
use syntax::ext::hygiene::Mark;
34+
use syntax::ext::hygiene::ExpnId;
3535
use syntax_pos::{self, Span, BytePos, Pos, DUMMY_SP, NO_EXPANSION};
3636
use log::debug;
3737

@@ -458,7 +458,7 @@ crate fn proc_macro_def_path_table(crate_root: &CrateRoot<'_>,
458458
crate_root,
459459
ast::DUMMY_NODE_ID,
460460
DefPathData::MacroNs(name.as_interned_str()),
461-
Mark::root(),
461+
ExpnId::root(),
462462
DUMMY_SP);
463463
debug!("definition for {:?} is {:?}", name, def_index);
464464
assert_eq!(def_index, DefIndex::from_proc_macro_index(index));

0 commit comments

Comments
 (0)