From 957140df64594e6e488e61524c5b3008de4adf08 Mon Sep 17 00:00:00 2001 From: Folkert Date: Mon, 14 Feb 2022 20:32:31 +0100 Subject: [PATCH] remove builtin lookup function being passed around --- ast/src/module.rs | 1 - cli/src/build.rs | 3 -- compiler/can/src/module.rs | 10 ++----- compiler/load/src/file.rs | 56 +++++++++----------------------------- docs/src/lib.rs | 2 -- repl_eval/src/gen.rs | 2 -- 6 files changed, 16 insertions(+), 58 deletions(-) diff --git a/ast/src/module.rs b/ast/src/module.rs index f13028e8d1..f8186d5faf 100644 --- a/ast/src/module.rs +++ b/ast/src/module.rs @@ -21,7 +21,6 @@ pub fn load_module(src_file: &Path) -> LoadedModule { }), subs_by_module, TargetInfo::default_x86_64(), - roc_can::builtins::builtin_defs_map, ); match loaded { diff --git a/cli/src/build.rs b/cli/src/build.rs index 29e4feab04..4786df2e65 100644 --- a/cli/src/build.rs +++ b/cli/src/build.rs @@ -4,7 +4,6 @@ use roc_build::{ program, }; use roc_builtins::bitcode; -use roc_can::builtins::builtin_defs_map; use roc_collections::all::MutMap; use roc_load::file::LoadingProblem; use roc_mono::ir::OptLevel; @@ -74,7 +73,6 @@ pub fn build_file<'a>( src_dir.as_path(), subs_by_module, target_info, - builtin_defs_map, )?; use target_lexicon::Architecture; @@ -376,7 +374,6 @@ pub fn check_file( src_dir.as_path(), subs_by_module, target_info, - builtin_defs_map, )?; let buf = &mut String::with_capacity(1024); diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index 8fe6ff5cef..8deb5a9671 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -67,7 +67,7 @@ fn validate_generate_with<'a>( // TODO trim these down #[allow(clippy::too_many_arguments)] -pub fn canonicalize_module_defs<'a, F>( +pub fn canonicalize_module_defs<'a>( arena: &Bump, loc_defs: &'a [Loc>], header_for: &roc_parse::header::HeaderFor, @@ -79,11 +79,7 @@ pub fn canonicalize_module_defs<'a, F>( exposed_imports: MutMap, exposed_symbols: &MutSet, var_store: &mut VarStore, - look_up_builtin: F, -) -> Result -where - F: Fn(Symbol, &mut VarStore) -> Option + 'static + Send + Copy, -{ +) -> Result { let mut can_exposed_imports = MutMap::default(); let mut scope = Scope::new(home, var_store); let mut env = Env::new(home, dep_idents, module_ids, exposed_ident_ids); @@ -482,7 +478,7 @@ where for symbol in references.iter() { if symbol.is_builtin() { // this can fail when the symbol is for builtin types, or has no implementation yet - if let Some(def) = look_up_builtin(*symbol, var_store) { + if let Some(def) = crate::builtins::builtin_defs_map(*symbol, var_store) { declarations.push(Declaration::Builtin(def)); } } diff --git a/compiler/load/src/file.rs b/compiler/load/src/file.rs index 686f5bde3c..6d338bc1c3 100644 --- a/compiler/load/src/file.rs +++ b/compiler/load/src/file.rs @@ -6,7 +6,7 @@ use crossbeam::thread; use parking_lot::Mutex; use roc_builtins::std::StdLib; use roc_can::constraint::Constraint; -use roc_can::def::{Declaration, Def}; +use roc_can::def::Declaration; use roc_can::module::{canonicalize_module_defs, Module}; use roc_collections::all::{default_hasher, BumpMap, MutMap, MutSet}; use roc_constrain::module::{ @@ -765,18 +765,14 @@ fn enqueue_task<'a>( Ok(()) } -pub fn load_and_typecheck<'a, F>( +pub fn load_and_typecheck<'a>( arena: &'a Bump, filename: PathBuf, stdlib: &'a StdLib, src_dir: &Path, exposed_types: SubsByModule, target_info: TargetInfo, - look_up_builtin: F, -) -> Result> -where - F: Fn(Symbol, &mut VarStore) -> Option + 'static + Send + Copy, -{ +) -> Result> { use LoadResult::*; let load_start = LoadStart::from_path(arena, filename)?; @@ -789,7 +785,6 @@ where exposed_types, Phase::SolveTypes, target_info, - look_up_builtin, )? { Monomorphized(_) => unreachable!(""), TypeChecked(module) => Ok(module), @@ -797,18 +792,14 @@ where } /// Main entry point to the compiler from the CLI and tests -pub fn load_and_monomorphize<'a, F>( +pub fn load_and_monomorphize<'a>( arena: &'a Bump, filename: PathBuf, stdlib: &'a StdLib, src_dir: &Path, exposed_types: SubsByModule, target_info: TargetInfo, - look_up_builtin: F, -) -> Result, LoadingProblem<'a>> -where - F: Fn(Symbol, &mut VarStore) -> Option + 'static + Send + Copy, -{ +) -> Result, LoadingProblem<'a>> { use LoadResult::*; let load_start = LoadStart::from_path(arena, filename)?; @@ -821,7 +812,6 @@ where exposed_types, Phase::MakeSpecializations, target_info, - look_up_builtin, )? { Monomorphized(module) => Ok(module), TypeChecked(_) => unreachable!(""), @@ -829,7 +819,7 @@ where } #[allow(clippy::too_many_arguments)] -pub fn load_and_monomorphize_from_str<'a, F>( +pub fn load_and_monomorphize_from_str<'a>( arena: &'a Bump, filename: PathBuf, src: &'a str, @@ -837,11 +827,7 @@ pub fn load_and_monomorphize_from_str<'a, F>( src_dir: &Path, exposed_types: SubsByModule, target_info: TargetInfo, - look_up_builtin: F, -) -> Result, LoadingProblem<'a>> -where - F: Fn(Symbol, &mut VarStore) -> Option + 'static + Send + Copy, -{ +) -> Result, LoadingProblem<'a>> { use LoadResult::*; let load_start = LoadStart::from_str(arena, filename, src)?; @@ -854,7 +840,6 @@ where exposed_types, Phase::MakeSpecializations, target_info, - look_up_builtin, )? { Monomorphized(module) => Ok(module), TypeChecked(_) => unreachable!(""), @@ -1001,7 +986,7 @@ enum LoadResult<'a> { /// specializations, so if none of their specializations changed, we don't even need /// to rebuild the module and can link in the cached one directly.) #[allow(clippy::too_many_arguments)] -fn load<'a, F>( +fn load<'a>( arena: &'a Bump, //filename: PathBuf, load_start: LoadStart<'a>, @@ -1010,11 +995,7 @@ fn load<'a, F>( exposed_types: SubsByModule, goal_phase: Phase, target_info: TargetInfo, - look_up_builtins: F, -) -> Result, LoadingProblem<'a>> -where - F: Fn(Symbol, &mut VarStore) -> Option + 'static + Send + Copy, -{ +) -> Result, LoadingProblem<'a>> { let LoadStart { arc_modules, ident_ids_by_module, @@ -1126,7 +1107,6 @@ where src_dir, msg_tx.clone(), target_info, - look_up_builtins, ); match result { @@ -2992,18 +2972,14 @@ fn fabricate_pkg_config_module<'a>( #[allow(clippy::too_many_arguments)] #[allow(clippy::unnecessary_wraps)] -fn canonicalize_and_constrain<'a, F>( +fn canonicalize_and_constrain<'a>( arena: &'a Bump, module_ids: &ModuleIds, dep_idents: MutMap, exposed_symbols: MutSet, aliases: MutMap, parsed: ParsedModule<'a>, - look_up_builtins: F, -) -> Result, LoadingProblem<'a>> -where - F: Fn(Symbol, &mut VarStore) -> Option + 'static + Send + Copy, -{ +) -> Result, LoadingProblem<'a>> { let canonicalize_start = SystemTime::now(); let ParsedModule { @@ -3031,7 +3007,6 @@ where exposed_imports, &exposed_symbols, &mut var_store, - look_up_builtins, ); let canonicalize_end = SystemTime::now(); @@ -3512,17 +3487,13 @@ fn add_def_to_module<'a>( } } -fn run_task<'a, F>( +fn run_task<'a>( task: BuildTask<'a>, arena: &'a Bump, src_dir: &Path, msg_tx: MsgSender<'a>, target_info: TargetInfo, - look_up_builtins: F, -) -> Result<(), LoadingProblem<'a>> -where - F: Fn(Symbol, &mut VarStore) -> Option + 'static + Send + Copy, -{ +) -> Result<(), LoadingProblem<'a>> { use BuildTask::*; let msg = match task { @@ -3554,7 +3525,6 @@ where exposed_symbols, aliases, parsed, - look_up_builtins, ), Solve { module, diff --git a/docs/src/lib.rs b/docs/src/lib.rs index 8c791b72ee..5749caf14c 100644 --- a/docs/src/lib.rs +++ b/docs/src/lib.rs @@ -5,7 +5,6 @@ use def::defs_to_html; use docs_error::DocsResult; use expr::expr_to_html; use roc_builtins::std::StdLib; -use roc_can::builtins::builtin_defs_map; use roc_can::scope::Scope; use roc_collections::all::MutMap; use roc_load::docs::DocEntry::DocDef; @@ -429,7 +428,6 @@ pub fn load_modules_for_files(filenames: Vec, std_lib: StdLib) -> Vec modules.push(loaded), Err(LoadingProblem::FormattedReport(report)) => { diff --git a/repl_eval/src/gen.rs b/repl_eval/src/gen.rs index 0874c42b49..a11ba966b8 100644 --- a/repl_eval/src/gen.rs +++ b/repl_eval/src/gen.rs @@ -1,7 +1,6 @@ use bumpalo::Bump; use std::path::{Path, PathBuf}; -use roc_can::builtins::builtin_defs_map; use roc_collections::all::MutMap; use roc_fmt::annotation::Formattable; use roc_fmt::annotation::{Newlines, Parens}; @@ -65,7 +64,6 @@ pub fn compile_to_mono<'a>( src_dir, exposed_types, target_info, - builtin_defs_map, ); let mut loaded = match loaded {