mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 00:24:34 +00:00
more efficient approach for finding new rigids
This commit is contained in:
parent
6370a80c62
commit
97b0e3df9b
2 changed files with 18 additions and 14 deletions
|
@ -1642,8 +1642,6 @@ fn instantiate_rigids(
|
||||||
let mut annotation = annotation.clone();
|
let mut annotation = annotation.clone();
|
||||||
let mut rigid_substitution: ImMap<Variable, Type> = ImMap::default();
|
let mut rigid_substitution: ImMap<Variable, Type> = ImMap::default();
|
||||||
|
|
||||||
let outside_rigids: Vec<Variable> = ftv.values().copied().collect();
|
|
||||||
|
|
||||||
for (name, var) in introduced_vars.var_by_name.iter() {
|
for (name, var) in introduced_vars.var_by_name.iter() {
|
||||||
use std::collections::hash_map::Entry::*;
|
use std::collections::hash_map::Entry::*;
|
||||||
|
|
||||||
|
@ -1655,11 +1653,27 @@ fn instantiate_rigids(
|
||||||
Vacant(vacant) => {
|
Vacant(vacant) => {
|
||||||
// It's possible to use this rigid in nested defs
|
// It's possible to use this rigid in nested defs
|
||||||
vacant.insert(*var);
|
vacant.insert(*var);
|
||||||
// new_rigids.push(*var);
|
new_rigids.push(*var);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// wildcards are always freshly introduced in this annotation
|
||||||
|
for (i, wildcard) in introduced_vars.wildcards.iter().enumerate() {
|
||||||
|
ftv.insert(format!("*{}", i).into(), *wildcard);
|
||||||
|
new_rigids.push(*wildcard);
|
||||||
|
}
|
||||||
|
|
||||||
|
// lambda set vars are always freshly introduced in this annotation
|
||||||
|
for var in introduced_vars.lambda_sets.iter() {
|
||||||
|
new_rigids.push(*var);
|
||||||
|
}
|
||||||
|
|
||||||
|
// lambda set vars are always freshly introduced in this annotation
|
||||||
|
for var in introduced_vars.inferred.iter() {
|
||||||
|
new_rigids.push(*var);
|
||||||
|
}
|
||||||
|
|
||||||
// Instantiate rigid variables
|
// Instantiate rigid variables
|
||||||
if !rigid_substitution.is_empty() {
|
if !rigid_substitution.is_empty() {
|
||||||
annotation.substitute(&rigid_substitution);
|
annotation.substitute(&rigid_substitution);
|
||||||
|
@ -1670,20 +1684,10 @@ fn instantiate_rigids(
|
||||||
&Loc::at(loc_pattern.region, &annotation),
|
&Loc::at(loc_pattern.region, &annotation),
|
||||||
) {
|
) {
|
||||||
for (symbol, loc_type) in new_headers {
|
for (symbol, loc_type) in new_headers {
|
||||||
for var in loc_type.value.variables() {
|
|
||||||
// a rigid is only new if this annotation is the first occurrence of this rigid
|
|
||||||
if !outside_rigids.contains(&var) {
|
|
||||||
new_rigids.push(var);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
headers.insert(symbol, loc_type);
|
headers.insert(symbol, loc_type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i, wildcard) in introduced_vars.wildcards.iter().enumerate() {
|
|
||||||
ftv.insert(format!("*{}", i).into(), *wildcard);
|
|
||||||
}
|
|
||||||
|
|
||||||
annotation
|
annotation
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -158,7 +158,7 @@ pub fn can_expr_with<'a>(
|
||||||
let constraint = constrain_expr(
|
let constraint = constrain_expr(
|
||||||
&mut constraints,
|
&mut constraints,
|
||||||
&roc_constrain::expr::Env {
|
&roc_constrain::expr::Env {
|
||||||
rigids: ImMap::default(),
|
rigids: MutMap::default(),
|
||||||
home,
|
home,
|
||||||
},
|
},
|
||||||
loc_expr.region,
|
loc_expr.region,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue