From 1364f1e51848f9d039ae77444996ac33865a29b5 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 8 Jul 2022 16:39:20 -0400 Subject: [PATCH 01/17] Reproduce #3451 --- .../tests/fixtures/build/app_with_deps/Dep3/Blah.roc | 4 ++-- .../tests/fixtures/build/app_with_deps/Dep3/Other.roc | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 crates/compiler/load_internal/tests/fixtures/build/app_with_deps/Dep3/Other.roc diff --git a/crates/compiler/load_internal/tests/fixtures/build/app_with_deps/Dep3/Blah.roc b/crates/compiler/load_internal/tests/fixtures/build/app_with_deps/Dep3/Blah.roc index da94d8c6a7..b868374a0d 100644 --- a/crates/compiler/load_internal/tests/fixtures/build/app_with_deps/Dep3/Blah.roc +++ b/crates/compiler/load_internal/tests/fixtures/build/app_with_deps/Dep3/Blah.roc @@ -1,10 +1,10 @@ interface Dep3.Blah exposes [one, two, foo, bar] - imports [] + imports [Dep3.Other] one = 1 two = 2 foo = "foo from Dep3" -bar = "bar from Dep3" +bar = Dep3.Other.bar diff --git a/crates/compiler/load_internal/tests/fixtures/build/app_with_deps/Dep3/Other.roc b/crates/compiler/load_internal/tests/fixtures/build/app_with_deps/Dep3/Other.roc new file mode 100644 index 0000000000..67df17c8a7 --- /dev/null +++ b/crates/compiler/load_internal/tests/fixtures/build/app_with_deps/Dep3/Other.roc @@ -0,0 +1,6 @@ +interface Dep3.Other + exposes [foo, bar] + imports [] + +foo = "foo from Dep3.Other" +bar = "bar from Dep3.Other" From a6d99aa3573345b86f72d8d666a26c354d0af9f1 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 8 Jul 2022 17:55:56 -0400 Subject: [PATCH 02/17] Move src_dir into LoadStart --- crates/ast/src/module.rs | 15 +++++++------ crates/bindgen/src/main.rs | 2 +- crates/cli/src/build.rs | 4 ++-- crates/cli/src/lib.rs | 2 +- crates/compiler/load/build.rs | 2 +- crates/compiler/load/src/lib.rs | 26 ++++++++--------------- crates/compiler/load_internal/src/file.rs | 22 ++++++++++--------- crates/docs/src/lib.rs | 2 +- crates/repl_eval/src/gen.rs | 4 ++-- 9 files changed, 38 insertions(+), 41 deletions(-) diff --git a/crates/ast/src/module.rs b/crates/ast/src/module.rs index b01c46f02c..0e95fea098 100644 --- a/crates/ast/src/module.rs +++ b/crates/ast/src/module.rs @@ -10,12 +10,15 @@ pub fn load_module(src_file: &Path, threading: Threading) -> LoadedModule { let loaded = roc_load::load_and_typecheck( &arena, src_file.to_path_buf(), - src_file.parent().unwrap_or_else(|| { - panic!( - "src_file {:?} did not have a parent directory but I need to have one.", - src_file - ) - }), + src_file + .parent() + .unwrap_or_else(|| { + panic!( + "src_file {:?} did not have a parent directory but I need to have one.", + src_file + ) + }) + .to_path_buf(), subs_by_module, TargetInfo::default_x86_64(), roc_reporting::report::RenderTarget::ColorTerminal, diff --git a/crates/bindgen/src/main.rs b/crates/bindgen/src/main.rs index 68336737a1..9a1c2d5b2a 100644 --- a/crates/bindgen/src/main.rs +++ b/crates/bindgen/src/main.rs @@ -56,7 +56,7 @@ pub fn main() { } }; - match load_types(input_path.clone(), &cwd, Threading::AllAvailable) { + match load_types(input_path.clone(), cwd, Threading::AllAvailable) { Ok(types_and_targets) => { let mut file = File::create(output_path.clone()).unwrap_or_else(|err| { eprintln!( diff --git a/crates/cli/src/build.rs b/crates/cli/src/build.rs index b4d03a5bee..5cf4a7106e 100644 --- a/crates/cli/src/build.rs +++ b/crates/cli/src/build.rs @@ -55,7 +55,7 @@ pub fn build_file<'a>( let loaded = roc_load::load_and_monomorphize( arena, app_module_path.clone(), - src_dir.as_path(), + src_dir, subs_by_module, target_info, // TODO: expose this from CLI? @@ -436,7 +436,7 @@ pub fn check_file( let mut loaded = roc_load::load_and_typecheck( arena, roc_file_path, - src_dir.as_path(), + src_dir, subs_by_module, target_info, // TODO: expose this from CLI? diff --git a/crates/cli/src/lib.rs b/crates/cli/src/lib.rs index 84cf30890d..3dd67c7c5a 100644 --- a/crates/cli/src/lib.rs +++ b/crates/cli/src/lib.rs @@ -367,7 +367,7 @@ pub fn test(matches: &ArgMatches, triple: Triple) -> io::Result { let loaded = roc_load::load_and_monomorphize( arena, path, - src_dir.as_path(), + src_dir, subs_by_module, target_info, // TODO: expose this from CLI? diff --git a/crates/compiler/load/build.rs b/crates/compiler/load/build.rs index 001be13ee3..924eaa8796 100644 --- a/crates/compiler/load/build.rs +++ b/crates/compiler/load/build.rs @@ -40,7 +40,7 @@ fn write_subs_for_module(module_id: ModuleId, filename: &str) { &arena, PathBuf::from(filename), source, - &src_dir, + src_dir, Default::default(), target_info, roc_reporting::report::RenderTarget::ColorTerminal, diff --git a/crates/compiler/load/src/lib.rs b/crates/compiler/load/src/lib.rs index 645299d7f6..cbc256b51e 100644 --- a/crates/compiler/load/src/lib.rs +++ b/crates/compiler/load/src/lib.rs @@ -7,7 +7,7 @@ use roc_module::symbol::{ModuleId, Symbol}; use roc_reporting::report::RenderTarget; use roc_target::TargetInfo; use roc_types::subs::{Subs, Variable}; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; pub use roc_load_internal::docs; pub use roc_load_internal::file::{ @@ -18,7 +18,6 @@ pub use roc_load_internal::file::{ fn load<'a>( arena: &'a Bump, load_start: LoadStart<'a>, - src_dir: &Path, exposed_types: ExposedByModule, goal_phase: Phase, target_info: TargetInfo, @@ -30,7 +29,6 @@ fn load<'a>( roc_load_internal::file::load( arena, load_start, - src_dir, exposed_types, goal_phase, target_info, @@ -44,7 +42,6 @@ fn load<'a>( pub fn load_single_threaded<'a>( arena: &'a Bump, load_start: LoadStart<'a>, - src_dir: &Path, exposed_types: ExposedByModule, goal_phase: Phase, target_info: TargetInfo, @@ -55,7 +52,6 @@ pub fn load_single_threaded<'a>( roc_load_internal::file::load_single_threaded( arena, load_start, - src_dir, exposed_types, goal_phase, target_info, @@ -69,7 +65,7 @@ pub fn load_and_monomorphize_from_str<'a>( arena: &'a Bump, filename: PathBuf, src: &'a str, - src_dir: &Path, + src_dir: PathBuf, exposed_types: ExposedByModule, target_info: TargetInfo, render: RenderTarget, @@ -77,12 +73,11 @@ pub fn load_and_monomorphize_from_str<'a>( ) -> Result, LoadingProblem<'a>> { use LoadResult::*; - let load_start = LoadStart::from_str(arena, filename, src)?; + let load_start = LoadStart::from_str(arena, filename, src, src_dir)?; match load( arena, load_start, - src_dir, exposed_types, Phase::MakeSpecializations, target_info, @@ -97,7 +92,7 @@ pub fn load_and_monomorphize_from_str<'a>( pub fn load_and_monomorphize<'a>( arena: &'a Bump, filename: PathBuf, - src_dir: &Path, + src_dir: PathBuf, exposed_types: ExposedByModule, target_info: TargetInfo, render: RenderTarget, @@ -105,12 +100,11 @@ pub fn load_and_monomorphize<'a>( ) -> Result, LoadingProblem<'a>> { use LoadResult::*; - let load_start = LoadStart::from_path(arena, filename, render)?; + let load_start = LoadStart::from_path(arena, src_dir, filename, render)?; match load( arena, load_start, - src_dir, exposed_types, Phase::MakeSpecializations, target_info, @@ -125,7 +119,7 @@ pub fn load_and_monomorphize<'a>( pub fn load_and_typecheck<'a>( arena: &'a Bump, filename: PathBuf, - src_dir: &Path, + src_dir: PathBuf, exposed_types: ExposedByModule, target_info: TargetInfo, render: RenderTarget, @@ -133,12 +127,11 @@ pub fn load_and_typecheck<'a>( ) -> Result> { use LoadResult::*; - let load_start = LoadStart::from_path(arena, filename, render)?; + let load_start = LoadStart::from_path(arena, src_dir, filename, render)?; match load( arena, load_start, - src_dir, exposed_types, Phase::SolveTypes, target_info, @@ -154,14 +147,14 @@ pub fn load_and_typecheck_str<'a>( arena: &'a Bump, filename: PathBuf, source: &'a str, - src_dir: &Path, + src_dir: PathBuf, exposed_types: ExposedByModule, target_info: TargetInfo, render: RenderTarget, ) -> Result> { use LoadResult::*; - let load_start = LoadStart::from_str(arena, filename, source)?; + let load_start = LoadStart::from_str(arena, filename, source, src_dir)?; // NOTE: this function is meant for tests, and so we use single-threaded // solving so we don't use too many threads per-test. That gives higher @@ -169,7 +162,6 @@ pub fn load_and_typecheck_str<'a>( match load_single_threaded( arena, load_start, - src_dir, exposed_types, Phase::SolveTypes, target_info, diff --git a/crates/compiler/load_internal/src/file.rs b/crates/compiler/load_internal/src/file.rs index 3a89dee23b..bef20d1b89 100644 --- a/crates/compiler/load_internal/src/file.rs +++ b/crates/compiler/load_internal/src/file.rs @@ -1067,7 +1067,7 @@ pub fn load_and_typecheck_str<'a>( arena: &'a Bump, filename: PathBuf, source: &'a str, - src_dir: &Path, + src_dir: PathBuf, exposed_types: ExposedByModule, target_info: TargetInfo, render: RenderTarget, @@ -1075,7 +1075,7 @@ pub fn load_and_typecheck_str<'a>( ) -> Result> { use LoadResult::*; - let load_start = LoadStart::from_str(arena, filename, source)?; + let load_start = LoadStart::from_str(arena, filename, source, src_dir)?; // this function is used specifically in the case // where we want to regenerate the cached data @@ -1084,7 +1084,6 @@ pub fn load_and_typecheck_str<'a>( match load( arena, load_start, - src_dir, exposed_types, Phase::SolveTypes, target_info, @@ -1108,11 +1107,13 @@ pub struct LoadStart<'a> { ident_ids_by_module: SharedIdentIdsByModule, root_id: ModuleId, root_msg: Msg<'a>, + src_dir: PathBuf, } impl<'a> LoadStart<'a> { pub fn from_path( arena: &'a Bump, + mut src_dir: PathBuf, filename: PathBuf, render: RenderTarget, ) -> Result> { @@ -1166,6 +1167,7 @@ impl<'a> LoadStart<'a> { Ok(LoadStart { arc_modules, ident_ids_by_module, + src_dir, root_id, root_msg, }) @@ -1175,6 +1177,7 @@ impl<'a> LoadStart<'a> { arena: &'a Bump, filename: PathBuf, src: &'a str, + src_dir: PathBuf, ) -> Result> { let arc_modules = Arc::new(Mutex::new(PackageModuleIds::default())); let root_exposed_ident_ids = IdentIds::exposed_builtins(0); @@ -1196,6 +1199,7 @@ impl<'a> LoadStart<'a> { Ok(LoadStart { arc_modules, + src_dir, ident_ids_by_module, root_id, root_msg, @@ -1269,7 +1273,6 @@ pub enum Threading { pub fn load<'a>( arena: &'a Bump, load_start: LoadStart<'a>, - src_dir: &Path, exposed_types: ExposedByModule, goal_phase: Phase, target_info: TargetInfo, @@ -1305,7 +1308,6 @@ pub fn load<'a>( Threads::Single => load_single_threaded( arena, load_start, - src_dir, exposed_types, goal_phase, target_info, @@ -1315,7 +1317,6 @@ pub fn load<'a>( Threads::Many(threads) => load_multi_threaded( arena, load_start, - src_dir, exposed_types, goal_phase, target_info, @@ -1331,7 +1332,6 @@ pub fn load<'a>( pub fn load_single_threaded<'a>( arena: &'a Bump, load_start: LoadStart<'a>, - src_dir: &Path, exposed_types: ExposedByModule, goal_phase: Phase, target_info: TargetInfo, @@ -1343,6 +1343,7 @@ pub fn load_single_threaded<'a>( ident_ids_by_module, root_id, root_msg, + src_dir, .. } = load_start; @@ -1394,7 +1395,7 @@ pub fn load_single_threaded<'a>( stealers, &worker_msg_rx, &msg_tx, - src_dir, + &src_dir, target_info, ); @@ -1532,7 +1533,6 @@ fn state_thread_step<'a>( fn load_multi_threaded<'a>( arena: &'a Bump, load_start: LoadStart<'a>, - src_dir: &Path, exposed_types: ExposedByModule, goal_phase: Phase, target_info: TargetInfo, @@ -1545,6 +1545,7 @@ fn load_multi_threaded<'a>( ident_ids_by_module, root_id, root_msg, + src_dir, .. } = load_start; @@ -1622,8 +1623,9 @@ fn load_multi_threaded<'a>( // We only want to move a *reference* to the main task queue's // injector in the thread, not the injector itself - // (since other threads need to reference it too). + // (since other threads need to reference it too). Same with src_dir. let injector = &injector; + let src_dir = &src_dir; // Record this thread's handle so the main thread can join it later. let res_join_handle = thread_scope diff --git a/crates/docs/src/lib.rs b/crates/docs/src/lib.rs index c3995c8bc3..0af885947e 100644 --- a/crates/docs/src/lib.rs +++ b/crates/docs/src/lib.rs @@ -438,7 +438,7 @@ pub fn load_modules_for_files(filenames: Vec) -> Vec { match roc_load::load_and_typecheck( &arena, filename, - src_dir.as_path(), + src_dir, Default::default(), roc_target::TargetInfo::default_x86_64(), // This is just type-checking for docs, so "target" doesn't matter roc_reporting::report::RenderTarget::ColorTerminal, diff --git a/crates/repl_eval/src/gen.rs b/crates/repl_eval/src/gen.rs index 24efacca36..07ba4e644e 100644 --- a/crates/repl_eval/src/gen.rs +++ b/crates/repl_eval/src/gen.rs @@ -1,7 +1,7 @@ use bumpalo::Bump; use roc_load::Threading; use roc_reporting::report::Palette; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; use roc_fmt::annotation::Formattable; use roc_fmt::annotation::{Newlines, Parens}; @@ -49,7 +49,7 @@ pub fn compile_to_mono<'a>( palette: Palette, ) -> Result, Vec> { let filename = PathBuf::from(""); - let src_dir = Path::new("fake/test/path"); + let src_dir = PathBuf::from("fake/test/path"); let module_src = arena.alloc(promote_expr_to_module(src)); From 9cc658119e2c90f8591802cd65e36b1b16c1edee Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 8 Jul 2022 17:56:30 -0400 Subject: [PATCH 03/17] Consider nested interface module paths in src_dir --- crates/compiler/load_internal/src/file.rs | 35 ++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/crates/compiler/load_internal/src/file.rs b/crates/compiler/load_internal/src/file.rs index bef20d1b89..6490470501 100644 --- a/crates/compiler/load_internal/src/file.rs +++ b/crates/compiler/load_internal/src/file.rs @@ -1136,7 +1136,40 @@ impl<'a> LoadStart<'a> { ); match res_loaded { - Ok(good) => good, + Ok((module_id, msg)) => match &msg { + Msg::Header(ModuleHeader { + module_id: header_id, + module_name, + module_path, + is_root_module, + .. + }) => { + debug_assert_eq!(*header_id, module_id); + debug_assert!(is_root_module); + + match &module_name { + ModuleNameEnum::Interface(name) => { + // Interface modules can have names like Foo.Bar.Baz, + // in which case we need to adjust the src_dir to + // remove the "Bar/Baz" directories in order to correctly + // resolve this interface module's imports! + let dirs_to_pop = name.as_str().matches('.').count(); + + if dirs_to_pop > 0 { + for _ in 0..dirs_to_pop { + src_dir.pop(); + } + + (module_id, msg) + } else { + (module_id, msg) + } + } + _ => (module_id, msg), + } + } + _ => (module_id, msg), + }, Err(LoadingProblem::ParsingFailed(problem)) => { let module_ids = Arc::try_unwrap(arc_modules) From 281f2d68421ca428ebca6a06796b79256f178a69 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 8 Jul 2022 17:59:26 -0400 Subject: [PATCH 04/17] Use if let over some matches --- crates/compiler/load_internal/src/file.rs | 38 +++++++++-------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/crates/compiler/load_internal/src/file.rs b/crates/compiler/load_internal/src/file.rs index 6490470501..ce8a933bc0 100644 --- a/crates/compiler/load_internal/src/file.rs +++ b/crates/compiler/load_internal/src/file.rs @@ -1136,40 +1136,32 @@ impl<'a> LoadStart<'a> { ); match res_loaded { - Ok((module_id, msg)) => match &msg { - Msg::Header(ModuleHeader { + Ok((module_id, msg)) => { + if let Msg::Header(ModuleHeader { module_id: header_id, module_name, - module_path, is_root_module, .. - }) => { + }) = &msg + { debug_assert_eq!(*header_id, module_id); debug_assert!(is_root_module); - match &module_name { - ModuleNameEnum::Interface(name) => { - // Interface modules can have names like Foo.Bar.Baz, - // in which case we need to adjust the src_dir to - // remove the "Bar/Baz" directories in order to correctly - // resolve this interface module's imports! - let dirs_to_pop = name.as_str().matches('.').count(); + if let ModuleNameEnum::Interface(name) = module_name { + // Interface modules can have names like Foo.Bar.Baz, + // in which case we need to adjust the src_dir to + // remove the "Bar/Baz" directories in order to correctly + // resolve this interface module's imports! + let dirs_to_pop = name.as_str().matches('.').count(); - if dirs_to_pop > 0 { - for _ in 0..dirs_to_pop { - src_dir.pop(); - } - - (module_id, msg) - } else { - (module_id, msg) - } + for _ in 0..dirs_to_pop { + src_dir.pop(); } - _ => (module_id, msg), } } - _ => (module_id, msg), - }, + + (module_id, msg) + } Err(LoadingProblem::ParsingFailed(problem)) => { let module_ids = Arc::try_unwrap(arc_modules) From f45e3dbb467ded3aff96bdc17b07624649894bdd Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 8 Jul 2022 18:14:26 -0400 Subject: [PATCH 05/17] Fix tests --- crates/bindgen/src/load.rs | 4 +-- crates/bindgen/tests/helpers/mod.rs | 2 +- crates/compiler/load/src/lib.rs | 12 +++---- .../compiler/load_internal/tests/test_load.rs | 31 ++++++------------- crates/compiler/solve/tests/solve_expr.rs | 6 ++-- crates/compiler/test_derive/src/encoding.rs | 2 +- crates/compiler/test_gen/src/helpers/llvm.rs | 4 +-- crates/compiler/test_mono/src/tests.rs | 4 +-- crates/reporting/tests/test_reporting.rs | 2 +- 9 files changed, 27 insertions(+), 40 deletions(-) diff --git a/crates/bindgen/src/load.rs b/crates/bindgen/src/load.rs index c66e2216d1..528d3ac17c 100644 --- a/crates/bindgen/src/load.rs +++ b/crates/bindgen/src/load.rs @@ -4,13 +4,13 @@ use roc_load::{LoadedModule, Threading}; use roc_reporting::report::RenderTarget; use roc_target::{Architecture, TargetInfo}; use std::io; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; use strum::IntoEnumIterator; use target_lexicon::Triple; pub fn load_types( full_file_path: PathBuf, - dir: &Path, + dir: PathBuf, threading: Threading, ) -> Result, io::Error> { let target_info = (&Triple::host()).into(); diff --git a/crates/bindgen/tests/helpers/mod.rs b/crates/bindgen/tests/helpers/mod.rs index 410d3eac90..d1cf822fb8 100644 --- a/crates/bindgen/tests/helpers/mod.rs +++ b/crates/bindgen/tests/helpers/mod.rs @@ -33,7 +33,7 @@ pub fn generate_bindings(decl_src: &str) -> String { let mut file = File::create(file_path).unwrap(); writeln!(file, "{}", &src).unwrap(); - let result = load_types(full_file_path, dir.path(), Threading::Single); + let result = load_types(full_file_path, dir.path().to_path_buf(), Threading::Single); dir.close().expect("Unable to close tempdir"); diff --git a/crates/compiler/load/src/lib.rs b/crates/compiler/load/src/lib.rs index cbc256b51e..cee9864eac 100644 --- a/crates/compiler/load/src/lib.rs +++ b/crates/compiler/load/src/lib.rs @@ -89,15 +89,15 @@ pub fn load_and_monomorphize_from_str<'a>( } } -pub fn load_and_monomorphize<'a>( - arena: &'a Bump, +pub fn load_and_monomorphize( + arena: &Bump, filename: PathBuf, src_dir: PathBuf, exposed_types: ExposedByModule, target_info: TargetInfo, render: RenderTarget, threading: Threading, -) -> Result, LoadingProblem<'a>> { +) -> Result, LoadingProblem<'_>> { use LoadResult::*; let load_start = LoadStart::from_path(arena, src_dir, filename, render)?; @@ -116,15 +116,15 @@ pub fn load_and_monomorphize<'a>( } } -pub fn load_and_typecheck<'a>( - arena: &'a Bump, +pub fn load_and_typecheck( + arena: &Bump, filename: PathBuf, src_dir: PathBuf, exposed_types: ExposedByModule, target_info: TargetInfo, render: RenderTarget, threading: Threading, -) -> Result> { +) -> Result> { use LoadResult::*; let load_start = LoadStart::from_path(arena, src_dir, filename, render)?; diff --git a/crates/compiler/load_internal/tests/test_load.rs b/crates/compiler/load_internal/tests/test_load.rs index 35909a02f4..ac15c4ae41 100644 --- a/crates/compiler/load_internal/tests/test_load.rs +++ b/crates/compiler/load_internal/tests/test_load.rs @@ -30,23 +30,22 @@ use roc_target::TargetInfo; use roc_types::pretty_print::name_and_print_var; use roc_types::pretty_print::DebugPrint; use std::collections::HashMap; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; -fn load_and_typecheck<'a>( - arena: &'a Bump, +fn load_and_typecheck( + arena: &Bump, filename: PathBuf, - src_dir: &Path, + src_dir: PathBuf, exposed_types: ExposedByModule, target_info: TargetInfo, -) -> Result> { +) -> Result { use LoadResult::*; - let load_start = LoadStart::from_path(arena, filename, RenderTarget::Generic)?; + let load_start = LoadStart::from_path(arena, src_dir, filename, RenderTarget::Generic)?; match roc_load_internal::file::load( arena, load_start, - src_dir, exposed_types, Phase::SolveTypes, target_info, @@ -167,7 +166,7 @@ fn multiple_modules_help<'a>( load_and_typecheck( arena, full_file_path, - dir.path(), + dir.path().to_path_buf(), Default::default(), TARGET_INFO, ) @@ -184,13 +183,7 @@ fn load_fixture( let src_dir = fixtures_dir().join(dir_name); let filename = src_dir.join(format!("{}.roc", module_name)); let arena = Bump::new(); - let loaded = load_and_typecheck( - &arena, - filename, - src_dir.as_path(), - subs_by_module, - TARGET_INFO, - ); + let loaded = load_and_typecheck(&arena, filename, src_dir, subs_by_module, TARGET_INFO); let mut loaded_module = match loaded { Ok(x) => x, Err(roc_load_internal::file::LoadingProblem::FormattedReport(report)) => { @@ -346,13 +339,7 @@ fn interface_with_deps() { let src_dir = fixtures_dir().join("interface_with_deps"); let filename = src_dir.join("Primary.roc"); let arena = Bump::new(); - let loaded = load_and_typecheck( - &arena, - filename, - src_dir.as_path(), - subs_by_module, - TARGET_INFO, - ); + let loaded = load_and_typecheck(&arena, filename, src_dir, subs_by_module, TARGET_INFO); let mut loaded_module = loaded.expect("Test module failed to load"); let home = loaded_module.module_id; diff --git a/crates/compiler/solve/tests/solve_expr.rs b/crates/compiler/solve/tests/solve_expr.rs index 47568cf4e6..ffb5f7a1dc 100644 --- a/crates/compiler/solve/tests/solve_expr.rs +++ b/crates/compiler/solve/tests/solve_expr.rs @@ -98,7 +98,7 @@ mod solve_expr { arena, file_path, module_src, - dir.path(), + dir.path().to_path_buf(), exposed_types, roc_target::TargetInfo::default_x86_64(), roc_reporting::report::RenderTarget::Generic, @@ -6572,7 +6572,7 @@ mod solve_expr { A := {} id1 = \@A {} -> @A {} #^^^{-1} - + id2 = \@A {} -> id1 (@A {}) #^^^{-1} ^^^ @@ -6919,7 +6919,7 @@ mod solve_expr { Ok u -> [Pair u (List.drop inp 1)] _ -> [] - main = any + main = any "# ), "Parser U8", diff --git a/crates/compiler/test_derive/src/encoding.rs b/crates/compiler/test_derive/src/encoding.rs index 592673dac5..ed03d51ab1 100644 --- a/crates/compiler/test_derive/src/encoding.rs +++ b/crates/compiler/test_derive/src/encoding.rs @@ -234,7 +234,7 @@ where &arena, encode_path().file_name().unwrap().into(), source, - encode_path().parent().unwrap(), + encode_path().parent().unwrap().to_path_buf(), Default::default(), target_info, roc_reporting::report::RenderTarget::ColorTerminal, diff --git a/crates/compiler/test_gen/src/helpers/llvm.rs b/crates/compiler/test_gen/src/helpers/llvm.rs index 5f94857cdb..8fa04da09c 100644 --- a/crates/compiler/test_gen/src/helpers/llvm.rs +++ b/crates/compiler/test_gen/src/helpers/llvm.rs @@ -34,12 +34,12 @@ fn create_llvm_module<'a>( target: &Triple, opt_level: OptLevel, ) -> (&'static str, String, &'a Module<'a>) { - use std::path::{Path, PathBuf}; + use std::path::PathBuf; let target_info = roc_target::TargetInfo::from(target); let filename = PathBuf::from("Test.roc"); - let src_dir = Path::new("fake/test/path"); + let src_dir = PathBuf::from("fake/test/path"); let module_src; let temp; diff --git a/crates/compiler/test_mono/src/tests.rs b/crates/compiler/test_mono/src/tests.rs index b5d9d85804..2876d797a9 100644 --- a/crates/compiler/test_mono/src/tests.rs +++ b/crates/compiler/test_mono/src/tests.rs @@ -73,12 +73,12 @@ fn promote_expr_to_module(src: &str) -> String { fn compiles_to_ir(test_name: &str, src: &str) { use bumpalo::Bump; - use std::path::{Path, PathBuf}; + use std::path::PathBuf; let arena = &Bump::new(); let filename = PathBuf::from("Test.roc"); - let src_dir = Path::new("fake/test/path"); + let src_dir = PathBuf::from("fake/test/path"); let module_src; let temp; diff --git a/crates/reporting/tests/test_reporting.rs b/crates/reporting/tests/test_reporting.rs index df051983fd..bb8dca4f68 100644 --- a/crates/reporting/tests/test_reporting.rs +++ b/crates/reporting/tests/test_reporting.rs @@ -86,7 +86,7 @@ mod test_reporting { let result = roc_load::load_and_typecheck( arena, full_file_path, - dir.path(), + dir.path().to_path_buf(), exposed_types, roc_target::TargetInfo::default_x86_64(), RenderTarget::Generic, From 4956fc5ef41dfe5ec29b83ac79db47f4ffe8e339 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 10 Jul 2022 01:22:30 +0200 Subject: [PATCH 06/17] remove transitive builtins --- crates/compiler/can/src/builtins.rs | 15 --------------- crates/compiler/can/src/module.rs | 10 ---------- 2 files changed, 25 deletions(-) diff --git a/crates/compiler/can/src/builtins.rs b/crates/compiler/can/src/builtins.rs index 168a1d37f3..9fd73d3055 100644 --- a/crates/compiler/can/src/builtins.rs +++ b/crates/compiler/can/src/builtins.rs @@ -244,21 +244,6 @@ map_symbol_to_lowlevel_and_arity! { /// lookup (if the bounds check passed). That internal function is hardcoded in code gen, /// which works fine because it doesn't involve any open tag unions. -/// Does a builtin depend on any other builtins? -/// -/// NOTE: you are supposed to give all symbols that are relied on, -/// even those that are relied on transitively! -pub fn builtin_dependencies(symbol: Symbol) -> &'static [Symbol] { - match symbol { - Symbol::LIST_SORT_ASC => &[Symbol::LIST_SORT_WITH, Symbol::NUM_COMPARE], - Symbol::LIST_SORT_DESC => &[Symbol::LIST_SORT_WITH], - Symbol::LIST_PRODUCT => &[Symbol::LIST_WALK, Symbol::NUM_MUL], - Symbol::LIST_SUM => &[Symbol::LIST_WALK, Symbol::NUM_ADD], - Symbol::LIST_SET => &[Symbol::LIST_REPLACE], - _ => &[], - } -} - /// Implementation for a builtin pub fn builtin_defs_map(symbol: Symbol, var_store: &mut VarStore) -> Option { debug_assert!(symbol.is_builtin()); diff --git a/crates/compiler/can/src/module.rs b/crates/compiler/can/src/module.rs index 24d0affda4..110a7741b9 100644 --- a/crates/compiler/can/src/module.rs +++ b/crates/compiler/can/src/module.rs @@ -415,16 +415,6 @@ pub fn canonicalize_module_defs<'a>( referenced_values.extend(env.qualified_value_lookups.iter().copied()); referenced_types.extend(env.qualified_type_lookups.iter().copied()); - // add any builtins used by other builtins - let transitive_builtins: Vec = referenced_values - .iter() - .filter(|s| s.is_builtin()) - .flat_map(|s| crate::builtins::builtin_dependencies(*s)) - .copied() - .collect(); - - referenced_values.extend(transitive_builtins); - // NOTE previously we inserted builtin defs into the list of defs here // this is now done later, in file.rs. From 081b1d26122d13eafa32cae3775e0d3afec543e4 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sat, 9 Jul 2022 19:23:22 -0400 Subject: [PATCH 07/17] Fix a gen test for dev backend --- crates/compiler/test_gen/src/helpers/dev.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/compiler/test_gen/src/helpers/dev.rs b/crates/compiler/test_gen/src/helpers/dev.rs index 963c117a71..0df8563b7b 100644 --- a/crates/compiler/test_gen/src/helpers/dev.rs +++ b/crates/compiler/test_gen/src/helpers/dev.rs @@ -30,11 +30,11 @@ pub fn helper( _leak: bool, lazy_literals: bool, ) -> (String, Vec, Library) { - use std::path::{Path, PathBuf}; + use std::path::PathBuf; let dir = tempdir().unwrap(); let filename = PathBuf::from("Test.roc"); - let src_dir = Path::new("fake/test/path"); + let src_dir = PathBuf::from("fake/test/path"); let app_o_file = dir.path().join("app.o"); let module_src; From 86ee6b0e035056c0e0103c6720f6971c1a47712d Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sat, 9 Jul 2022 19:23:36 -0400 Subject: [PATCH 08/17] Fix some warnings in gen dev tests --- crates/compiler/test_gen/src/gen_abilities.rs | 5 +---- crates/compiler/test_gen/src/gen_records.rs | 2 +- crates/compiler/test_gen/src/gen_tags.rs | 3 ++- crates/compiler/test_gen/src/helpers/dev.rs | 4 +++- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/compiler/test_gen/src/gen_abilities.rs b/crates/compiler/test_gen/src/gen_abilities.rs index b207f42561..d8f3f36f5b 100644 --- a/crates/compiler/test_gen/src/gen_abilities.rs +++ b/crates/compiler/test_gen/src/gen_abilities.rs @@ -1,13 +1,10 @@ #[cfg(feature = "gen-llvm")] use crate::helpers::llvm::assert_evals_to; -#[cfg(feature = "gen-dev")] -use crate::helpers::dev::assert_evals_to; - #[cfg(feature = "gen-wasm")] use crate::helpers::wasm::assert_evals_to; -#[cfg(test)] +#[cfg(all(test, any(feature = "gen-llvm", feature = "gen-wasm")))] use indoc::indoc; #[cfg(all(test, any(feature = "gen-llvm", feature = "gen-wasm")))] diff --git a/crates/compiler/test_gen/src/gen_records.rs b/crates/compiler/test_gen/src/gen_records.rs index 7da336b3b1..bfeec21557 100644 --- a/crates/compiler/test_gen/src/gen_records.rs +++ b/crates/compiler/test_gen/src/gen_records.rs @@ -10,7 +10,7 @@ use crate::helpers::wasm::{assert_evals_to, expect_runtime_error_panic}; // use crate::assert_wasm_evals_to as assert_evals_to; use indoc::indoc; -#[cfg(test)] +#[cfg(all(test, any(feature = "gen-llvm", feature = "gen-wasm")))] use roc_std::{RocList, RocStr}; #[test] diff --git a/crates/compiler/test_gen/src/gen_tags.rs b/crates/compiler/test_gen/src/gen_tags.rs index a654b754e8..52cf2a6e86 100644 --- a/crates/compiler/test_gen/src/gen_tags.rs +++ b/crates/compiler/test_gen/src/gen_tags.rs @@ -9,7 +9,8 @@ use crate::helpers::wasm::assert_evals_to; #[cfg(test)] use indoc::indoc; -#[cfg(test)] + +#[cfg(all(test, any(feature = "gen-llvm", feature = "gen-wasm")))] use roc_std::{RocList, RocStr}; #[test] diff --git a/crates/compiler/test_gen/src/helpers/dev.rs b/crates/compiler/test_gen/src/helpers/dev.rs index 0df8563b7b..611e400354 100644 --- a/crates/compiler/test_gen/src/helpers/dev.rs +++ b/crates/compiler/test_gen/src/helpers/dev.rs @@ -1,11 +1,13 @@ use libloading::Library; use roc_build::link::{link, LinkType}; use roc_builtins::bitcode; -use roc_collections::all::MutMap; use roc_load::Threading; use roc_region::all::LineInfo; use tempfile::tempdir; +#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] +use roc_collections::all::MutMap; + #[allow(unused_imports)] use roc_mono::ir::pretty_print_ir_symbols; From 90c96b939194fff0153127eeae5d9cbff0c80ecc Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 10 Jul 2022 01:52:13 +0200 Subject: [PATCH 09/17] update mono tests --- crates/compiler/mono/src/ir.rs | 2 +- .../test_mono/generated/call_function_in_empty_list.txt | 9 +++------ .../generated/call_function_in_empty_list_unbound.txt | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/crates/compiler/mono/src/ir.rs b/crates/compiler/mono/src/ir.rs index 790bb2d407..eef307f16a 100644 --- a/crates/compiler/mono/src/ir.rs +++ b/crates/compiler/mono/src/ir.rs @@ -9261,7 +9261,7 @@ fn union_lambda_set_to_switch<'a>( // code gen to proceed. We then assume that we hit another (more descriptive) error before // hitting this one - let msg = "a Lambda Set isempty. Most likely there is a type error in your program."; + let msg = "a Lambda Set is empty. Most likely there is a type error in your program."; return Stmt::RuntimeError(msg); } diff --git a/crates/compiler/test_mono/generated/call_function_in_empty_list.txt b/crates/compiler/test_mono/generated/call_function_in_empty_list.txt index 365de111dd..e07068b993 100644 --- a/crates/compiler/test_mono/generated/call_function_in_empty_list.txt +++ b/crates/compiler/test_mono/generated/call_function_in_empty_list.txt @@ -5,14 +5,11 @@ procedure List.5 (#Attr.2, #Attr.3): procedure Test.2 (Test.3): let Test.7 : {} = Struct {}; - let Test.6 : {} = CallByName Test.8 Test.7; - ret Test.6; - -procedure Test.8 (Test.9): - Error The `#UserApp.IdentId(8)` function could not be generated, likely due to a type error. + let Test.8 : U8 = GetTagId Test.3; + Error a Lambda Set is empty. Most likely there is a type error in your program. procedure Test.0 (): - let Test.1 : List {} = Array []; + let Test.1 : List [] = Array []; let Test.5 : {} = Struct {}; let Test.4 : List {} = CallByName List.5 Test.1 Test.5; ret Test.4; diff --git a/crates/compiler/test_mono/generated/call_function_in_empty_list_unbound.txt b/crates/compiler/test_mono/generated/call_function_in_empty_list_unbound.txt index 3c7c952300..4215d21295 100644 --- a/crates/compiler/test_mono/generated/call_function_in_empty_list_unbound.txt +++ b/crates/compiler/test_mono/generated/call_function_in_empty_list_unbound.txt @@ -2,5 +2,5 @@ procedure List.5 (#Attr.2, #Attr.3): Error UnresolvedTypeVar crates/compiler/mono/src/ir.rs line 5035 procedure Test.0 (): - let Test.1 : List {} = Array []; + let Test.1 : List [] = Array []; Error UnresolvedTypeVar crates/compiler/mono/src/ir.rs line 4562 From c8d8b6adb69c673c7e1046379cdbb45b12351d45 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sat, 9 Jul 2022 21:25:18 -0400 Subject: [PATCH 10/17] Fix wasm gen dev tests --- crates/compiler/test_gen/src/helpers/wasm.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/compiler/test_gen/src/helpers/wasm.rs b/crates/compiler/test_gen/src/helpers/wasm.rs index de0e863397..d1e77c446c 100644 --- a/crates/compiler/test_gen/src/helpers/wasm.rs +++ b/crates/compiler/test_gen/src/helpers/wasm.rs @@ -73,7 +73,7 @@ fn compile_roc_to_wasm_bytes<'a, T: Wasm32Result>( _test_wrapper_type_info: PhantomData, ) -> Vec { let filename = PathBuf::from("Test.roc"); - let src_dir = Path::new("fake/test/path"); + let src_dir = PathBuf::from("fake/test/path"); let module_src; let temp; From 57260d53f951506025685a593c7841851832080a Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sat, 9 Jul 2022 22:32:29 -0400 Subject: [PATCH 11/17] Allow single-line comments in multiline annotations --- crates/compiler/fmt/src/collection.rs | 65 ++++++++++++++++++++------- crates/compiler/fmt/tests/test_fmt.rs | 40 ++++++++++++++--- 2 files changed, 83 insertions(+), 22 deletions(-) diff --git a/crates/compiler/fmt/src/collection.rs b/crates/compiler/fmt/src/collection.rs index f68c25c032..47fe924f55 100644 --- a/crates/compiler/fmt/src/collection.rs +++ b/crates/compiler/fmt/src/collection.rs @@ -1,8 +1,8 @@ -use roc_parse::ast::{Collection, ExtractSpaces}; +use roc_parse::ast::{Collection, CommentOrNewline, ExtractSpaces}; use crate::{ annotation::{Formattable, Newlines}, - spaces::{count_leading_newlines, fmt_comments_only, NewlineAt, INDENT}, + spaces::{fmt_comments_only, NewlineAt, INDENT}, Buf, }; @@ -41,24 +41,43 @@ pub fn fmt_collection<'a, 'buf, T: ExtractSpaces<'a> + Formattable>( buf.push(start); for (index, item) in items.iter().enumerate() { - let item = item.extract_spaces(); let is_first_item = index == 0; + let item = item.extract_spaces(); + let is_only_newlines = item.before.iter().all(|s| s.is_newline()); - buf.newline(); + if item.before.is_empty() || is_only_newlines { + buf.ensure_ends_in_newline(); + } else { + if is_first_item { + // The first item in a multiline collection always begins with exactly + // one newline (so the delimiter is at the end of its own line), + // and that newline appears before the first comment (if there is one). + buf.ensure_ends_in_newline(); + } else { + if item.before.starts_with(&[CommentOrNewline::Newline]) { + buf.ensure_ends_in_newline(); + } - if !item.before.is_empty() { - let is_only_newlines = item.before.iter().all(|s| s.is_newline()); + if item + .before + .starts_with(&[CommentOrNewline::Newline, CommentOrNewline::Newline]) + { + // If there's a comment, and it's not on the first item, + // and it's preceded by at least one blank line, maintain 1 blank line. + // (We already ensured that it ends in a newline, so this will turn that + // into a blank line.) - if !is_first_item - && !is_only_newlines - && count_leading_newlines(item.before.iter()) > 1 - { - buf.newline(); + buf.newline(); + } } - fmt_comments_only(buf, item.before.iter(), NewlineAt::Bottom, item_indent); + fmt_comments_only(buf, item.before.iter(), NewlineAt::None, item_indent); + + if !is_only_newlines { + if item.before.ends_with(&[CommentOrNewline::Newline]) { + buf.newline(); + } - if !is_only_newlines && count_leading_newlines(item.before.iter().rev()) > 0 { buf.newline(); } } @@ -68,21 +87,33 @@ pub fn fmt_collection<'a, 'buf, T: ExtractSpaces<'a> + Formattable>( buf.push(','); if !item.after.is_empty() { - fmt_comments_only(buf, item.after.iter(), NewlineAt::Top, item_indent); + if item.after.iter().any(|s| s.is_newline()) { + buf.newline(); + } + + fmt_comments_only(buf, item.after.iter(), NewlineAt::None, item_indent); } } - if count_leading_newlines(items.final_comments().iter()) > 1 { + if items.final_comments().iter().any(|s| s.is_newline()) { + buf.newline(); + } + + if items + .final_comments() + .starts_with(&[CommentOrNewline::Newline, CommentOrNewline::Newline]) + { buf.newline(); } fmt_comments_only( buf, items.final_comments().iter(), - NewlineAt::Top, + NewlineAt::None, item_indent, ); - buf.newline(); + + buf.ensure_ends_in_newline(); buf.indent(braces_indent); } else { // is_multiline == false diff --git a/crates/compiler/fmt/tests/test_fmt.rs b/crates/compiler/fmt/tests/test_fmt.rs index a914d08510..8e8f137067 100644 --- a/crates/compiler/fmt/tests/test_fmt.rs +++ b/crates/compiler/fmt/tests/test_fmt.rs @@ -2347,8 +2347,7 @@ mod test_fmt { indoc!( r#" f : { - x : Int *, - # comment 1 + x : Int *, # comment 1 # comment 2 } @@ -4588,7 +4587,7 @@ mod test_fmt { } #[test] - fn multiline_tag_union_annotation() { + fn multiline_tag_union_annotation_no_comments() { expr_formats_same(indoc!( r#" b : [ @@ -4694,8 +4693,7 @@ mod test_fmt { b : [ True, # comment 1 - False, - # comment 2 + False, # comment 2 # comment 3 ] @@ -5082,6 +5080,38 @@ mod test_fmt { ); } + #[test] + fn comments_in_multiline_tag_union_annotation() { + expr_formats_to( + indoc!( + r#" + UnionAnn : [ + Foo, # comment 1 + Bar, # comment 2 + Baz, # comment 3 + # comment 4 line 1 + # comment 4 line 2 + ] + + 0 + "# + ), + indoc!( + r#" + UnionAnn : [ + Foo, # comment 1 + Bar, # comment 2 + Baz, # comment 3 + # comment 4 line 1 + # comment 4 line 2 + ] + + 0 + "# + ), + ); + } + #[test] /// Test that everything under examples/ is formatted correctly /// If this test fails on your diff, it probably means you need to re-format the examples. From 032a8a892b0c9eaca0cb0d2e43b710f2c8dceaf9 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Sun, 10 Jul 2022 13:42:38 -0400 Subject: [PATCH 12/17] Use correct callconv for Str.toNum --- crates/compiler/gen_llvm/src/llvm/build.rs | 2 +- crates/compiler/test_gen/src/gen_str.rs | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/crates/compiler/gen_llvm/src/llvm/build.rs b/crates/compiler/gen_llvm/src/llvm/build.rs index 23b41fb931..97464a092c 100644 --- a/crates/compiler/gen_llvm/src/llvm/build.rs +++ b/crates/compiler/gen_llvm/src/llvm/build.rs @@ -5347,7 +5347,7 @@ fn run_low_level<'a, 'ctx, 'env>( let string = load_symbol(scope, &args[0]); - let result = call_bitcode_fn(env, &[string], intrinsic); + let result = call_bitcode_fn_fixing_for_convention(env, &[string], layout, intrinsic); // zig passes the result as a packed integer sometimes, instead of a struct. So we cast let expected_type = basic_type_from_layout(env, layout); diff --git a/crates/compiler/test_gen/src/gen_str.rs b/crates/compiler/test_gen/src/gen_str.rs index 3ee7db96c1..f9eeecabb0 100644 --- a/crates/compiler/test_gen/src/gen_str.rs +++ b/crates/compiler/test_gen/src/gen_str.rs @@ -1377,7 +1377,6 @@ fn str_to_nat() { } #[test] -#[ignore = "TODO: figure out why returning i128 across FFI boundary is an issue"] #[cfg(any(feature = "gen-llvm"))] fn str_to_i128() { assert_evals_to!( @@ -1395,7 +1394,6 @@ fn str_to_i128() { } #[test] -#[ignore = "TODO: figure out why returning i128 across FFI boundary is an issue"] #[cfg(any(feature = "gen-llvm"))] fn str_to_u128() { assert_evals_to!( @@ -1569,7 +1567,6 @@ fn str_to_f32() { } #[test] -#[ignore = "TODO: figure out why returning i128 across FFI boundary is an issue"] #[cfg(any(feature = "gen-llvm"))] fn str_to_dec() { use roc_std::RocDec; From 25ba744cdd30e7fdbfdc407d2b0f39146c01b7eb Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Sun, 10 Jul 2022 13:44:35 -0400 Subject: [PATCH 13/17] Unignore most list gen tests --- crates/compiler/test_gen/src/gen_list.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/crates/compiler/test_gen/src/gen_list.rs b/crates/compiler/test_gen/src/gen_list.rs index 796c3a278a..a782dc55bc 100644 --- a/crates/compiler/test_gen/src/gen_list.rs +++ b/crates/compiler/test_gen/src/gen_list.rs @@ -1622,7 +1622,6 @@ fn first_int_list() { #[test] #[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] -#[ignore] fn first_wildcard_empty_list() { assert_evals_to!( indoc!( @@ -1671,7 +1670,6 @@ fn last_int_list() { #[test] #[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] -#[ignore] fn last_wildcard_empty_list() { assert_evals_to!( indoc!( @@ -1720,7 +1718,6 @@ fn get_empty_list() { #[test] #[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] -#[ignore] fn get_wildcard_empty_list() { assert_evals_to!( indoc!( From c211ec9790d7d602f3396acc9e27284abcdafa49 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Sun, 10 Jul 2022 13:53:41 -0400 Subject: [PATCH 14/17] Don't include DelayedAlias in illegal cycle checks --- crates/compiler/solve/tests/solve_expr.rs | 17 +++++++++++++++++ crates/compiler/types/src/types.rs | 2 ++ 2 files changed, 19 insertions(+) diff --git a/crates/compiler/solve/tests/solve_expr.rs b/crates/compiler/solve/tests/solve_expr.rs index 935ae95b90..89e60d7538 100644 --- a/crates/compiler/solve/tests/solve_expr.rs +++ b/crates/compiler/solve/tests/solve_expr.rs @@ -7324,4 +7324,21 @@ mod solve_expr { "OList", ); } + + #[test] + fn rosetree_with_result_is_legal_recursive_type() { + infer_eq_without_problem( + indoc!( + r#" + Rose a : [Rose (Result (List (Rose a)) I64)] + + x : Rose I64 + x = Rose (Ok []) + + x + "# + ), + "Rose I64", + ); + } } diff --git a/crates/compiler/types/src/types.rs b/crates/compiler/types/src/types.rs index df0a5a2d32..adfd08b72a 100644 --- a/crates/compiler/types/src/types.rs +++ b/crates/compiler/types/src/types.rs @@ -1482,6 +1482,8 @@ impl Type { Type::Apply(Symbol::LIST_LIST | Symbol::SET_SET, _, _) => false, Type::Apply(..) => internal_error!("cannot chase an Apply!"), Type::Alias { .. } => internal_error!("should be dealiased"), + // Must be conservative here because we don't know what the alias expands to yet + Type::DelayedAlias(..) => false, // Non-composite types are trivially narrow _ => true, } From 4ced6faa9abf1704088456359b6afb75cc72592e Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Sun, 10 Jul 2022 13:54:48 -0400 Subject: [PATCH 15/17] Enable ignored rosetree compare test --- crates/compiler/test_gen/src/gen_compare.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/crates/compiler/test_gen/src/gen_compare.rs b/crates/compiler/test_gen/src/gen_compare.rs index 495ddee3c0..31db80dddd 100644 --- a/crates/compiler/test_gen/src/gen_compare.rs +++ b/crates/compiler/test_gen/src/gen_compare.rs @@ -542,10 +542,7 @@ fn eq_different_rosetrees() { #[test] #[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] -#[ignore] fn rosetree_with_tag() { - // currently stack overflows in type checking - assert_evals_to!( indoc!( r#" From 08c54678563069e9bb2194363035a2222a56f42c Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Sun, 10 Jul 2022 13:58:16 -0400 Subject: [PATCH 16/17] Enable tests that failed due to now-fixed exhaustiveness checking Closes #786 --- crates/compiler/test_gen/src/gen_tags.rs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/crates/compiler/test_gen/src/gen_tags.rs b/crates/compiler/test_gen/src/gen_tags.rs index ddb28002a2..15bb82d1e1 100644 --- a/crates/compiler/test_gen/src/gen_tags.rs +++ b/crates/compiler/test_gen/src/gen_tags.rs @@ -533,14 +533,12 @@ fn if_guard_vanilla() { #[test] #[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] -#[ignore] fn when_on_single_value_tag() { - // this fails because the switched-on symbol is not defined assert_evals_to!( indoc!( r#" when Identity 0 is - Identity 0 -> 0 + Identity 0 -> 6 Identity s -> s "# ), @@ -1047,9 +1045,7 @@ fn alignment_in_multi_tag_pattern_match() { #[test] #[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] -#[ignore] fn phantom_polymorphic() { - // see https://github.com/rtfeldman/roc/issues/786 and below assert_evals_to!( indoc!( r"# @@ -1073,11 +1069,7 @@ fn phantom_polymorphic() { #[test] #[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] -#[ignore] fn phantom_polymorphic_record() { - // see https://github.com/rtfeldman/roc/issues/786 - // also seemed to hit an issue where we check whether `add` - // has a Closure layout while the type is not fully specialized yet assert_evals_to!( indoc!( r#" From 419a29caebf649f9a6732d9207098a57d5e0703d Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Sun, 10 Jul 2022 14:03:18 -0400 Subject: [PATCH 17/17] Turn on working test --- crates/compiler/test_gen/src/gen_primitives.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/compiler/test_gen/src/gen_primitives.rs b/crates/compiler/test_gen/src/gen_primitives.rs index 29ec9c0700..428e8fe48a 100644 --- a/crates/compiler/test_gen/src/gen_primitives.rs +++ b/crates/compiler/test_gen/src/gen_primitives.rs @@ -2464,7 +2464,6 @@ fn expanded_result() { #[test] #[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] -#[ignore] fn backpassing_result() { assert_evals_to!( indoc!(