diff --git a/Cargo.lock b/Cargo.lock index 30bfdff722..63d93d71c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3218,6 +3218,7 @@ dependencies = [ "indoc 0.3.6", "inlinable_string", "maplit", + "morphic_lib", "num_cpus", "parking_lot", "pretty_assertions 0.5.1", diff --git a/compiler/load/Cargo.toml b/compiler/load/Cargo.toml index 01d0a82f5b..6ed6e3cc63 100644 --- a/compiler/load/Cargo.toml +++ b/compiler/load/Cargo.toml @@ -19,6 +19,7 @@ roc_parse = { path = "../parse" } roc_solve = { path = "../solve" } roc_mono = { path = "../mono" } roc_reporting = { path = "../reporting" } +morphic_lib = { path = "../../vendor/morphic_lib" } ven_pretty = { path = "../../vendor/pretty" } bumpalo = { version = "3.6.1", features = ["collections"] } inlinable_string = "0.1" diff --git a/compiler/load/src/file.rs b/compiler/load/src/file.rs index 2b6f7a69bc..8d41d91932 100644 --- a/compiler/load/src/file.rs +++ b/compiler/load/src/file.rs @@ -706,6 +706,7 @@ pub struct MonomorphizedModule<'a> { pub type_problems: MutMap>, pub mono_problems: MutMap>, pub procedures: MutMap<(Symbol, TopLevelFunctionLayout<'a>), Proc<'a>>, + pub alias_analysis_solutions: AliasAnalysisSolutions, pub exposed_to_host: MutMap, pub header_sources: MutMap)>, pub sources: MutMap)>, @@ -863,6 +864,19 @@ struct State<'a> { pub layout_caches: std::vec::Vec>, pub procs: Procs<'a>, + + pub alias_analysis_solutions: AliasAnalysisSolutions, +} + +pub enum AliasAnalysisSolutions { + NotAvailable, + Available(morphic_lib::Solutions), +} + +impl std::fmt::Debug for AliasAnalysisSolutions { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "AliasAnalysisSolutions {{}}") + } } #[derive(Debug)] @@ -1472,6 +1486,7 @@ where specializations_in_flight: 0, layout_caches: std::vec::Vec::with_capacity(num_cpus::get()), procs: Procs::new_in(arena), + alias_analysis_solutions: AliasAnalysisSolutions::NotAvailable, }; // We've now distributed one worker queue to each thread. @@ -2061,14 +2076,6 @@ fn update<'a>( println!("{}", result); } - if false { - let it = state.procedures.iter().map(|x| x.1); - - if let Err(e) = roc_mono::alias_analysis::spec_program(it) { - println!("Error in alias analysis: {:?}", e) - } - } - Proc::insert_refcount_operations(arena, &mut state.procedures); Proc::optimize_refcount_operations( @@ -2078,6 +2085,18 @@ fn update<'a>( &mut state.procedures, ); + if true { + let it = state.procedures.iter().map(|x| x.1); + + match roc_mono::alias_analysis::spec_program(it) { + Err(e) => panic!("Error in alias analysis: {:?}", e), + Ok(solutions) => { + state.alias_analysis_solutions = + AliasAnalysisSolutions::Available(solutions) + } + } + } + state.constrained_ident_ids.insert(module_id, ident_ids); for (module_id, requested) in external_specializations_requested { @@ -2157,6 +2176,7 @@ fn finish_specialization( let State { procedures, + alias_analysis_solutions, module_cache, output_path, platform_path, @@ -2218,6 +2238,7 @@ fn finish_specialization( subs, interns, procedures, + alias_analysis_solutions, sources, header_sources, timings: state.timings, diff --git a/compiler/mono/src/alias_analysis.rs b/compiler/mono/src/alias_analysis.rs index b2f8a96389..6bb080066c 100644 --- a/compiler/mono/src/alias_analysis.rs +++ b/compiler/mono/src/alias_analysis.rs @@ -16,7 +16,7 @@ use bumpalo::Bump; // just using one module for now const MOD_LIST: ModName = ModName(b"UserApp"); -const MOD_APP: ModName = ModName(b"UserApp"); +pub const MOD_APP: ModName = ModName(b"UserApp"); pub fn spec_program<'a, I>(procs: I) -> Result where @@ -182,7 +182,7 @@ fn stmt_spec( } Ret(symbol) => Ok(env.symbols[symbol]), Refcounting(modify_rc, continuation) => match modify_rc { - ModifyRc::Inc(symbol, _) | ModifyRc::Dec(symbol) | ModifyRc::DecRef(symbol) => { + ModifyRc::Inc(symbol, _) | ModifyRc::Dec(symbol) => { let result_type = builder.add_tuple_type(&[])?; let argument = env.symbols[symbol]; @@ -191,6 +191,10 @@ fn stmt_spec( stmt_spec(builder, env, block, layout, continuation) } + ModifyRc::DecRef(_symbol) => { + // TODO a decref is a non-recursive decrement of a structure + stmt_spec(builder, env, block, layout, continuation) + } }, Join { id,