Skip to content

Commit

Permalink
Rename Unsized to Meta
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Jan 9, 2020
1 parent e632940 commit a4fa5bb
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
6 changes: 3 additions & 3 deletions src/librustc_mir/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,13 +465,13 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
Ok(Some((size, align)))
}
ty::Dynamic(..) => {
let vtable = metadata.unwrap_unsized();
let vtable = metadata.unwrap_meta();
// Read size and align from vtable (already checks size).
Ok(Some(self.read_size_and_align_from_vtable(vtable)?))
}

ty::Slice(_) | ty::Str => {
let len = metadata.unwrap_unsized().to_machine_usize(self)?;
let len = metadata.unwrap_meta().to_machine_usize(self)?;
let elem = layout.field(self, 0)?;

// Make sure the slice is not too big.
Expand Down Expand Up @@ -817,7 +817,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
" by align({}){} ref:",
mplace.align.bytes(),
match mplace.meta {
MemPlaceMeta::Unsized(meta) => format!(" meta({:?})", meta),
MemPlaceMeta::Meta(meta) => format!(" meta({:?})", meta),
MemPlaceMeta::Poison | MemPlaceMeta::None => String::new(),
}
)
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/interpret/intern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ impl<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx
{
// Validation has already errored on an invalid vtable pointer so we can safely not
// do anything if this is not a real pointer.
if let Scalar::Ptr(vtable) = mplace.meta.unwrap_unsized() {
if let Scalar::Ptr(vtable) = mplace.meta.unwrap_meta() {
// Explicitly choose `Immutable` here, since vtables are immutable, even
// if the reference of the fat pointer is mutable.
self.intern_shallow(vtable.alloc_id, Mutability::Not, None)?;
Expand Down Expand Up @@ -227,7 +227,7 @@ impl<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx
ty::Array(_, n)
if n.eval_usize(self.ecx.tcx.tcx, self.ecx.param_env) == 0 => {}
ty::Slice(_)
if mplace.meta.unwrap_unsized().to_machine_usize(self.ecx)? == 0 => {}
if mplace.meta.unwrap_meta().to_machine_usize(self.ecx)? == 0 => {}
_ => bug!("const qualif failed to prevent mutable references"),
},
}
Expand Down
28 changes: 14 additions & 14 deletions src/librustc_mir/interpret/place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use super::{
/// Information required for the sound usage of a `MemPlace`.
pub enum MemPlaceMeta<Tag = (), Id = AllocId> {
/// The unsized payload (e.g. length for slices or vtable pointer for trait objects).
Unsized(Scalar<Tag, Id>),
Meta(Scalar<Tag, Id>),
/// `Sized` types or unsized `extern type`
None,
/// The address of this place may not be taken. This protects the `MemPlace` from coming from
Expand All @@ -35,17 +35,17 @@ pub enum MemPlaceMeta<Tag = (), Id = AllocId> {
}

impl<Tag, Id> MemPlaceMeta<Tag, Id> {
pub fn unwrap_unsized(self) -> Scalar<Tag, Id> {
pub fn unwrap_meta(self) -> Scalar<Tag, Id> {
match self {
Self::Unsized(s) => s,
Self::Meta(s) => s,
Self::None | Self::Poison => {
bug!("expected wide pointer extra data (e.g. slice length or trait object vtable)")
}
}
}
fn is_unsized(self) -> bool {
fn has_meta(self) -> bool {
match self {
Self::Unsized(_) => true,
Self::Meta(_) => true,
Self::None | Self::Poison => false,
}
}
Expand All @@ -54,7 +54,7 @@ impl<Tag, Id> MemPlaceMeta<Tag, Id> {
impl<Tag> MemPlaceMeta<Tag> {
pub fn erase_tag(self) -> MemPlaceMeta<()> {
match self {
Self::Unsized(s) => MemPlaceMeta::Unsized(s.erase_tag()),
Self::Meta(s) => MemPlaceMeta::Meta(s.erase_tag()),
Self::None => MemPlaceMeta::None,
Self::Poison => MemPlaceMeta::Poison,
}
Expand Down Expand Up @@ -154,7 +154,7 @@ impl<Tag> MemPlace<Tag> {
pub fn to_ref(self) -> Immediate<Tag> {
match self.meta {
MemPlaceMeta::None => Immediate::Scalar(self.ptr.into()),
MemPlaceMeta::Unsized(meta) => Immediate::ScalarPair(self.ptr.into(), meta.into()),
MemPlaceMeta::Meta(meta) => Immediate::ScalarPair(self.ptr.into(), meta.into()),
MemPlaceMeta::Poison => bug!(
"MPlaceTy::dangling may never be used to produce a \
place that will have the address of its pointee taken"
Expand Down Expand Up @@ -214,7 +214,7 @@ impl<'tcx, Tag> MPlaceTy<'tcx, Tag> {
// We need to consult `meta` metadata
match self.layout.ty.kind {
ty::Slice(..) | ty::Str => {
return self.mplace.meta.unwrap_unsized().to_machine_usize(cx);
return self.mplace.meta.unwrap_meta().to_machine_usize(cx);
}
_ => bug!("len not supported on unsized type {:?}", self.layout.ty),
}
Expand All @@ -231,7 +231,7 @@ impl<'tcx, Tag> MPlaceTy<'tcx, Tag> {
#[inline]
pub(super) fn vtable(self) -> Scalar<Tag> {
match self.layout.ty.kind {
ty::Dynamic(..) => self.mplace.meta.unwrap_unsized(),
ty::Dynamic(..) => self.mplace.meta.unwrap_meta(),
_ => bug!("vtable not supported on type {:?}", self.layout.ty),
}
}
Expand Down Expand Up @@ -312,7 +312,7 @@ where
let (ptr, meta) = match *val {
Immediate::Scalar(ptr) => (ptr.not_undef()?, MemPlaceMeta::None),
Immediate::ScalarPair(ptr, meta) => {
(ptr.not_undef()?, MemPlaceMeta::Unsized(meta.not_undef()?))
(ptr.not_undef()?, MemPlaceMeta::Meta(meta.not_undef()?))
}
};

Expand Down Expand Up @@ -354,7 +354,7 @@ where
) -> InterpResult<'tcx, Option<Pointer<M::PointerTag>>> {
let size = size.unwrap_or_else(|| {
assert!(!place.layout.is_unsized());
assert!(!place.meta.is_unsized());
assert!(!place.meta.has_meta());
place.layout.size
});
self.memory.check_ptr_access(place.ptr, size, place.align)
Expand Down Expand Up @@ -505,7 +505,7 @@ where
ty::Array(inner, _) => (MemPlaceMeta::None, self.tcx.mk_array(inner, inner_len)),
ty::Slice(..) => {
let len = Scalar::from_uint(inner_len, self.pointer_size());
(MemPlaceMeta::Unsized(len), base.layout.ty)
(MemPlaceMeta::Meta(len), base.layout.ty)
}
_ => bug!("cannot subslice non-array type: `{:?}`", base.layout.ty),
};
Expand All @@ -519,7 +519,7 @@ where
variant: VariantIdx,
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> {
// Downcasts only change the layout
assert!(!base.meta.is_unsized());
assert!(!base.meta.has_meta());
Ok(MPlaceTy { layout: base.layout.for_variant(self, variant), ..base })
}

Expand Down Expand Up @@ -1081,7 +1081,7 @@ where
let mplace = MemPlace {
ptr: ptr.into(),
align: Align::from_bytes(1).unwrap(),
meta: MemPlaceMeta::Unsized(meta),
meta: MemPlaceMeta::Meta(meta),
};

let layout = self.layout_of(self.tcx.mk_static_str()).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/interpret/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ impl_snapshot_for!(

impl_snapshot_for!(
enum MemPlaceMeta {
Unsized(s),
Meta(s),
None,
Poison,
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/interpret/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, 'tcx, M
let tail = self.ecx.tcx.struct_tail_erasing_lifetimes(pointee.ty, self.ecx.param_env);
match tail.kind {
ty::Dynamic(..) => {
let vtable = meta.unwrap_unsized();
let vtable = meta.unwrap_meta();
try_validation!(
self.ecx.memory.check_ptr_access(
vtable,
Expand All @@ -276,7 +276,7 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, 'tcx, M
}
ty::Slice(..) | ty::Str => {
let _len = try_validation!(
meta.unwrap_unsized().to_machine_usize(self.ecx),
meta.unwrap_meta().to_machine_usize(self.ecx),
"non-integer slice length in wide pointer",
self.path
);
Expand Down

0 comments on commit a4fa5bb

Please sign in to comment.