Skip to content

Commit 1a08b96

Browse files
author
Michael Benfield
committed
Change name of "dataful" variant to "untagged"
This is in anticipation of a new enum layout, in which the niche optimization may be applied even when multiple variants have data.
1 parent f91ca28 commit 1a08b96

File tree

12 files changed

+46
-45
lines changed

12 files changed

+46
-45
lines changed

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: 3 additions & 3 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
};

compiler/rustc_const_eval/src/interpret/place.rs

Lines changed: 2 additions & 2 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()

compiler/rustc_middle/src/ty/layout.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
10471047
assert!(def.is_enum());
10481048

10491049
// The current code for niche-filling relies on variant indices
1050-
// instead of actual discriminants, so dataful enums with
1050+
// instead of actual discriminants, so untagged enums with
10511051
// explicit discriminants (RFC #2363) would misbehave.
10521052
let no_explicit_discriminants = def
10531053
.variants()
@@ -1058,7 +1058,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
10581058

10591059
// Niche-filling enum optimization.
10601060
if !def.repr().inhibit_enum_layout_opt() && no_explicit_discriminants {
1061-
let mut dataful_variant = None;
1061+
let mut untagged_variant = None;
10621062
let mut niche_variants = VariantIdx::MAX..=VariantIdx::new(0);
10631063

10641064
// Find one non-ZST variant.
@@ -1068,11 +1068,11 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
10681068
}
10691069
for f in fields {
10701070
if !f.is_zst() {
1071-
if dataful_variant.is_none() {
1072-
dataful_variant = Some(v);
1071+
if untagged_variant.is_none() {
1072+
untagged_variant = Some(v);
10731073
continue 'variants;
10741074
} else {
1075-
dataful_variant = None;
1075+
untagged_variant = None;
10761076
break 'variants;
10771077
}
10781078
}
@@ -1081,10 +1081,10 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
10811081
}
10821082

10831083
if niche_variants.start() > niche_variants.end() {
1084-
dataful_variant = None;
1084+
untagged_variant = None;
10851085
}
10861086

1087-
if let Some(i) = dataful_variant {
1087+
if let Some(i) = untagged_variant {
10881088
let count = (niche_variants.end().as_u32()
10891089
- niche_variants.start().as_u32()
10901090
+ 1) as u128;
@@ -1152,7 +1152,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
11521152
variants: Variants::Multiple {
11531153
tag: niche_scalar,
11541154
tag_encoding: TagEncoding::Niche {
1155-
dataful_variant: i,
1155+
untagged_variant: i,
11561156
niche_variants,
11571157
niche_start,
11581158
},
@@ -2559,11 +2559,11 @@ where
25592559
// using more niches than just null (e.g., the first page of
25602560
// the address space, or unaligned pointers).
25612561
Variants::Multiple {
2562-
tag_encoding: TagEncoding::Niche { dataful_variant, .. },
2562+
tag_encoding: TagEncoding::Niche { untagged_variant, .. },
25632563
tag_field,
25642564
..
25652565
} if this.fields.offset(tag_field) == offset => {
2566-
Some(this.for_variant(cx, dataful_variant))
2566+
Some(this.for_variant(cx, untagged_variant))
25672567
}
25682568
_ => Some(this),
25692569
};

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/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
},

0 commit comments

Comments
 (0)