Skip to content
Permalink
Browse files

Revert the `LazyConst` PR

  • Loading branch information...
oli-obk committed Mar 14, 2019
1 parent 2c8bbf5 commit 5cd28066214a4a255bac6655c20bf05cb95730fd
Showing with 367 additions and 562 deletions.
  1. +7 −1 src/librustc/mir/interpret/value.rs
  2. +5 −14 src/librustc/mir/mod.rs
  3. +2 −2 src/librustc/mir/visit.rs
  4. +6 −5 src/librustc/traits/project.rs
  5. +6 −5 src/librustc/traits/query/normalize.rs
  6. +6 −6 src/librustc/ty/codec.rs
  7. +17 −26 src/librustc/ty/context.rs
  8. +3 −6 src/librustc/ty/error.rs
  9. +24 −14 src/librustc/ty/flags.rs
  10. +6 −10 src/librustc/ty/fold.rs
  11. +7 −12 src/librustc/ty/inhabitedness/mod.rs
  12. +1 −1 src/librustc/ty/mod.rs
  13. +9 −26 src/librustc/ty/print/pretty.rs
  14. +5 −5 src/librustc/ty/relate.rs
  15. +28 −58 src/librustc/ty/structural_impls.rs
  16. +3 −76 src/librustc/ty/sty.rs
  17. +13 −16 src/librustc/ty/subst.rs
  18. +2 −2 src/librustc/ty/util.rs
  19. +3 −1 src/librustc/ty/walk.rs
  20. +3 −2 src/librustc/ty/wf.rs
  21. +11 −20 src/librustc_codegen_ssa/mir/constant.rs
  22. +1 −0 src/librustc_codegen_ssa/mir/operand.rs
  23. +2 −2 src/librustc_mir/borrow_check/error_reporting.rs
  24. +2 −2 src/librustc_mir/borrow_check/mutability_errors.rs
  25. +1 −1 src/librustc_mir/borrow_check/nll/renumber.rs
  26. +32 −35 src/librustc_mir/borrow_check/nll/type_check/mod.rs
  27. +2 −2 src/librustc_mir/build/expr/as_rvalue.rs
  28. +1 −1 src/librustc_mir/build/matches/test.rs
  29. +1 −1 src/librustc_mir/build/misc.rs
  30. +1 −1 src/librustc_mir/build/mod.rs
  31. +2 −2 src/librustc_mir/const_eval.rs
  32. +23 −17 src/librustc_mir/hair/cx/expr.rs
  33. +6 −6 src/librustc_mir/hair/cx/mod.rs
  34. +2 −2 src/librustc_mir/hair/mod.rs
  35. +1 −1 src/librustc_mir/hair/pattern/_match.rs
  36. +7 −9 src/librustc_mir/hair/pattern/mod.rs
  37. +12 −25 src/librustc_mir/interpret/operand.rs
  38. +31 −48 src/librustc_mir/monomorphize/collector.rs
  39. +10 −14 src/librustc_mir/monomorphize/item.rs
  40. +6 −6 src/librustc_mir/shim.rs
  41. +1 −1 src/librustc_mir/transform/const_prop.rs
  42. +2 −2 src/librustc_mir/transform/elaborate_drops.rs
  43. +1 −1 src/librustc_mir/transform/erase_regions.rs
  44. +4 −4 src/librustc_mir/transform/generator.rs
  45. +4 −3 src/librustc_mir/transform/qualify_consts.rs
  46. +2 −2 src/librustc_mir/transform/simplify_branches.rs
  47. +2 −2 src/librustc_mir/util/elaborate_drops.rs
  48. +5 −14 src/librustc_mir/util/pretty.rs
  49. +4 −7 src/librustc_traits/chalk_context/mod.rs
  50. +1 −1 src/librustc_traits/chalk_context/program_clauses.rs
  51. +10 −10 src/librustc_typeck/astconv.rs
  52. +2 −2 src/librustc_typeck/check/mod.rs
  53. +4 −10 src/librustc_typeck/check/wfcheck.rs
  54. +3 −6 src/librustc_typeck/constrained_type_params.rs
  55. +4 −6 src/librustc_typeck/variance/constraints.rs
  56. +8 −8 src/librustdoc/clean/mod.rs
@@ -1,7 +1,8 @@
use std::fmt;
use rustc_macros::HashStable;

use crate::ty::{Ty, InferConst, ParamConst, layout::{HasDataLayout, Size}};
use crate::ty::{Ty, InferConst, ParamConst, layout::{HasDataLayout, Size}, subst::SubstsRef};
use crate::hir::def_id::DefId;

use super::{EvalResult, Pointer, PointerArithmetic, Allocation, AllocId, sign_extend, truncate};

@@ -42,6 +43,10 @@ pub enum ConstValue<'tcx> {
/// An allocation together with a pointer into the allocation.
/// Invariant: the pointer's `AllocId` resolves to the allocation.
ByRef(Pointer, &'tcx Allocation),

/// Used in the HIR by using `Unevaluated` everywhere and later normalizing to one of the other
/// variants when the code is monomorphic enough for that.
Unevaluated(DefId, SubstsRef<'tcx>),
}

#[cfg(target_arch = "x86_64")]
@@ -54,6 +59,7 @@ impl<'tcx> ConstValue<'tcx> {
ConstValue::Param(_) |
ConstValue::Infer(_) |
ConstValue::ByRef(..) |
ConstValue::Unevaluated(..) |
ConstValue::Slice(..) => None,
ConstValue::Scalar(val) => Some(val),
}
@@ -2179,8 +2179,8 @@ impl<'tcx> Operand<'tcx> {
span,
ty,
user_ty: None,
literal: tcx.mk_lazy_const(
ty::LazyConst::Evaluated(ty::Const::zero_sized(ty)),
literal: tcx.mk_const(
ty::Const::zero_sized(ty),
),
})
}
@@ -2497,7 +2497,7 @@ pub struct Constant<'tcx> {
/// Needed for NLL to impose user-given type constraints.
pub user_ty: Option<UserTypeAnnotationIndex>,

pub literal: &'tcx ty::LazyConst<'tcx>,
pub literal: &'tcx ty::Const<'tcx>,
}

/// A collection of projections into user types.
@@ -2696,18 +2696,9 @@ newtype_index! {
impl<'tcx> Debug for Constant<'tcx> {
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
write!(fmt, "const ")?;
fmt_lazy_const_val(fmt, self.literal)
fmt_const_val(fmt, *self.literal)
}
}

/// Write a `ConstValue` in a way closer to the original source code than the `Debug` output.
pub fn fmt_lazy_const_val(f: &mut impl Write, const_val: &ty::LazyConst<'_>) -> fmt::Result {
match *const_val {
ty::LazyConst::Unevaluated(..) => write!(f, "{:?}", const_val),
ty::LazyConst::Evaluated(c) => fmt_const_val(f, c),
}
}

/// Write a `ConstValue` in a way closer to the original source code than the `Debug` output.
pub fn fmt_const_val(f: &mut impl Write, const_val: ty::Const<'_>) -> fmt::Result {
use crate::ty::TyKind::*;
@@ -2760,7 +2751,7 @@ pub fn fmt_const_val(f: &mut impl Write, const_val: ty::Const<'_>) -> fmt::Resul
}
}
// just raw dump everything else
write!(f, "{:?}:{}", value, ty)
write!(f, "{:?} : {}", value, ty)
}

fn def_path_str(def_id: DefId) -> String {
@@ -232,7 +232,7 @@ macro_rules! make_mir_visitor {
}

fn visit_const(&mut self,
constant: & $($mutability)? &'tcx ty::LazyConst<'tcx>,
constant: & $($mutability)? &'tcx ty::Const<'tcx>,
_: Location) {
self.super_const(constant);
}
@@ -886,7 +886,7 @@ macro_rules! make_mir_visitor {
fn super_region(&mut self, _region: & $($mutability)? ty::Region<'tcx>) {
}

fn super_const(&mut self, _const: & $($mutability)? &'tcx ty::LazyConst<'tcx>) {
fn super_const(&mut self, _const: & $($mutability)? &'tcx ty::Const<'tcx>) {
}

fn super_substs(&mut self, _substs: & $($mutability)? SubstsRef<'tcx>) {
@@ -15,7 +15,7 @@ use super::util;
use crate::hir::def_id::DefId;
use crate::infer::{InferCtxt, InferOk, LateBoundRegionConversionTime};
use crate::infer::type_variable::TypeVariableOrigin;
use crate::mir::interpret::{GlobalId};
use crate::mir::interpret::{GlobalId, ConstValue};
use rustc_data_structures::snapshot_map::{Snapshot, SnapshotMap};
use rustc_macros::HashStable;
use syntax::ast::Ident;
@@ -397,8 +397,8 @@ impl<'a, 'b, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for AssociatedTypeNormalizer<'a,
}
}

fn fold_const(&mut self, constant: &'tcx ty::LazyConst<'tcx>) -> &'tcx ty::LazyConst<'tcx> {
if let ty::LazyConst::Unevaluated(def_id, substs) = *constant {
fn fold_const(&mut self, constant: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
if let ConstValue::Unevaluated(def_id, substs) = constant.val {
let tcx = self.selcx.tcx().global_tcx();
if let Some(param_env) = self.tcx().lift_to_global(&self.param_env) {
if substs.needs_infer() || substs.has_placeholders() {
@@ -411,8 +411,9 @@ impl<'a, 'b, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for AssociatedTypeNormalizer<'a,
};
if let Ok(evaluated) = tcx.const_eval(param_env.and(cid)) {
let substs = tcx.lift_to_global(&substs).unwrap();
let evaluated = tcx.mk_const(evaluated);
let evaluated = evaluated.subst(tcx, substs);
return tcx.mk_lazy_const(ty::LazyConst::Evaluated(evaluated));
return evaluated;
}
}
} else {
@@ -424,7 +425,7 @@ impl<'a, 'b, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for AssociatedTypeNormalizer<'a,
promoted: None
};
if let Ok(evaluated) = tcx.const_eval(param_env.and(cid)) {
return tcx.mk_lazy_const(ty::LazyConst::Evaluated(evaluated));
return tcx.mk_const(evaluated);
}
}
}
@@ -5,7 +5,7 @@
use crate::infer::at::At;
use crate::infer::canonical::OriginalQueryValues;
use crate::infer::{InferCtxt, InferOk};
use crate::mir::interpret::GlobalId;
use crate::mir::interpret::{GlobalId, ConstValue};
use crate::traits::project::Normalized;
use crate::traits::{Obligation, ObligationCause, PredicateObligation, Reveal};
use crate::ty::fold::{TypeFoldable, TypeFolder};
@@ -188,8 +188,8 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for QueryNormalizer<'cx, 'gcx, 'tcx
}
}

fn fold_const(&mut self, constant: &'tcx ty::LazyConst<'tcx>) -> &'tcx ty::LazyConst<'tcx> {
if let ty::LazyConst::Unevaluated(def_id, substs) = *constant {
fn fold_const(&mut self, constant: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
if let ConstValue::Unevaluated(def_id, substs) = constant.val {
let tcx = self.infcx.tcx.global_tcx();
if let Some(param_env) = self.tcx().lift_to_global(&self.param_env) {
if substs.needs_infer() || substs.has_placeholders() {
@@ -202,8 +202,9 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for QueryNormalizer<'cx, 'gcx, 'tcx
};
if let Ok(evaluated) = tcx.const_eval(param_env.and(cid)) {
let substs = tcx.lift_to_global(&substs).unwrap();
let evaluated = tcx.mk_const(evaluated);
let evaluated = evaluated.subst(tcx, substs);
return tcx.mk_lazy_const(ty::LazyConst::Evaluated(evaluated));
return evaluated;
}
}
} else {
@@ -215,7 +216,7 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for QueryNormalizer<'cx, 'gcx, 'tcx
promoted: None,
};
if let Ok(evaluated) = tcx.const_eval(param_env.and(cid)) {
return tcx.mk_lazy_const(ty::LazyConst::Evaluated(evaluated));
return tcx.mk_const(evaluated);
}
}
}
@@ -247,12 +247,12 @@ pub fn decode_canonical_var_infos<'a, 'tcx, D>(decoder: &mut D)
}

#[inline]
pub fn decode_lazy_const<'a, 'tcx, D>(decoder: &mut D)
-> Result<&'tcx ty::LazyConst<'tcx>, D::Error>
pub fn decode_const<'a, 'tcx, D>(decoder: &mut D)
-> Result<&'tcx ty::Const<'tcx>, D::Error>
where D: TyDecoder<'a, 'tcx>,
'tcx: 'a,
{
Ok(decoder.tcx().mk_lazy_const(Decodable::decode(decoder)?))
Ok(decoder.tcx().mk_const(Decodable::decode(decoder)?))
}

#[inline]
@@ -389,10 +389,10 @@ macro_rules! implement_ty_decoder {
}
}

impl<$($typaram),*> SpecializedDecoder<&'tcx $crate::ty::LazyConst<'tcx>>
impl<$($typaram),*> SpecializedDecoder<&'tcx $crate::ty::Const<'tcx>>
for $DecoderName<$($typaram),*> {
fn specialized_decode(&mut self) -> Result<&'tcx ty::LazyConst<'tcx>, Self::Error> {
decode_lazy_const(self)
fn specialized_decode(&mut self) -> Result<&'tcx ty::Const<'tcx>, Self::Error> {
decode_const(self)
}
}

@@ -28,7 +28,7 @@ use crate::traits;
use crate::traits::{Clause, Clauses, GoalKind, Goal, Goals};
use crate::ty::{self, DefIdTree, Ty, TypeAndMut};
use crate::ty::{TyS, TyKind, List};
use crate::ty::{AdtKind, AdtDef, ClosureSubsts, GeneratorSubsts, Region, Const, LazyConst};
use crate::ty::{AdtKind, AdtDef, ClosureSubsts, GeneratorSubsts, Region, Const};
use crate::ty::{PolyFnSig, InferTy, ParamTy, ProjectionTy, ExistentialPredicate, Predicate};
use crate::ty::RegionKind;
use crate::ty::{TyVar, TyVid, IntVar, IntVid, FloatVar, FloatVid, ConstVid};
@@ -126,7 +126,7 @@ pub struct CtxtInterners<'tcx> {
goal: InternedSet<'tcx, GoalKind<'tcx>>,
goal_list: InternedSet<'tcx, List<Goal<'tcx>>>,
projs: InternedSet<'tcx, List<ProjectionKind<'tcx>>>,
lazy_const: InternedSet<'tcx, LazyConst<'tcx>>,
const_: InternedSet<'tcx, Const<'tcx>>,
}

impl<'gcx: 'tcx, 'tcx> CtxtInterners<'tcx> {
@@ -144,7 +144,7 @@ impl<'gcx: 'tcx, 'tcx> CtxtInterners<'tcx> {
goal: Default::default(),
goal_list: Default::default(),
projs: Default::default(),
lazy_const: Default::default(),
const_: Default::default(),
}
}

@@ -874,14 +874,11 @@ impl CanonicalUserType<'gcx> {
_ => false,
},

UnpackedKind::Const(ct) => match ct {
ty::LazyConst::Evaluated(ty::Const {
val: ConstValue::Infer(InferConst::Canonical(debruijn, b)),
..
}) => {
UnpackedKind::Const(ct) => match ct.val {
ConstValue::Infer(InferConst::Canonical(debruijn, b)) => {
// We only allow a `ty::INNERMOST` index in substitutions.
assert_eq!(*debruijn, ty::INNERMOST);
cvar == *b
assert_eq!(debruijn, ty::INNERMOST);
cvar == b
}
_ => false,
},
@@ -1788,7 +1785,7 @@ macro_rules! nop_list_lift {
nop_lift!{Ty<'a> => Ty<'tcx>}
nop_lift!{Region<'a> => Region<'tcx>}
nop_lift!{Goal<'a> => Goal<'tcx>}
nop_lift!{&'a LazyConst<'a> => &'tcx LazyConst<'tcx>}
nop_lift!{&'a Const<'a> => &'tcx Const<'tcx>}

nop_list_lift!{Goal<'a> => Goal<'tcx>}
nop_list_lift!{Clause<'a> => Clause<'tcx>}
@@ -2274,12 +2271,6 @@ impl<'tcx: 'lcx, 'lcx> Borrow<GoalKind<'lcx>> for Interned<'tcx, GoalKind<'tcx>>
}
}

impl<'tcx: 'lcx, 'lcx> Borrow<LazyConst<'lcx>> for Interned<'tcx, LazyConst<'tcx>> {
fn borrow<'a>(&'a self) -> &'a LazyConst<'lcx> {
&self.0
}
}

impl<'tcx: 'lcx, 'lcx> Borrow<[ExistentialPredicate<'lcx>]>
for Interned<'tcx, List<ExistentialPredicate<'tcx>>> {
fn borrow<'a>(&'a self) -> &'a [ExistentialPredicate<'lcx>] {
@@ -2387,7 +2378,7 @@ pub fn keep_local<'tcx, T: ty::TypeFoldable<'tcx>>(x: &T) -> bool {
direct_interners!('tcx,
region: mk_region(|r: &RegionKind| r.keep_in_local_tcx()) -> RegionKind,
goal: mk_goal(|c: &GoalKind<'_>| keep_local(c)) -> GoalKind<'tcx>,
lazy_const: mk_lazy_const(|c: &LazyConst<'_>| keep_local(&c)) -> LazyConst<'tcx>
const_: mk_const(|c: &Const<'_>| keep_local(&c)) -> Const<'tcx>
);

macro_rules! slice_interners {
@@ -2575,8 +2566,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {

#[inline]
pub fn mk_array(self, ty: Ty<'tcx>, n: u64) -> Ty<'tcx> {
self.mk_ty(Array(ty, self.mk_lazy_const(
ty::LazyConst::Evaluated(ty::Const::from_usize(self.global_tcx(), n))
self.mk_ty(Array(ty, self.mk_const(
ty::Const::from_usize(self.global_tcx(), n)
)))
}

@@ -2670,11 +2661,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
}

#[inline]
pub fn mk_const_var(self, v: ConstVid<'tcx>, ty: Ty<'tcx>) -> &'tcx LazyConst<'tcx> {
self.mk_lazy_const(LazyConst::Evaluated(ty::Const {
pub fn mk_const_var(self, v: ConstVid<'tcx>, ty: Ty<'tcx>) -> &'tcx Const<'tcx> {
self.mk_const(ty::Const {
val: ConstValue::Infer(InferConst::Var(v)),
ty,
}))
})
}

#[inline]
@@ -2705,11 +2696,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
index: u32,
name: InternedString,
ty: Ty<'tcx>
) -> &'tcx LazyConst<'tcx> {
self.mk_lazy_const(LazyConst::Evaluated(ty::Const {
) -> &'tcx Const<'tcx> {
self.mk_const(ty::Const {
val: ConstValue::Param(ParamConst { index, name }),
ty,
}))
})
}

#[inline]
@@ -176,12 +176,9 @@ impl<'a, 'gcx, 'lcx, 'tcx> ty::TyS<'tcx> {

ty::Adt(def, _) => format!("{} `{}`", def.descr(), tcx.def_path_str(def.did)).into(),
ty::Foreign(def_id) => format!("extern type `{}`", tcx.def_path_str(def_id)).into(),
ty::Array(_, n) => match n {
ty::LazyConst::Evaluated(n) => match n.assert_usize(tcx) {
Some(n) => format!("array of {} elements", n).into(),
None => "array".into(),
},
ty::LazyConst::Unevaluated(..) => "array".into(),
ty::Array(_, n) => match n.assert_usize(tcx) {
Some(n) => format!("array of {} elements", n).into(),
None => "array".into(),
}
ty::Slice(_) => "slice".into(),
ty::RawPtr(_) => "*-ptr".into(),
Oops, something went wrong.

0 comments on commit 5cd2806

Please sign in to comment.
You can’t perform that action at this time.