Skip to content

Commit 30ae64e

Browse files
committed
Create a table for fn_has_self_parameter.
1 parent 1ddb944 commit 30ae64e

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -1115,10 +1115,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
11151115
}
11161116

11171117
fn get_fn_has_self_parameter(self, id: DefIndex) -> bool {
1118-
match self.kind(id) {
1119-
EntryKind::AssocFn { has_self } => has_self,
1120-
_ => false,
1121-
}
1118+
self.root.tables.fn_has_self_parameter.get(self, id).is_some()
11221119
}
11231120

11241121
fn get_associated_item_def_ids(
@@ -1138,12 +1135,13 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
11381135
fn get_associated_item(self, id: DefIndex) -> ty::AssocItem {
11391136
let name = self.item_name(id);
11401137

1141-
let (kind, has_self) = match self.kind(id) {
1142-
EntryKind::AssocConst => (ty::AssocKind::Const, false),
1143-
EntryKind::AssocFn { has_self } => (ty::AssocKind::Fn, has_self),
1144-
EntryKind::AssocType => (ty::AssocKind::Type, false),
1138+
let kind = match self.kind(id) {
1139+
EntryKind::AssocConst => ty::AssocKind::Const,
1140+
EntryKind::AssocFn => ty::AssocKind::Fn,
1141+
EntryKind::AssocType => ty::AssocKind::Type,
11451142
_ => bug!("cannot get associated-item of `{:?}`", self.def_key(id)),
11461143
};
1144+
let has_self = self.get_fn_has_self_parameter(id);
11471145
let container = self.root.tables.assoc_container.get(self, id).unwrap();
11481146

11491147
ty::AssocItem {

compiler/rustc_metadata/src/rmeta/encoder.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -1344,9 +1344,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
13441344
};
13451345
self.tables.asyncness.set(def_id.index, m_sig.header.asyncness);
13461346
self.tables.constness.set(def_id.index, hir::Constness::NotConst);
1347-
record!(self.tables.kind[def_id] <- EntryKind::AssocFn {
1348-
has_self: trait_item.fn_has_self_parameter,
1349-
});
1347+
if trait_item.fn_has_self_parameter {
1348+
self.tables.fn_has_self_parameter.set(def_id.index, ());
1349+
}
1350+
record!(self.tables.kind[def_id] <- EntryKind::AssocFn );
13501351
}
13511352
ty::AssocKind::Type => {
13521353
self.encode_explicit_item_bounds(def_id);
@@ -1382,9 +1383,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
13821383
hir::Constness::NotConst
13831384
};
13841385
self.tables.constness.set(def_id.index, constness);
1385-
record!(self.tables.kind[def_id] <- EntryKind::AssocFn {
1386-
has_self: impl_item.fn_has_self_parameter,
1387-
});
1386+
if impl_item.fn_has_self_parameter {
1387+
self.tables.fn_has_self_parameter.set(def_id.index, ());
1388+
}
1389+
record!(self.tables.kind[def_id] <- EntryKind::AssocFn);
13881390
}
13891391
ty::AssocKind::Type => {
13901392
record!(self.tables.kind[def_id] <- EntryKind::AssocType);

compiler/rustc_metadata/src/rmeta/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,8 @@ define_tables! {
397397
assoc_container: Table<DefIndex, ty::AssocItemContainer>,
398398
macro_definition: Table<DefIndex, LazyValue<ast::MacroDef>>,
399399
proc_macro: Table<DefIndex, MacroKind>,
400+
// Slot is full when there is a self parameter.
401+
fn_has_self_parameter: Table<DefIndex, ()>,
400402
}
401403

402404
#[derive(Copy, Clone, MetadataEncodable, MetadataDecodable)]
@@ -426,7 +428,7 @@ enum EntryKind {
426428
Generator,
427429
Trait,
428430
Impl,
429-
AssocFn { has_self: bool },
431+
AssocFn,
430432
AssocType,
431433
AssocConst,
432434
TraitAlias,

0 commit comments

Comments
 (0)