metadata: Eliminate FullProcMacro
Fix caching of loaded proc macros
This commit is contained in:
parent
52c62eaae4
commit
2065ee9acc
@ -95,11 +95,6 @@ pub struct CrateMetadata {
|
||||
pub raw_proc_macros: Option<&'static [ProcMacro]>,
|
||||
}
|
||||
|
||||
pub struct FullProcMacro {
|
||||
pub name: ast::Name,
|
||||
pub ext: Lrc<SyntaxExtension>
|
||||
}
|
||||
|
||||
pub struct CStore {
|
||||
metas: RwLock<IndexVec<CrateNum, Option<Lrc<CrateMetadata>>>>,
|
||||
/// Map from NodeId's of local extern crate statements to crate numbers
|
||||
@ -109,7 +104,7 @@ pub struct CStore {
|
||||
|
||||
pub enum LoadedMacro {
|
||||
MacroDef(ast::Item),
|
||||
ProcMacro(Lrc<SyntaxExtension>),
|
||||
ProcMacro(SyntaxExtension),
|
||||
}
|
||||
|
||||
impl CStore {
|
||||
|
@ -434,7 +434,7 @@ impl cstore::CStore {
|
||||
pub fn load_macro_untracked(&self, id: DefId, sess: &Session) -> LoadedMacro {
|
||||
let data = self.get_crate_data(id.krate);
|
||||
if data.is_proc_macro_crate() {
|
||||
return LoadedMacro::ProcMacro(data.get_proc_macro(id.index, sess).ext);
|
||||
return LoadedMacro::ProcMacro(data.load_proc_macro(id.index, sess));
|
||||
}
|
||||
|
||||
let def = data.get_macro(id.index);
|
||||
|
@ -1,6 +1,6 @@
|
||||
// Decoding metadata from a single crate's metadata
|
||||
|
||||
use crate::cstore::{self, CrateMetadata, MetadataBlob, NativeLibrary, ForeignModule, FullProcMacro};
|
||||
use crate::cstore::{self, CrateMetadata, MetadataBlob, NativeLibrary, ForeignModule};
|
||||
use crate::schema::*;
|
||||
|
||||
use rustc_data_structures::indexed_vec::IndexVec;
|
||||
@ -512,26 +512,8 @@ impl<'a, 'tcx> CrateMetadata {
|
||||
self.entry(index).span.decode((self, sess))
|
||||
}
|
||||
|
||||
|
||||
pub fn get_proc_macro(&self, id: DefIndex, sess: &Session) -> FullProcMacro {
|
||||
if sess.opts.debugging_opts.dual_proc_macros {
|
||||
let host_lib = self.host_lib.as_ref().unwrap();
|
||||
self.load_proc_macro(
|
||||
&host_lib.metadata.get_root(),
|
||||
id,
|
||||
sess
|
||||
)
|
||||
} else {
|
||||
self.load_proc_macro(&self.root, id, sess)
|
||||
}
|
||||
}
|
||||
|
||||
fn load_proc_macro(&self, root: &CrateRoot<'_>,
|
||||
id: DefIndex,
|
||||
sess: &Session)
|
||||
-> FullProcMacro {
|
||||
let raw_macro = self.raw_proc_macro(id);
|
||||
let (name, kind, helper_attrs) = match *raw_macro {
|
||||
crate fn load_proc_macro(&self, id: DefIndex, sess: &Session) -> SyntaxExtension {
|
||||
let (name, kind, helper_attrs) = match *self.raw_proc_macro(id) {
|
||||
ProcMacro::CustomDerive { trait_name, attributes, client } => {
|
||||
let helper_attrs =
|
||||
attributes.iter().cloned().map(Symbol::intern).collect::<Vec<_>>();
|
||||
@ -550,20 +532,21 @@ impl<'a, 'tcx> CrateMetadata {
|
||||
name, SyntaxExtensionKind::Bang(Box::new(BangProcMacro { client })), Vec::new()
|
||||
)
|
||||
};
|
||||
let name = Symbol::intern(name);
|
||||
let edition = if sess.opts.debugging_opts.dual_proc_macros {
|
||||
self.host_lib.as_ref().unwrap().metadata.get_root().edition
|
||||
} else {
|
||||
self.root.edition
|
||||
};
|
||||
|
||||
FullProcMacro {
|
||||
name,
|
||||
ext: Lrc::new(SyntaxExtension::new(
|
||||
&sess.parse_sess,
|
||||
kind,
|
||||
self.get_span(id, sess),
|
||||
helper_attrs,
|
||||
root.edition,
|
||||
name,
|
||||
&self.get_attributes(&self.entry(id), sess),
|
||||
)),
|
||||
}
|
||||
SyntaxExtension::new(
|
||||
&sess.parse_sess,
|
||||
kind,
|
||||
self.get_span(id, sess),
|
||||
helper_attrs,
|
||||
edition,
|
||||
Symbol::intern(name),
|
||||
&self.get_attributes(&self.entry(id), sess),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn get_trait_def(&self, item_id: DefIndex, sess: &Session) -> ty::TraitDef {
|
||||
|
@ -150,12 +150,12 @@ impl<'a> Resolver<'a> {
|
||||
return Some(ext.clone());
|
||||
}
|
||||
|
||||
let macro_def = match self.cstore.load_macro_untracked(def_id, &self.session) {
|
||||
LoadedMacro::MacroDef(macro_def) => macro_def,
|
||||
LoadedMacro::ProcMacro(ext) => return Some(ext),
|
||||
};
|
||||
let ext = Lrc::new(match self.cstore.load_macro_untracked(def_id, &self.session) {
|
||||
LoadedMacro::MacroDef(item) =>
|
||||
self.compile_macro(&item, self.cstore.crate_edition_untracked(def_id.krate)),
|
||||
LoadedMacro::ProcMacro(ext) => ext,
|
||||
});
|
||||
|
||||
let ext = self.compile_macro(¯o_def, self.cstore.crate_edition_untracked(def_id.krate));
|
||||
self.macro_map.insert(def_id, ext.clone());
|
||||
Some(ext)
|
||||
}
|
||||
@ -1104,7 +1104,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
|
||||
let expansion = parent_scope.expansion;
|
||||
let (ext, ident, span, is_legacy) = match &item.node {
|
||||
ItemKind::MacroDef(def) => {
|
||||
let ext = self.r.compile_macro(item, self.r.session.edition());
|
||||
let ext = Lrc::new(self.r.compile_macro(item, self.r.session.edition()));
|
||||
(ext, item.ident, item.span, def.legacy)
|
||||
}
|
||||
ItemKind::Fn(..) => match Self::proc_macro_stub(item) {
|
||||
|
@ -800,7 +800,7 @@ impl<'a> Resolver<'a> {
|
||||
|
||||
/// Compile the macro into a `SyntaxExtension` and possibly replace it with a pre-defined
|
||||
/// extension partially or entirely for built-in macros and legacy plugin macros.
|
||||
crate fn compile_macro(&mut self, item: &ast::Item, edition: Edition) -> Lrc<SyntaxExtension> {
|
||||
crate fn compile_macro(&mut self, item: &ast::Item, edition: Edition) -> SyntaxExtension {
|
||||
let mut result = macro_rules::compile(
|
||||
&self.session.parse_sess, self.session.features_untracked(), item, edition
|
||||
);
|
||||
@ -822,6 +822,6 @@ impl<'a> Resolver<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
Lrc::new(result)
|
||||
result
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user