aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2021-03-01 12:54:17 +0000
committerLukas Wirth <[email protected]>2021-03-01 12:54:17 +0000
commit4b7fc693150f333cefe0e69d93271807f32741c4 (patch)
tree8232ad3db121f32350aa78a1151aca46df373ace /crates/hir_ty/src
parent11a1f13cd1cf6da484fd4b8bfb5f72a625c2186a (diff)
Assert index relationship between type_variable_table and var_unification_table
Diffstat (limited to 'crates/hir_ty/src')
-rw-r--r--crates/hir_ty/src/infer/unify.rs31
-rw-r--r--crates/hir_ty/src/lib.rs4
2 files changed, 13 insertions, 22 deletions
diff --git a/crates/hir_ty/src/infer/unify.rs b/crates/hir_ty/src/infer/unify.rs
index 1e9a94c04..b481aa1b3 100644
--- a/crates/hir_ty/src/infer/unify.rs
+++ b/crates/hir_ty/src/infer/unify.rs
@@ -225,36 +225,27 @@ impl InferenceTable {
225 } 225 }
226 } 226 }
227 227
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
228 pub(crate) fn new_type_var(&mut self) -> Ty { 235 pub(crate) fn new_type_var(&mut self) -> Ty {
229 self.type_variable_table.push(TypeVariableData { diverging: false }); 236 self.new_var(TyVariableKind::General, false)
230 Ty::InferenceVar(
231 InferenceVar::from_inner(self.var_unification_table.new_key(TypeVarValue::Unknown)),
232 TyVariableKind::General,
233 )
234 } 237 }
235 238
236 pub(crate) fn new_integer_var(&mut self) -> Ty { 239 pub(crate) fn new_integer_var(&mut self) -> Ty {
237 self.type_variable_table.push(TypeVariableData { diverging: false }); 240 self.new_var(TyVariableKind::Integer, false)
238 Ty::InferenceVar(
239 InferenceVar::from_inner(self.var_unification_table.new_key(TypeVarValue::Unknown)),
240 TyVariableKind::Integer,
241 )
242 } 241 }
243 242
244 pub(crate) fn new_float_var(&mut self) -> Ty { 243 pub(crate) fn new_float_var(&mut self) -> Ty {
245 self.type_variable_table.push(TypeVariableData { diverging: false }); 244 self.new_var(TyVariableKind::Float, false)
246 Ty::InferenceVar(
247 InferenceVar::from_inner(self.var_unification_table.new_key(TypeVarValue::Unknown)),
248 TyVariableKind::Float,
249 )
250 } 245 }
251 246
252 pub(crate) fn new_maybe_never_var(&mut self) -> Ty { 247 pub(crate) fn new_maybe_never_var(&mut self) -> Ty {
253 self.type_variable_table.push(TypeVariableData { diverging: true }); 248 self.new_var(TyVariableKind::General, true)
254 Ty::InferenceVar(
255 InferenceVar::from_inner(self.var_unification_table.new_key(TypeVarValue::Unknown)),
256 TyVariableKind::General,
257 )
258 } 249 }
259 250
260 pub(crate) fn resolve_ty_completely(&mut self, ty: Ty) -> Ty { 251 pub(crate) fn resolve_ty_completely(&mut self, ty: Ty) -> Ty {
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs
index 762437bf4..1131eaf92 100644
--- a/crates/hir_ty/src/lib.rs
+++ b/crates/hir_ty/src/lib.rs
@@ -527,11 +527,11 @@ impl TypeWalk for GenericPredicate {
527#[derive(Debug, Clone, PartialEq, Eq, Hash)] 527#[derive(Debug, Clone, PartialEq, Eq, Hash)]
528pub struct Canonical<T> { 528pub struct Canonical<T> {
529 pub value: T, 529 pub value: T,
530 pub kinds: Arc<[chalk_ir::TyVariableKind]>, 530 pub kinds: Arc<[TyVariableKind]>,
531} 531}
532 532
533impl<T> Canonical<T> { 533impl<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 {
535 Self { value, kinds: kinds.into_iter().collect() } 535 Self { value, kinds: kinds.into_iter().collect() }
536 } 536 }
537} 537}