Skip to content

Commit 38a6eca

Browse files
author
Samuel Wilson
committed
issue-49938: Reference tagged unions discr(iminant) as tag
Refer #49938 Previously tagged unions' tag was refered to as a discr(iminant). Here the changes use tag instead which is the correct terminology when refering to the memory representation of tagged unions.
1 parent 2c31547 commit 38a6eca

File tree

6 files changed

+18
-18
lines changed

6 files changed

+18
-18
lines changed

src/librustc/ty/layout.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
10571057
}
10581058
tcx.intern_layout(LayoutDetails {
10591059
variants: Variants::Tagged {
1060-
discr: tag,
1060+
tag,
10611061
variants: layout_variants,
10621062
},
10631063
fields: FieldPlacement::Arbitrary {
@@ -1218,7 +1218,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
12181218
})
12191219
.collect();
12201220
record(adt_kind.into(), adt_packed, match layout.variants {
1221-
Variants::Tagged { ref discr, .. } => Some(discr.value.size(self)),
1221+
Variants::Tagged { ref tag, .. } => Some(tag.value.size(self)),
12221222
_ => None
12231223
}, variant_infos);
12241224
}
@@ -1622,7 +1622,7 @@ impl<'a, 'tcx, C> TyLayoutMethods<'tcx, C> for Ty<'tcx>
16221622
}
16231623

16241624
// Discriminant field for enums (where applicable).
1625-
Variants::Tagged { ref discr, .. } |
1625+
Variants::Tagged { tag: ref discr, .. } |
16261626
Variants::NicheFilling { niche: ref discr, .. } => {
16271627
assert_eq!(i, 0);
16281628
let layout = LayoutDetails::scalar(tcx, discr.clone());
@@ -1736,10 +1736,10 @@ impl<'a> HashStable<StableHashingContext<'a>> for Variants {
17361736
index.hash_stable(hcx, hasher);
17371737
}
17381738
Tagged {
1739-
ref discr,
1739+
ref tag,
17401740
ref variants,
17411741
} => {
1742-
discr.hash_stable(hcx, hasher);
1742+
tag.hash_stable(hcx, hasher);
17431743
variants.hash_stable(hcx, hasher);
17441744
}
17451745
NicheFilling {

src/librustc_lint/types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -820,8 +820,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for VariantSizeDifferences {
820820
bug!("failed to get layout for `{}`: {}", t, e)
821821
});
822822

823-
if let layout::Variants::Tagged { ref variants, ref discr, .. } = layout.variants {
824-
let discr_size = discr.value.size(cx.tcx).bytes();
823+
if let layout::Variants::Tagged { ref variants, ref tag, .. } = layout.variants {
824+
let discr_size = tag.value.size(cx.tcx).bytes();
825825

826826
debug!("enum `{}` is {} bytes large with layout:\n{:#?}",
827827
t, layout.size.bytes(), layout);

src/librustc_mir/interpret/eval_context.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -960,20 +960,20 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
960960
layout::Abi::Uninhabited);
961961
}
962962
}
963-
layout::Variants::Tagged { ref discr, .. } => {
963+
layout::Variants::Tagged { ref tag, .. } => {
964964
let discr_val = dest_ty.ty_adt_def().unwrap()
965965
.discriminant_for_variant(*self.tcx, variant_index)
966966
.val;
967967

968968
// raw discriminants for enums are isize or bigger during
969969
// their computation, but the in-memory tag is the smallest possible
970970
// representation
971-
let size = discr.value.size(self.tcx.tcx).bits();
971+
let size = tag.value.size(self.tcx.tcx).bits();
972972
let amt = 128 - size;
973973
let discr_val = (discr_val << amt) >> amt;
974974

975-
let (discr_dest, discr) = self.place_field(dest, mir::Field::new(0), layout)?;
976-
self.write_primval(discr_dest, PrimVal::Bytes(discr_val), discr.ty)?;
975+
let (discr_dest, tag) = self.place_field(dest, mir::Field::new(0), layout)?;
976+
self.write_primval(discr_dest, PrimVal::Bytes(discr_val), tag.ty)?;
977977
}
978978
layout::Variants::NicheFilling {
979979
dataful_variant,

src/librustc_target/abi/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -716,10 +716,10 @@ pub enum Variants {
716716
},
717717

718718
/// General-case enums: for each case there is a struct, and they all have
719-
/// all space reserved for the discriminant, and their first field starts
720-
/// at a non-0 offset, after where the discriminant would go.
719+
/// all space reserved for the tag, and their first field starts
720+
/// at a non-0 offset, after where the tag would go.
721721
Tagged {
722-
discr: Scalar,
722+
tag: Scalar,
723723
variants: Vec<LayoutDetails>,
724724
},
725725

src/librustc_trans/debuginfo/metadata.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1429,8 +1429,8 @@ fn prepare_enum_metadata<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
14291429
let discriminant_type_metadata = match layout.variants {
14301430
layout::Variants::Single { .. } |
14311431
layout::Variants::NicheFilling { .. } => None,
1432-
layout::Variants::Tagged { ref discr, .. } => {
1433-
Some(discriminant_type_metadata(discr.value))
1432+
layout::Variants::Tagged { ref tag, .. } => {
1433+
Some(discriminant_type_metadata(tag.value))
14341434
}
14351435
};
14361436

src/librustc_trans/mir/place.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,8 @@ impl<'a, 'tcx> PlaceRef<'tcx> {
273273
let lldiscr = discr.load(bx).immediate();
274274
match self.layout.variants {
275275
layout::Variants::Single { .. } => bug!(),
276-
layout::Variants::Tagged { ref discr, .. } => {
277-
let signed = match discr.value {
276+
layout::Variants::Tagged { ref tag, .. } => {
277+
let signed = match tag.value {
278278
layout::Int(_, signed) => signed,
279279
_ => false
280280
};

0 commit comments

Comments
 (0)