1
Fork 0

Use LocalExpnId where possible.

This commit is contained in:
Camille GILLOT 2021-06-25 20:43:04 +02:00
parent 6e78d6c9d6
commit 078dd37f88
19 changed files with 169 additions and 147 deletions

View file

@ -16,7 +16,7 @@ use rustc_parse::{self, nt_to_tokenstream, parser, MACRO_ARGUMENTS};
use rustc_session::{parse::ParseSess, Limit, Session};
use rustc_span::def_id::{CrateNum, DefId};
use rustc_span::edition::Edition;
use rustc_span::hygiene::{AstPass, ExpnData, ExpnId, ExpnKind};
use rustc_span::hygiene::{AstPass, ExpnData, ExpnKind, LocalExpnId};
use rustc_span::source_map::SourceMap;
use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::{FileName, MultiSpan, Span, DUMMY_SP};
@ -813,7 +813,7 @@ impl SyntaxExtension {
pub fn expn_data(
&self,
parent: ExpnId,
parent: LocalExpnId,
call_site: Span,
descr: Symbol,
macro_def_id: Option<DefId>,
@ -821,7 +821,7 @@ impl SyntaxExtension {
) -> ExpnData {
ExpnData::new(
ExpnKind::Macro(self.macro_kind(), descr),
parent,
parent.to_expn_id(),
call_site,
self.span,
self.allow_internal_unstable.clone(),
@ -843,7 +843,11 @@ pub trait ResolverExpand {
fn next_node_id(&mut self) -> NodeId;
fn resolve_dollar_crates(&mut self);
fn visit_ast_fragment_with_placeholders(&mut self, expn_id: ExpnId, fragment: &AstFragment);
fn visit_ast_fragment_with_placeholders(
&mut self,
expn_id: LocalExpnId,
fragment: &AstFragment,
);
fn register_builtin_macro(&mut self, name: Symbol, ext: SyntaxExtensionKind);
fn expansion_for_ast_pass(
@ -852,37 +856,41 @@ pub trait ResolverExpand {
pass: AstPass,
features: &[Symbol],
parent_module_id: Option<NodeId>,
) -> ExpnId;
) -> LocalExpnId;
fn resolve_imports(&mut self);
fn resolve_macro_invocation(
&mut self,
invoc: &Invocation,
eager_expansion_root: ExpnId,
eager_expansion_root: LocalExpnId,
force: bool,
) -> Result<Lrc<SyntaxExtension>, Indeterminate>;
fn check_unused_macros(&mut self);
/// Some parent node that is close enough to the given macro call.
fn lint_node_id(&self, expn_id: ExpnId) -> NodeId;
fn lint_node_id(&self, expn_id: LocalExpnId) -> NodeId;
// Resolver interfaces for specific built-in macros.
/// Does `#[derive(...)]` attribute with the given `ExpnId` have built-in `Copy` inside it?
fn has_derive_copy(&self, expn_id: ExpnId) -> bool;
fn has_derive_copy(&self, expn_id: LocalExpnId) -> bool;
/// Resolve paths inside the `#[derive(...)]` attribute with the given `ExpnId`.
fn resolve_derives(
&mut self,
expn_id: ExpnId,
expn_id: LocalExpnId,
force: bool,
derive_paths: &dyn Fn() -> DeriveResolutions,
) -> Result<(), Indeterminate>;
/// Take resolutions for paths inside the `#[derive(...)]` attribute with the given `ExpnId`
/// back from resolver.
fn take_derive_resolutions(&mut self, expn_id: ExpnId) -> Option<DeriveResolutions>;
fn take_derive_resolutions(&mut self, expn_id: LocalExpnId) -> Option<DeriveResolutions>;
/// Path resolution logic for `#[cfg_accessible(path)]`.
fn cfg_accessible(&mut self, expn_id: ExpnId, path: &ast::Path) -> Result<bool, Indeterminate>;
fn cfg_accessible(
&mut self,
expn_id: LocalExpnId,
path: &ast::Path,
) -> Result<bool, Indeterminate>;
/// Decodes the proc-macro quoted span in the specified crate, with the specified id.
/// No caching is performed.
@ -913,7 +921,7 @@ impl ModuleData {
#[derive(Clone)]
pub struct ExpansionData {
pub id: ExpnId,
pub id: LocalExpnId,
pub depth: usize,
pub module: Rc<ModuleData>,
pub dir_ownership: DirOwnership,
@ -958,7 +966,7 @@ impl<'a> ExtCtxt<'a> {
extern_mod_loaded,
root_path: PathBuf::new(),
current_expansion: ExpansionData {
id: ExpnId::root(),
id: LocalExpnId::ROOT,
depth: 0,
module: Default::default(),
dir_ownership: DirOwnership::Owned { relative: None },
@ -995,19 +1003,19 @@ impl<'a> ExtCtxt<'a> {
/// Equivalent of `Span::def_site` from the proc macro API,
/// except that the location is taken from the span passed as an argument.
pub fn with_def_site_ctxt(&self, span: Span) -> Span {
span.with_def_site_ctxt(self.current_expansion.id)
span.with_def_site_ctxt(self.current_expansion.id.to_expn_id())
}
/// Equivalent of `Span::call_site` from the proc macro API,
/// except that the location is taken from the span passed as an argument.
pub fn with_call_site_ctxt(&self, span: Span) -> Span {
span.with_call_site_ctxt(self.current_expansion.id)
span.with_call_site_ctxt(self.current_expansion.id.to_expn_id())
}
/// Equivalent of `Span::mixed_site` from the proc macro API,
/// except that the location is taken from the span passed as an argument.
pub fn with_mixed_site_ctxt(&self, span: Span) -> Span {
span.with_mixed_site_ctxt(self.current_expansion.id)
span.with_mixed_site_ctxt(self.current_expansion.id.to_expn_id())
}
/// Returns span for the macro which originally caused the current expansion to happen.

View file

@ -31,7 +31,7 @@ use rustc_session::lint::BuiltinLintDiagnostics;
use rustc_session::parse::{feature_err, ParseSess};
use rustc_session::Limit;
use rustc_span::symbol::{sym, Ident};
use rustc_span::{ExpnId, FileName, Span};
use rustc_span::{FileName, LocalExpnId, Span};
use smallvec::{smallvec, SmallVec};
use std::ops::DerefMut;
@ -508,7 +508,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
.map(|(path, item, _exts)| {
// FIXME: Consider using the derive resolutions (`_exts`)
// instead of enqueuing the derives to be resolved again later.
let expn_id = ExpnId::fresh_empty();
let expn_id = LocalExpnId::fresh_empty();
derive_invocations.push((
Invocation {
kind: InvocationKind::Derive { path, item },
@ -993,7 +993,7 @@ struct InvocationCollector<'a, 'b> {
impl<'a, 'b> InvocationCollector<'a, 'b> {
fn collect(&mut self, fragment_kind: AstFragmentKind, kind: InvocationKind) -> AstFragment {
let expn_id = ExpnId::fresh_empty();
let expn_id = LocalExpnId::fresh_empty();
let vis = kind.placeholder_visibility();
self.invocations.push((
Invocation {

View file

@ -8,7 +8,7 @@ use rustc_ast::tokenstream::{DelimSpan, TokenStream, TokenTree, TreeAndSpacing};
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::sync::Lrc;
use rustc_errors::{pluralize, PResult};
use rustc_span::hygiene::{ExpnId, Transparency};
use rustc_span::hygiene::{LocalExpnId, Transparency};
use rustc_span::symbol::MacroRulesNormalizedIdent;
use rustc_span::Span;
@ -16,7 +16,7 @@ use smallvec::{smallvec, SmallVec};
use std::mem;
// A Marker adds the given mark to the syntax context.
struct Marker(ExpnId, Transparency);
struct Marker(LocalExpnId, Transparency);
impl MutVisitor for Marker {
fn token_visiting_enabled(&self) -> bool {
@ -24,7 +24,7 @@ impl MutVisitor for Marker {
}
fn visit_span(&mut self, span: &mut Span) {
*span = span.apply_mark(self.0, self.1)
*span = span.apply_mark(self.0.to_expn_id(), self.1)
}
}