Fix type errors

This commit is contained in:
Ayaz Hafiz 2022-05-11 14:51:11 -04:00
parent fe2f2b2027
commit 28d6f30cc7
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
4 changed files with 41 additions and 20 deletions

View file

@ -1,3 +1,5 @@
use std::iter::FromIterator;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct VecMap<K, V> { pub struct VecMap<K, V> {
keys: Vec<K>, keys: Vec<K>,
@ -184,3 +186,15 @@ impl<K, V> ExactSizeIterator for IntoIter<K, V> {
self.len self.len
} }
} }
impl<K: PartialEq, V> FromIterator<(K, V)> for VecMap<K, V> {
fn from_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> Self {
let iter = iter.into_iter();
let size_hint = iter.size_hint();
let mut map = VecMap::with_capacity(size_hint.1.unwrap_or(size_hint.0));
for (k, v) in iter {
map.insert(k, v);
}
map
}
}

View file

@ -1,3 +1,5 @@
use std::iter::FromIterator;
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub struct VecSet<T> { pub struct VecSet<T> {
elements: Vec<T>, elements: Vec<T>,
@ -101,6 +103,14 @@ impl<A: Ord> Extend<A> for VecSet<A> {
} }
} }
impl<A: Ord> FromIterator<A> for VecSet<A> {
fn from_iter<T: IntoIterator<Item = A>>(iter: T) -> Self {
let mut set = VecSet::default();
set.extend(iter);
set
}
}
impl<T> IntoIterator for VecSet<T> { impl<T> IntoIterator for VecSet<T> {
type Item = T; type Item = T;

View file

@ -183,6 +183,7 @@ pub fn frontload_ability_constraints(
signature, signature,
} = &member_data.typ } = &member_data.typ
{ {
let signature_var = *signature_var;
let rigids = Default::default(); let rigids = Default::default();
let mut env = Env { let mut env = Env {
home, home,
@ -195,22 +196,21 @@ pub fn frontload_ability_constraints(
constraints, constraints,
&mut env, &mut env,
&pattern, &pattern,
Type::Variable(member_data.signature_var), Type::Variable(signature_var),
); );
debug_assert!(env.resolutions_to_make.is_empty()); debug_assert!(env.resolutions_to_make.is_empty());
def_pattern_state.vars.push(member_data.signature_var); def_pattern_state.vars.push(signature_var);
let vars = &member_data.variables;
let rigid_variables = vars.rigid_vars.iter().chain(vars.able_vars.iter()).copied(); let rigid_variables = vars.rigid_vars.iter().chain(vars.able_vars.iter()).copied();
let infer_variables = vars.flex_vars.iter().copied(); let infer_variables = vars.flex_vars.iter().copied();
def_pattern_state def_pattern_state
.constraints .constraints
.push(constraints.equal_types_var( .push(constraints.equal_types_var(
member_data.signature_var, signature_var,
Expected::NoExpectation(member_data.signature.clone()), Expected::NoExpectation(signature.clone()),
Category::Storage(file!(), line!()), Category::Storage(file!(), line!()),
Region::zero(), Region::zero(),
)); ));

View file

@ -3679,22 +3679,19 @@ fn run_solve_solve(
// STORE ABILITIES // STORE ABILITIES
let module_id = module.module_id; let module_id = module.module_id;
let known_specializations = let solved_specializations: SolvedSpecializations = abilities_store
abilities_store .iter_specializations()
.get_known_specializations() .filter(|((member, typ), _)| {
.filter(|(member, typ)| {
// This module solved this specialization if either the member or the type comes from the // This module solved this specialization if either the member or the type comes from the
// module. // module.
member.module_id() == module_id || typ.module_id() == module_id member.module_id() == module_id || typ.module_id() == module_id
}); })
.collect();
let mut solved_specializations: SolvedSpecializations = VecMap::default(); let specialization_symbols: VecSet<_> = solved_specializations
let mut specialization_symbols = VecSet::default(); .values()
for (member, typ) in known_specializations { .map(|ms| ms.symbol)
let specialization = abilities_store.get_specialization(member, typ).unwrap(); .collect();
specialization_symbols.insert(specialization.symbol);
solved_specializations.insert((member, typ), specialization);
}
// END STORE ABILITIES // END STORE ABILITIES
// Expose anything that is explicitly exposed by the header, or is a specialization of an // Expose anything that is explicitly exposed by the header, or is a specialization of an