Skip to content

Commit

Permalink
review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Jul 9, 2022
1 parent 052651d commit ac265cd
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 21 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ pub(crate) fn codegen_const_value<'tcx>(
}

match const_val {
ConstValue::ZST => unreachable!(), // we already handles ZST above
ConstValue::Zst => unreachable!(), // we already handles ZST above
ConstValue::Scalar(x) => match x {
Scalar::Int(int) => {
if fx.clif_type(layout.ty).is_some() {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/mir/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> {
let llval = bx.scalar_to_backend(x, scalar, bx.immediate_backend_type(layout));
OperandValue::Immediate(llval)
}
ConstValue::ZST => {
ConstValue::Zst => {
let llval = bx.zst_to_backend(bx.immediate_backend_type(layout));
OperandValue::Immediate(llval)
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/const_eval/eval_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub(super) fn op_to_const<'tcx>(
"this MPlaceTy must come from a validated constant, thus we can assume the \
alignment is correct",
);
ConstValue::ZST
ConstValue::Zst
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/const_eval/valtrees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ pub fn valtree_to_const_value<'tcx>(
match ty.kind() {
ty::FnDef(..) => {
assert!(valtree.unwrap_branch().is_empty());
ConstValue::ZST
ConstValue::Zst
}
ty::Bool | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Char => match valtree {
ty::ValTree::Leaf(scalar_int) => ConstValue::Scalar(Scalar::Int(scalar_int)),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/interpret/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
Operand::Indirect(MemPlace::from_ptr(ptr.into()))
}
ConstValue::Scalar(x) => Operand::Immediate(tag_scalar(x)?.into()),
ConstValue::ZST => Operand::Immediate(Immediate::Uninit),
ConstValue::Zst => Operand::Immediate(Immediate::Uninit),
ConstValue::Slice { data, start, end } => {
// We rely on mutability being set correctly in `data` to prevent writes
// where none should happen.
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/mir/interpret/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub enum ConstValue<'tcx> {
Scalar(Scalar),

/// Only used for ZSTs.
ZST,
Zst,

/// Used only for `&[u8]` and `&str`
Slice { data: ConstAllocation<'tcx>, start: usize, end: usize },
Expand All @@ -58,7 +58,7 @@ impl<'a, 'tcx> Lift<'tcx> for ConstValue<'a> {
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<ConstValue<'tcx>> {
Some(match self {
ConstValue::Scalar(s) => ConstValue::Scalar(s),
ConstValue::ZST => ConstValue::ZST,
ConstValue::Zst => ConstValue::Zst,
ConstValue::Slice { data, start, end } => {
ConstValue::Slice { data: tcx.lift(data)?, start, end }
}
Expand All @@ -73,7 +73,7 @@ impl<'tcx> ConstValue<'tcx> {
#[inline]
pub fn try_to_scalar(&self) -> Option<Scalar<AllocId>> {
match *self {
ConstValue::ByRef { .. } | ConstValue::Slice { .. } | ConstValue::ZST => None,
ConstValue::ByRef { .. } | ConstValue::Slice { .. } | ConstValue::Zst => None,
ConstValue::Scalar(val) => Some(val),
}
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1711,7 +1711,7 @@ impl<'tcx> Operand<'tcx> {
Operand::Constant(Box::new(Constant {
span,
user_ty: None,
literal: ConstantKind::Val(ConstValue::ZST, ty),
literal: ConstantKind::Val(ConstValue::Zst, ty),
}))
}

Expand Down Expand Up @@ -2196,7 +2196,7 @@ impl<'tcx> ConstantKind<'tcx> {

#[inline]
pub fn zero_sized(ty: Ty<'tcx>) -> Self {
let cv = ConstValue::ZST;
let cv = ConstValue::Zst;
Self::Val(cv, ty)
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/mir/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> {
}

let fmt_val = |val: &ConstValue<'tcx>| match val {
ConstValue::ZST => format!("ZST"),
ConstValue::Zst => format!("ZST"),
ConstValue::Scalar(s) => format!("Scalar({:?})", s),
ConstValue::Slice { .. } => format!("Slice(..)"),
ConstValue::ByRef { .. } => format!("ByRef(..)"),
Expand Down Expand Up @@ -680,7 +680,7 @@ pub fn write_allocations<'tcx>(
ConstValue::Scalar(interpret::Scalar::Int { .. }) => {
Either::Left(Either::Right(std::iter::empty()))
}
ConstValue::ZST => Either::Left(Either::Right(std::iter::empty())),
ConstValue::Zst => Either::Left(Either::Right(std::iter::empty())),
ConstValue::ByRef { alloc, .. } | ConstValue::Slice { data: alloc, .. } => {
Either::Right(alloc_ids_from_alloc(alloc))
}
Expand Down
6 changes: 0 additions & 6 deletions compiler/rustc_middle/src/thir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,12 +458,6 @@ pub enum ExprKind<'tcx> {
},
}

impl<'tcx> ExprKind<'tcx> {
pub fn zero_sized_literal(user_ty: Option<Canonical<'tcx, UserType<'tcx>>>) -> Self {
ExprKind::ZstLiteral { user_ty }
}
}

/// Represents the association of a field identifier and an expression.
///
/// This is used in struct constructors.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/build/expr/as_constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
inferred_ty: ty,
})
});
let literal = ConstantKind::Val(ConstValue::ZST, ty);
let literal = ConstantKind::Val(ConstValue::Zst, ty);

Constant { span, user_ty: user_ty, literal }
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir_build/src/thir/cx/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ impl<'tcx> Cx<'tcx> {
}
};
let ty = self.tcx().mk_fn_def(def_id, substs);
Expr { temp_lifetime, ty, span, kind: ExprKind::zero_sized_literal(user_ty) }
Expr { temp_lifetime, ty, span, kind: ExprKind::ZstLiteral { user_ty } }
}

fn convert_arm(&mut self, arm: &'tcx hir::Arm<'tcx>) -> ArmId {
Expand Down Expand Up @@ -828,7 +828,7 @@ impl<'tcx> Cx<'tcx> {
| Res::Def(DefKind::Ctor(_, CtorKind::Fn), _)
| Res::SelfCtor(_) => {
let user_ty = self.user_substs_applied_to_res(expr.hir_id, res);
ExprKind::zero_sized_literal(user_ty)
ExprKind::ZstLiteral { user_ty }
}

Res::Def(DefKind::ConstParam, def_id) => {
Expand Down

0 comments on commit ac265cd

Please sign in to comment.