fix load tests

This commit is contained in:
Folkert 2020-10-07 23:25:47 +02:00
parent 6976682783
commit f16e17823e
4 changed files with 50 additions and 18 deletions

View file

@ -155,9 +155,7 @@ pub fn gen(
let proc = PartialProc { let proc = PartialProc {
annotation, annotation,
// This is a 0-arity thunk, so it has no arguments. // This is a 0-arity thunk, so it has no arguments.
pattern_symbols: bumpalo::collections::Vec::new_in( pattern_symbols: &[],
mono_env.arena,
),
is_tail_recursive: false, is_tail_recursive: false,
body, body,
}; };

View file

@ -105,6 +105,7 @@ enum Msg<'a> {
layout_cache: LayoutCache<'a>, layout_cache: LayoutCache<'a>,
procs: Procs<'a>, procs: Procs<'a>,
problems: Vec<roc_mono::ir::MonoProblem>, problems: Vec<roc_mono::ir::MonoProblem>,
solved_subs: &'a mut Subs,
}, },
Specialized { Specialized {
specialization: (), specialization: (),
@ -584,6 +585,7 @@ pub fn load(
msg_tx.clone(), msg_tx.clone(),
&injector, &injector,
worker_listeners, worker_listeners,
&arena,
)?; )?;
} }
} }
@ -602,6 +604,7 @@ fn update<'a>(
msg_tx: MsgSender<'a>, msg_tx: MsgSender<'a>,
injector: &Injector<BuildTask<'a>>, injector: &Injector<BuildTask<'a>>,
worker_listeners: &'a [Sender<WorkerMsg>], worker_listeners: &'a [Sender<WorkerMsg>],
arena: &'a Bump,
) -> Result<State<'a>, LoadingProblem> { ) -> Result<State<'a>, LoadingProblem> {
use self::Msg::*; use self::Msg::*;
@ -761,6 +764,7 @@ fn update<'a>(
solve_listeners, solve_listeners,
.. ..
} = &mut state; } = &mut state;
let waiting_for = waiting_for_solve.get_mut(&module_id).unwrap_or_else(|| { let waiting_for = waiting_for_solve.get_mut(&module_id).unwrap_or_else(|| {
panic!( panic!(
"Could not find module ID {:?} in waiting_for_solve", "Could not find module ID {:?} in waiting_for_solve",
@ -832,9 +836,15 @@ fn update<'a>(
} => { } => {
module_timing.end_time = SystemTime::now(); module_timing.end_time = SystemTime::now();
if true { // After getting this to work with Procs and combining all the things recursively
todo!("After getting this to work with Procs and combining all the things recursively (which will have bad asymptotics - need to keep iterating over the entire Procs every single time we get a new thing, to diff it and add all the new entries to the main list)...well, actually, is that true though? Or can we just clone Procs and give that to each module? No, that's the bare minimum - we have to do that, *and* we have to traverse it again afterwards to reabsorb. So we can improve on this by having two Procs (or something) which we pass to Expr::new - first, all_procs, and second, new_procs. Every time we want to look something up, first we check all_procs, then we check new_procs. That way, it's exactly 2 lookups every time in the Expr logic, but outside the expr, we don't have to re-traverse the entire massive list of Procs every time. Instead, we can just traverse new_procs and that's it!"); // (which will have bad asymptotics - need to keep iterating over the entire Procs every single time we get a new thing,
} // to diff it and add all the new entries to the main list)...well, actually, is that true though?
// Or can we just clone Procs and give that to each module?
// No, that's the bare minimum - we have to do that, *and* we have to traverse it again afterwards to reabsorb.
// So we can improve on this by having two Procs (or something) which we pass to Expr::new - first, all_procs, and second, new_procs.
// Every time we want to look something up, first we check all_procs, then we check new_procs.
// That way, it's exactly 2 lookups every time in the Expr logic, but outside the expr, we don't have to re-traverse the entire massive list of Procs every time.
// Instead, we can just traverse new_procs and that's it!");
if module_id == state.root_id { if module_id == state.root_id {
// If we don't need to specialize at this point, it's // If we don't need to specialize at this point, it's
@ -853,6 +863,10 @@ fn update<'a>(
}) })
.map_err(|_| LoadingProblem::MsgChannelDied)?; .map_err(|_| LoadingProblem::MsgChannelDied)?;
// bookkeeping
state.declarations_by_id.insert(module_id, decls);
state.constrained_ident_ids.insert(module_id, ident_ids);
// As far as type-checking goes, once we've solved // As far as type-checking goes, once we've solved
// the originally requested module, we're all done! // the originally requested module, we're all done!
return Ok(state); return Ok(state);
@ -943,6 +957,10 @@ fn update<'a>(
decls, decls,
}, },
)?; )?;
} else {
// bookkeeping
state.declarations_by_id.insert(module_id, decls);
state.constrained_ident_ids.insert(module_id, ident_ids);
} }
Ok(state) Ok(state)
@ -950,9 +968,10 @@ fn update<'a>(
PendingSpecializationsDone { PendingSpecializationsDone {
module_id, module_id,
mut ident_ids, mut ident_ids,
layout_cache, mut layout_cache,
problems, problems,
procs: new_procs, procs: new_procs,
solved_subs: root_subs,
} => { } => {
state.mono_problems.extend(problems); state.mono_problems.extend(problems);
@ -969,10 +988,6 @@ fn update<'a>(
state.pending_specializations_needed = false; state.pending_specializations_needed = false;
} }
// We're done with this layout cache, so return it to the pool.
// That way, other specialization processes can reuse it later.
state.layout_caches.push(layout_cache);
// Absorb the contents of the new procs into our state's procs. // Absorb the contents of the new procs into our state's procs.
state.procs.absorb(new_procs); state.procs.absorb(new_procs);
@ -981,9 +996,9 @@ fn update<'a>(
// If no remaining pending specializations are needed, we're done! // If no remaining pending specializations are needed, we're done!
if state.needs_specialization.is_empty() { if state.needs_specialization.is_empty() {
let mut mono_env = roc_mono::ir::Env { let mut mono_env = roc_mono::ir::Env {
arena: root_arena, arena,
problems: &mut state.mono_problems, problems: &mut state.mono_problems,
subs: state.root_subs.unwrap(), subs: root_subs,
home: state.root_id, home: state.root_id,
ident_ids: &mut ident_ids, ident_ids: &mut ident_ids,
}; };
@ -991,11 +1006,20 @@ fn update<'a>(
// TODO: for now this final specialization pass is sequential, // TODO: for now this final specialization pass is sequential,
// with no parallelization at all. We should try to parallelize // with no parallelization at all. We should try to parallelize
// this, but doing so will require a redesign of Procs. // this, but doing so will require a redesign of Procs.
let mut procs = let procs =
roc_mono::ir::specialize_all(&mut mono_env, state.procs, &mut layout_cache); roc_mono::ir::specialize_all(&mut mono_env, state.procs, &mut layout_cache);
// We're done with this layout cache, so return it to the pool.
// That way, other specialization processes can reuse it later.
state.layout_caches.push(layout_cache);
todo!("We're finished! Send off the final Procs, ident_ids, etc."); todo!("We're finished! Send off the final Procs, ident_ids, etc.");
} else { } else {
// TODO is this required if we're done?
// We're done with this layout cache, so return it to the pool.
// That way, other specialization processes can reuse it later.
state.layout_caches.push(layout_cache);
// Notify all the listeners that this solved. // Notify all the listeners that this solved.
if let Some(listeners) = state.solve_listeners.remove(&module_id) { if let Some(listeners) = state.solve_listeners.remove(&module_id) {
for listener_id in listeners { for listener_id in listeners {
@ -1047,6 +1071,9 @@ fn update<'a>(
todo!(); todo!();
} }
Msg::Specialized { .. } => {
unreachable!();
}
Msg::Finished { .. } => { Msg::Finished { .. } => {
unreachable!(); unreachable!();
} }
@ -1690,10 +1717,11 @@ fn build_pending_specializations<'a>(
// let mut layout_ids = LayoutIds::default(); // let mut layout_ids = LayoutIds::default();
let mut procs = Procs::default(); let mut procs = Procs::default();
let mut mono_problems = std::vec::Vec::new(); let mut mono_problems = std::vec::Vec::new();
let subs = arena.alloc(solved_subs.into_inner());
let mut mono_env = roc_mono::ir::Env { let mut mono_env = roc_mono::ir::Env {
arena, arena,
problems: &mut mono_problems, problems: &mut mono_problems,
subs: arena.alloc(solved_subs.into_inner()), subs,
home, home,
ident_ids: &mut ident_ids, ident_ids: &mut ident_ids,
}; };
@ -1753,12 +1781,15 @@ fn build_pending_specializations<'a>(
} }
} }
let problems = mono_env.problems.to_vec();
let solved_subs = mono_env.subs;
Msg::PendingSpecializationsDone { Msg::PendingSpecializationsDone {
module_id: home, module_id: home,
ident_ids, ident_ids,
layout_cache, layout_cache,
procs, procs,
problems: mono_env.problems.to_vec(), problems,
solved_subs,
} }
} }
@ -1813,7 +1844,7 @@ fn run_task<'a>(
decls, decls,
module_timing, module_timing,
layout_cache, layout_cache,
mut solved_subs, solved_subs,
} => Ok(build_pending_specializations( } => Ok(build_pending_specializations(
arena, arena,
solved_subs, solved_subs,

View file

@ -88,6 +88,7 @@ mod test_load {
assert_eq!(loaded_module.can_problems, Vec::new()); assert_eq!(loaded_module.can_problems, Vec::new());
assert_eq!(loaded_module.type_problems, Vec::new()); assert_eq!(loaded_module.type_problems, Vec::new());
dbg!(&loaded_module.declarations_by_id);
for decl in loaded_module.declarations_by_id.remove(&home).unwrap() { for decl in loaded_module.declarations_by_id.remove(&home).unwrap() {
match decl { match decl {
Declare(def) => expect_def( Declare(def) => expect_def(

View file

@ -20,7 +20,7 @@ mod test_uniq_load {
use roc_can::def::Def; use roc_can::def::Def;
use roc_collections::all::MutMap; use roc_collections::all::MutMap;
use roc_constrain::module::SubsByModule; use roc_constrain::module::SubsByModule;
use roc_load::file::{load, LoadedModule}; use roc_load::file::{load, LoadedModule, Phases};
use roc_module::symbol::{Interns, ModuleId}; use roc_module::symbol::{Interns, ModuleId};
use roc_types::pretty_print::{content_to_string, name_all_type_vars}; use roc_types::pretty_print::{content_to_string, name_all_type_vars};
use roc_types::subs::Subs; use roc_types::subs::Subs;
@ -40,6 +40,7 @@ mod test_uniq_load {
&unique::uniq_stdlib(), &unique::uniq_stdlib(),
src_dir.as_path(), src_dir.as_path(),
subs_by_module, subs_by_module,
Phases::TypeCheck,
); );
let loaded_module = loaded.expect("Test module failed to load"); let loaded_module = loaded.expect("Test module failed to load");
@ -134,6 +135,7 @@ mod test_uniq_load {
&roc_builtins::std::standard_stdlib(), &roc_builtins::std::standard_stdlib(),
src_dir.as_path(), src_dir.as_path(),
subs_by_module, subs_by_module,
Phases::TypeCheck,
); );
let mut loaded_module = loaded.expect("Test module failed to load"); let mut loaded_module = loaded.expect("Test module failed to load");