Skip to content

Commit 512bd84

Browse files
committedSep 7, 2022
Auto merge of #94075 - mikebenfield:wip-enum, r=oli-obk
Use niche-filling optimization even when multiple variants have data. Fixes #46213
·
1.88.01.65.0
2 parents c2804e6 + d7a750b commit 512bd84

File tree

22 files changed

+377
-196
lines changed

22 files changed

+377
-196
lines changed
 

‎compiler/rustc_ast/src/ast.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3075,7 +3075,8 @@ mod size_asserts {
30753075
static_assert_size!(Block, 48);
30763076
static_assert_size!(Expr, 104);
30773077
static_assert_size!(ExprKind, 72);
3078-
static_assert_size!(Fn, 192);
3078+
#[cfg(not(bootstrap))]
3079+
static_assert_size!(Fn, 184);
30793080
static_assert_size!(ForeignItem, 96);
30803081
static_assert_size!(ForeignItemKind, 24);
30813082
static_assert_size!(GenericArg, 24);

‎compiler/rustc_codegen_cranelift/src/discriminant.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ pub(crate) fn codegen_set_discriminant<'tcx>(
4242
Variants::Multiple {
4343
tag: _,
4444
tag_field,
45-
tag_encoding: TagEncoding::Niche { dataful_variant, ref niche_variants, niche_start },
45+
tag_encoding: TagEncoding::Niche { untagged_variant, ref niche_variants, niche_start },
4646
variants: _,
4747
} => {
48-
if variant_index != dataful_variant {
48+
if variant_index != untagged_variant {
4949
let niche = place.place_field(fx, mir::Field::new(tag_field));
5050
let niche_value = variant_index.as_u32() - niche_variants.start().as_u32();
5151
let niche_value = ty::ScalarInt::try_from_uint(
@@ -113,7 +113,7 @@ pub(crate) fn codegen_get_discriminant<'tcx>(
113113
let res = CValue::by_val(val, dest_layout);
114114
dest.write_cvalue(fx, res);
115115
}
116-
TagEncoding::Niche { dataful_variant, ref niche_variants, niche_start } => {
116+
TagEncoding::Niche { untagged_variant, ref niche_variants, niche_start } => {
117117
// Rebase from niche values to discriminants, and check
118118
// whether the result is in range for the niche variants.
119119

@@ -169,8 +169,9 @@ pub(crate) fn codegen_get_discriminant<'tcx>(
169169
fx.bcx.ins().iadd_imm(relative_discr, i64::from(niche_variants.start().as_u32()))
170170
};
171171

172-
let dataful_variant = fx.bcx.ins().iconst(cast_to, i64::from(dataful_variant.as_u32()));
173-
let discr = fx.bcx.ins().select(is_niche, niche_discr, dataful_variant);
172+
let untagged_variant =
173+
fx.bcx.ins().iconst(cast_to, i64::from(untagged_variant.as_u32()));
174+
let discr = fx.bcx.ins().select(is_niche, niche_discr, untagged_variant);
174175
let res = CValue::by_val(discr, dest_layout);
175176
dest.write_cvalue(fx, res);
176177
}

‎compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ const SINGLE_VARIANT_VIRTUAL_DISR: u64 = 0;
9999
/// compiler versions.
100100
///
101101
/// Niche-tag enums have one special variant, usually called the
102-
/// "dataful variant". This variant has a field that
102+
/// "untagged variant". This variant has a field that
103103
/// doubles as the tag of the enum. The variant is active when the value of
104104
/// that field is within a pre-defined range. Therefore the variant struct
105105
/// has a `DISCR_BEGIN` and `DISCR_END` field instead of `DISCR_EXACT` in
@@ -249,7 +249,7 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>(
249249
None,
250250
),
251251
Variants::Multiple {
252-
tag_encoding: TagEncoding::Niche { dataful_variant, .. },
252+
tag_encoding: TagEncoding::Niche { untagged_variant, .. },
253253
ref variants,
254254
tag_field,
255255
..
@@ -260,7 +260,7 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>(
260260
enum_type_di_node,
261261
variants.indices(),
262262
tag_field,
263-
Some(dataful_variant),
263+
Some(untagged_variant),
264264
),
265265
}
266266
},
@@ -391,7 +391,7 @@ fn build_union_fields_for_enum<'ll, 'tcx>(
391391
enum_type_di_node: &'ll DIType,
392392
variant_indices: impl Iterator<Item = VariantIdx> + Clone,
393393
tag_field: usize,
394-
dataful_variant_index: Option<VariantIdx>,
394+
untagged_variant_index: Option<VariantIdx>,
395395
) -> SmallVec<&'ll DIType> {
396396
let tag_base_type = super::tag_base_type(cx, enum_type_and_layout);
397397

@@ -436,7 +436,7 @@ fn build_union_fields_for_enum<'ll, 'tcx>(
436436
variant_names_type_di_node,
437437
tag_base_type,
438438
tag_field,
439-
dataful_variant_index,
439+
untagged_variant_index,
440440
)
441441
}
442442

@@ -472,7 +472,7 @@ fn build_variant_struct_wrapper_type_di_node<'ll, 'tcx>(
472472
enum_or_generator_type_and_layout: TyAndLayout<'tcx>,
473473
enum_or_generator_type_di_node: &'ll DIType,
474474
variant_index: VariantIdx,
475-
dataful_variant_index: Option<VariantIdx>,
475+
untagged_variant_index: Option<VariantIdx>,
476476
variant_struct_type_di_node: &'ll DIType,
477477
variant_names_type_di_node: &'ll DIType,
478478
tag_base_type_di_node: &'ll DIType,
@@ -517,7 +517,7 @@ fn build_variant_struct_wrapper_type_di_node<'ll, 'tcx>(
517517
}
518518
}
519519
DiscrResult::Range(min, max) => {
520-
assert_eq!(Some(variant_index), dataful_variant_index);
520+
assert_eq!(Some(variant_index), untagged_variant_index);
521521
if is_128_bits {
522522
DiscrKind::Range128(min, max)
523523
} else {
@@ -757,7 +757,7 @@ fn build_union_fields_for_direct_tag_enum_or_generator<'ll, 'tcx>(
757757
discr_type_di_node: &'ll DIType,
758758
tag_base_type: Ty<'tcx>,
759759
tag_field: usize,
760-
dataful_variant_index: Option<VariantIdx>,
760+
untagged_variant_index: Option<VariantIdx>,
761761
) -> SmallVec<&'ll DIType> {
762762
let tag_base_type_di_node = type_di_node(cx, tag_base_type);
763763
let mut unions_fields = SmallVec::with_capacity(variant_field_infos.len() + 1);
@@ -776,7 +776,7 @@ fn build_union_fields_for_direct_tag_enum_or_generator<'ll, 'tcx>(
776776
enum_type_and_layout,
777777
enum_type_di_node,
778778
variant_member_info.variant_index,
779-
dataful_variant_index,
779+
untagged_variant_index,
780780
variant_member_info.variant_struct_type_di_node,
781781
discr_type_di_node,
782782
tag_base_type_di_node,

‎compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ impl DiscrResult {
417417
/// Returns the discriminant value corresponding to the variant index.
418418
///
419419
/// Will return `None` if there is less than two variants (because then the enum won't have)
420-
/// a tag, and if this is the dataful variant of a niche-layout enum (because then there is no
420+
/// a tag, and if this is the untagged variant of a niche-layout enum (because then there is no
421421
/// single discriminant value).
422422
fn compute_discriminant_value<'ll, 'tcx>(
423423
cx: &CodegenCx<'ll, 'tcx>,
@@ -430,11 +430,11 @@ fn compute_discriminant_value<'ll, 'tcx>(
430430
enum_type_and_layout.ty.discriminant_for_variant(cx.tcx, variant_index).unwrap().val,
431431
),
432432
&Variants::Multiple {
433-
tag_encoding: TagEncoding::Niche { ref niche_variants, niche_start, dataful_variant },
433+
tag_encoding: TagEncoding::Niche { ref niche_variants, niche_start, untagged_variant },
434434
tag,
435435
..
436436
} => {
437-
if variant_index == dataful_variant {
437+
if variant_index == untagged_variant {
438438
let valid_range = enum_type_and_layout
439439
.for_variant(cx, variant_index)
440440
.largest_niche

‎compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ fn build_discr_member_di_node<'ll, 'tcx>(
378378
///
379379
/// The DW_AT_discr_value is optional, and is omitted if
380380
/// - This is the only variant of a univariant enum (i.e. their is no discriminant)
381-
/// - This is the "dataful" variant of a niche-layout enum
381+
/// - This is the "untagged" variant of a niche-layout enum
382382
/// (where only the other variants are identified by a single value)
383383
///
384384
/// There is only ever a single member, the type of which is a struct that describes the

‎compiler/rustc_codegen_ssa/src/mir/place.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
244244
};
245245
bx.intcast(tag.immediate(), cast_to, signed)
246246
}
247-
TagEncoding::Niche { dataful_variant, ref niche_variants, niche_start } => {
247+
TagEncoding::Niche { untagged_variant, ref niche_variants, niche_start } => {
248248
// Rebase from niche values to discriminants, and check
249249
// whether the result is in range for the niche variants.
250250
let niche_llty = bx.cx().immediate_backend_type(tag.layout);
@@ -302,7 +302,7 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
302302
bx.select(
303303
is_niche,
304304
niche_discr,
305-
bx.cx().const_uint(cast_to, dataful_variant.as_u32() as u64),
305+
bx.cx().const_uint(cast_to, untagged_variant.as_u32() as u64),
306306
)
307307
}
308308
}
@@ -337,11 +337,11 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
337337
}
338338
Variants::Multiple {
339339
tag_encoding:
340-
TagEncoding::Niche { dataful_variant, ref niche_variants, niche_start },
340+
TagEncoding::Niche { untagged_variant, ref niche_variants, niche_start },
341341
tag_field,
342342
..
343343
} => {
344-
if variant_index != dataful_variant {
344+
if variant_index != untagged_variant {
345345
let niche = self.project_field(bx, tag_field);
346346
let niche_llty = bx.cx().immediate_backend_type(niche.layout);
347347
let niche_value = variant_index.as_u32() - niche_variants.start().as_u32();

‎compiler/rustc_const_eval/src/interpret/operand.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
718718
// Return the cast value, and the index.
719719
(discr_val, index.0)
720720
}
721-
TagEncoding::Niche { dataful_variant, ref niche_variants, niche_start } => {
721+
TagEncoding::Niche { untagged_variant, ref niche_variants, niche_start } => {
722722
let tag_val = tag_val.to_scalar();
723723
// Compute the variant this niche value/"tag" corresponds to. With niche layout,
724724
// discriminant (encoded in niche/tag) and variant index are the same.
@@ -736,7 +736,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
736736
if !ptr_valid {
737737
throw_ub!(InvalidTag(dbg_val))
738738
}
739-
dataful_variant
739+
untagged_variant
740740
}
741741
Ok(tag_bits) => {
742742
let tag_bits = tag_bits.assert_bits(tag_layout.size);
@@ -766,7 +766,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
766766
assert!(usize::try_from(variant_index).unwrap() < variants_len);
767767
VariantIdx::from_u32(variant_index)
768768
} else {
769-
dataful_variant
769+
untagged_variant
770770
}
771771
}
772772
};
@@ -780,13 +780,13 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
780780
}
781781

782782
// Some nodes are used a lot. Make sure they don't unintentionally get bigger.
783-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
783+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64", not(bootstrap)))]
784784
mod size_asserts {
785785
use super::*;
786786
use rustc_data_structures::static_assert_size;
787787
// These are in alphabetical order, which is easy to maintain.
788-
static_assert_size!(Immediate, 56);
789-
static_assert_size!(ImmTy<'_>, 72);
790-
static_assert_size!(Operand, 64);
791-
static_assert_size!(OpTy<'_>, 88);
788+
static_assert_size!(Immediate, 48);
789+
static_assert_size!(ImmTy<'_>, 64);
790+
static_assert_size!(Operand, 56);
791+
static_assert_size!(OpTy<'_>, 80);
792792
}

‎compiler/rustc_const_eval/src/interpret/place.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -817,15 +817,15 @@ where
817817
}
818818
abi::Variants::Multiple {
819819
tag_encoding:
820-
TagEncoding::Niche { dataful_variant, ref niche_variants, niche_start },
820+
TagEncoding::Niche { untagged_variant, ref niche_variants, niche_start },
821821
tag: tag_layout,
822822
tag_field,
823823
..
824824
} => {
825825
// No need to validate that the discriminant here because the
826826
// `TyAndLayout::for_variant()` call earlier already checks the variant is valid.
827827

828-
if variant_index != dataful_variant {
828+
if variant_index != untagged_variant {
829829
let variants_start = niche_variants.start().as_u32();
830830
let variant_index_relative = variant_index
831831
.as_u32()
@@ -890,6 +890,8 @@ mod size_asserts {
890890
static_assert_size!(MemPlaceMeta, 24);
891891
static_assert_size!(MemPlace, 40);
892892
static_assert_size!(MPlaceTy<'_>, 64);
893-
static_assert_size!(Place, 48);
894-
static_assert_size!(PlaceTy<'_>, 72);
893+
#[cfg(not(bootstrap))]
894+
static_assert_size!(Place, 40);
895+
#[cfg(not(bootstrap))]
896+
static_assert_size!(PlaceTy<'_>, 64);
895897
}

‎compiler/rustc_data_structures/src/obligation_forest/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ pub trait ObligationProcessor {
117117
}
118118

119119
/// The result type used by `process_obligation`.
120+
// `repr(C)` to inhibit the niche filling optimization. Otherwise, the `match` appearing
121+
// in `process_obligations` is significantly slower, which can substantially affect
122+
// benchmarks like `rustc-perf`'s inflate and keccak.
123+
#[repr(C)]
120124
#[derive(Debug)]
121125
pub enum ProcessResult<O, E> {
122126
Unchanged,

‎compiler/rustc_errors/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ pub type PResult<'a, T> = Result<T, DiagnosticBuilder<'a, ErrorGuaranteed>>;
6969
// (See also the comment on `DiagnosticBuilder`'s `diagnostic` field.)
7070
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
7171
rustc_data_structures::static_assert_size!(PResult<'_, ()>, 16);
72-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
73-
rustc_data_structures::static_assert_size!(PResult<'_, bool>, 24);
72+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64", not(bootstrap)))]
73+
rustc_data_structures::static_assert_size!(PResult<'_, bool>, 16);
7474

7575
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, Encodable, Decodable)]
7676
pub enum SuggestionStyle {

‎compiler/rustc_hir/src/hir.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3473,12 +3473,15 @@ mod size_asserts {
34733473
static_assert_size!(FnDecl<'_>, 40);
34743474
static_assert_size!(ForeignItem<'_>, 72);
34753475
static_assert_size!(ForeignItemKind<'_>, 40);
3476-
static_assert_size!(GenericArg<'_>, 40);
3476+
#[cfg(not(bootstrap))]
3477+
static_assert_size!(GenericArg<'_>, 32);
34773478
static_assert_size!(GenericBound<'_>, 48);
34783479
static_assert_size!(Generics<'_>, 56);
34793480
static_assert_size!(Impl<'_>, 80);
3480-
static_assert_size!(ImplItem<'_>, 88);
3481-
static_assert_size!(ImplItemKind<'_>, 40);
3481+
#[cfg(not(bootstrap))]
3482+
static_assert_size!(ImplItem<'_>, 80);
3483+
#[cfg(not(bootstrap))]
3484+
static_assert_size!(ImplItemKind<'_>, 32);
34823485
static_assert_size!(Item<'_>, 80);
34833486
static_assert_size!(ItemKind<'_>, 48);
34843487
static_assert_size!(Local<'_>, 64);
@@ -3490,8 +3493,10 @@ mod size_asserts {
34903493
static_assert_size!(QPath<'_>, 24);
34913494
static_assert_size!(Stmt<'_>, 32);
34923495
static_assert_size!(StmtKind<'_>, 16);
3493-
static_assert_size!(TraitItem<'_>, 96);
3494-
static_assert_size!(TraitItemKind<'_>, 56);
3496+
#[cfg(not(bootstrap))]
3497+
static_assert_size!(TraitItem<'static>, 88);
3498+
#[cfg(not(bootstrap))]
3499+
static_assert_size!(TraitItemKind<'_>, 48);
34953500
static_assert_size!(Ty<'_>, 72);
34963501
static_assert_size!(TyKind<'_>, 56);
34973502
}

‎compiler/rustc_middle/src/mir/syntax.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,8 @@ pub enum BinOp {
12311231
mod size_asserts {
12321232
use super::*;
12331233
// These are in alphabetical order, which is easy to maintain.
1234-
static_assert_size!(AggregateKind<'_>, 48);
1234+
#[cfg(not(bootstrap))]
1235+
static_assert_size!(AggregateKind<'_>, 40);
12351236
static_assert_size!(Operand<'_>, 24);
12361237
static_assert_size!(Place<'_>, 16);
12371238
static_assert_size!(PlaceElem<'_>, 24);

‎compiler/rustc_middle/src/thir.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -825,8 +825,12 @@ mod size_asserts {
825825
static_assert_size!(Block, 56);
826826
static_assert_size!(Expr<'_>, 64);
827827
static_assert_size!(ExprKind<'_>, 40);
828-
static_assert_size!(Pat<'_>, 72);
829-
static_assert_size!(PatKind<'_>, 56);
830-
static_assert_size!(Stmt<'_>, 56);
831-
static_assert_size!(StmtKind<'_>, 48);
828+
#[cfg(not(bootstrap))]
829+
static_assert_size!(Pat<'_>, 64);
830+
#[cfg(not(bootstrap))]
831+
static_assert_size!(PatKind<'_>, 48);
832+
#[cfg(not(bootstrap))]
833+
static_assert_size!(Stmt<'_>, 48);
834+
#[cfg(not(bootstrap))]
835+
static_assert_size!(StmtKind<'_>, 40);
832836
}

‎compiler/rustc_middle/src/ty/layout.rs

Lines changed: 200 additions & 118 deletions
Large diffs are not rendered by default.

‎compiler/rustc_target/src/abi/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,7 @@ pub enum TagEncoding {
11301130

11311131
/// Niche (values invalid for a type) encoding the discriminant:
11321132
/// Discriminant and variant index coincide.
1133-
/// The variant `dataful_variant` contains a niche at an arbitrary
1133+
/// The variant `untagged_variant` contains a niche at an arbitrary
11341134
/// offset (field `tag_field` of the enum), which for a variant with
11351135
/// discriminant `d` is set to
11361136
/// `(d - niche_variants.start).wrapping_add(niche_start)`.
@@ -1139,7 +1139,7 @@ pub enum TagEncoding {
11391139
/// `None` has a null pointer for the second tuple field, and
11401140
/// `Some` is the identity function (with a non-null reference).
11411141
Niche {
1142-
dataful_variant: VariantIdx,
1142+
untagged_variant: VariantIdx,
11431143
niche_variants: RangeInclusive<VariantIdx>,
11441144
niche_start: u128,
11451145
},

‎src/librustdoc/clean/types.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2532,7 +2532,8 @@ mod size_asserts {
25322532
// These are in alphabetical order, which is easy to maintain.
25332533
static_assert_size!(Crate, 72); // frequently moved by-value
25342534
static_assert_size!(DocFragment, 32);
2535-
static_assert_size!(GenericArg, 64);
2535+
#[cfg(not(bootstrap))]
2536+
static_assert_size!(GenericArg, 56);
25362537
static_assert_size!(GenericArgs, 32);
25372538
static_assert_size!(GenericParamDef, 56);
25382539
static_assert_size!(Item, 56);

‎src/test/debuginfo/msvc-pretty-enums.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@
5353
// cdb-command: dx niche128_none
5454
// cdb-check: niche128_none : None [Type: enum2$<core::option::Option<core::num::nonzero::NonZeroI128> >]
5555

56-
// cdb-command: dx wrapping_niche128_dataful
57-
// cdb-check: wrapping_niche128_dataful : X [Type: enum2$<msvc_pretty_enums::Wrapping128Niche>]
56+
// cdb-command: dx wrapping_niche128_untagged
57+
// cdb-check: wrapping_niche128_untagged : X [Type: enum2$<msvc_pretty_enums::Wrapping128Niche>]
5858
// cdb-check: [+0x[...]] __0 [Type: msvc_pretty_enums::Wrapping128]
5959

6060
// cdb-command: dx wrapping_niche128_none1
@@ -213,7 +213,7 @@ fn main() {
213213
let niche128_some = Some(NonZeroI128::new(123456).unwrap());
214214
let niche128_none: Option<NonZeroI128> = None;
215215

216-
let wrapping_niche128_dataful =
216+
let wrapping_niche128_untagged =
217217
unsafe { Wrapping128Niche::X(Wrapping128(340282366920938463463374607431768211454)) };
218218
let wrapping_niche128_none1 = Wrapping128Niche::Y;
219219
let wrapping_niche128_none2 = Wrapping128Niche::Z;

‎src/test/ui/layout/issue-96158-scalarpair-payload-might-be-uninit.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ error: layout_of(NicheFirst) = Layout {
411411
valid_range: 0..=4,
412412
},
413413
tag_encoding: Niche {
414-
dataful_variant: 0,
414+
untagged_variant: 0,
415415
niche_variants: 1..=2,
416416
niche_start: 3,
417417
},
@@ -555,7 +555,7 @@ error: layout_of(NicheSecond) = Layout {
555555
valid_range: 0..=4,
556556
},
557557
tag_encoding: Niche {
558-
dataful_variant: 0,
558+
untagged_variant: 0,
559559
niche_variants: 1..=2,
560560
niche_start: 3,
561561
},

‎src/test/ui/layout/zero-sized-array-enum-niche.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ error: layout_of(std::result::Result<[u32; 0], Packed<U16IsZero>>) = Layout {
353353
valid_range: 0..=1,
354354
},
355355
tag_encoding: Niche {
356-
dataful_variant: 1,
356+
untagged_variant: 1,
357357
niche_variants: 0..=0,
358358
niche_start: 1,
359359
},

‎src/test/ui/stats/hir-stats.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// check-pass
22
// compile-flags: -Zhir-stats
33
// only-x86_64
4+
// ignore-stage1
45

56
// The aim here is to include at least one of every different type of top-level
67
// AST/HIR node reported by `-Zhir-stats`.

‎src/test/ui/stats/hir-stats.stderr

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,39 +21,39 @@ ast-stats-1 - MacCall 32 ( 0.4%) 1
2121
ast-stats-1 - Expr 96 ( 1.1%) 3
2222
ast-stats-1 Param 160 ( 1.9%) 4 40
2323
ast-stats-1 FnDecl 200 ( 2.4%) 5 40
24-
ast-stats-1 Variant 240 ( 2.8%) 2 120
24+
ast-stats-1 Variant 240 ( 2.9%) 2 120
2525
ast-stats-1 Block 288 ( 3.4%) 6 48
2626
ast-stats-1 GenericBound 352 ( 4.2%) 4 88
2727
ast-stats-1 - Trait 352 ( 4.2%) 4
2828
ast-stats-1 AssocItem 416 ( 4.9%) 4 104
2929
ast-stats-1 - TyAlias 208 ( 2.5%) 2
3030
ast-stats-1 - Fn 208 ( 2.5%) 2
31-
ast-stats-1 GenericParam 520 ( 6.1%) 5 104
32-
ast-stats-1 PathSegment 720 ( 8.5%) 30 24
33-
ast-stats-1 Expr 832 ( 9.8%) 8 104
31+
ast-stats-1 GenericParam 480 ( 5.7%) 5 96
32+
ast-stats-1 PathSegment 720 ( 8.6%) 30 24
33+
ast-stats-1 Expr 832 ( 9.9%) 8 104
3434
ast-stats-1 - Path 104 ( 1.2%) 1
3535
ast-stats-1 - Match 104 ( 1.2%) 1
3636
ast-stats-1 - Struct 104 ( 1.2%) 1
3737
ast-stats-1 - Lit 208 ( 2.5%) 2
3838
ast-stats-1 - Block 312 ( 3.7%) 3
39-
ast-stats-1 Pat 840 ( 9.9%) 7 120
39+
ast-stats-1 Pat 840 (10.0%) 7 120
4040
ast-stats-1 - Struct 120 ( 1.4%) 1
4141
ast-stats-1 - Wild 120 ( 1.4%) 1
4242
ast-stats-1 - Ident 600 ( 7.1%) 5
43-
ast-stats-1 Ty 1_344 (15.9%) 14 96
43+
ast-stats-1 Ty 1_344 (16.0%) 14 96
4444
ast-stats-1 - Rptr 96 ( 1.1%) 1
4545
ast-stats-1 - Ptr 96 ( 1.1%) 1
4646
ast-stats-1 - ImplicitSelf 192 ( 2.3%) 2
4747
ast-stats-1 - Path 960 (11.4%) 10
48-
ast-stats-1 Item 1_656 (19.6%) 9 184
48+
ast-stats-1 Item 1_656 (19.7%) 9 184
4949
ast-stats-1 - Trait 184 ( 2.2%) 1
5050
ast-stats-1 - Enum 184 ( 2.2%) 1
5151
ast-stats-1 - ForeignMod 184 ( 2.2%) 1
5252
ast-stats-1 - Impl 184 ( 2.2%) 1
5353
ast-stats-1 - Fn 368 ( 4.4%) 2
54-
ast-stats-1 - Use 552 ( 6.5%) 3
54+
ast-stats-1 - Use 552 ( 6.6%) 3
5555
ast-stats-1 ----------------------------------------------------------------
56-
ast-stats-1 Total 8_456
56+
ast-stats-1 Total 8_416
5757
ast-stats-1
5858
ast-stats-2 POST EXPANSION AST STATS
5959
ast-stats-2 Name Accumulated Size Count Item Size
@@ -86,25 +86,25 @@ ast-stats-2 - Trait 352 ( 3.8%) 4
8686
ast-stats-2 AssocItem 416 ( 4.5%) 4 104
8787
ast-stats-2 - TyAlias 208 ( 2.3%) 2
8888
ast-stats-2 - Fn 208 ( 2.3%) 2
89-
ast-stats-2 GenericParam 520 ( 5.7%) 5 104
90-
ast-stats-2 PathSegment 792 ( 8.6%) 33 24
91-
ast-stats-2 Pat 840 ( 9.1%) 7 120
89+
ast-stats-2 GenericParam 480 ( 5.2%) 5 96
90+
ast-stats-2 PathSegment 792 ( 8.7%) 33 24
91+
ast-stats-2 Pat 840 ( 9.2%) 7 120
9292
ast-stats-2 - Struct 120 ( 1.3%) 1
9393
ast-stats-2 - Wild 120 ( 1.3%) 1
94-
ast-stats-2 - Ident 600 ( 6.5%) 5
94+
ast-stats-2 - Ident 600 ( 6.6%) 5
9595
ast-stats-2 Expr 936 (10.2%) 9 104
9696
ast-stats-2 - Path 104 ( 1.1%) 1
9797
ast-stats-2 - Match 104 ( 1.1%) 1
9898
ast-stats-2 - Struct 104 ( 1.1%) 1
9999
ast-stats-2 - InlineAsm 104 ( 1.1%) 1
100100
ast-stats-2 - Lit 208 ( 2.3%) 2
101101
ast-stats-2 - Block 312 ( 3.4%) 3
102-
ast-stats-2 Ty 1_344 (14.6%) 14 96
102+
ast-stats-2 Ty 1_344 (14.7%) 14 96
103103
ast-stats-2 - Rptr 96 ( 1.0%) 1
104104
ast-stats-2 - Ptr 96 ( 1.0%) 1
105105
ast-stats-2 - ImplicitSelf 192 ( 2.1%) 2
106106
ast-stats-2 - Path 960 (10.5%) 10
107-
ast-stats-2 Item 2_024 (22.0%) 11 184
107+
ast-stats-2 Item 2_024 (22.1%) 11 184
108108
ast-stats-2 - Trait 184 ( 2.0%) 1
109109
ast-stats-2 - Enum 184 ( 2.0%) 1
110110
ast-stats-2 - ExternCrate 184 ( 2.0%) 1
@@ -113,15 +113,15 @@ ast-stats-2 - Impl 184 ( 2.0%) 1
113113
ast-stats-2 - Fn 368 ( 4.0%) 2
114114
ast-stats-2 - Use 736 ( 8.0%) 4
115115
ast-stats-2 ----------------------------------------------------------------
116-
ast-stats-2 Total 9_184
116+
ast-stats-2 Total 9_144
117117
ast-stats-2
118118
hir-stats HIR STATS
119119
hir-stats Name Accumulated Size Count Item Size
120120
hir-stats ----------------------------------------------------------------
121121
hir-stats ForeignItemRef 24 ( 0.2%) 1 24
122122
hir-stats Mod 32 ( 0.3%) 1 32
123123
hir-stats ExprField 40 ( 0.4%) 1 40
124-
hir-stats TraitItemRef 56 ( 0.5%) 2 28
124+
hir-stats TraitItemRef 56 ( 0.6%) 2 28
125125
hir-stats Param 64 ( 0.6%) 2 32
126126
hir-stats Local 64 ( 0.6%) 1 64
127127
hir-stats InlineAsm 72 ( 0.7%) 1 72
@@ -135,11 +135,11 @@ hir-stats - Semi 32 ( 0.3%) 1
135135
hir-stats - Expr 32 ( 0.3%) 1
136136
hir-stats FnDecl 120 ( 1.2%) 3 40
137137
hir-stats Attribute 128 ( 1.3%) 4 32
138+
hir-stats GenericArg 128 ( 1.3%) 4 32
139+
hir-stats - Type 32 ( 0.3%) 1
140+
hir-stats - Lifetime 96 ( 0.9%) 3
138141
hir-stats GenericArgs 144 ( 1.4%) 3 48
139142
hir-stats Variant 160 ( 1.6%) 2 80
140-
hir-stats GenericArg 160 ( 1.6%) 4 40
141-
hir-stats - Type 40 ( 0.4%) 1
142-
hir-stats - Lifetime 120 ( 1.2%) 3
143143
hir-stats GenericBound 192 ( 1.9%) 4 48
144144
hir-stats - Trait 192 ( 1.9%) 4
145145
hir-stats WherePredicate 216 ( 2.1%) 3 72
@@ -151,7 +151,7 @@ hir-stats - Wild 88 ( 0.9%) 1
151151
hir-stats - Struct 88 ( 0.9%) 1
152152
hir-stats - Binding 264 ( 2.6%) 3
153153
hir-stats Generics 560 ( 5.5%) 10 56
154-
hir-stats Expr 768 ( 7.5%) 12 64
154+
hir-stats Expr 768 ( 7.6%) 12 64
155155
hir-stats - Path 64 ( 0.6%) 1
156156
hir-stats - Struct 64 ( 0.6%) 1
157157
hir-stats - Match 64 ( 0.6%) 1
@@ -173,5 +173,5 @@ hir-stats - Path 936 ( 9.2%) 13
173173
hir-stats Path 1_536 (15.1%) 32 48
174174
hir-stats PathSegment 2_240 (22.0%) 40 56
175175
hir-stats ----------------------------------------------------------------
176-
hir-stats Total 10_200
176+
hir-stats Total 10_168
177177
hir-stats

‎src/test/ui/structs-enums/type-sizes.rs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,54 @@ pub enum AlwaysTaggedBecauseItHasNoNiche {
120120
B
121121
}
122122

123+
pub enum NicheFilledMultipleFields {
124+
A(bool, u8),
125+
B(u8),
126+
C(u8),
127+
D(bool),
128+
E,
129+
F,
130+
G,
131+
}
132+
133+
struct BoolInTheMiddle(std::num::NonZeroU16, bool, u8);
134+
135+
enum NicheWithData {
136+
A,
137+
B([u16; 5]),
138+
Largest { a1: u32, a2: BoolInTheMiddle, a3: u32 },
139+
C,
140+
D(u32, u32),
141+
}
142+
143+
// A type with almost 2^16 invalid values.
144+
#[repr(u16)]
145+
pub enum NicheU16 {
146+
_0,
147+
}
148+
149+
pub enum EnumManyVariant<X> {
150+
Dataful(u8, X),
151+
152+
// 0x100 niche variants.
153+
_00, _01, _02, _03, _04, _05, _06, _07, _08, _09, _0A, _0B, _0C, _0D, _0E, _0F,
154+
_10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _1A, _1B, _1C, _1D, _1E, _1F,
155+
_20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _2A, _2B, _2C, _2D, _2E, _2F,
156+
_30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _3A, _3B, _3C, _3D, _3E, _3F,
157+
_40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _4A, _4B, _4C, _4D, _4E, _4F,
158+
_50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _5A, _5B, _5C, _5D, _5E, _5F,
159+
_60, _61, _62, _63, _64, _65, _66, _67, _68, _69, _6A, _6B, _6C, _6D, _6E, _6F,
160+
_70, _71, _72, _73, _74, _75, _76, _77, _78, _79, _7A, _7B, _7C, _7D, _7E, _7F,
161+
_80, _81, _82, _83, _84, _85, _86, _87, _88, _89, _8A, _8B, _8C, _8D, _8E, _8F,
162+
_90, _91, _92, _93, _94, _95, _96, _97, _98, _99, _9A, _9B, _9C, _9D, _9E, _9F,
163+
_A0, _A1, _A2, _A3, _A4, _A5, _A6, _A7, _A8, _A9, _AA, _AB, _AC, _AD, _AE, _AF,
164+
_B0, _B1, _B2, _B3, _B4, _B5, _B6, _B7, _B8, _B9, _BA, _BB, _BC, _BD, _BE, _BF,
165+
_C0, _C1, _C2, _C3, _C4, _C5, _C6, _C7, _C8, _C9, _CA, _CB, _CC, _CD, _CE, _CF,
166+
_D0, _D1, _D2, _D3, _D4, _D5, _D6, _D7, _D8, _D9, _DA, _DB, _DC, _DD, _DE, _DF,
167+
_E0, _E1, _E2, _E3, _E4, _E5, _E6, _E7, _E8, _E9, _EA, _EB, _EC, _ED, _EE, _EF,
168+
_F0, _F1, _F2, _F3, _F4, _F5, _F6, _F7, _F8, _F9, _FA, _FB, _FC, _FD, _FE, _FF,
169+
}
170+
123171
pub fn main() {
124172
assert_eq!(size_of::<u8>(), 1 as usize);
125173
assert_eq!(size_of::<u32>(), 4 as usize);
@@ -170,4 +218,35 @@ pub fn main() {
170218
assert_eq!(size_of::<AlwaysTaggedBecauseItHasNoNiche>(), 8);
171219
assert_eq!(size_of::<Option<AlwaysTaggedBecauseItHasNoNiche>>(), 8);
172220
assert_eq!(size_of::<Option<Option<AlwaysTaggedBecauseItHasNoNiche>>>(), 8);
221+
222+
assert_eq!(size_of::<NicheFilledMultipleFields>(), 2);
223+
assert_eq!(size_of::<Option<NicheFilledMultipleFields>>(), 2);
224+
assert_eq!(size_of::<Option<Option<NicheFilledMultipleFields>>>(), 2);
225+
226+
struct S1{ a: u16, b: std::num::NonZeroU16, c: u16, d: u8, e: u32, f: u64, g:[u8;2] }
227+
assert_eq!(size_of::<S1>(), 24);
228+
assert_eq!(size_of::<Option<S1>>(), 24);
229+
230+
assert_eq!(size_of::<NicheWithData>(), 12);
231+
assert_eq!(size_of::<Option<NicheWithData>>(), 12);
232+
assert_eq!(size_of::<Option<Option<NicheWithData>>>(), 12);
233+
assert_eq!(
234+
size_of::<Option<Option2<&(), Option<NicheWithData>>>>(),
235+
size_of::<(&(), NicheWithData)>()
236+
);
237+
238+
pub enum FillPadding { A(std::num::NonZeroU8, u32), B }
239+
assert_eq!(size_of::<FillPadding>(), 8);
240+
assert_eq!(size_of::<Option<FillPadding>>(), 8);
241+
assert_eq!(size_of::<Option<Option<FillPadding>>>(), 8);
242+
243+
assert_eq!(size_of::<Result<(std::num::NonZeroU8, u8, u8), u16>>(), 4);
244+
assert_eq!(size_of::<Option<Result<(std::num::NonZeroU8, u8, u8), u16>>>(), 4);
245+
assert_eq!(size_of::<Result<(std::num::NonZeroU8, u8, u8, u8), u16>>(), 4);
246+
247+
assert_eq!(size_of::<EnumManyVariant<u16>>(), 6);
248+
assert_eq!(size_of::<EnumManyVariant<NicheU16>>(), 4);
249+
assert_eq!(size_of::<EnumManyVariant<Option<NicheU16>>>(), 4);
250+
assert_eq!(size_of::<EnumManyVariant<Option2<NicheU16,u8>>>(), 6);
251+
assert_eq!(size_of::<EnumManyVariant<Option<(NicheU16,u8)>>>(), 6);
173252
}

0 commit comments

Comments
 (0)
Please sign in to comment.