mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 08:11:12 +00:00
use VecSet in IntroducedVariables
This commit is contained in:
parent
9f453a7ba2
commit
7f3ca4458a
4 changed files with 25 additions and 17 deletions
|
@ -58,8 +58,8 @@ pub struct IntroducedVariables {
|
|||
pub wildcards: Vec<Loc<Variable>>,
|
||||
pub lambda_sets: Vec<Variable>,
|
||||
pub inferred: Vec<Loc<Variable>>,
|
||||
pub named: Vec<NamedVariable>,
|
||||
pub able: Vec<AbleVariable>,
|
||||
pub named: VecSet<NamedVariable>,
|
||||
pub able: VecSet<AbleVariable>,
|
||||
pub host_exposed_aliases: MutMap<Symbol, Variable>,
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ impl IntroducedVariables {
|
|||
first_seen: var.region,
|
||||
};
|
||||
|
||||
self.named.push(named_variable);
|
||||
self.named.insert(named_variable);
|
||||
}
|
||||
|
||||
pub fn insert_able(&mut self, name: Lowercase, var: Loc<Variable>, ability: Symbol) {
|
||||
|
@ -97,7 +97,7 @@ impl IntroducedVariables {
|
|||
first_seen: var.region,
|
||||
};
|
||||
|
||||
self.able.push(able_variable);
|
||||
self.able.insert(able_variable);
|
||||
}
|
||||
|
||||
pub fn insert_wildcard(&mut self, var: Loc<Variable>) {
|
||||
|
@ -128,12 +128,7 @@ impl IntroducedVariables {
|
|||
.extend(other.host_exposed_aliases.clone());
|
||||
|
||||
self.named.extend(other.named.iter().cloned());
|
||||
self.named.sort();
|
||||
self.named.dedup();
|
||||
|
||||
self.able.extend(other.able.iter().cloned());
|
||||
self.able.sort();
|
||||
self.able.dedup();
|
||||
}
|
||||
|
||||
pub fn union_owned(&mut self, other: Self) {
|
||||
|
@ -143,8 +138,7 @@ impl IntroducedVariables {
|
|||
self.host_exposed_aliases.extend(other.host_exposed_aliases);
|
||||
|
||||
self.named.extend(other.named);
|
||||
self.named.sort();
|
||||
self.named.dedup();
|
||||
self.able.extend(other.able.iter().cloned());
|
||||
}
|
||||
|
||||
pub fn var_by_name(&self, name: &Lowercase) -> Option<Variable> {
|
||||
|
|
|
@ -344,7 +344,8 @@ pub fn canonicalize_defs<'a>(
|
|||
|
||||
let mut named = can_ann.introduced_variables.named;
|
||||
for loc_lowercase in vars.iter() {
|
||||
match named.iter().position(|nv| nv.name == loc_lowercase.value) {
|
||||
let opt_index = named.iter().position(|nv| nv.name == loc_lowercase.value);
|
||||
match opt_index {
|
||||
Some(index) => {
|
||||
// This is a valid lowercase rigid var for the type def.
|
||||
let named_variable = named.swap_remove(index);
|
||||
|
|
|
@ -241,6 +241,18 @@ impl<T: PartialEq> VecSet<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.elements.len()
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.elements.is_empty()
|
||||
}
|
||||
|
||||
pub fn swap_remove(&mut self, index: usize) -> T {
|
||||
self.elements.swap_remove(index)
|
||||
}
|
||||
|
||||
pub fn insert(&mut self, value: T) -> bool {
|
||||
if self.elements.contains(&value) {
|
||||
true
|
||||
|
@ -273,17 +285,18 @@ impl<T: PartialEq> VecSet<T> {
|
|||
|
||||
impl<A: Ord> Extend<A> for VecSet<A> {
|
||||
fn extend<T: IntoIterator<Item = A>>(&mut self, iter: T) {
|
||||
let mut it = iter.into_iter();
|
||||
let it = iter.into_iter();
|
||||
let hint = it.size_hint();
|
||||
|
||||
match hint {
|
||||
(0, Some(0)) => {
|
||||
// done, do nothing
|
||||
}
|
||||
(1, Some(1)) => {
|
||||
let value = it.next().unwrap();
|
||||
(1, Some(1)) | (2, Some(2)) => {
|
||||
for value in it {
|
||||
self.insert(value);
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
self.elements.extend(it);
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ use roc_types::solved_types::Solved;
|
|||
use roc_types::subs::{Subs, VarStore, Variable};
|
||||
use roc_types::types::{Alias, AliasCommon, TypeExtension};
|
||||
use std::collections::hash_map::Entry::{Occupied, Vacant};
|
||||
use std::collections::{HashMap, };
|
||||
use std::collections::HashMap;
|
||||
use std::io;
|
||||
use std::iter;
|
||||
use std::ops::ControlFlow;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue