mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-06 12:18:33 +00:00
issue-49938: Reference tagged unions discr(iminant) as tag
Refer https://github.com/rust-lang/rust/issues/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.
This commit is contained in:
parent
2c315475ea
commit
38a6eca29d
@ -1057,7 +1057,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
|
|||||||
}
|
}
|
||||||
tcx.intern_layout(LayoutDetails {
|
tcx.intern_layout(LayoutDetails {
|
||||||
variants: Variants::Tagged {
|
variants: Variants::Tagged {
|
||||||
discr: tag,
|
tag,
|
||||||
variants: layout_variants,
|
variants: layout_variants,
|
||||||
},
|
},
|
||||||
fields: FieldPlacement::Arbitrary {
|
fields: FieldPlacement::Arbitrary {
|
||||||
@ -1218,7 +1218,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
|
|||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
record(adt_kind.into(), adt_packed, match layout.variants {
|
record(adt_kind.into(), adt_packed, match layout.variants {
|
||||||
Variants::Tagged { ref discr, .. } => Some(discr.value.size(self)),
|
Variants::Tagged { ref tag, .. } => Some(tag.value.size(self)),
|
||||||
_ => None
|
_ => None
|
||||||
}, variant_infos);
|
}, variant_infos);
|
||||||
}
|
}
|
||||||
@ -1622,7 +1622,7 @@ impl<'a, 'tcx, C> TyLayoutMethods<'tcx, C> for Ty<'tcx>
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Discriminant field for enums (where applicable).
|
// Discriminant field for enums (where applicable).
|
||||||
Variants::Tagged { ref discr, .. } |
|
Variants::Tagged { tag: ref discr, .. } |
|
||||||
Variants::NicheFilling { niche: ref discr, .. } => {
|
Variants::NicheFilling { niche: ref discr, .. } => {
|
||||||
assert_eq!(i, 0);
|
assert_eq!(i, 0);
|
||||||
let layout = LayoutDetails::scalar(tcx, discr.clone());
|
let layout = LayoutDetails::scalar(tcx, discr.clone());
|
||||||
@ -1736,10 +1736,10 @@ impl<'a> HashStable<StableHashingContext<'a>> for Variants {
|
|||||||
index.hash_stable(hcx, hasher);
|
index.hash_stable(hcx, hasher);
|
||||||
}
|
}
|
||||||
Tagged {
|
Tagged {
|
||||||
ref discr,
|
ref tag,
|
||||||
ref variants,
|
ref variants,
|
||||||
} => {
|
} => {
|
||||||
discr.hash_stable(hcx, hasher);
|
tag.hash_stable(hcx, hasher);
|
||||||
variants.hash_stable(hcx, hasher);
|
variants.hash_stable(hcx, hasher);
|
||||||
}
|
}
|
||||||
NicheFilling {
|
NicheFilling {
|
||||||
|
@ -820,8 +820,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for VariantSizeDifferences {
|
|||||||
bug!("failed to get layout for `{}`: {}", t, e)
|
bug!("failed to get layout for `{}`: {}", t, e)
|
||||||
});
|
});
|
||||||
|
|
||||||
if let layout::Variants::Tagged { ref variants, ref discr, .. } = layout.variants {
|
if let layout::Variants::Tagged { ref variants, ref tag, .. } = layout.variants {
|
||||||
let discr_size = discr.value.size(cx.tcx).bytes();
|
let discr_size = tag.value.size(cx.tcx).bytes();
|
||||||
|
|
||||||
debug!("enum `{}` is {} bytes large with layout:\n{:#?}",
|
debug!("enum `{}` is {} bytes large with layout:\n{:#?}",
|
||||||
t, layout.size.bytes(), layout);
|
t, layout.size.bytes(), layout);
|
||||||
|
@ -960,7 +960,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
|
|||||||
layout::Abi::Uninhabited);
|
layout::Abi::Uninhabited);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
layout::Variants::Tagged { ref discr, .. } => {
|
layout::Variants::Tagged { ref tag, .. } => {
|
||||||
let discr_val = dest_ty.ty_adt_def().unwrap()
|
let discr_val = dest_ty.ty_adt_def().unwrap()
|
||||||
.discriminant_for_variant(*self.tcx, variant_index)
|
.discriminant_for_variant(*self.tcx, variant_index)
|
||||||
.val;
|
.val;
|
||||||
@ -968,12 +968,12 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
|
|||||||
// raw discriminants for enums are isize or bigger during
|
// raw discriminants for enums are isize or bigger during
|
||||||
// their computation, but the in-memory tag is the smallest possible
|
// their computation, but the in-memory tag is the smallest possible
|
||||||
// representation
|
// representation
|
||||||
let size = discr.value.size(self.tcx.tcx).bits();
|
let size = tag.value.size(self.tcx.tcx).bits();
|
||||||
let amt = 128 - size;
|
let amt = 128 - size;
|
||||||
let discr_val = (discr_val << amt) >> amt;
|
let discr_val = (discr_val << amt) >> amt;
|
||||||
|
|
||||||
let (discr_dest, discr) = self.place_field(dest, mir::Field::new(0), layout)?;
|
let (discr_dest, tag) = self.place_field(dest, mir::Field::new(0), layout)?;
|
||||||
self.write_primval(discr_dest, PrimVal::Bytes(discr_val), discr.ty)?;
|
self.write_primval(discr_dest, PrimVal::Bytes(discr_val), tag.ty)?;
|
||||||
}
|
}
|
||||||
layout::Variants::NicheFilling {
|
layout::Variants::NicheFilling {
|
||||||
dataful_variant,
|
dataful_variant,
|
||||||
|
@ -716,10 +716,10 @@ pub enum Variants {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/// General-case enums: for each case there is a struct, and they all have
|
/// General-case enums: for each case there is a struct, and they all have
|
||||||
/// all space reserved for the discriminant, and their first field starts
|
/// all space reserved for the tag, and their first field starts
|
||||||
/// at a non-0 offset, after where the discriminant would go.
|
/// at a non-0 offset, after where the tag would go.
|
||||||
Tagged {
|
Tagged {
|
||||||
discr: Scalar,
|
tag: Scalar,
|
||||||
variants: Vec<LayoutDetails>,
|
variants: Vec<LayoutDetails>,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1429,8 +1429,8 @@ fn prepare_enum_metadata<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
|
|||||||
let discriminant_type_metadata = match layout.variants {
|
let discriminant_type_metadata = match layout.variants {
|
||||||
layout::Variants::Single { .. } |
|
layout::Variants::Single { .. } |
|
||||||
layout::Variants::NicheFilling { .. } => None,
|
layout::Variants::NicheFilling { .. } => None,
|
||||||
layout::Variants::Tagged { ref discr, .. } => {
|
layout::Variants::Tagged { ref tag, .. } => {
|
||||||
Some(discriminant_type_metadata(discr.value))
|
Some(discriminant_type_metadata(tag.value))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -273,8 +273,8 @@ impl<'a, 'tcx> PlaceRef<'tcx> {
|
|||||||
let lldiscr = discr.load(bx).immediate();
|
let lldiscr = discr.load(bx).immediate();
|
||||||
match self.layout.variants {
|
match self.layout.variants {
|
||||||
layout::Variants::Single { .. } => bug!(),
|
layout::Variants::Single { .. } => bug!(),
|
||||||
layout::Variants::Tagged { ref discr, .. } => {
|
layout::Variants::Tagged { ref tag, .. } => {
|
||||||
let signed = match discr.value {
|
let signed = match tag.value {
|
||||||
layout::Int(_, signed) => signed,
|
layout::Int(_, signed) => signed,
|
||||||
_ => false
|
_ => false
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user