Skip to content

Commit c888af5

Browse files
committed
Replace ConstVariableTable with UnificationTable
1 parent 2308d2d commit c888af5

File tree

9 files changed

+181
-328
lines changed

9 files changed

+181
-328
lines changed

src/librustc/infer/combine.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use super::{InferCtxt, MiscVariable, TypeTrace};
2828
use super::lub::Lub;
2929
use super::sub::Sub;
3030
use super::type_variable::TypeVariableValue;
31-
use super::const_variable::ConstVariableValue;
31+
use super::unify_key::{ConstVarValue, ConstVariableValue, ConstVariableOrigin};
3232

3333
use crate::hir::def_id::DefId;
3434
use crate::mir::interpret::ConstValue;
@@ -40,7 +40,7 @@ use crate::ty::subst::SubstsRef;
4040
use crate::traits::{Obligation, PredicateObligations};
4141

4242
use syntax::ast;
43-
use syntax_pos::Span;
43+
use syntax_pos::{Span, DUMMY_SP};
4444

4545
#[derive(Clone)]
4646
pub struct CombineFields<'infcx, 'gcx: 'infcx+'tcx, 'tcx: 'infcx> {
@@ -166,7 +166,10 @@ impl<'infcx, 'gcx, 'tcx> InferCtxt<'infcx, 'gcx, 'tcx> {
166166
) -> RelateResult<'tcx, &'tcx LazyConst<'tcx>> {
167167
self.const_unification_table
168168
.borrow_mut()
169-
.unify_var_value(vid, ConstVariableValue::Known { value })
169+
.unify_var_value(vid, ConstVarValue {
170+
origin: ConstVariableOrigin::ConstInference(DUMMY_SP),
171+
val: ConstVariableValue::Known { value },
172+
})
170173
.map_err(|e| const_unification_error(vid_is_expected, e))?;
171174
Ok(value)
172175
}
@@ -590,7 +593,7 @@ impl<'cx, 'gcx, 'tcx> TypeRelation<'cx, 'gcx, 'tcx> for Generalizer<'cx, 'gcx, '
590593
..
591594
}) => {
592595
let mut variable_table = self.infcx.const_unification_table.borrow_mut();
593-
match variable_table.probe(*vid).known() {
596+
match variable_table.probe_value(*vid).val.known() {
594597
Some(u) => {
595598
self.relate(&u, &u)
596599
}

src/librustc/infer/const_variable.rs

Lines changed: 0 additions & 271 deletions
This file was deleted.

src/librustc/infer/equate.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::ty::TyVar;
88
use crate::ty::subst::SubstsRef;
99
use crate::ty::relate::{self, Relate, RelateResult, TypeRelation};
1010
use crate::mir::interpret::ConstValue;
11+
use crate::infer::unify_key::replace_if_possible;
1112

1213
/// Ensures `a` is made equal to `b`. Returns `a` on success.
1314
pub struct Equate<'combine, 'infcx: 'combine, 'gcx: 'infcx+'tcx, 'tcx: 'infcx> {
@@ -110,8 +111,8 @@ impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx>
110111
if a == b { return Ok(a); }
111112

112113
let infcx = self.fields.infcx;
113-
let a = infcx.const_unification_table.borrow_mut().replace_if_possible(a);
114-
let b = infcx.const_unification_table.borrow_mut().replace_if_possible(b);
114+
let a = replace_if_possible(infcx.const_unification_table.borrow_mut(), a);
115+
let b = replace_if_possible(infcx.const_unification_table.borrow_mut(), b);
115116
let a_is_expected = self.a_is_expected();
116117
if let (&ty::LazyConst::Evaluated(a_eval), &ty::LazyConst::Evaluated(b_eval)) = (a, b) {
117118
match (a_eval.val, b_eval.val) {

src/librustc/infer/freshen.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for TypeFreshener<'a, 'gcx, 'tcx> {
232232
ConstValue::Infer(ty::InferConst::Var(v)) => {
233233
let opt_ct = self.infcx.const_unification_table
234234
.borrow_mut()
235-
.probe(*v)
235+
.probe_value(*v)
236+
.val
236237
.known();
237238
return self.freshen_const(
238239
opt_ct,

src/librustc/infer/fudge.rs

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -181,26 +181,16 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for InferenceFudger<'a, 'gcx, 'tcx>
181181
val: ConstValue::Infer(ty::InferConst::Var(vid)),
182182
ty,
183183
}) = *ct {
184-
match self.const_variables.get(&vid) {
185-
None => {
186-
// This variable was created before the
187-
// "fudging". Since we refresh all
188-
// variables to their binding anyhow, we know
189-
// that it is unbound, so we can just return
190-
// it.
191-
debug_assert!(
192-
self.infcx.const_unification_table.borrow_mut()
193-
.probe(vid)
194-
.is_unknown()
195-
);
196-
ct
197-
}
198-
Some(&origin) => {
199-
// This variable was created during the
200-
// fudging. Recreate it with a fresh variable
201-
// here.
202-
self.infcx.next_const_var(ty, origin)
203-
}
184+
if self.const_variables.contains(&vid) {
185+
// This variable was created during the
186+
// fudging. Recreate it with a fresh variable
187+
// here.
188+
let origin = self.infcx.const_unification_table.borrow_mut()
189+
.probe_value(vid)
190+
.origin;
191+
self.infcx.next_const_var(ty, origin)
192+
} else {
193+
ct
204194
}
205195
} else {
206196
ct.super_fold_with(self)

0 commit comments

Comments
 (0)