mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 07:14:28 +00:00
Use tables for macros.
This commit is contained in:
parent
ca9f5645f3
commit
1ddb944311
@ -4,7 +4,6 @@ use crate::creader::{CStore, CrateMetadataRef};
|
||||
use crate::rmeta::*;
|
||||
|
||||
use rustc_ast as ast;
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_data_structures::captures::Captures;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::svh::Svh;
|
||||
@ -1025,10 +1024,15 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
||||
let vis = self.get_visibility(child_index);
|
||||
let span = self.get_span(child_index, sess);
|
||||
let macro_rules = match kind {
|
||||
DefKind::Macro(..) => match self.kind(child_index) {
|
||||
EntryKind::MacroDef(_, macro_rules) => macro_rules,
|
||||
_ => unreachable!(),
|
||||
},
|
||||
DefKind::Macro(..) => {
|
||||
self.root
|
||||
.tables
|
||||
.macro_definition
|
||||
.get(self, child_index)
|
||||
.unwrap()
|
||||
.decode((self, sess))
|
||||
.macro_rules
|
||||
}
|
||||
_ => false,
|
||||
};
|
||||
|
||||
@ -1344,8 +1348,8 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
||||
|
||||
fn get_macro(self, id: DefIndex, sess: &Session) -> ast::MacroDef {
|
||||
match self.kind(id) {
|
||||
EntryKind::MacroDef(mac_args, macro_rules) => {
|
||||
ast::MacroDef { body: P(mac_args.decode((self, sess))), macro_rules }
|
||||
EntryKind::MacroDef => {
|
||||
self.root.tables.macro_definition.get(self, id).unwrap().decode((self, sess))
|
||||
}
|
||||
_ => bug!(),
|
||||
}
|
||||
|
@ -1512,7 +1512,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||
EntryKind::Fn
|
||||
}
|
||||
hir::ItemKind::Macro(ref macro_def, _) => {
|
||||
EntryKind::MacroDef(self.lazy(&*macro_def.body), macro_def.macro_rules)
|
||||
record!(self.tables.macro_definition[def_id] <- macro_def);
|
||||
EntryKind::MacroDef
|
||||
}
|
||||
hir::ItemKind::Mod(ref m) => {
|
||||
return self.encode_info_for_mod(item.def_id, m);
|
||||
@ -1819,7 +1820,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||
|
||||
let def_id = id.to_def_id();
|
||||
self.tables.opt_def_kind.set(def_id.index, DefKind::Macro(macro_kind));
|
||||
record!(self.tables.kind[def_id] <- EntryKind::ProcMacro(macro_kind));
|
||||
self.tables.proc_macro.set(def_id.index, macro_kind);
|
||||
record!(self.tables.kind[def_id] <- EntryKind::ProcMacro);
|
||||
self.encode_attrs(id);
|
||||
record!(self.tables.def_keys[def_id] <- def_key);
|
||||
record!(self.tables.def_ident_span[def_id] <- span);
|
||||
|
@ -395,6 +395,8 @@ define_tables! {
|
||||
may_have_doc_links: Table<DefIndex, ()>,
|
||||
variant_data: Table<DefIndex, LazyValue<VariantData>>,
|
||||
assoc_container: Table<DefIndex, ty::AssocItemContainer>,
|
||||
macro_definition: Table<DefIndex, LazyValue<ast::MacroDef>>,
|
||||
proc_macro: Table<DefIndex, MacroKind>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, MetadataEncodable, MetadataDecodable)]
|
||||
@ -418,8 +420,8 @@ enum EntryKind {
|
||||
Fn,
|
||||
ForeignFn,
|
||||
Mod(LazyArray<ModChild>),
|
||||
MacroDef(LazyValue<ast::MacArgs>, /*macro_rules*/ bool),
|
||||
ProcMacro(MacroKind),
|
||||
MacroDef,
|
||||
ProcMacro,
|
||||
Closure,
|
||||
Generator,
|
||||
Trait,
|
||||
|
@ -148,6 +148,14 @@ fixed_size_enum! {
|
||||
}
|
||||
}
|
||||
|
||||
fixed_size_enum! {
|
||||
MacroKind {
|
||||
( Attr )
|
||||
( Bang )
|
||||
( Derive )
|
||||
}
|
||||
}
|
||||
|
||||
// We directly encode `DefPathHash` because a `LazyValue` would incur a 25% cost.
|
||||
impl FixedSizeEncoding for Option<DefPathHash> {
|
||||
type ByteArray = [u8; 16];
|
||||
|
@ -64,7 +64,7 @@ trivially_parameterized_over_tcx! {
|
||||
ty::adjustment::CoerceUnsizedInfo,
|
||||
ty::fast_reject::SimplifiedTypeGen<DefId>,
|
||||
rustc_ast::Attribute,
|
||||
rustc_ast::MacArgs,
|
||||
rustc_ast::MacroDef,
|
||||
rustc_attr::ConstStability,
|
||||
rustc_attr::DefaultBodyStability,
|
||||
rustc_attr::Deprecation,
|
||||
|
Loading…
Reference in New Issue
Block a user