diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-02-14 18:02:54 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-14 18:02:54 +0100 |
| commit | f68864cbcab91f175210f4477bccfe04d54d1bfc (patch) | |
| tree | a07f7c4d59c82af5051b02b1f2ac79522e5c8103 /compiler/rustc_middle | |
| parent | 8804e7f3dc771b6a10ff4cad25b45abd18d85529 (diff) | |
| parent | 936bf29d4cec40c328930daf83277d7e77cc9602 (diff) | |
Rollup merge of #108029 - oli-obk:🞋_usize, r=RalfJung
s/eval_usize/eval_target_usize/ for clarity r? `@nnethercote` as discussed in https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/.60Const.60.20and.20.60usize.60.2F.60u64.60 it is unclear what `usize` means and why we use a `u64` for something talking about `usize`. This renaming should make it clear that we're talking about `usize`s on the target platform, irrespective of the compiler host platform.
Diffstat (limited to 'compiler/rustc_middle')
| -rw-r--r-- | compiler/rustc_middle/src/mir/mod.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/mir/tcx.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/consts.rs | 12 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/context.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/inhabitedness/inhabited_predicate.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/relate.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/sty.rs | 2 |
7 files changed, 20 insertions, 12 deletions
diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 6f42b69633c..6378ca6e77d 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -2344,9 +2344,13 @@ impl<'tcx> ConstantKind<'tcx> { } #[inline] - pub fn try_eval_usize(&self, tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> Option<u64> { + pub fn try_eval_target_usize( + &self, + tcx: TyCtxt<'tcx>, + param_env: ty::ParamEnv<'tcx>, + ) -> Option<u64> { match self { - Self::Ty(ct) => ct.try_eval_usize(tcx, param_env), + Self::Ty(ct) => ct.try_eval_target_usize(tcx, param_env), Self::Val(val, _) => val.try_to_machine_usize(tcx), Self::Unevaluated(uneval, _) => { match tcx.const_eval_resolve(param_env, *uneval, None) { diff --git a/compiler/rustc_middle/src/mir/tcx.rs b/compiler/rustc_middle/src/mir/tcx.rs index 9f544de9f87..97dc8a99f9b 100644 --- a/compiler/rustc_middle/src/mir/tcx.rs +++ b/compiler/rustc_middle/src/mir/tcx.rs @@ -97,7 +97,7 @@ impl<'tcx> PlaceTy<'tcx> { ty::Slice(..) => self.ty, ty::Array(inner, _) if !from_end => tcx.mk_array(*inner, (to - from) as u64), ty::Array(inner, size) if from_end => { - let size = size.eval_usize(tcx, param_env); + let size = size.eval_target_usize(tcx, param_env); let len = size - (from as u64) - (to as u64); tcx.mk_array(*inner, len) } diff --git a/compiler/rustc_middle/src/ty/consts.rs b/compiler/rustc_middle/src/ty/consts.rs index 65cbac3e8f1..3ad56e8f273 100644 --- a/compiler/rustc_middle/src/ty/consts.rs +++ b/compiler/rustc_middle/src/ty/consts.rs @@ -175,7 +175,7 @@ impl<'tcx> Const<'tcx> { #[inline] /// Creates an interned usize constant. - pub fn from_usize(tcx: TyCtxt<'tcx>, n: u64) -> Self { + pub fn from_target_usize(tcx: TyCtxt<'tcx>, n: u64) -> Self { Self::from_bits(tcx, n as u128, ParamEnv::empty().and(tcx.types.usize)) } @@ -201,7 +201,11 @@ impl<'tcx> Const<'tcx> { } #[inline] - pub fn try_eval_usize(self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>) -> Option<u64> { + pub fn try_eval_target_usize( + self, + tcx: TyCtxt<'tcx>, + param_env: ParamEnv<'tcx>, + ) -> Option<u64> { self.kind().eval(tcx, param_env).try_to_machine_usize(tcx) } @@ -229,8 +233,8 @@ impl<'tcx> Const<'tcx> { #[inline] /// Panics if the value cannot be evaluated or doesn't contain a valid `usize`. - pub fn eval_usize(self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>) -> u64 { - self.try_eval_usize(tcx, param_env) + pub fn eval_target_usize(self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>) -> u64 { + self.try_eval_target_usize(tcx, param_env) .unwrap_or_else(|| bug!("expected usize, got {:#?}", self)) } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 02088fffeb6..e67c89c194e 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -1787,7 +1787,7 @@ impl<'tcx> TyCtxt<'tcx> { #[inline] pub fn mk_array(self, ty: Ty<'tcx>, n: u64) -> Ty<'tcx> { - self.mk_ty(Array(ty, ty::Const::from_usize(self, n))) + self.mk_ty(Array(ty, ty::Const::from_target_usize(self, n))) } #[inline] diff --git a/compiler/rustc_middle/src/ty/inhabitedness/inhabited_predicate.rs b/compiler/rustc_middle/src/ty/inhabitedness/inhabited_predicate.rs index 33f72729798..8d0c7bf2f47 100644 --- a/compiler/rustc_middle/src/ty/inhabitedness/inhabited_predicate.rs +++ b/compiler/rustc_middle/src/ty/inhabitedness/inhabited_predicate.rs @@ -57,7 +57,7 @@ impl<'tcx> InhabitedPredicate<'tcx> { match self { Self::False => Ok(false), Self::True => Ok(true), - Self::ConstIsZero(const_) => match const_.try_eval_usize(tcx, param_env) { + Self::ConstIsZero(const_) => match const_.try_eval_target_usize(tcx, param_env) { None | Some(0) => Ok(true), Some(1..) => Ok(false), }, diff --git a/compiler/rustc_middle/src/ty/relate.rs b/compiler/rustc_middle/src/ty/relate.rs index 3b22da41a57..8b08ea9a58c 100644 --- a/compiler/rustc_middle/src/ty/relate.rs +++ b/compiler/rustc_middle/src/ty/relate.rs @@ -511,8 +511,8 @@ pub fn super_relate_tys<'tcx, R: TypeRelation<'tcx>>( // we however cannot end up with errors in `Relate` during both // `type_of` and `predicates_of`. This means that evaluating the // constants should not cause cycle errors here. - let sz_a = sz_a.try_eval_usize(tcx, relation.param_env()); - let sz_b = sz_b.try_eval_usize(tcx, relation.param_env()); + let sz_a = sz_a.try_eval_target_usize(tcx, relation.param_env()); + let sz_b = sz_b.try_eval_target_usize(tcx, relation.param_env()); match (sz_a, sz_b) { (Some(sz_a_val), Some(sz_b_val)) if sz_a_val != sz_b_val => Err( TypeError::FixedArraySize(expected_found(relation, sz_a_val, sz_b_val)), diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index abde81236e2..c613b3627f2 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -1879,7 +1879,7 @@ impl<'tcx> Ty<'tcx> { // The way we evaluate the `N` in `[T; N]` here only works since we use // `simd_size_and_type` post-monomorphization. It will probably start to ICE // if we use it in generic code. See the `simd-array-trait` ui test. - (f0_len.eval_usize(tcx, ParamEnv::empty()) as u64, *f0_elem_ty) + (f0_len.eval_target_usize(tcx, ParamEnv::empty()) as u64, *f0_elem_ty) } // Otherwise, the fields of this Adt are the SIMD components (and we assume they // all have the same type). |
