mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-22 19:42:31 +00:00
Store multiple abilities as a VecSet
This commit is contained in:
parent
603160dae3
commit
2011ec97c3
3 changed files with 27 additions and 9 deletions
|
@ -127,7 +127,7 @@ pub struct NamedVariable {
|
|||
pub struct AbleVariable {
|
||||
pub variable: Variable,
|
||||
pub name: Lowercase,
|
||||
pub abilities: Vec<Symbol>,
|
||||
pub abilities: VecSet<Symbol>,
|
||||
// NB: there may be multiple occurrences of a variable
|
||||
pub first_seen: Region,
|
||||
}
|
||||
|
@ -166,7 +166,7 @@ impl IntroducedVariables {
|
|||
self.named.insert(named_variable);
|
||||
}
|
||||
|
||||
pub fn insert_able(&mut self, name: Lowercase, var: Loc<Variable>, abilities: Vec<Symbol>) {
|
||||
pub fn insert_able(&mut self, name: Lowercase, var: Loc<Variable>, abilities: VecSet<Symbol>) {
|
||||
self.debug_assert_not_already_present(var.value);
|
||||
|
||||
let able_variable = AbleVariable {
|
||||
|
@ -539,7 +539,11 @@ fn can_annotation_help(
|
|||
|
||||
// Generate an variable bound to the ability so we can keep compiling.
|
||||
let var = var_store.fresh();
|
||||
introduced_variables.insert_able(fresh_ty_var, Loc::at(region, var), vec![symbol]);
|
||||
introduced_variables.insert_able(
|
||||
fresh_ty_var,
|
||||
Loc::at(region, var),
|
||||
VecSet::singleton(symbol),
|
||||
);
|
||||
return Type::Variable(var);
|
||||
}
|
||||
|
||||
|
@ -930,7 +934,7 @@ fn canonicalize_has_clause(
|
|||
);
|
||||
let var_name = Lowercase::from(var_name);
|
||||
|
||||
let mut can_abilities = Vec::with_capacity(abilities.len());
|
||||
let mut can_abilities = VecSet::with_capacity(abilities.len());
|
||||
for &Loc {
|
||||
region,
|
||||
value: ability,
|
||||
|
@ -957,10 +961,10 @@ fn canonicalize_has_clause(
|
|||
};
|
||||
|
||||
references.insert(ability);
|
||||
if can_abilities.contains(&ability) {
|
||||
let already_seen = can_abilities.insert(ability);
|
||||
|
||||
if already_seen {
|
||||
env.problem(roc_problem::can::Problem::DuplicateHasAbility { ability, region });
|
||||
} else {
|
||||
can_abilities.push(ability);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -136,7 +136,7 @@ pub struct Module {
|
|||
#[derive(Debug, Default)]
|
||||
pub struct RigidVariables {
|
||||
pub named: MutMap<Variable, Lowercase>,
|
||||
pub able: MutMap<Variable, (Lowercase, Vec<Symbol>)>,
|
||||
pub able: MutMap<Variable, (Lowercase, VecSet<Symbol>)>,
|
||||
pub wildcards: VecSet<Variable>,
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue