Skip to content

Commit 65f6819

Browse files
Encode adt flags directly and make fundamental flag EncodeCrossCrate::No
1 parent 59a4f02 commit 65f6819

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};
@@ -253,15 +253,25 @@ impl Into<DataTypeKind> for AdtKind {
253253
}
254254

255255
impl AdtDefData {
256+
pub(super) fn new_from_flags(
257+
did: DefId,
258+
variants: IndexVec<VariantIdx, VariantDef>,
259+
flags: AdtFlags,
260+
repr: ReprOptions,
261+
) -> Self {
262+
AdtDefData { did, variants, flags, repr }
263+
}
264+
256265
/// Creates a new `AdtDefData`.
257266
pub(super) fn new(
258267
tcx: TyCtxt<'_>,
259-
did: DefId,
268+
did: LocalDefId,
260269
kind: AdtKind,
261270
variants: IndexVec<VariantIdx, VariantDef>,
262271
repr: ReprOptions,
263272
is_anonymous: bool,
264273
) -> Self {
274+
let did = did.to_def_id();
265275
debug!(
266276
"AdtDef::new({:?}, {:?}, {:?}, {:?}, {:?})",
267277
did, kind, variants, repr, is_anonymous

compiler/rustc_middle/src/ty/context.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -1408,9 +1408,19 @@ impl<'tcx> TyCtxt<'tcx> {
14081408
self.arena.alloc(Steal::new(promoted))
14091409
}
14101410

1411-
pub fn mk_adt_def(
1411+
pub fn mk_adt_def_from_flags(
14121412
self,
14131413
did: DefId,
1414+
variants: IndexVec<VariantIdx, ty::VariantDef>,
1415+
flags: ty::AdtFlags,
1416+
repr: ReprOptions,
1417+
) -> ty::AdtDef<'tcx> {
1418+
self.mk_adt_def_from_data(ty::AdtDefData::new_from_flags(did, variants, flags, repr))
1419+
}
1420+
1421+
pub fn mk_adt_def(
1422+
self,
1423+
did: LocalDefId,
14141424
kind: AdtKind,
14151425
variants: IndexVec<VariantIdx, ty::VariantDef>,
14161426
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)