remove builtin lookup function being passed around

This commit is contained in:
Folkert 2022-02-14 20:32:31 +01:00
parent 154d55985b
commit 957140df64
6 changed files with 16 additions and 58 deletions

View file

@ -21,7 +21,6 @@ pub fn load_module(src_file: &Path) -> LoadedModule {
}), }),
subs_by_module, subs_by_module,
TargetInfo::default_x86_64(), TargetInfo::default_x86_64(),
roc_can::builtins::builtin_defs_map,
); );
match loaded { match loaded {

View file

@ -4,7 +4,6 @@ use roc_build::{
program, program,
}; };
use roc_builtins::bitcode; use roc_builtins::bitcode;
use roc_can::builtins::builtin_defs_map;
use roc_collections::all::MutMap; use roc_collections::all::MutMap;
use roc_load::file::LoadingProblem; use roc_load::file::LoadingProblem;
use roc_mono::ir::OptLevel; use roc_mono::ir::OptLevel;
@ -74,7 +73,6 @@ pub fn build_file<'a>(
src_dir.as_path(), src_dir.as_path(),
subs_by_module, subs_by_module,
target_info, target_info,
builtin_defs_map,
)?; )?;
use target_lexicon::Architecture; use target_lexicon::Architecture;
@ -376,7 +374,6 @@ pub fn check_file(
src_dir.as_path(), src_dir.as_path(),
subs_by_module, subs_by_module,
target_info, target_info,
builtin_defs_map,
)?; )?;
let buf = &mut String::with_capacity(1024); let buf = &mut String::with_capacity(1024);

View file

@ -67,7 +67,7 @@ fn validate_generate_with<'a>(
// TODO trim these down // TODO trim these down
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub fn canonicalize_module_defs<'a, F>( pub fn canonicalize_module_defs<'a>(
arena: &Bump, arena: &Bump,
loc_defs: &'a [Loc<ast::Def<'a>>], loc_defs: &'a [Loc<ast::Def<'a>>],
header_for: &roc_parse::header::HeaderFor, header_for: &roc_parse::header::HeaderFor,
@ -79,11 +79,7 @@ pub fn canonicalize_module_defs<'a, F>(
exposed_imports: MutMap<Ident, (Symbol, Region)>, exposed_imports: MutMap<Ident, (Symbol, Region)>,
exposed_symbols: &MutSet<Symbol>, exposed_symbols: &MutSet<Symbol>,
var_store: &mut VarStore, var_store: &mut VarStore,
look_up_builtin: F, ) -> Result<ModuleOutput, RuntimeError> {
) -> Result<ModuleOutput, RuntimeError>
where
F: Fn(Symbol, &mut VarStore) -> Option<Def> + 'static + Send + Copy,
{
let mut can_exposed_imports = MutMap::default(); let mut can_exposed_imports = MutMap::default();
let mut scope = Scope::new(home, var_store); let mut scope = Scope::new(home, var_store);
let mut env = Env::new(home, dep_idents, module_ids, exposed_ident_ids); let mut env = Env::new(home, dep_idents, module_ids, exposed_ident_ids);
@ -482,7 +478,7 @@ where
for symbol in references.iter() { for symbol in references.iter() {
if symbol.is_builtin() { if symbol.is_builtin() {
// this can fail when the symbol is for builtin types, or has no implementation yet // 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)); declarations.push(Declaration::Builtin(def));
} }
} }

View file

@ -6,7 +6,7 @@ use crossbeam::thread;
use parking_lot::Mutex; use parking_lot::Mutex;
use roc_builtins::std::StdLib; use roc_builtins::std::StdLib;
use roc_can::constraint::Constraint; 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_can::module::{canonicalize_module_defs, Module};
use roc_collections::all::{default_hasher, BumpMap, MutMap, MutSet}; use roc_collections::all::{default_hasher, BumpMap, MutMap, MutSet};
use roc_constrain::module::{ use roc_constrain::module::{
@ -765,18 +765,14 @@ fn enqueue_task<'a>(
Ok(()) Ok(())
} }
pub fn load_and_typecheck<'a, F>( pub fn load_and_typecheck<'a>(
arena: &'a Bump, arena: &'a Bump,
filename: PathBuf, filename: PathBuf,
stdlib: &'a StdLib, stdlib: &'a StdLib,
src_dir: &Path, src_dir: &Path,
exposed_types: SubsByModule, exposed_types: SubsByModule,
target_info: TargetInfo, target_info: TargetInfo,
look_up_builtin: F, ) -> Result<LoadedModule, LoadingProblem<'a>> {
) -> Result<LoadedModule, LoadingProblem<'a>>
where
F: Fn(Symbol, &mut VarStore) -> Option<Def> + 'static + Send + Copy,
{
use LoadResult::*; use LoadResult::*;
let load_start = LoadStart::from_path(arena, filename)?; let load_start = LoadStart::from_path(arena, filename)?;
@ -789,7 +785,6 @@ where
exposed_types, exposed_types,
Phase::SolveTypes, Phase::SolveTypes,
target_info, target_info,
look_up_builtin,
)? { )? {
Monomorphized(_) => unreachable!(""), Monomorphized(_) => unreachable!(""),
TypeChecked(module) => Ok(module), TypeChecked(module) => Ok(module),
@ -797,18 +792,14 @@ where
} }
/// Main entry point to the compiler from the CLI and tests /// 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, arena: &'a Bump,
filename: PathBuf, filename: PathBuf,
stdlib: &'a StdLib, stdlib: &'a StdLib,
src_dir: &Path, src_dir: &Path,
exposed_types: SubsByModule, exposed_types: SubsByModule,
target_info: TargetInfo, target_info: TargetInfo,
look_up_builtin: F, ) -> Result<MonomorphizedModule<'a>, LoadingProblem<'a>> {
) -> Result<MonomorphizedModule<'a>, LoadingProblem<'a>>
where
F: Fn(Symbol, &mut VarStore) -> Option<Def> + 'static + Send + Copy,
{
use LoadResult::*; use LoadResult::*;
let load_start = LoadStart::from_path(arena, filename)?; let load_start = LoadStart::from_path(arena, filename)?;
@ -821,7 +812,6 @@ where
exposed_types, exposed_types,
Phase::MakeSpecializations, Phase::MakeSpecializations,
target_info, target_info,
look_up_builtin,
)? { )? {
Monomorphized(module) => Ok(module), Monomorphized(module) => Ok(module),
TypeChecked(_) => unreachable!(""), TypeChecked(_) => unreachable!(""),
@ -829,7 +819,7 @@ where
} }
#[allow(clippy::too_many_arguments)] #[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, arena: &'a Bump,
filename: PathBuf, filename: PathBuf,
src: &'a str, src: &'a str,
@ -837,11 +827,7 @@ pub fn load_and_monomorphize_from_str<'a, F>(
src_dir: &Path, src_dir: &Path,
exposed_types: SubsByModule, exposed_types: SubsByModule,
target_info: TargetInfo, target_info: TargetInfo,
look_up_builtin: F, ) -> Result<MonomorphizedModule<'a>, LoadingProblem<'a>> {
) -> Result<MonomorphizedModule<'a>, LoadingProblem<'a>>
where
F: Fn(Symbol, &mut VarStore) -> Option<Def> + 'static + Send + Copy,
{
use LoadResult::*; use LoadResult::*;
let load_start = LoadStart::from_str(arena, filename, src)?; let load_start = LoadStart::from_str(arena, filename, src)?;
@ -854,7 +840,6 @@ where
exposed_types, exposed_types,
Phase::MakeSpecializations, Phase::MakeSpecializations,
target_info, target_info,
look_up_builtin,
)? { )? {
Monomorphized(module) => Ok(module), Monomorphized(module) => Ok(module),
TypeChecked(_) => unreachable!(""), TypeChecked(_) => unreachable!(""),
@ -1001,7 +986,7 @@ enum LoadResult<'a> {
/// specializations, so if none of their specializations changed, we don't even need /// 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.) /// to rebuild the module and can link in the cached one directly.)
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
fn load<'a, F>( fn load<'a>(
arena: &'a Bump, arena: &'a Bump,
//filename: PathBuf, //filename: PathBuf,
load_start: LoadStart<'a>, load_start: LoadStart<'a>,
@ -1010,11 +995,7 @@ fn load<'a, F>(
exposed_types: SubsByModule, exposed_types: SubsByModule,
goal_phase: Phase, goal_phase: Phase,
target_info: TargetInfo, target_info: TargetInfo,
look_up_builtins: F, ) -> Result<LoadResult<'a>, LoadingProblem<'a>> {
) -> Result<LoadResult<'a>, LoadingProblem<'a>>
where
F: Fn(Symbol, &mut VarStore) -> Option<Def> + 'static + Send + Copy,
{
let LoadStart { let LoadStart {
arc_modules, arc_modules,
ident_ids_by_module, ident_ids_by_module,
@ -1126,7 +1107,6 @@ where
src_dir, src_dir,
msg_tx.clone(), msg_tx.clone(),
target_info, target_info,
look_up_builtins,
); );
match result { match result {
@ -2992,18 +2972,14 @@ fn fabricate_pkg_config_module<'a>(
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
#[allow(clippy::unnecessary_wraps)] #[allow(clippy::unnecessary_wraps)]
fn canonicalize_and_constrain<'a, F>( fn canonicalize_and_constrain<'a>(
arena: &'a Bump, arena: &'a Bump,
module_ids: &ModuleIds, module_ids: &ModuleIds,
dep_idents: MutMap<ModuleId, IdentIds>, dep_idents: MutMap<ModuleId, IdentIds>,
exposed_symbols: MutSet<Symbol>, exposed_symbols: MutSet<Symbol>,
aliases: MutMap<Symbol, Alias>, aliases: MutMap<Symbol, Alias>,
parsed: ParsedModule<'a>, parsed: ParsedModule<'a>,
look_up_builtins: F, ) -> Result<Msg<'a>, LoadingProblem<'a>> {
) -> Result<Msg<'a>, LoadingProblem<'a>>
where
F: Fn(Symbol, &mut VarStore) -> Option<Def> + 'static + Send + Copy,
{
let canonicalize_start = SystemTime::now(); let canonicalize_start = SystemTime::now();
let ParsedModule { let ParsedModule {
@ -3031,7 +3007,6 @@ where
exposed_imports, exposed_imports,
&exposed_symbols, &exposed_symbols,
&mut var_store, &mut var_store,
look_up_builtins,
); );
let canonicalize_end = SystemTime::now(); 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>, task: BuildTask<'a>,
arena: &'a Bump, arena: &'a Bump,
src_dir: &Path, src_dir: &Path,
msg_tx: MsgSender<'a>, msg_tx: MsgSender<'a>,
target_info: TargetInfo, target_info: TargetInfo,
look_up_builtins: F, ) -> Result<(), LoadingProblem<'a>> {
) -> Result<(), LoadingProblem<'a>>
where
F: Fn(Symbol, &mut VarStore) -> Option<Def> + 'static + Send + Copy,
{
use BuildTask::*; use BuildTask::*;
let msg = match task { let msg = match task {
@ -3554,7 +3525,6 @@ where
exposed_symbols, exposed_symbols,
aliases, aliases,
parsed, parsed,
look_up_builtins,
), ),
Solve { Solve {
module, module,

View file

@ -5,7 +5,6 @@ use def::defs_to_html;
use docs_error::DocsResult; use docs_error::DocsResult;
use expr::expr_to_html; use expr::expr_to_html;
use roc_builtins::std::StdLib; use roc_builtins::std::StdLib;
use roc_can::builtins::builtin_defs_map;
use roc_can::scope::Scope; use roc_can::scope::Scope;
use roc_collections::all::MutMap; use roc_collections::all::MutMap;
use roc_load::docs::DocEntry::DocDef; use roc_load::docs::DocEntry::DocDef;
@ -429,7 +428,6 @@ pub fn load_modules_for_files(filenames: Vec<PathBuf>, std_lib: StdLib) -> Vec<L
src_dir.as_path(), src_dir.as_path(),
MutMap::default(), MutMap::default(),
roc_target::TargetInfo::default_x86_64(), // This is just type-checking for docs, so "target" doesn't matter roc_target::TargetInfo::default_x86_64(), // This is just type-checking for docs, so "target" doesn't matter
builtin_defs_map,
) { ) {
Ok(loaded) => modules.push(loaded), Ok(loaded) => modules.push(loaded),
Err(LoadingProblem::FormattedReport(report)) => { Err(LoadingProblem::FormattedReport(report)) => {

View file

@ -1,7 +1,6 @@
use bumpalo::Bump; use bumpalo::Bump;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use roc_can::builtins::builtin_defs_map;
use roc_collections::all::MutMap; use roc_collections::all::MutMap;
use roc_fmt::annotation::Formattable; use roc_fmt::annotation::Formattable;
use roc_fmt::annotation::{Newlines, Parens}; use roc_fmt::annotation::{Newlines, Parens};
@ -65,7 +64,6 @@ pub fn compile_to_mono<'a>(
src_dir, src_dir,
exposed_types, exposed_types,
target_info, target_info,
builtin_defs_map,
); );
let mut loaded = match loaded { let mut loaded = match loaded {