Skip to content

Commit

Permalink
hygiene: Merge ExpnInfo and InternalExpnData
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Aug 15, 2019
1 parent aca1353 commit 1a44773
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 67 deletions.
2 changes: 1 addition & 1 deletion src/librustc/hir/lowering.rs
Expand Up @@ -704,7 +704,7 @@ impl<'a> LoweringContext<'a> {
span: Span,
allow_internal_unstable: Option<Lrc<[Symbol]>>,
) -> Span {
span.fresh_expansion(ExpnId::root(), ExpnInfo {
span.fresh_expansion(ExpnInfo {
def_site: span,
allow_internal_unstable,
..ExpnInfo::default(ExpnKind::Desugaring(reason), span, self.sess.edition())
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/ich/impls_syntax.rs
Expand Up @@ -398,8 +398,9 @@ impl_stable_hash_for!(enum ::syntax_pos::hygiene::Transparency {
});

impl_stable_hash_for!(struct ::syntax_pos::hygiene::ExpnInfo {
call_site,
kind,
parent -> _,
call_site,
def_site,
default_transparency,
allow_internal_unstable,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/query/on_disk_cache.rs
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 `InternalExpnData::parent` or
// FIXME(mw): This method does not restore `ExpnInfo::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::with_root_ctxt(lo, hi);
let recover_from_expn_info = |this: &Self, expn_info, pos| {
let span = location().fresh_expansion(ExpnId::root(), expn_info);
let span = location().fresh_expansion(expn_info);
this.synthetic_expansion_infos.borrow_mut().insert(pos, span.ctxt());
span
};
Expand Down
11 changes: 6 additions & 5 deletions src/librustc_resolve/macros.rs
Expand Up @@ -97,7 +97,7 @@ impl<'a> base::Resolver for Resolver<'a> {
}

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

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

let span = invoc.span();
invoc.expansion_data.id.set_expn_info(ext.expn_info(span, fast_print_path(path)));
invoc.expansion_data.id.set_expn_info(
ext.expn_info(parent_scope.expansion, span, fast_print_path(path))
);

if let Res::Def(_, def_id) = res {
if after_derive {
Expand Down
5 changes: 3 additions & 2 deletions src/libsyntax/ext/base.rs
Expand Up @@ -640,10 +640,11 @@ impl SyntaxExtension {
SyntaxExtension::default(SyntaxExtensionKind::NonMacroAttr { mark_used }, edition)
}

pub fn expn_info(&self, call_site: Span, descr: Symbol) -> ExpnInfo {
pub fn expn_info(&self, parent: ExpnId, call_site: Span, descr: Symbol) -> ExpnInfo {
ExpnInfo {
call_site,
kind: ExpnKind::Macro(self.macro_kind(), descr),
parent,
call_site,
def_site: self.span,
default_transparency: self.default_transparency,
allow_internal_unstable: self.allow_internal_unstable.clone(),
Expand Down
15 changes: 9 additions & 6 deletions src/libsyntax/ext/expand.rs
Expand Up @@ -353,7 +353,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
derives.reserve(traits.len());
invocations.reserve(traits.len());
for path in traits {
let expn_id = ExpnId::fresh(self.cx.current_expansion.id, None);
let expn_id = ExpnId::fresh(None);
derives.push(expn_id);
invocations.push(Invocation {
kind: InvocationKind::Derive { path, item: item.clone() },
Expand Down Expand Up @@ -800,13 +800,16 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
// with exception of the derive container case which is not resolved and can get
// its expansion info immediately.
let expn_info = match &kind {
InvocationKind::DeriveContainer { item, .. } => Some(ExpnInfo::default(
ExpnKind::Macro(MacroKind::Attr, sym::derive),
item.span(), self.cx.parse_sess.edition,
)),
InvocationKind::DeriveContainer { item, .. } => Some(ExpnInfo {
parent: self.cx.current_expansion.id,
..ExpnInfo::default(
ExpnKind::Macro(MacroKind::Attr, sym::derive),
item.span(), self.cx.parse_sess.edition,
)
}),
_ => None,
};
let expn_id = ExpnId::fresh(self.cx.current_expansion.id, expn_info);
let expn_id = ExpnId::fresh(expn_info);
self.invocations.push(Invocation {
kind,
fragment_kind,
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax_ext/deriving/clone.rs
Expand Up @@ -35,7 +35,7 @@ pub fn expand_deriving_clone(cx: &mut ExtCtxt<'_>,
match annitem.node {
ItemKind::Struct(_, Generics { ref params, .. }) |
ItemKind::Enum(_, Generics { ref params, .. }) => {
let container_id = cx.current_expansion.id.parent();
let container_id = cx.current_expansion.id.expn_info().parent;
if cx.resolver.has_derives(container_id, SpecialDerives::COPY) &&
!params.iter().any(|param| match param.kind {
ast::GenericParamKind::Type { .. } => true,
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax_ext/deriving/cmp/eq.rs
Expand Up @@ -13,7 +13,7 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt<'_>,
mitem: &MetaItem,
item: &Annotatable,
push: &mut dyn FnMut(Annotatable)) {
cx.resolver.add_derives(cx.current_expansion.id.parent(), SpecialDerives::EQ);
cx.resolver.add_derives(cx.current_expansion.id.expn_info().parent, SpecialDerives::EQ);

let inline = cx.meta_word(span, sym::inline);
let hidden = cx.meta_list_item_word(span, sym::hidden);
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax_ext/deriving/cmp/partial_eq.rs
Expand Up @@ -13,7 +13,7 @@ pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt<'_>,
mitem: &MetaItem,
item: &Annotatable,
push: &mut dyn FnMut(Annotatable)) {
cx.resolver.add_derives(cx.current_expansion.id.parent(), SpecialDerives::PARTIAL_EQ);
cx.resolver.add_derives(cx.current_expansion.id.expn_info().parent, SpecialDerives::PARTIAL_EQ);

// structures are equal if all fields are equal, and non equal, if
// any fields are not equal or if the enum variants are different
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax_ext/deriving/generic/mod.rs
Expand Up @@ -425,7 +425,7 @@ impl<'a> TraitDef<'a> {
return;
}
};
let container_id = cx.current_expansion.id.parent();
let container_id = cx.current_expansion.id.expn_info().parent;
let is_always_copy =
cx.resolver.has_derives(container_id, SpecialDerives::COPY) &&
has_no_type_params;
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax_ext/plugin_macro_defs.rs
Expand Up @@ -11,7 +11,7 @@ use syntax::source_map::respan;
use syntax::symbol::sym;
use syntax::tokenstream::*;
use syntax_pos::{Span, DUMMY_SP};
use syntax_pos::hygiene::{ExpnId, ExpnInfo, ExpnKind, MacroKind};
use syntax_pos::hygiene::{ExpnInfo, ExpnKind, MacroKind};

use std::mem;

Expand Down Expand Up @@ -43,7 +43,7 @@ pub fn inject(
) {
if !named_exts.is_empty() {
let mut extra_items = Vec::new();
let span = DUMMY_SP.fresh_expansion(ExpnId::root(), ExpnInfo::allow_unstable(
let span = DUMMY_SP.fresh_expansion(ExpnInfo::allow_unstable(
ExpnKind::Macro(MacroKind::Attr, sym::plugin), DUMMY_SP, edition,
[sym::rustc_attrs][..].into(),
));
Expand Down
3 changes: 1 addition & 2 deletions src/libsyntax_ext/proc_macro_harness.rs
Expand Up @@ -6,7 +6,6 @@ use syntax::attr;
use syntax::source_map::{ExpnInfo, ExpnKind, respan};
use syntax::ext::base::{ExtCtxt, MacroKind};
use syntax::ext::expand::{AstFragment, ExpansionConfig};
use syntax::ext::hygiene::ExpnId;
use syntax::ext::proc_macro::is_proc_macro_attr;
use syntax::parse::ParseSess;
use syntax::ptr::P;
Expand Down Expand Up @@ -328,7 +327,7 @@ fn mk_decls(
custom_attrs: &[ProcMacroDef],
custom_macros: &[ProcMacroDef],
) -> P<ast::Item> {
let span = DUMMY_SP.fresh_expansion(ExpnId::root(), ExpnInfo::allow_unstable(
let span = DUMMY_SP.fresh_expansion(ExpnInfo::allow_unstable(
ExpnKind::Macro(MacroKind::Attr, sym::proc_macro), DUMMY_SP, cx.parse_sess.edition,
[sym::rustc_attrs, sym::proc_macro_internals][..].into(),
));
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax_ext/standard_library_imports.rs
@@ -1,6 +1,6 @@
use syntax::{ast, attr};
use syntax::edition::Edition;
use syntax::ext::hygiene::{ExpnId, MacroKind};
use syntax::ext::hygiene::MacroKind;
use syntax::ptr::P;
use syntax::source_map::{ExpnInfo, ExpnKind, dummy_spanned, respan};
use syntax::symbol::{Ident, Symbol, kw, sym};
Expand Down Expand Up @@ -55,7 +55,7 @@ pub fn inject(
// the prelude.
let name = names[0];

let span = DUMMY_SP.fresh_expansion(ExpnId::root(), ExpnInfo::allow_unstable(
let span = DUMMY_SP.fresh_expansion(ExpnInfo::allow_unstable(
ExpnKind::Macro(MacroKind::Attr, sym::std_inject), DUMMY_SP, edition,
[sym::prelude_import][..].into(),
));
Expand Down
5 changes: 2 additions & 3 deletions src/libsyntax_ext/test_harness.rs
Expand Up @@ -5,9 +5,8 @@ use smallvec::{smallvec, SmallVec};
use syntax::ast::{self, Ident};
use syntax::attr;
use syntax::entry::{self, EntryPointType};
use syntax::ext::base::{ExtCtxt, Resolver};
use syntax::ext::base::{ExtCtxt, MacroKind, Resolver};
use syntax::ext::expand::{AstFragment, ExpansionConfig};
use syntax::ext::hygiene::{ExpnId, MacroKind};
use syntax::feature_gate::Features;
use syntax::mut_visit::{*, ExpectOne};
use syntax::parse::ParseSess;
Expand Down Expand Up @@ -269,7 +268,7 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
// #![main]
// test::test_main_static(&[..tests]);
// }
let sp = DUMMY_SP.fresh_expansion(ExpnId::root(), ExpnInfo::allow_unstable(
let sp = DUMMY_SP.fresh_expansion(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(),
));
Expand Down

0 comments on commit 1a44773

Please sign in to comment.