Skip to content

Commit 1ddb944

Browse files
committed
Use tables for macros.
1 parent ca9f564 commit 1ddb944

File tree

5 files changed

+28
-12
lines changed

5 files changed

+28
-12
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::creader::{CStore, CrateMetadataRef};
44
use crate::rmeta::*;
55

66
use rustc_ast as ast;
7-
use rustc_ast::ptr::P;
87
use rustc_data_structures::captures::Captures;
98
use rustc_data_structures::fx::FxHashMap;
109
use rustc_data_structures::svh::Svh;
@@ -1025,10 +1024,15 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
10251024
let vis = self.get_visibility(child_index);
10261025
let span = self.get_span(child_index, sess);
10271026
let macro_rules = match kind {
1028-
DefKind::Macro(..) => match self.kind(child_index) {
1029-
EntryKind::MacroDef(_, macro_rules) => macro_rules,
1030-
_ => unreachable!(),
1031-
},
1027+
DefKind::Macro(..) => {
1028+
self.root
1029+
.tables
1030+
.macro_definition
1031+
.get(self, child_index)
1032+
.unwrap()
1033+
.decode((self, sess))
1034+
.macro_rules
1035+
}
10321036
_ => false,
10331037
};
10341038

@@ -1344,8 +1348,8 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
13441348

13451349
fn get_macro(self, id: DefIndex, sess: &Session) -> ast::MacroDef {
13461350
match self.kind(id) {
1347-
EntryKind::MacroDef(mac_args, macro_rules) => {
1348-
ast::MacroDef { body: P(mac_args.decode((self, sess))), macro_rules }
1351+
EntryKind::MacroDef => {
1352+
self.root.tables.macro_definition.get(self, id).unwrap().decode((self, sess))
13491353
}
13501354
_ => bug!(),
13511355
}

compiler/rustc_metadata/src/rmeta/encoder.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1512,7 +1512,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
15121512
EntryKind::Fn
15131513
}
15141514
hir::ItemKind::Macro(ref macro_def, _) => {
1515-
EntryKind::MacroDef(self.lazy(&*macro_def.body), macro_def.macro_rules)
1515+
record!(self.tables.macro_definition[def_id] <- macro_def);
1516+
EntryKind::MacroDef
15161517
}
15171518
hir::ItemKind::Mod(ref m) => {
15181519
return self.encode_info_for_mod(item.def_id, m);
@@ -1819,7 +1820,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
18191820

18201821
let def_id = id.to_def_id();
18211822
self.tables.opt_def_kind.set(def_id.index, DefKind::Macro(macro_kind));
1822-
record!(self.tables.kind[def_id] <- EntryKind::ProcMacro(macro_kind));
1823+
self.tables.proc_macro.set(def_id.index, macro_kind);
1824+
record!(self.tables.kind[def_id] <- EntryKind::ProcMacro);
18231825
self.encode_attrs(id);
18241826
record!(self.tables.def_keys[def_id] <- def_key);
18251827
record!(self.tables.def_ident_span[def_id] <- span);

compiler/rustc_metadata/src/rmeta/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,8 @@ define_tables! {
395395
may_have_doc_links: Table<DefIndex, ()>,
396396
variant_data: Table<DefIndex, LazyValue<VariantData>>,
397397
assoc_container: Table<DefIndex, ty::AssocItemContainer>,
398+
macro_definition: Table<DefIndex, LazyValue<ast::MacroDef>>,
399+
proc_macro: Table<DefIndex, MacroKind>,
398400
}
399401

400402
#[derive(Copy, Clone, MetadataEncodable, MetadataDecodable)]
@@ -418,8 +420,8 @@ enum EntryKind {
418420
Fn,
419421
ForeignFn,
420422
Mod(LazyArray<ModChild>),
421-
MacroDef(LazyValue<ast::MacArgs>, /*macro_rules*/ bool),
422-
ProcMacro(MacroKind),
423+
MacroDef,
424+
ProcMacro,
423425
Closure,
424426
Generator,
425427
Trait,

compiler/rustc_metadata/src/rmeta/table.rs

+8
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,14 @@ fixed_size_enum! {
148148
}
149149
}
150150

151+
fixed_size_enum! {
152+
MacroKind {
153+
( Attr )
154+
( Bang )
155+
( Derive )
156+
}
157+
}
158+
151159
// We directly encode `DefPathHash` because a `LazyValue` would incur a 25% cost.
152160
impl FixedSizeEncoding for Option<DefPathHash> {
153161
type ByteArray = [u8; 16];

compiler/rustc_middle/src/ty/parameterized.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ trivially_parameterized_over_tcx! {
6464
ty::adjustment::CoerceUnsizedInfo,
6565
ty::fast_reject::SimplifiedTypeGen<DefId>,
6666
rustc_ast::Attribute,
67-
rustc_ast::MacArgs,
67+
rustc_ast::MacroDef,
6868
rustc_attr::ConstStability,
6969
rustc_attr::DefaultBodyStability,
7070
rustc_attr::Deprecation,

0 commit comments

Comments
 (0)