Refactor alias cloning logic a bit

This commit is contained in:
Richard Feldman 2020-05-26 00:50:12 -04:00
parent c47dc57fc2
commit 11e2f998fc

View file

@ -16,7 +16,7 @@ use roc_parse::parser::{Fail, Parser, State};
use roc_region::all::{Located, Region}; use roc_region::all::{Located, Region};
use roc_solve::module::SolvedModule; use roc_solve::module::SolvedModule;
use roc_solve::solve; use roc_solve::solve;
use roc_types::solved_types::{BuiltinAlias, Solved, SolvedType}; use roc_types::solved_types::{Solved, SolvedType};
use roc_types::subs::{Subs, VarStore, Variable}; use roc_types::subs::{Subs, VarStore, Variable};
use roc_types::types; use roc_types::types;
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
@ -837,19 +837,15 @@ fn spawn_solve_module(
}); });
} }
None => { None => {
if stdlib.applies.contains(&symbol) { let is_valid_alias = stdlib.applies.contains(&symbol)
// do nothing
} else {
// This wasn't a builtin value or Apply; maybe it was a builtin alias. // This wasn't a builtin value or Apply; maybe it was a builtin alias.
match stdlib.aliases.get(&symbol) { || stdlib.aliases.contains_key(&symbol);
Some(_) => {
// do nothing if !is_valid_alias {
} panic!(
None => panic!( "Could not find {:?} in builtin types {:?} or aliases {:?}",
"Could not find {:?} in builtin types {:?} or aliases {:?}", symbol, stdlib.types, stdlib.aliases
symbol, stdlib.types, stdlib.aliases );
),
}
} }
} }
} }
@ -906,12 +902,13 @@ fn spawn_solve_module(
); );
} }
// TODO include only the aliases actually used in this module let mut aliases = Vec::with_capacity(stdlib.aliases.len());
let aliases = stdlib
.aliases // We need to clone these to send them to another thread, but
.iter() // all the thread does is iterate over them, so use a Vec instead of a Map.
.map(|(symbol, alias)| (*symbol, alias.clone())) for (symbol, alias) in stdlib.aliases.iter() {
.collect::<Vec<(Symbol, BuiltinAlias)>>(); aliases.push((*symbol, alias.clone()));
}
// Start solving this module in the background. // Start solving this module in the background.
spawn_blocking(move || { spawn_blocking(move || {