This commit is contained in:
Folkert 2021-10-27 00:01:21 +02:00
parent 44b8b1ca4c
commit d561f2661d
4 changed files with 52 additions and 47 deletions

View file

@ -205,6 +205,7 @@ mod cli_run {
example.use_valgrind, example.use_valgrind,
); );
#[cfg(not(debug_assertions))]
check_output_with_stdin( check_output_with_stdin(
&file_name, &file_name,
example.stdin, example.stdin,

View file

@ -3852,7 +3852,7 @@ fn build_procedures_help<'a, 'ctx, 'env>(
let it = procedures.iter().map(|x| x.1); let it = procedures.iter().map(|x| x.1);
let solutions = match roc_mono::alias_analysis::spec_program(entry_point, it) { let solutions = match roc_mono::alias_analysis::spec_program(opt_level, entry_point, it) {
Err(e) => panic!("Error in alias analysis: {}", e), Err(e) => panic!("Error in alias analysis: {}", e),
Ok(solutions) => solutions, Ok(solutions) => solutions,
}; };

View file

@ -10,7 +10,8 @@ use roc_module::symbol::Symbol;
use std::convert::TryFrom; use std::convert::TryFrom;
use crate::ir::{ use crate::ir::{
Call, CallType, Expr, HostExposedLayouts, ListLiteralElement, Literal, ModifyRc, Proc, Stmt, Call, CallType, Expr, HostExposedLayouts, ListLiteralElement, Literal, ModifyRc, OptLevel,
Proc, Stmt,
}; };
use crate::layout::{Builtin, Layout, ListLayout, RawFunctionLayout, UnionLayout}; use crate::layout::{Builtin, Layout, ListLayout, RawFunctionLayout, UnionLayout};
@ -109,6 +110,7 @@ fn bytes_as_ascii(bytes: &[u8]) -> String {
} }
pub fn spec_program<'a, I>( pub fn spec_program<'a, I>(
opt_level: OptLevel,
entry_point: crate::ir::EntryPoint<'a>, entry_point: crate::ir::EntryPoint<'a>,
procs: I, procs: I,
) -> Result<morphic_lib::Solutions> ) -> Result<morphic_lib::Solutions>
@ -239,7 +241,10 @@ where
eprintln!("{}", program.to_source_string()); eprintln!("{}", program.to_source_string());
} }
morphic_lib::solve(program) match opt_level {
OptLevel::Development | OptLevel::Normal => morphic_lib::solve_trivial(program),
OptLevel::Optimize => morphic_lib::solve(program),
}
} }
/// if you want an "escape hatch" which allows you construct "best-case scenario" values /// if you want an "escape hatch" which allows you construct "best-case scenario" values

View file

@ -1767,13 +1767,9 @@ fn specialize_all_help<'a>(
externals_others_need: ExternalSpecializations<'a>, externals_others_need: ExternalSpecializations<'a>,
layout_cache: &mut LayoutCache<'a>, layout_cache: &mut LayoutCache<'a>,
) { ) {
let mut symbol_solved_type = Vec::new_in(env.arena);
for (symbol, solved_types) in externals_others_need.specs.iter() { for (symbol, solved_types) in externals_others_need.specs.iter() {
// for some unclear reason, the MutSet does not deduplicate according to the hash // for some unclear reason, the MutSet does not deduplicate according to the hash
// instance. So we do it manually here // instance. So we do it manually here
let mut as_vec: std::vec::Vec<_> = solved_types.iter().collect();
use std::collections::hash_map::DefaultHasher; use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher}; use std::hash::{Hash, Hasher};
@ -1783,50 +1779,53 @@ fn specialize_all_help<'a>(
hasher.finish() hasher.finish()
}; };
as_vec.sort_by_key(|x| hash_the_thing(x)); let mut as_vec = Vec::from_iter_in(
as_vec.dedup_by_key(|x| hash_the_thing(x)); solved_types.iter().map(|x| (hash_the_thing(x), x)),
env.arena,
);
for s in as_vec { as_vec.sort_by_key(|(k, _)| *k);
symbol_solved_type.push((*symbol, s.clone())); as_vec.dedup_by_key(|(k, _)| *k);
}
}
for (name, solved_type) in symbol_solved_type.into_iter() { for (_, solved_type) in as_vec {
let partial_proc = match procs.partial_procs.get(&name) { let name = *symbol;
Some(v) => v.clone(),
None => {
panic!("Cannot find a partial proc for {:?}", name);
}
};
// TODO I believe this sis also duplicated let partial_proc = match procs.partial_procs.get(&name) {
match specialize_solved_type( Some(v) => v.clone(),
env, None => {
procs, panic!("Cannot find a partial proc for {:?}", name);
name,
layout_cache,
solved_type,
BumpMap::new_in(env.arena),
partial_proc,
) {
Ok((proc, layout)) => {
let top_level = ProcLayout::from_raw(env.arena, layout);
if procs.is_module_thunk(name) {
debug_assert!(top_level.arguments.is_empty());
} }
};
procs.specialized.insert((name, top_level), Done(proc)); // TODO I believe this sis also duplicated
} match specialize_solved_type(
Err(SpecializeFailure { env,
problem: _, procs,
attempted_layout, name,
}) => { layout_cache,
let proc = generate_runtime_error_function(env, name, attempted_layout); solved_type,
BumpMap::new_in(env.arena),
partial_proc,
) {
Ok((proc, layout)) => {
let top_level = ProcLayout::from_raw(env.arena, layout);
let top_level = ProcLayout::from_raw(env.arena, attempted_layout); if procs.is_module_thunk(name) {
debug_assert!(top_level.arguments.is_empty());
}
procs.specialized.insert((name, top_level), Done(proc)); procs.specialized.insert((name, top_level), Done(proc));
}
Err(SpecializeFailure {
problem: _,
attempted_layout,
}) => {
let proc = generate_runtime_error_function(env, name, attempted_layout);
let top_level = ProcLayout::from_raw(env.arena, attempted_layout);
procs.specialized.insert((name, top_level), Done(proc));
}
} }
} }
} }
@ -2421,7 +2420,7 @@ fn specialize<'a>(
procs, procs,
proc_name, proc_name,
layout_cache, layout_cache,
solved_type, &solved_type,
host_exposed_aliases, host_exposed_aliases,
partial_proc, partial_proc,
) )
@ -2451,7 +2450,7 @@ fn specialize_solved_type<'a>(
procs: &mut Procs<'a>, procs: &mut Procs<'a>,
proc_name: Symbol, proc_name: Symbol,
layout_cache: &mut LayoutCache<'a>, layout_cache: &mut LayoutCache<'a>,
solved_type: SolvedType, solved_type: &SolvedType,
host_exposed_aliases: BumpMap<Symbol, SolvedType>, host_exposed_aliases: BumpMap<Symbol, SolvedType>,
partial_proc: PartialProc<'a>, partial_proc: PartialProc<'a>,
) -> Result<SpecializeSuccess<'a>, SpecializeFailure<'a>> { ) -> Result<SpecializeSuccess<'a>, SpecializeFailure<'a>> {
@ -2460,7 +2459,7 @@ fn specialize_solved_type<'a>(
procs, procs,
proc_name, proc_name,
layout_cache, layout_cache,
|env| introduce_solved_type_to_subs(env, &solved_type), |env| introduce_solved_type_to_subs(env, solved_type),
host_exposed_aliases, host_exposed_aliases,
partial_proc, partial_proc,
) )