Skip to content

Commit 39cd395

Browse files
committed
rename the fields in infer/mod to make ty less special
Also add krates to the snapshots.
1 parent 4e2371e commit 39cd395

File tree

3 files changed

+32
-28
lines changed

3 files changed

+32
-28
lines changed

chalk-rust/src/solve/infer/mod.rs

+21-17
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ use self::lifetime_var::LifetimeInferenceVariable;
1818

1919
#[derive(Clone)]
2020
pub struct InferenceTable {
21-
unify: ena::UnificationTable<TyInferenceVariable>,
22-
values: Vec<Arc<Ty>>,
21+
ty_unify: ena::UnificationTable<TyInferenceVariable>,
22+
ty_values: Vec<Arc<Ty>>,
2323

2424
krate_unify: ena::UnificationTable<KrateInferenceVariable>,
2525

@@ -30,8 +30,10 @@ pub struct InferenceTable {
3030
}
3131

3232
pub struct InferenceSnapshot {
33-
unify_snapshot: ena::Snapshot<TyInferenceVariable>,
34-
values_len: usize,
33+
ty_unify_snapshot: ena::Snapshot<TyInferenceVariable>,
34+
ty_values_len: usize,
35+
36+
krate_unify_snapshot: ena::Snapshot<KrateInferenceVariable>,
3537
}
3638

3739
pub type ParameterInferenceVariable = ParameterKind<TyInferenceVariable,
@@ -41,9 +43,9 @@ pub type ParameterInferenceVariable = ParameterKind<TyInferenceVariable,
4143
impl InferenceTable {
4244
pub fn new() -> Self {
4345
InferenceTable {
44-
unify: ena::UnificationTable::new(),
46+
ty_unify: ena::UnificationTable::new(),
4547
krate_unify: ena::UnificationTable::new(),
46-
values: vec![],
48+
ty_values: vec![],
4749
lifetime_vars: vec![],
4850
}
4951
}
@@ -57,7 +59,7 @@ impl InferenceTable {
5759
}
5860

5961
pub fn new_variable(&mut self, ui: UniverseIndex) -> TyInferenceVariable {
60-
self.unify.new_key(TyInferenceValue::Unbound(ui))
62+
self.ty_unify.new_key(TyInferenceValue::Unbound(ui))
6163
}
6264

6365
pub fn new_lifetime_variable(&mut self, ui: UniverseIndex) -> LifetimeInferenceVariable {
@@ -84,20 +86,22 @@ impl InferenceTable {
8486
}
8587

8688
pub fn snapshot(&mut self) -> InferenceSnapshot {
87-
let unify_snapshot = self.unify.snapshot();
89+
let ty_unify_snapshot = self.ty_unify.snapshot();
90+
let krate_unify_snapshot = self.krate_unify.snapshot();
8891
InferenceSnapshot {
89-
unify_snapshot: unify_snapshot,
90-
values_len: self.values.len(),
92+
ty_unify_snapshot,
93+
krate_unify_snapshot,
94+
ty_values_len: self.ty_values.len(),
9195
}
9296
}
9397

9498
pub fn rollback_to(&mut self, snapshot: InferenceSnapshot) {
95-
self.unify.rollback_to(snapshot.unify_snapshot);
96-
self.values.truncate(snapshot.values_len);
99+
self.ty_unify.rollback_to(snapshot.ty_unify_snapshot);
100+
self.ty_values.truncate(snapshot.ty_values_len);
97101
}
98102

99103
fn commit(&mut self, snapshot: InferenceSnapshot) {
100-
self.unify.commit(snapshot.unify_snapshot);
104+
self.ty_unify.commit(snapshot.ty_unify_snapshot);
101105
}
102106

103107
fn commit_if_ok<F, R>(&mut self, op: F) -> Result<R>
@@ -120,9 +124,9 @@ impl InferenceTable {
120124
fn normalize_shallow(&mut self, leaf: &Ty) -> Option<Arc<Ty>> {
121125
leaf.inference_var()
122126
.and_then(|var| {
123-
match self.unify.probe_value(var) {
127+
match self.ty_unify.probe_value(var) {
124128
TyInferenceValue::Unbound(_) => None,
125-
TyInferenceValue::Bound(val) => Some(self.values[val.as_usize()].clone()),
129+
TyInferenceValue::Bound(val) => Some(self.ty_values[val.as_usize()].clone()),
126130
}
127131
})
128132
}
@@ -135,9 +139,9 @@ impl InferenceTable {
135139
}
136140

137141
fn probe_var(&mut self, var: TyInferenceVariable) -> Option<Arc<Ty>> {
138-
match self.unify.probe_value(var) {
142+
match self.ty_unify.probe_value(var) {
139143
TyInferenceValue::Unbound(_) => None,
140-
TyInferenceValue::Bound(val) => Some(self.values[val.as_usize()].clone()),
144+
TyInferenceValue::Bound(val) => Some(self.ty_values[val.as_usize()].clone()),
141145
}
142146
}
143147

chalk-rust/src/solve/infer/query.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ impl<'q> Querifier<'q> {
4747
free_vars.into_iter()
4848
.map(|p_v| match p_v {
4949
ParameterKind::Ty(v) => {
50-
debug_assert!(table.unify.find(v) == v);
51-
match table.unify.probe_value(v) {
50+
debug_assert!(table.ty_unify.find(v) == v);
51+
match table.ty_unify.probe_value(v) {
5252
TyInferenceValue::Unbound(ui) => ParameterKind::Ty(ui),
5353
TyInferenceValue::Bound(_) => panic!("free var now bound"),
5454
}
@@ -97,7 +97,7 @@ impl<'q> Folder for Querifier<'q> {
9797
// canonical index `root_var` in the union-find table,
9898
// and then map `root_var` to a fresh index that is
9999
// unique to this quantification.
100-
let free_var = ParameterKind::Ty(self.table.unify.find(var));
100+
let free_var = ParameterKind::Ty(self.table.ty_unify.find(var));
101101
let position = self.add(free_var) + binders;
102102
Ok(TyInferenceVariable::from_depth(position).to_ty())
103103
}

chalk-rust/src/solve/infer/unify.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl<'t> Unifier<'t> {
8787
let var2 = TyInferenceVariable::from_depth(depth2);
8888
debug!("unify_ty_ty: unify_var_var({:?}, {:?})", var1, var2);
8989
Ok(self.table
90-
.unify
90+
.ty_unify
9191
.unify_var_var(var1, var2)
9292
.expect("unification of two unbound variables cannot fail"))
9393
}
@@ -203,16 +203,16 @@ impl<'t> Unifier<'t> {
203203
// `forall` binders that had been introduced at the point
204204
// this variable was created -- though it may change over time
205205
// as the variable is unified.
206-
let universe_index = match self.table.unify.probe_value(var) {
206+
let universe_index = match self.table.ty_unify.probe_value(var) {
207207
TyInferenceValue::Unbound(ui) => ui,
208208
TyInferenceValue::Bound(_) => panic!("`unify_var_apply` invoked on bound var"),
209209
};
210210

211211
OccursCheck::new(self, var, universe_index).check_ty(ty)?;
212212

213-
let value_index = ValueIndex::new(self.table.values.len());
214-
self.table.values.push(Arc::new(ty.clone()));
215-
self.table.unify.unify_var_value(var, TyInferenceValue::Bound(value_index)).unwrap();
213+
let value_index = ValueIndex::new(self.table.ty_values.len());
214+
self.table.ty_values.push(Arc::new(ty.clone()));
215+
self.table.ty_unify.unify_var_value(var, TyInferenceValue::Bound(value_index)).unwrap();
216216
debug!("unify_var_ty: var {:?} set to {:?}", var, ty);
217217

218218
Ok(())
@@ -340,14 +340,14 @@ impl<'u, 't> OccursCheck<'u, 't> {
340340

341341
Ty::Var(depth) => {
342342
let v = TyInferenceVariable::from_depth(depth - self.binders);
343-
let ui = match self.unifier.table.unify.probe_value(v) {
343+
let ui = match self.unifier.table.ty_unify.probe_value(v) {
344344
TyInferenceValue::Unbound(ui) => ui,
345345
TyInferenceValue::Bound(_) => {
346346
unreachable!("expected `parameter` to be normalized")
347347
}
348348
};
349349

350-
if self.unifier.table.unify.unioned(v, self.var) {
350+
if self.unifier.table.ty_unify.unioned(v, self.var) {
351351
bail!("cycle during unification");
352352
}
353353

@@ -360,7 +360,7 @@ impl<'u, 't> OccursCheck<'u, 't> {
360360
// This is OK, if ?B is promoted to universe 0.
361361
self.unifier
362362
.table
363-
.unify
363+
.ty_unify
364364
.unify_var_value(v, TyInferenceValue::Unbound(self.universe_index))
365365
.unwrap();
366366
}

0 commit comments

Comments
 (0)