Skip to content

Commit 1a44773

Browse files
committed
hygiene: Merge ExpnInfo and InternalExpnData
1 parent aca1353 commit 1a44773

File tree

15 files changed

+67
-67
lines changed

15 files changed

+67
-67
lines changed

src/librustc/hir/lowering.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ impl<'a> LoweringContext<'a> {
704704
span: Span,
705705
allow_internal_unstable: Option<Lrc<[Symbol]>>,
706706
) -> Span {
707-
span.fresh_expansion(ExpnId::root(), ExpnInfo {
707+
span.fresh_expansion(ExpnInfo {
708708
def_site: span,
709709
allow_internal_unstable,
710710
..ExpnInfo::default(ExpnKind::Desugaring(reason), span, self.sess.edition())

src/librustc/ich/impls_syntax.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,9 @@ impl_stable_hash_for!(enum ::syntax_pos::hygiene::Transparency {
398398
});
399399

400400
impl_stable_hash_for!(struct ::syntax_pos::hygiene::ExpnInfo {
401-
call_site,
402401
kind,
402+
parent -> _,
403+
call_site,
403404
def_site,
404405
default_transparency,
405406
allow_internal_unstable,

src/librustc/ty/query/on_disk_cache.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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 `InternalExpnData::parent` or
591+
// FIXME(mw): This method does not restore `ExpnInfo::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::with_root_ctxt(lo, hi);
596596
let recover_from_expn_info = |this: &Self, expn_info, pos| {
597-
let span = location().fresh_expansion(ExpnId::root(), expn_info);
597+
let span = location().fresh_expansion(expn_info);
598598
this.synthetic_expansion_infos.borrow_mut().insert(pos, span.ctxt());
599599
span
600600
};

src/librustc_resolve/macros.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl<'a> base::Resolver for Resolver<'a> {
9797
}
9898

9999
fn get_module_scope(&mut self, id: ast::NodeId) -> ExpnId {
100-
let expn_id = ExpnId::fresh(ExpnId::root(), Some(ExpnInfo::default(
100+
let expn_id = ExpnId::fresh(Some(ExpnInfo::default(
101101
ExpnKind::Macro(MacroKind::Attr, sym::test_case), DUMMY_SP, self.session.edition()
102102
)));
103103
let module = self.module_map[&self.definitions.local_def_id(id)];
@@ -120,7 +120,8 @@ impl<'a> base::Resolver for Resolver<'a> {
120120
&mut self, expansion: ExpnId, fragment: &AstFragment, derives: &[ExpnId]
121121
) {
122122
// Fill in some data for derives if the fragment is from a derive container.
123-
let parent_scope = self.invocation_parent_scopes[&expansion];
123+
// We are inside the `expansion` now, but other parent scope components are still the same.
124+
let parent_scope = ParentScope { expansion, ..self.invocation_parent_scopes[&expansion] };
124125
let parent_def = self.definitions.invocation_parent(expansion);
125126
self.invocation_parent_scopes.extend(derives.iter().map(|&derive| (derive, parent_scope)));
126127
for &derive_invoc_id in derives {
@@ -130,9 +131,7 @@ impl<'a> base::Resolver for Resolver<'a> {
130131
parent_scope.module.unresolved_invocations.borrow_mut().extend(derives);
131132

132133
// Integrate the new AST fragment into all the definition and module structures.
133-
// We are inside the `expansion` new, but other parent scope components are still the same.
134134
fragment.visit_with(&mut DefCollector::new(&mut self.definitions, expansion));
135-
let parent_scope = ParentScope { expansion, ..parent_scope };
136135
let output_legacy_scope = self.build_reduced_graph(fragment, parent_scope);
137136
self.output_legacy_scopes.insert(expansion, output_legacy_scope);
138137
}
@@ -186,7 +185,9 @@ impl<'a> base::Resolver for Resolver<'a> {
186185
let (ext, res) = self.smart_resolve_macro_path(path, kind, parent_scope, force)?;
187186

188187
let span = invoc.span();
189-
invoc.expansion_data.id.set_expn_info(ext.expn_info(span, fast_print_path(path)));
188+
invoc.expansion_data.id.set_expn_info(
189+
ext.expn_info(parent_scope.expansion, span, fast_print_path(path))
190+
);
190191

191192
if let Res::Def(_, def_id) = res {
192193
if after_derive {

src/libsyntax/ext/base.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,10 +640,11 @@ impl SyntaxExtension {
640640
SyntaxExtension::default(SyntaxExtensionKind::NonMacroAttr { mark_used }, edition)
641641
}
642642

643-
pub fn expn_info(&self, call_site: Span, descr: Symbol) -> ExpnInfo {
643+
pub fn expn_info(&self, parent: ExpnId, call_site: Span, descr: Symbol) -> ExpnInfo {
644644
ExpnInfo {
645-
call_site,
646645
kind: ExpnKind::Macro(self.macro_kind(), descr),
646+
parent,
647+
call_site,
647648
def_site: self.span,
648649
default_transparency: self.default_transparency,
649650
allow_internal_unstable: self.allow_internal_unstable.clone(),

src/libsyntax/ext/expand.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
353353
derives.reserve(traits.len());
354354
invocations.reserve(traits.len());
355355
for path in traits {
356-
let expn_id = ExpnId::fresh(self.cx.current_expansion.id, None);
356+
let expn_id = ExpnId::fresh(None);
357357
derives.push(expn_id);
358358
invocations.push(Invocation {
359359
kind: InvocationKind::Derive { path, item: item.clone() },
@@ -800,13 +800,16 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
800800
// with exception of the derive container case which is not resolved and can get
801801
// its expansion info immediately.
802802
let expn_info = match &kind {
803-
InvocationKind::DeriveContainer { item, .. } => Some(ExpnInfo::default(
804-
ExpnKind::Macro(MacroKind::Attr, sym::derive),
805-
item.span(), self.cx.parse_sess.edition,
806-
)),
803+
InvocationKind::DeriveContainer { item, .. } => Some(ExpnInfo {
804+
parent: self.cx.current_expansion.id,
805+
..ExpnInfo::default(
806+
ExpnKind::Macro(MacroKind::Attr, sym::derive),
807+
item.span(), self.cx.parse_sess.edition,
808+
)
809+
}),
807810
_ => None,
808811
};
809-
let expn_id = ExpnId::fresh(self.cx.current_expansion.id, expn_info);
812+
let expn_id = ExpnId::fresh(expn_info);
810813
self.invocations.push(Invocation {
811814
kind,
812815
fragment_kind,

src/libsyntax_ext/deriving/clone.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn expand_deriving_clone(cx: &mut ExtCtxt<'_>,
3535
match annitem.node {
3636
ItemKind::Struct(_, Generics { ref params, .. }) |
3737
ItemKind::Enum(_, Generics { ref params, .. }) => {
38-
let container_id = cx.current_expansion.id.parent();
38+
let container_id = cx.current_expansion.id.expn_info().parent;
3939
if cx.resolver.has_derives(container_id, SpecialDerives::COPY) &&
4040
!params.iter().any(|param| match param.kind {
4141
ast::GenericParamKind::Type { .. } => true,

src/libsyntax_ext/deriving/cmp/eq.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt<'_>,
1313
mitem: &MetaItem,
1414
item: &Annotatable,
1515
push: &mut dyn FnMut(Annotatable)) {
16-
cx.resolver.add_derives(cx.current_expansion.id.parent(), SpecialDerives::EQ);
16+
cx.resolver.add_derives(cx.current_expansion.id.expn_info().parent, SpecialDerives::EQ);
1717

1818
let inline = cx.meta_word(span, sym::inline);
1919
let hidden = cx.meta_list_item_word(span, sym::hidden);

src/libsyntax_ext/deriving/cmp/partial_eq.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt<'_>,
1313
mitem: &MetaItem,
1414
item: &Annotatable,
1515
push: &mut dyn FnMut(Annotatable)) {
16-
cx.resolver.add_derives(cx.current_expansion.id.parent(), SpecialDerives::PARTIAL_EQ);
16+
cx.resolver.add_derives(cx.current_expansion.id.expn_info().parent, SpecialDerives::PARTIAL_EQ);
1717

1818
// structures are equal if all fields are equal, and non equal, if
1919
// any fields are not equal or if the enum variants are different

src/libsyntax_ext/deriving/generic/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ impl<'a> TraitDef<'a> {
425425
return;
426426
}
427427
};
428-
let container_id = cx.current_expansion.id.parent();
428+
let container_id = cx.current_expansion.id.expn_info().parent;
429429
let is_always_copy =
430430
cx.resolver.has_derives(container_id, SpecialDerives::COPY) &&
431431
has_no_type_params;

src/libsyntax_ext/plugin_macro_defs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use syntax::source_map::respan;
1111
use syntax::symbol::sym;
1212
use syntax::tokenstream::*;
1313
use syntax_pos::{Span, DUMMY_SP};
14-
use syntax_pos::hygiene::{ExpnId, ExpnInfo, ExpnKind, MacroKind};
14+
use syntax_pos::hygiene::{ExpnInfo, ExpnKind, MacroKind};
1515

1616
use std::mem;
1717

@@ -43,7 +43,7 @@ pub fn inject(
4343
) {
4444
if !named_exts.is_empty() {
4545
let mut extra_items = Vec::new();
46-
let span = DUMMY_SP.fresh_expansion(ExpnId::root(), ExpnInfo::allow_unstable(
46+
let span = DUMMY_SP.fresh_expansion(ExpnInfo::allow_unstable(
4747
ExpnKind::Macro(MacroKind::Attr, sym::plugin), DUMMY_SP, edition,
4848
[sym::rustc_attrs][..].into(),
4949
));

src/libsyntax_ext/proc_macro_harness.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use syntax::attr;
66
use syntax::source_map::{ExpnInfo, ExpnKind, respan};
77
use syntax::ext::base::{ExtCtxt, MacroKind};
88
use syntax::ext::expand::{AstFragment, ExpansionConfig};
9-
use syntax::ext::hygiene::ExpnId;
109
use syntax::ext::proc_macro::is_proc_macro_attr;
1110
use syntax::parse::ParseSess;
1211
use syntax::ptr::P;
@@ -328,7 +327,7 @@ fn mk_decls(
328327
custom_attrs: &[ProcMacroDef],
329328
custom_macros: &[ProcMacroDef],
330329
) -> P<ast::Item> {
331-
let span = DUMMY_SP.fresh_expansion(ExpnId::root(), ExpnInfo::allow_unstable(
330+
let span = DUMMY_SP.fresh_expansion(ExpnInfo::allow_unstable(
332331
ExpnKind::Macro(MacroKind::Attr, sym::proc_macro), DUMMY_SP, cx.parse_sess.edition,
333332
[sym::rustc_attrs, sym::proc_macro_internals][..].into(),
334333
));

src/libsyntax_ext/standard_library_imports.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use syntax::{ast, attr};
22
use syntax::edition::Edition;
3-
use syntax::ext::hygiene::{ExpnId, MacroKind};
3+
use syntax::ext::hygiene::MacroKind;
44
use syntax::ptr::P;
55
use syntax::source_map::{ExpnInfo, ExpnKind, dummy_spanned, respan};
66
use syntax::symbol::{Ident, Symbol, kw, sym};
@@ -55,7 +55,7 @@ pub fn inject(
5555
// the prelude.
5656
let name = names[0];
5757

58-
let span = DUMMY_SP.fresh_expansion(ExpnId::root(), ExpnInfo::allow_unstable(
58+
let span = DUMMY_SP.fresh_expansion(ExpnInfo::allow_unstable(
5959
ExpnKind::Macro(MacroKind::Attr, sym::std_inject), DUMMY_SP, edition,
6060
[sym::prelude_import][..].into(),
6161
));

src/libsyntax_ext/test_harness.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ use smallvec::{smallvec, SmallVec};
55
use syntax::ast::{self, Ident};
66
use syntax::attr;
77
use syntax::entry::{self, EntryPointType};
8-
use syntax::ext::base::{ExtCtxt, Resolver};
8+
use syntax::ext::base::{ExtCtxt, MacroKind, Resolver};
99
use syntax::ext::expand::{AstFragment, ExpansionConfig};
10-
use syntax::ext::hygiene::{ExpnId, MacroKind};
1110
use syntax::feature_gate::Features;
1211
use syntax::mut_visit::{*, ExpectOne};
1312
use syntax::parse::ParseSess;
@@ -269,7 +268,7 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
269268
// #![main]
270269
// test::test_main_static(&[..tests]);
271270
// }
272-
let sp = DUMMY_SP.fresh_expansion(ExpnId::root(), ExpnInfo::allow_unstable(
271+
let sp = DUMMY_SP.fresh_expansion(ExpnInfo::allow_unstable(
273272
ExpnKind::Macro(MacroKind::Attr, sym::test_case), DUMMY_SP, cx.ext_cx.parse_sess.edition,
274273
[sym::main, sym::test, sym::rustc_attrs][..].into(),
275274
));

0 commit comments

Comments
 (0)