Skip to content

Commit e89a228

Browse files
Encode adt flags directly and make fundamental flag EncodeCrossCrate::No
1 parent 30f0108 commit e89a228

File tree

8 files changed

+32
-8
lines changed

8 files changed

+32
-8
lines changed

compiler/rustc_feature/src/builtin_attrs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
654654
// Internal attributes: Type system related:
655655
// ==========================================================================
656656

657-
gated!(fundamental, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::Yes, experimental!(fundamental)),
657+
gated!(fundamental, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No, experimental!(fundamental)),
658658
gated!(
659659
may_dangle, Normal, template!(Word), WarnFollowing,
660660
EncodeCrossCrate::No, dropck_eyepatch,

compiler/rustc_hir_analysis/src/collect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1180,7 +1180,7 @@ fn adt_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::AdtDef<'_> {
11801180
}
11811181
_ => bug!("{:?} is not an ADT", item.owner_id.def_id),
11821182
};
1183-
tcx.mk_adt_def(def_id.to_def_id(), kind, variants, repr, is_anonymous)
1183+
tcx.mk_adt_def(def_id, kind, variants, repr, is_anonymous)
11841184
}
11851185

11861186
fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {

compiler/rustc_metadata/src/rmeta/decoder.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,9 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
11511151
DefKind::Union => ty::AdtKind::Union,
11521152
_ => bug!("get_adt_def called on a non-ADT {:?}", did),
11531153
};
1154+
11541155
let repr = self.root.tables.repr_options.get(self, item_id).unwrap().decode(self);
1156+
let flags = self.root.tables.adt_flags.get(self, item_id).unwrap().decode(self);
11551157

11561158
let mut variants: Vec<_> = if let ty::AdtKind::Enum = adt_kind {
11571159
self.root
@@ -1174,12 +1176,11 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
11741176

11751177
variants.sort_by_key(|(idx, _)| *idx);
11761178

1177-
tcx.mk_adt_def(
1179+
tcx.mk_adt_def_from_flags(
11781180
did,
1179-
adt_kind,
11801181
variants.into_iter().map(|(_, variant)| variant).collect(),
1182+
flags,
11811183
repr,
1182-
false,
11831184
)
11841185
}
11851186

compiler/rustc_metadata/src/rmeta/encoder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1533,6 +1533,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
15331533
let tcx = self.tcx;
15341534
let adt_def = tcx.adt_def(def_id);
15351535
record!(self.tables.repr_options[def_id] <- adt_def.repr());
1536+
record!(self.tables.adt_flags[def_id] <- adt_def.flags());
15361537

15371538
let params_in_repr = self.tcx.params_in_repr(def_id);
15381539
record!(self.tables.params_in_repr[def_id] <- params_in_repr);

compiler/rustc_metadata/src/rmeta/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ define_tables! {
452452
expn_that_defined: Table<DefIndex, LazyValue<ExpnId>>,
453453
params_in_repr: Table<DefIndex, LazyValue<BitSet<u32>>>,
454454
repr_options: Table<DefIndex, LazyValue<ReprOptions>>,
455+
adt_flags: Table<DefIndex, LazyValue<ty::AdtFlags>>,
455456
// `def_keys` and `def_path_hashes` represent a lazy version of a
456457
// `DefPathTable`. This allows us to avoid deserializing an entire
457458
// `DefPathTable` up front, since we may only ever use a few

compiler/rustc_middle/src/ty/adt.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_data_structures::stable_hasher::HashingControls;
99
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
1010
use rustc_errors::ErrorGuaranteed;
1111
use rustc_hir::def::{CtorKind, DefKind, Res};
12-
use rustc_hir::def_id::DefId;
12+
use rustc_hir::def_id::{DefId, LocalDefId};
1313
use rustc_hir::{self as hir, LangItem};
1414
use rustc_index::{IndexSlice, IndexVec};
1515
use rustc_macros::{HashStable, TyDecodable, TyEncodable};
@@ -249,15 +249,25 @@ impl Into<DataTypeKind> for AdtKind {
249249
}
250250

251251
impl AdtDefData {
252+
pub(super) fn new_from_flags(
253+
did: DefId,
254+
variants: IndexVec<VariantIdx, VariantDef>,
255+
flags: AdtFlags,
256+
repr: ReprOptions,
257+
) -> Self {
258+
AdtDefData { did, variants, flags, repr }
259+
}
260+
252261
/// Creates a new `AdtDefData`.
253262
pub(super) fn new(
254263
tcx: TyCtxt<'_>,
255-
did: DefId,
264+
did: LocalDefId,
256265
kind: AdtKind,
257266
variants: IndexVec<VariantIdx, VariantDef>,
258267
repr: ReprOptions,
259268
is_anonymous: bool,
260269
) -> Self {
270+
let did = did.to_def_id();
261271
debug!(
262272
"AdtDef::new({:?}, {:?}, {:?}, {:?}, {:?})",
263273
did, kind, variants, repr, is_anonymous

compiler/rustc_middle/src/ty/context.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -1393,9 +1393,19 @@ impl<'tcx> TyCtxt<'tcx> {
13931393
self.arena.alloc(Steal::new(promoted))
13941394
}
13951395

1396-
pub fn mk_adt_def(
1396+
pub fn mk_adt_def_from_flags(
13971397
self,
13981398
did: DefId,
1399+
variants: IndexVec<VariantIdx, ty::VariantDef>,
1400+
flags: ty::AdtFlags,
1401+
repr: ReprOptions,
1402+
) -> ty::AdtDef<'tcx> {
1403+
self.mk_adt_def_from_data(ty::AdtDefData::new_from_flags(did, variants, flags, repr))
1404+
}
1405+
1406+
pub fn mk_adt_def(
1407+
self,
1408+
did: LocalDefId,
13991409
kind: AdtKind,
14001410
variants: IndexVec<VariantIdx, ty::VariantDef>,
14011411
repr: ReprOptions,

compiler/rustc_middle/src/ty/parameterized.rs

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ trivially_parameterized_over_tcx! {
6363
crate::middle::lib_features::FeatureStability,
6464
crate::middle::resolve_bound_vars::ObjectLifetimeDefault,
6565
crate::mir::ConstQualifs,
66+
ty::AdtFlags,
6667
ty::AssocItemContainer,
6768
ty::Asyncness,
6869
ty::DeducedParamAttrs,

0 commit comments

Comments
 (0)