diff --git a/cli_utils/Cargo.lock b/cli_utils/Cargo.lock index f6cf4cf5a9..514966d291 100644 --- a/cli_utils/Cargo.lock +++ b/cli_utils/Cargo.lock @@ -964,12 +964,6 @@ dependencies = [ "toml", ] -[[package]] -name = "fixedbitset" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37ab347416e802de484e4d03c7316c48f1ecb56574dfd4a46a80f173ce1de04d" - [[package]] name = "flate2" version = "1.0.22" @@ -2047,14 +2041,11 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" dependencies = [ - "backtrace", "cfg-if 1.0.0", "instant", "libc", - "petgraph", "redox_syscall", "smallvec", - "thread-id", "winapi", ] @@ -2107,16 +2098,6 @@ dependencies = [ "sha-1", ] -[[package]] -name = "petgraph" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "467d164a6de56270bd7c4d070df81d07beace25012d5103ced4e9ff08d6afdb7" -dependencies = [ - "fixedbitset", - "indexmap", -] - [[package]] name = "phf" version = "0.9.0" @@ -2799,6 +2780,7 @@ dependencies = [ "bumpalo", "lazy_static", "roc_collections", + "roc_error_macros", "roc_ident", "roc_region", "snafu", @@ -2815,6 +2797,7 @@ dependencies = [ "roc_builtins", "roc_can", "roc_collections", + "roc_error_macros", "roc_module", "roc_problem", "roc_region", @@ -2865,6 +2848,7 @@ dependencies = [ "inkwell 0.1.0", "libloading 0.7.1", "roc_build", + "roc_builtins", "roc_collections", "roc_gen_llvm", "roc_load", @@ -2946,6 +2930,7 @@ version = "0.1.0" dependencies = [ "bumpalo", "roc_collections", + "roc_error_macros", "roc_module", "roc_region", "static_assertions", @@ -2956,6 +2941,7 @@ dependencies = [ name = "roc_unify" version = "0.1.0" dependencies = [ + "bitflags", "roc_collections", "roc_module", "roc_types", @@ -3402,17 +3388,6 @@ dependencies = [ "syn", ] -[[package]] -name = "thread-id" -version = "4.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fdfe0627923f7411a43ec9ec9c39c3a9b4151be313e0922042581fb6c9b717f" -dependencies = [ - "libc", - "redox_syscall", - "winapi", -] - [[package]] name = "threadpool" version = "1.8.1" diff --git a/compiler/load/src/file.rs b/compiler/load/src/file.rs index 6d338bc1c3..bb38213777 100644 --- a/compiler/load/src/file.rs +++ b/compiler/load/src/file.rs @@ -1074,71 +1074,24 @@ fn load<'a>( // (since other threads need to reference it too). let injector = &injector; + + // Record this thread's handle so the main thread can join it later. let res_join_handle = thread_scope .builder() .stack_size(EXPANDED_STACK_SIZE) .spawn(move |_| { - // Keep listening until we receive a Shutdown msg - - for msg in worker_msg_rx.iter() { - match msg { - WorkerMsg::Shutdown => { - // We've finished all our work. It's time to - // shut down the thread, so when the main thread - // blocks on joining with all the worker threads, - // it can finally exit too! - return Ok(()); - } - WorkerMsg::TaskAdded => { - // Find a task - either from this thread's queue, - // or from the main queue, or from another worker's - // queue - and run it. - // - // There might be no tasks to work on! That could - // happen if another thread is working on a task - // which will later result in more tasks being - // added. In that case, do nothing, and keep waiting - // until we receive a Shutdown message. - if let Some(task) = find_task(&worker, injector, stealers) { - let result = run_task( - task, - worker_arena, - src_dir, - msg_tx.clone(), - target_info, - ); - - match result { - Ok(()) => {} - Err(LoadingProblem::MsgChannelDied) => { - panic!("Msg channel closed unexpectedly.") - } - Err(LoadingProblem::ParsingFailed(problem)) => { - msg_tx.send(Msg::FailedToParse(problem)).unwrap(); - } - Err(LoadingProblem::FileProblem { - filename, - error, - }) => { - msg_tx - .send(Msg::FailedToReadFile { filename, error }) - .unwrap(); - } - Err(other) => { - return Err(other); - } - } - } - } - } - } - - // Needed to prevent a borrow checker error about this closure - // outliving its enclosing function. - drop(worker_msg_rx); - - Ok(()) + // will process messages until we run out + worker_task( + worker_arena, + worker, + injector, + stealers, + worker_msg_rx, + msg_tx, + src_dir, + target_info, + ) }); res_join_handle.unwrap(); @@ -1302,6 +1255,65 @@ fn load<'a>( .unwrap() } +#[allow(clippy::too_many_arguments)] +fn worker_task<'a>( + worker_arena: &'a Bump, + worker: Worker>, + injector: &Injector>, + stealers: &[Stealer>], + worker_msg_rx: crossbeam::channel::Receiver, + msg_tx: MsgSender<'a>, + src_dir: &Path, + target_info: TargetInfo, +) -> Result<(), LoadingProblem<'a>> { + // Keep listening until we receive a Shutdown msg + for msg in worker_msg_rx.iter() { + match msg { + WorkerMsg::Shutdown => { + // We've finished all our work. It's time to + // shut down the thread, so when the main thread + // blocks on joining with all the worker threads, + // it can finally exit too! + return Ok(()); + } + WorkerMsg::TaskAdded => { + // Find a task - either from this thread's queue, + // or from the main queue, or from another worker's + // queue - and run it. + // + // There might be no tasks to work on! That could + // happen if another thread is working on a task + // which will later result in more tasks being + // added. In that case, do nothing, and keep waiting + // until we receive a Shutdown message. + if let Some(task) = find_task(&worker, injector, stealers) { + let result = run_task(task, worker_arena, src_dir, msg_tx.clone(), target_info); + + match result { + Ok(()) => {} + Err(LoadingProblem::MsgChannelDied) => { + panic!("Msg channel closed unexpectedly.") + } + Err(LoadingProblem::ParsingFailed(problem)) => { + msg_tx.send(Msg::FailedToParse(problem)).unwrap(); + } + Err(LoadingProblem::FileProblem { filename, error }) => { + msg_tx + .send(Msg::FailedToReadFile { filename, error }) + .unwrap(); + } + Err(other) => { + return Err(other); + } + } + } + } + } + } + + Ok(()) +} + fn start_tasks<'a>( arena: &'a Bump, state: &mut State<'a>, diff --git a/compiler/load/tests/test_load.rs b/compiler/load/tests/test_load.rs index 8b4abdd7ca..dc1afddcc0 100644 --- a/compiler/load/tests/test_load.rs +++ b/compiler/load/tests/test_load.rs @@ -16,7 +16,6 @@ mod helpers; mod test_load { use crate::helpers::fixtures_dir; use bumpalo::Bump; - use roc_can::builtins::builtin_defs_map; use roc_can::def::Declaration::*; use roc_can::def::Def; use roc_collections::all::MutMap; @@ -111,7 +110,6 @@ mod test_load { dir.path(), exposed_types, TARGET_INFO, - builtin_defs_map, ) }; @@ -135,7 +133,6 @@ mod test_load { src_dir.as_path(), subs_by_module, TARGET_INFO, - builtin_defs_map, ); let mut loaded_module = match loaded { Ok(x) => x, @@ -301,7 +298,6 @@ mod test_load { src_dir.as_path(), subs_by_module, TARGET_INFO, - builtin_defs_map, ); let mut loaded_module = loaded.expect("Test module failed to load"); diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index d41886aea0..ef03d2a000 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -10,7 +10,6 @@ mod helpers; #[cfg(test)] mod solve_expr { use crate::helpers::with_larger_debug_stack; - use roc_can::builtins::builtin_defs_map; use roc_collections::all::MutMap; use roc_types::pretty_print::{content_to_string, name_all_type_vars}; @@ -64,7 +63,6 @@ mod solve_expr { dir.path(), exposed_types, roc_target::TargetInfo::default_x86_64(), - builtin_defs_map, ); dir.close()?; diff --git a/compiler/test_gen/src/helpers/dev.rs b/compiler/test_gen/src/helpers/dev.rs index d17c326161..8942c7356f 100644 --- a/compiler/test_gen/src/helpers/dev.rs +++ b/compiler/test_gen/src/helpers/dev.rs @@ -1,7 +1,6 @@ use libloading::Library; use roc_build::link::{link, LinkType}; use roc_builtins::bitcode; -use roc_can::builtins::builtin_defs_map; use roc_collections::all::MutMap; use roc_region::all::LineInfo; use tempfile::tempdir; @@ -58,7 +57,6 @@ pub fn helper( src_dir, exposed_types, roc_target::TargetInfo::default_x86_64(), - builtin_defs_map, ); let mut loaded = loaded.expect("failed to load module"); diff --git a/compiler/test_gen/src/helpers/llvm.rs b/compiler/test_gen/src/helpers/llvm.rs index d9af1a821d..d7a24effa9 100644 --- a/compiler/test_gen/src/helpers/llvm.rs +++ b/compiler/test_gen/src/helpers/llvm.rs @@ -3,7 +3,6 @@ use inkwell::module::Module; use libloading::Library; use roc_build::link::module_to_dylib; use roc_build::program::FunctionIterator; -use roc_can::builtins::builtin_defs_map; use roc_can::def::Def; use roc_collections::all::{MutMap, MutSet}; use roc_gen_llvm::llvm::externs::add_default_roc_externs; @@ -25,9 +24,6 @@ fn promote_expr_to_module(src: &str) -> String { buffer } -pub fn test_builtin_defs(symbol: Symbol, var_store: &mut VarStore) -> Option { - builtin_defs_map(symbol, var_store) -} #[allow(clippy::too_many_arguments)] fn create_llvm_module<'a>( @@ -67,7 +63,6 @@ fn create_llvm_module<'a>( src_dir, exposed_types, target_info, - test_builtin_defs, ); let mut loaded = match loaded { diff --git a/compiler/test_gen/src/helpers/wasm.rs b/compiler/test_gen/src/helpers/wasm.rs index a0fb311283..3420cb2498 100644 --- a/compiler/test_gen/src/helpers/wasm.rs +++ b/compiler/test_gen/src/helpers/wasm.rs @@ -7,7 +7,6 @@ use std::path::{Path, PathBuf}; use wasmer::{Memory, WasmPtr}; use crate::helpers::from_wasmer_memory::FromWasmerMemory; -use roc_can::builtins::builtin_defs_map; use roc_collections::all::{MutMap, MutSet}; use roc_gen_wasm::wasm32_result::Wasm32Result; use roc_gen_wasm::{DEBUG_LOG_SETTINGS, MEMORY_NAME}; @@ -94,7 +93,6 @@ fn compile_roc_to_wasm_bytes<'a, T: Wasm32Result>( src_dir, exposed_types, roc_target::TargetInfo::default_wasm32(), - builtin_defs_map, ); let loaded = loaded.expect("failed to load module"); diff --git a/compiler/test_mono/src/tests.rs b/compiler/test_mono/src/tests.rs index 34001fe46a..6903714eaa 100644 --- a/compiler/test_mono/src/tests.rs +++ b/compiler/test_mono/src/tests.rs @@ -18,7 +18,6 @@ const EXPANDED_STACK_SIZE: usize = 8 * 1024 * 1024; use test_mono_macros::*; -use roc_can::builtins::builtin_defs_map; use roc_collections::all::MutMap; use roc_module::symbol::Symbol; use roc_mono::ir::Proc; @@ -107,7 +106,6 @@ fn compiles_to_ir(test_name: &str, src: &str) { src_dir, exposed_types, TARGET_INFO, - builtin_defs_map, ); let mut loaded = match loaded {