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,
TargetInfo::default_x86_64(),
roc_can::builtins::builtin_defs_map,
);
match loaded {

View file

@ -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);

View file

@ -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<ast::Def<'a>>],
header_for: &roc_parse::header::HeaderFor,
@ -79,11 +79,7 @@ pub fn canonicalize_module_defs<'a, F>(
exposed_imports: MutMap<Ident, (Symbol, Region)>,
exposed_symbols: &MutSet<Symbol>,
var_store: &mut VarStore,
look_up_builtin: F,
) -> Result<ModuleOutput, RuntimeError>
where
F: Fn(Symbol, &mut VarStore) -> Option<Def> + 'static + Send + Copy,
{
) -> Result<ModuleOutput, RuntimeError> {
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));
}
}

View file

@ -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<LoadedModule, LoadingProblem<'a>>
where
F: Fn(Symbol, &mut VarStore) -> Option<Def> + 'static + Send + Copy,
{
) -> Result<LoadedModule, LoadingProblem<'a>> {
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<MonomorphizedModule<'a>, LoadingProblem<'a>>
where
F: Fn(Symbol, &mut VarStore) -> Option<Def> + 'static + Send + Copy,
{
) -> Result<MonomorphizedModule<'a>, 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<MonomorphizedModule<'a>, LoadingProblem<'a>>
where
F: Fn(Symbol, &mut VarStore) -> Option<Def> + 'static + Send + Copy,
{
) -> Result<MonomorphizedModule<'a>, 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<LoadResult<'a>, LoadingProblem<'a>>
where
F: Fn(Symbol, &mut VarStore) -> Option<Def> + 'static + Send + Copy,
{
) -> Result<LoadResult<'a>, 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<ModuleId, IdentIds>,
exposed_symbols: MutSet<Symbol>,
aliases: MutMap<Symbol, Alias>,
parsed: ParsedModule<'a>,
look_up_builtins: F,
) -> Result<Msg<'a>, LoadingProblem<'a>>
where
F: Fn(Symbol, &mut VarStore) -> Option<Def> + 'static + Send + Copy,
{
) -> Result<Msg<'a>, 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<Def> + '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,

View file

@ -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<PathBuf>, std_lib: StdLib) -> Vec<L
src_dir.as_path(),
MutMap::default(),
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),
Err(LoadingProblem::FormattedReport(report)) => {

View file

@ -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 {