Skip to content

Commit 5509991

Browse files
committed
Implement ConstValue::InferVar and friends
1 parent dd45a20 commit 5509991

File tree

14 files changed

+51
-42
lines changed

14 files changed

+51
-42
lines changed

src/librustc/ich/impls_ty.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,9 @@ for ::mir::interpret::ConstValue<'gcx> {
401401
Param(ref param) => {
402402
param.hash_stable(hcx, hasher);
403403
}
404+
InferVar(vid) => {
405+
vid.hash_stable(hcx, hasher);
406+
}
404407
}
405408
}
406409
}
@@ -910,7 +913,6 @@ for ty::TyKind<'gcx>
910913

911914
impl_stable_hash_for!(enum ty::InferTy {
912915
TyVar(a),
913-
ConstVar(a),
914916
IntVar(a),
915917
FloatVar(a),
916918
FreshTy(a),
@@ -1298,7 +1300,6 @@ impl_stable_hash_for!(enum infer::canonical::CanonicalVarKind {
12981300

12991301
impl_stable_hash_for!(enum infer::canonical::CanonicalTyVarKind {
13001302
General,
1301-
Const,
13021303
Int,
13031304
Float
13041305
});

src/librustc/infer/canonical/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,6 @@ pub enum CanonicalTyVarKind {
110110
/// General type variable `?T` that can be unified with arbitrary types.
111111
General,
112112

113-
/// Const type variable `?C` that can be unified with const expressions.
114-
Const,
115-
116113
/// Integral type variable `?I` (that can only be unified with integral types).
117114
Int,
118115

@@ -247,7 +244,6 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
247244
CanonicalTyVarKind::General => {
248245
self.next_ty_var(TypeVariableOrigin::MiscVariable(span))
249246
}
250-
CanonicalTyVarKind::Const => self.tcx.mk_const_var(self.next_const_var_id()),
251247
CanonicalTyVarKind::Int => self.tcx.mk_int_var(self.next_int_var_id()),
252248
CanonicalTyVarKind::Float => self.tcx.mk_float_var(self.next_float_var_id()),
253249
};

src/librustc/infer/freshen.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,7 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for TypeFreshener<'a, 'gcx, 'tcx> {
141141
ty::FreshTy)
142142
}
143143

144-
ty::Infer(ty::ConstVar(v)) => {
145-
self.freshen(
146-
self.infcx.const_unification_table.borrow_mut()
147-
.probe_value(v)
148-
.map(|v| v.to_type(tcx)),
149-
ty::ConstVar(v),
150-
ty::FreshIntTy
151-
)
152-
}
153-
154-
ty::Infer(ty::IntVar(v)) => {
144+
ty::TyInfer(ty::IntVar(v)) => {
155145
self.freshen(
156146
self.infcx.int_unification_table.borrow_mut()
157147
.probe_value(v)

src/librustc/infer/mod.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -902,8 +902,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
902902
self.tcx.mk_ty_var(self.next_ty_var_id(true, origin))
903903
}
904904

905-
pub fn next_const_var(&self) -> Ty<'tcx> {
906-
self.tcx.mk_const_var(self.next_const_var_id())
905+
pub fn next_const_var(&self, ty: Ty<'tcx>) -> &'tcx ty::Const<'tcx> {
906+
// TODO(const_generics): do we need this function?
907+
self.tcx.mk_const_var(self.next_const_var_id(), ty)
907908
}
908909

909910
pub fn next_const_var_id(&self) -> ConstVid {
@@ -950,7 +951,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
950951

951952
pub fn var_for_def(&self,
952953
span: Span,
953-
param: &ty::GenericParamDef)
954+
param: &ty::GenericParamDef<'tcx>)
954955
-> Kind<'tcx> {
955956
match param.kind {
956957
GenericParamDefKind::Lifetime => {
@@ -971,22 +972,17 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
971972
self.type_variables
972973
.borrow_mut()
973974
.new_var(self.universe(),
974-
false,
975-
TypeVariableOrigin::TypeParameterDefinition(span, param.name));
975+
false,
976+
TypeVariableOrigin::TypeParameterDefinition(span, param.name));
976977

977978
self.tcx.mk_ty_var(ty_var_id).into()
978979
}
979-
GenericParamDefKind::Const { .. } => {
980-
let _ty_var_id =
981-
self.type_variables
980+
GenericParamDefKind::Const { ty } => {
981+
let const_var_id =
982+
self.const_unification_table
982983
.borrow_mut()
983-
.new_var(
984-
self.universe(),
985-
false,
986-
TypeVariableOrigin::ConstParameterDefinition(span, param.name)
987-
);
988-
//self.tcx.mk_const(ty_var_id).into()
989-
unimplemented!()
984+
.new_key(None);
985+
self.tcx.mk_const_var(const_var_id, ty).into()
990986
}
991987
}
992988
}

src/librustc/mir/interpret/value.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ pub enum ConstValue<'tcx> {
1616
Unevaluated(DefId, &'tcx Substs<'tcx>),
1717
/// A const generic parameter.
1818
Param(ty::ParamConst),
19+
/// Infer the value of the const.
20+
InferVar(ty::ConstVid),
1921
/// Used only for types with layout::abi::Scalar ABI and ZSTs
2022
///
2123
/// Not using the enum `Value` to encode that this must not be `Undef`
@@ -36,6 +38,7 @@ impl<'tcx> ConstValue<'tcx> {
3638
ConstValue::ByRef(..) |
3739
ConstValue::ScalarPair(..) => None,
3840
ConstValue::Param(_) => unimplemented!(), // TODO(const_generics)
41+
ConstValue::InferVar(_) => unimplemented!(), // TODO(const_generics)
3942
ConstValue::Scalar(val) => Some(val),
4043
}
4144
}

src/librustc/ty/context.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2529,8 +2529,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
25292529
self.mk_infer(TyVar(v))
25302530
}
25312531

2532-
pub fn mk_const_var(self, v: ConstVid) -> Ty<'tcx> {
2533-
self.mk_infer(ConstVar(v))
2532+
pub fn mk_const_var(self, v: ConstVid, ty: Ty<'tcx>) -> &'tcx ty::Const<'tcx> {
2533+
self.mk_const(ty::Const {
2534+
val: ConstValue::InferVar(v),
2535+
ty,
2536+
})
25342537
}
25352538

25362539
pub fn mk_int_var(self, v: IntVid) -> Ty<'tcx> {

src/librustc/ty/flags.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ impl FlagComputation {
130130
}
131131

132132
ty::TyVar(_) |
133-
ty::ConstVar(_) |
134133
ty::IntVar(_) |
135134
ty::FloatVar(_) => {
136135
self.add_flags(TypeFlags::KEEP_IN_LOCAL_TCX)

src/librustc/ty/structural_impls.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,7 @@ impl<'tcx> TypeFoldable<'tcx> for ConstValue<'tcx> {
11441144
ConstValue::Unevaluated(def_id, substs.fold_with(folder))
11451145
}
11461146
ConstValue::Param(param) => ConstValue::Param(param),
1147+
ConstValue::InferVar(vid) => ConstValue::InferVar(vid),
11471148
}
11481149
}
11491150

@@ -1152,6 +1153,7 @@ impl<'tcx> TypeFoldable<'tcx> for ConstValue<'tcx> {
11521153
ConstValue::Scalar(_) |
11531154
ConstValue::ScalarPair(_, _) |
11541155
ConstValue::Param(_) | // TODO(const_generics)
1156+
ConstValue::InferVar(_) | // TODO(const_generics)
11551157
ConstValue::ByRef(_, _) => false,
11561158
ConstValue::Unevaluated(_, substs) => substs.visit_with(visitor),
11571159
}

src/librustc/ty/sty.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,6 @@ impl From<RegionVid> for usize {
12281228
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
12291229
pub enum InferTy {
12301230
TyVar(TyVid),
1231-
ConstVar(ConstVid),
12321231
IntVar(IntVid),
12331232
FloatVar(FloatVid),
12341233

src/librustc/util/ppaux.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,6 @@ define_print! {
950950
} else {
951951
match *self {
952952
ty::TyVar(_) => write!(f, "_"),
953-
ty::ConstVar(_) => write!(f, "{}", "{const}"),
954953
ty::IntVar(_) => write!(f, "{}", "{integer}"),
955954
ty::FloatVar(_) => write!(f, "{}", "{float}"),
956955
ty::CanonicalTy(_) => write!(f, "_"),
@@ -964,7 +963,6 @@ define_print! {
964963
debug {
965964
match *self {
966965
ty::TyVar(ref v) => write!(f, "{:?}", v),
967-
ty::ConstVar(ref v) => write!(f, "{:?}", v),
968966
ty::IntVar(ref v) => write!(f, "{:?}", v),
969967
ty::FloatVar(ref v) => write!(f, "{:?}", v),
970968
ty::CanonicalTy(v) => write!(f, "?{:?}", v.index()),

0 commit comments

Comments
 (0)