mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 13:59:08 +00:00
short-circuit aliases
This commit is contained in:
parent
f30c07edd0
commit
c18befeccf
3 changed files with 24 additions and 22 deletions
|
@ -3102,7 +3102,7 @@ fn run_solve<'a>(
|
|||
}
|
||||
|
||||
let (solved_subs, solved_env, problems) =
|
||||
roc_solve::module::run_solve(aliases, rigid_variables, constraint, var_store);
|
||||
roc_solve::module::run_solve(rigid_variables, constraint, var_store);
|
||||
|
||||
let mut exposed_vars_by_symbol: MutMap<Symbol, Variable> = solved_env.vars_by_symbol.clone();
|
||||
exposed_vars_by_symbol.retain(|k, _| exposed_symbols.contains(k));
|
||||
|
@ -3115,7 +3115,7 @@ fn run_solve<'a>(
|
|||
exposed_symbols: exposed_symbols.into_iter().collect::<Vec<_>>(),
|
||||
solved_types,
|
||||
problems,
|
||||
aliases: solved_env.aliases,
|
||||
aliases,
|
||||
};
|
||||
|
||||
// Record the final timings
|
||||
|
|
|
@ -17,14 +17,13 @@ pub struct SolvedModule {
|
|||
}
|
||||
|
||||
pub fn run_solve(
|
||||
aliases: MutMap<Symbol, Alias>,
|
||||
rigid_variables: MutMap<Variable, Lowercase>,
|
||||
constraint: Constraint,
|
||||
var_store: VarStore,
|
||||
) -> (Solved<Subs>, solve::Env, Vec<solve::TypeError>) {
|
||||
let env = solve::Env {
|
||||
vars_by_symbol: MutMap::default(),
|
||||
aliases,
|
||||
aliases: MutMap::default(),
|
||||
};
|
||||
|
||||
let mut subs = Subs::new_from_varstore(var_store);
|
||||
|
|
|
@ -82,6 +82,23 @@ pub struct Env {
|
|||
pub aliases: MutMap<Symbol, Alias>,
|
||||
}
|
||||
|
||||
impl Env {
|
||||
fn get_var_by_symbol(&self, symbol: &Symbol) -> Option<Variable> {
|
||||
self.vars_by_symbol.get(symbol).copied()
|
||||
}
|
||||
|
||||
fn insert_symbol_var_if_vacant(&mut self, symbol: Symbol, var: Variable) {
|
||||
match self.vars_by_symbol.entry(symbol) {
|
||||
Entry::Occupied(_) => {
|
||||
// keep the existing value
|
||||
}
|
||||
Entry::Vacant(vacant) => {
|
||||
vacant.insert(var);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const DEFAULT_POOLS: usize = 8;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
@ -312,7 +329,7 @@ fn solve(
|
|||
}
|
||||
}
|
||||
Lookup(symbol, expectation, region) => {
|
||||
match env.vars_by_symbol.get(symbol) {
|
||||
match env.get_var_by_symbol(symbol) {
|
||||
Some(var) => {
|
||||
// Deep copy the vars associated with this symbol before unifying them.
|
||||
// Otherwise, suppose we have this:
|
||||
|
@ -335,7 +352,7 @@ fn solve(
|
|||
// then we copy from that module's Subs into our own. If the value
|
||||
// is being looked up in this module, then we use our Subs as both
|
||||
// the source and destination.
|
||||
let actual = deep_copy_var(subs, rank, pools, *var);
|
||||
let actual = deep_copy_var(subs, rank, pools, var);
|
||||
let expected = type_to_var(
|
||||
subs,
|
||||
rank,
|
||||
|
@ -484,14 +501,7 @@ fn solve(
|
|||
|
||||
let mut new_env = env.clone();
|
||||
for (symbol, loc_var) in local_def_vars.iter() {
|
||||
match new_env.vars_by_symbol.entry(*symbol) {
|
||||
Entry::Occupied(_) => {
|
||||
// keep the existing value
|
||||
}
|
||||
Entry::Vacant(vacant) => {
|
||||
vacant.insert(loc_var.value);
|
||||
}
|
||||
}
|
||||
new_env.insert_symbol_var_if_vacant(*symbol, loc_var.value);
|
||||
}
|
||||
|
||||
stack.push(Work::Constraint {
|
||||
|
@ -625,14 +635,7 @@ fn solve(
|
|||
|
||||
let mut new_env = env.clone();
|
||||
for (symbol, loc_var) in local_def_vars.iter() {
|
||||
match new_env.vars_by_symbol.entry(*symbol) {
|
||||
Entry::Occupied(_) => {
|
||||
// keep the existing value
|
||||
}
|
||||
Entry::Vacant(vacant) => {
|
||||
vacant.insert(loc_var.value);
|
||||
}
|
||||
}
|
||||
new_env.insert_symbol_var_if_vacant(*symbol, loc_var.value);
|
||||
}
|
||||
|
||||
// Note that this vars_by_symbol is the one returned by the
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue