Skip to content

Commit 4b7fc69

Browse files
committed
Assert index relationship between type_variable_table and var_unification_table
1 parent 11a1f13 commit 4b7fc69

File tree

2 files changed

+13
-22
lines changed

2 files changed

+13
-22
lines changed

crates/hir_ty/src/infer/unify.rs

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -225,36 +225,27 @@ impl InferenceTable {
225225
}
226226
}
227227

228+
fn new_var(&mut self, kind: TyVariableKind, diverging: bool) -> Ty {
229+
self.type_variable_table.push(TypeVariableData { diverging });
230+
let key = self.var_unification_table.new_key(TypeVarValue::Unknown);
231+
assert_eq!(key.0 as usize, self.type_variable_table.inner.len() - 1);
232+
Ty::InferenceVar(InferenceVar::from_inner(key), kind)
233+
}
234+
228235
pub(crate) fn new_type_var(&mut self) -> Ty {
229-
self.type_variable_table.push(TypeVariableData { diverging: false });
230-
Ty::InferenceVar(
231-
InferenceVar::from_inner(self.var_unification_table.new_key(TypeVarValue::Unknown)),
232-
TyVariableKind::General,
233-
)
236+
self.new_var(TyVariableKind::General, false)
234237
}
235238

236239
pub(crate) fn new_integer_var(&mut self) -> Ty {
237-
self.type_variable_table.push(TypeVariableData { diverging: false });
238-
Ty::InferenceVar(
239-
InferenceVar::from_inner(self.var_unification_table.new_key(TypeVarValue::Unknown)),
240-
TyVariableKind::Integer,
241-
)
240+
self.new_var(TyVariableKind::Integer, false)
242241
}
243242

244243
pub(crate) fn new_float_var(&mut self) -> Ty {
245-
self.type_variable_table.push(TypeVariableData { diverging: false });
246-
Ty::InferenceVar(
247-
InferenceVar::from_inner(self.var_unification_table.new_key(TypeVarValue::Unknown)),
248-
TyVariableKind::Float,
249-
)
244+
self.new_var(TyVariableKind::Float, false)
250245
}
251246

252247
pub(crate) fn new_maybe_never_var(&mut self) -> Ty {
253-
self.type_variable_table.push(TypeVariableData { diverging: true });
254-
Ty::InferenceVar(
255-
InferenceVar::from_inner(self.var_unification_table.new_key(TypeVarValue::Unknown)),
256-
TyVariableKind::General,
257-
)
248+
self.new_var(TyVariableKind::General, true)
258249
}
259250

260251
pub(crate) fn resolve_ty_completely(&mut self, ty: Ty) -> Ty {

crates/hir_ty/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,11 +527,11 @@ impl TypeWalk for GenericPredicate {
527527
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
528528
pub struct Canonical<T> {
529529
pub value: T,
530-
pub kinds: Arc<[chalk_ir::TyVariableKind]>,
530+
pub kinds: Arc<[TyVariableKind]>,
531531
}
532532

533533
impl<T> Canonical<T> {
534-
pub fn new(value: T, kinds: impl IntoIterator<Item = chalk_ir::TyVariableKind>) -> Self {
534+
pub fn new(value: T, kinds: impl IntoIterator<Item = TyVariableKind>) -> Self {
535535
Self { value, kinds: kinds.into_iter().collect() }
536536
}
537537
}

0 commit comments

Comments
 (0)