Skip to content

Make ExpnData fields krate and orig_id private #80648

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

Merged
merged 1 commit into from
Jan 7, 2021
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
7 changes: 2 additions & 5 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ use rustc_session::lint::{builtin::BARE_TRAIT_OBJECTS, BuiltinLintDiagnostics, L
use rustc_session::parse::ParseSess;
use rustc_session::Session;
use rustc_span::hygiene::ExpnId;
use rustc_span::source_map::{respan, DesugaringKind, ExpnData, ExpnKind};
use rustc_span::source_map::{respan, DesugaringKind};
use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::Span;

Expand Down Expand Up @@ -743,10 +743,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
span: Span,
allow_internal_unstable: Option<Lrc<[Symbol]>>,
) -> Span {
span.fresh_expansion(ExpnData {
allow_internal_unstable,
..ExpnData::default(ExpnKind::Desugaring(reason), span, self.sess.edition(), None)
})
span.mark_with_reason(allow_internal_unstable, reason, self.sess.edition())
}

fn with_anonymous_lifetime_mode<R>(
Expand Down
20 changes: 9 additions & 11 deletions compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rustc_data_structures::sync::{self, Lrc};
use rustc_errors::{DiagnosticBuilder, ErrorReported};
use rustc_parse::{self, nt_to_tokenstream, parser, MACRO_ARGUMENTS};
use rustc_session::{parse::ParseSess, Limit, Session};
use rustc_span::def_id::{DefId, LOCAL_CRATE};
use rustc_span::def_id::DefId;
use rustc_span::edition::Edition;
use rustc_span::hygiene::{AstPass, ExpnData, ExpnId, ExpnKind};
use rustc_span::source_map::SourceMap;
Expand Down Expand Up @@ -842,19 +842,17 @@ impl SyntaxExtension {
descr: Symbol,
macro_def_id: Option<DefId>,
) -> ExpnData {
ExpnData {
kind: ExpnKind::Macro(self.macro_kind(), descr),
ExpnData::new(
ExpnKind::Macro(self.macro_kind(), descr),
parent,
call_site,
def_site: self.span,
allow_internal_unstable: self.allow_internal_unstable.clone(),
allow_internal_unsafe: self.allow_internal_unsafe,
local_inner_macros: self.local_inner_macros,
edition: self.edition,
self.span,
self.allow_internal_unstable.clone(),
self.allow_internal_unsafe,
self.local_inner_macros,
self.edition,
macro_def_id,
krate: LOCAL_CRATE,
orig_id: None,
}
)
}
}

Expand Down
11 changes: 6 additions & 5 deletions compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1020,15 +1020,16 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
// with exception of the derive container case which is not resolved and can get
// its expansion data immediately.
let expn_data = match &kind {
InvocationKind::DeriveContainer { item, .. } => Some(ExpnData {
parent: self.cx.current_expansion.id,
..ExpnData::default(
InvocationKind::DeriveContainer { item, .. } => {
let mut expn_data = ExpnData::default(
ExpnKind::Macro(MacroKind::Attr, sym::derive),
item.span(),
self.cx.sess.parse_sess.edition,
None,
)
}),
);
expn_data.parent = self.cx.current_expansion.id;
Some(expn_data)
}
_ => None,
};
let expn_id = ExpnId::fresh(expn_data);
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_mir/src/transform/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,11 +742,11 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Integrator<'a, 'tcx> {
}

fn visit_span(&mut self, span: &mut Span) {
let mut expn_data =
ExpnData::default(ExpnKind::Inlined, *span, self.tcx.sess.edition(), None);
expn_data.def_site = self.body_span;
// Make sure that all spans track the fact that they were inlined.
*span = self.callsite_span.fresh_expansion(ExpnData {
def_site: self.body_span,
..ExpnData::default(ExpnKind::Inlined, *span, self.tcx.sess.edition(), None)
});
*span = self.callsite_span.fresh_expansion(expn_data);
}

fn visit_place(&mut self, place: &mut Place<'tcx>, context: PlaceContext, location: Location) {
Expand Down
44 changes: 42 additions & 2 deletions compiler/rustc_span/src/hygiene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,20 @@ impl Span {
self.with_ctxt(data.apply_mark(SyntaxContext::root(), expn_id, transparency))
})
}

/// Reuses the span but adds information like the kind of the desugaring and features that are
/// allowed inside this span.
pub fn mark_with_reason(
self,
allow_internal_unstable: Option<Lrc<[Symbol]>>,
reason: DesugaringKind,
edition: Edition,
) -> Span {
self.fresh_expansion(ExpnData {
allow_internal_unstable,
..ExpnData::default(ExpnKind::Desugaring(reason), self, edition, None)
})
}
}

/// A subset of properties from both macro definition and macro call available through global data.
Expand Down Expand Up @@ -699,21 +713,47 @@ pub struct ExpnData {
/// created locally - when our serialized metadata is decoded,
/// foreign `ExpnId`s will have their `ExpnData` looked up
/// from the crate specified by `Crate
pub krate: CrateNum,
krate: CrateNum,
/// The raw that this `ExpnData` had in its original crate.
/// An `ExpnData` can be created before being assigned an `ExpnId`,
/// so this might be `None` until `set_expn_data` is called
// This is used only for serialization/deserialization purposes:
// two `ExpnData`s that differ only in their `orig_id` should
// be considered equivalent.
#[stable_hasher(ignore)]
pub orig_id: Option<u32>,
orig_id: Option<u32>,
}

// This would require special handling of `orig_id` and `parent`
impl !PartialEq for ExpnData {}

impl ExpnData {
pub fn new(
kind: ExpnKind,
parent: ExpnId,
call_site: Span,
def_site: Span,
allow_internal_unstable: Option<Lrc<[Symbol]>>,
allow_internal_unsafe: bool,
local_inner_macros: bool,
edition: Edition,
macro_def_id: Option<DefId>,
) -> ExpnData {
ExpnData {
kind,
parent,
call_site,
def_site,
allow_internal_unstable,
allow_internal_unsafe,
local_inner_macros,
edition,
macro_def_id,
krate: LOCAL_CRATE,
orig_id: None,
}
}

/// Constructs expansion data with default properties.
pub fn default(
kind: ExpnKind,
Expand Down