Skip to content

Commit 50568b8

Browse files
committed
metadata: Tweak the way in which declarative macros are encoded
To make the `macro_rules` flag more readily available without decoding everything else
1 parent 17b1afd commit 50568b8

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::rmeta::table::{FixedSizeEncoding, Table};
55
use crate::rmeta::*;
66

77
use rustc_ast as ast;
8+
use rustc_ast::ptr::P;
89
use rustc_attr as attr;
910
use rustc_data_structures::captures::Captures;
1011
use rustc_data_structures::fx::FxHashMap;
@@ -1402,9 +1403,11 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
14021403
tcx.arena.alloc_from_iter(self.root.exported_symbols.decode((self, tcx)))
14031404
}
14041405

1405-
fn get_macro(self, id: DefIndex, sess: &Session) -> MacroDef {
1406+
fn get_macro(self, id: DefIndex, sess: &Session) -> ast::MacroDef {
14061407
match self.kind(id) {
1407-
EntryKind::MacroDef(macro_def) => macro_def.decode((self, sess)),
1408+
EntryKind::MacroDef(mac_args, macro_rules) => {
1409+
ast::MacroDef { body: P(mac_args.decode((self, sess))), macro_rules }
1410+
}
14081411
_ => bug!(),
14091412
}
14101413
}

compiler/rustc_metadata/src/rmeta/encoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1407,7 +1407,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
14071407
EntryKind::Fn(self.lazy(data))
14081408
}
14091409
hir::ItemKind::Macro(ref macro_def, _) => {
1410-
EntryKind::MacroDef(self.lazy(macro_def.clone()))
1410+
EntryKind::MacroDef(self.lazy(&*macro_def.body), macro_def.macro_rules)
14111411
}
14121412
hir::ItemKind::Mod(ref m) => {
14131413
return self.encode_info_for_mod(item.def_id, m);

compiler/rustc_metadata/src/rmeta/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use decoder::Metadata;
22
use def_path_hash_map::DefPathHashMapRef;
33
use table::{Table, TableBuilder};
44

5-
use rustc_ast::{self as ast, MacroDef};
5+
use rustc_ast as ast;
66
use rustc_attr as attr;
77
use rustc_data_structures::svh::Svh;
88
use rustc_data_structures::sync::MetadataRef;
@@ -350,7 +350,7 @@ enum EntryKind {
350350
Fn(Lazy<FnData>),
351351
ForeignFn(Lazy<FnData>),
352352
Mod(Lazy<[ModChild]>),
353-
MacroDef(Lazy<MacroDef>),
353+
MacroDef(Lazy<ast::MacArgs>, /*macro_rules*/ bool),
354354
ProcMacro(MacroKind),
355355
Closure,
356356
Generator,

0 commit comments

Comments
 (0)