From b9c318e9fb65dc3d7f57f956a0a50f217fa9c571 Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 26 Jan 2022 15:59:21 +0100 Subject: [PATCH] update the tests --- Cargo.lock | 4 ++++ compiler/load/tests/test_load.rs | 8 +++++--- compiler/solve/Cargo.toml | 1 + compiler/solve/tests/solve_expr.rs | 2 +- compiler/test_gen/Cargo.toml | 1 + compiler/test_gen/src/gen_tags.rs | 6 +++--- compiler/test_gen/src/helpers/dev.rs | 2 +- compiler/test_gen/src/helpers/llvm.rs | 8 ++++---- compiler/test_gen/src/helpers/wasm.rs | 3 +-- compiler/test_mono/Cargo.toml | 1 + compiler/test_mono/src/tests.rs | 4 +++- reporting/Cargo.toml | 1 + reporting/tests/test_reporting.rs | 6 +++--- 13 files changed, 29 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8ff94289d0..53fc08cafd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3690,6 +3690,7 @@ dependencies = [ "roc_problem", "roc_region", "roc_solve", + "roc_target", "roc_test_utils", "roc_types", "ven_pretty", @@ -3712,6 +3713,7 @@ dependencies = [ "roc_problem", "roc_region", "roc_solve", + "roc_target", "roc_types", "roc_unify", "tempfile", @@ -4280,6 +4282,7 @@ dependencies = [ "roc_reporting", "roc_solve", "roc_std", + "roc_target", "roc_types", "roc_unify", "target-lexicon", @@ -4301,6 +4304,7 @@ dependencies = [ "roc_load", "roc_module", "roc_mono", + "roc_target", "test_mono_macros", ] diff --git a/compiler/load/tests/test_load.rs b/compiler/load/tests/test_load.rs index 7a72b7b98b..b0196c44e0 100644 --- a/compiler/load/tests/test_load.rs +++ b/compiler/load/tests/test_load.rs @@ -28,6 +28,8 @@ mod test_load { use roc_types::subs::Subs; use std::collections::HashMap; + const TARGET_INFO: roc_target::TargetInfo = roc_target::TargetInfo::default_x86_64(); + // HELPERS fn multiple_modules(files: Vec<(&str, &str)>) -> Result { @@ -110,7 +112,7 @@ mod test_load { arena.alloc(stdlib), dir.path(), exposed_types, - 8, + TARGET_INFO, builtin_defs_map, ) }; @@ -134,7 +136,7 @@ mod test_load { arena.alloc(roc_builtins::std::standard_stdlib()), src_dir.as_path(), subs_by_module, - 8, + TARGET_INFO, builtin_defs_map, ); let mut loaded_module = match loaded { @@ -305,7 +307,7 @@ mod test_load { arena.alloc(roc_builtins::std::standard_stdlib()), src_dir.as_path(), subs_by_module, - 8, + TARGET_INFO, builtin_defs_map, ); diff --git a/compiler/solve/Cargo.toml b/compiler/solve/Cargo.toml index 89da067e95..7b776821a3 100644 --- a/compiler/solve/Cargo.toml +++ b/compiler/solve/Cargo.toml @@ -21,6 +21,7 @@ roc_builtins = { path = "../builtins" } roc_problem = { path = "../problem" } roc_parse = { path = "../parse" } roc_solve = { path = "../solve" } +roc_target = { path = "../target" } pretty_assertions = "1.0.0" indoc = "1.0.3" tempfile = "3.2.0" diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index df5d36580f..b86caf3c81 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -63,7 +63,7 @@ mod solve_expr { &stdlib, dir.path(), exposed_types, - 8, + roc_target::TargetInfo::default_x86_64(), builtin_defs_map, ); diff --git a/compiler/test_gen/Cargo.toml b/compiler/test_gen/Cargo.toml index 162b058fd8..07fd0c91e7 100644 --- a/compiler/test_gen/Cargo.toml +++ b/compiler/test_gen/Cargo.toml @@ -31,6 +31,7 @@ roc_load = { path = "../load" } roc_can = { path = "../can" } roc_parse = { path = "../parse" } roc_build = { path = "../build" } +roc_target = { path = "../target" } roc_std = { path = "../../roc_std" } bumpalo = { version = "3.8.0", features = ["collections"] } either = "1.6.1" diff --git a/compiler/test_gen/src/gen_tags.rs b/compiler/test_gen/src/gen_tags.rs index bbbc9fa490..b4abaf711f 100644 --- a/compiler/test_gen/src/gen_tags.rs +++ b/compiler/test_gen/src/gen_tags.rs @@ -23,9 +23,9 @@ fn width_and_alignment_u8_u8() { let layout = Layout::Union(UnionLayout::NonRecursive(&tt)); - let ptr_width = 8; - assert_eq!(layout.alignment_bytes(ptr_width), 1); - assert_eq!(layout.stack_size(ptr_width), 2); + let target_info = roc_target::TargetInfo::default_x86_64(); + assert_eq!(layout.alignment_bytes(target_info), 1); + assert_eq!(layout.stack_size(target_info), 2); } #[test] diff --git a/compiler/test_gen/src/helpers/dev.rs b/compiler/test_gen/src/helpers/dev.rs index 31a87d9c57..3a562cbf8c 100644 --- a/compiler/test_gen/src/helpers/dev.rs +++ b/compiler/test_gen/src/helpers/dev.rs @@ -57,7 +57,7 @@ pub fn helper( &stdlib, src_dir, exposed_types, - 8, + roc_target::TargetInfo::default_x86_64(), builtin_defs_map, ); diff --git a/compiler/test_gen/src/helpers/llvm.rs b/compiler/test_gen/src/helpers/llvm.rs index 6dc6c2b7f4..1392b1ab13 100644 --- a/compiler/test_gen/src/helpers/llvm.rs +++ b/compiler/test_gen/src/helpers/llvm.rs @@ -42,6 +42,8 @@ fn create_llvm_module<'a>( ) -> (&'static str, String, &'a Module<'a>) { use std::path::{Path, PathBuf}; + let target_info = roc_target::TargetInfo::from(target); + let filename = PathBuf::from("Test.roc"); let src_dir = Path::new("fake/test/path"); @@ -56,8 +58,6 @@ fn create_llvm_module<'a>( module_src = &temp; } - let ptr_bytes = target.pointer_width().unwrap().bytes() as u32; - let exposed_types = MutMap::default(); let loaded = roc_load::file::load_and_monomorphize_from_str( arena, @@ -66,7 +66,7 @@ fn create_llvm_module<'a>( stdlib, src_dir, exposed_types, - ptr_bytes, + target_info, test_builtin_defs, ); @@ -213,7 +213,7 @@ fn create_llvm_module<'a>( context, interns, module, - target_info: ptr_bytes, + target_info, is_gen_test, // important! we don't want any procedures to get the C calling convention exposed_to_host: MutSet::default(), diff --git a/compiler/test_gen/src/helpers/wasm.rs b/compiler/test_gen/src/helpers/wasm.rs index f68f6b5da8..5d756fe921 100644 --- a/compiler/test_gen/src/helpers/wasm.rs +++ b/compiler/test_gen/src/helpers/wasm.rs @@ -94,7 +94,6 @@ fn compile_roc_to_wasm_bytes<'a, T: Wasm32TestResult>( } let exposed_types = MutMap::default(); - let ptr_bytes = 4; let loaded = roc_load::file::load_and_monomorphize_from_str( arena, filename, @@ -102,7 +101,7 @@ fn compile_roc_to_wasm_bytes<'a, T: Wasm32TestResult>( stdlib, src_dir, exposed_types, - ptr_bytes, + roc_target::TargetInfo::default_wasm32(), builtin_defs_map, ); diff --git a/compiler/test_mono/Cargo.toml b/compiler/test_mono/Cargo.toml index d599b1b64c..a2225349cb 100644 --- a/compiler/test_mono/Cargo.toml +++ b/compiler/test_mono/Cargo.toml @@ -16,6 +16,7 @@ roc_builtins = { path = "../builtins" } roc_load = { path = "../load" } roc_can = { path = "../can" } roc_mono = { path = "../mono" } +roc_target = { path = "../target" } test_mono_macros = { path = "../test_mono_macros" } pretty_assertions = "1.0.0" bumpalo = { version = "3.8.0", features = ["collections"] } diff --git a/compiler/test_mono/src/tests.rs b/compiler/test_mono/src/tests.rs index 4a398e6d38..2cf783baa2 100644 --- a/compiler/test_mono/src/tests.rs +++ b/compiler/test_mono/src/tests.rs @@ -25,6 +25,8 @@ use roc_mono::ir::Proc; use roc_mono::ir::ProcLayout; +const TARGET_INFO: roc_target::TargetInfo = roc_target::TargetInfo::default_x86_64(); + /// Without this, some tests pass in `cargo test --release` but fail without /// the --release flag because they run out of stack space. This increases /// stack size for debug builds only, while leaving the stack space at the default @@ -104,7 +106,7 @@ fn compiles_to_ir(test_name: &str, src: &str) { &stdlib, src_dir, exposed_types, - 8, + TARGET_INFO, builtin_defs_map, ); diff --git a/reporting/Cargo.toml b/reporting/Cargo.toml index 195406c968..be96603493 100644 --- a/reporting/Cargo.toml +++ b/reporting/Cargo.toml @@ -24,6 +24,7 @@ roc_constrain = { path = "../compiler/constrain" } roc_builtins = { path = "../compiler/builtins" } roc_problem = { path = "../compiler/problem" } roc_parse = { path = "../compiler/parse" } +roc_target = { path = "../compiler/target" } roc_test_utils = { path = "../test_utils" } pretty_assertions = "1.0.0" indoc = "1.0.3" diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index d0c6946def..45215dd437 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -96,8 +96,8 @@ mod test_reporting { let mut update_mode_ids = UpdateModeIds::new(); // Populate Procs and Subs, and get the low-level Expr from the canonical Expr - let ptr_bytes = 8; - let mut layout_cache = LayoutCache::new(ptr_bytes); + let target_info = roc_target::TargetInfo::default_x86_64(); + let mut layout_cache = LayoutCache::new(target_info); let mut mono_env = roc_mono::ir::Env { arena: &arena, subs: &mut subs, @@ -105,7 +105,7 @@ mod test_reporting { home, ident_ids: &mut ident_ids, update_mode_ids: &mut update_mode_ids, - target_info: ptr_bytes, + target_info, // call_specialization_counter=0 is reserved call_specialization_counter: 1, };