mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 06:14:46 +00:00
pass stdlib by reference
This commit is contained in:
parent
c4e5af554b
commit
ab6cb7ac93
9 changed files with 20 additions and 52 deletions
|
@ -42,7 +42,7 @@ pub fn build_file(
|
|||
let loaded = roc_load::file::load_and_monomorphize(
|
||||
&arena,
|
||||
roc_file_path.clone(),
|
||||
stdlib,
|
||||
&stdlib,
|
||||
src_dir.as_path(),
|
||||
subs_by_module,
|
||||
ptr_bytes,
|
||||
|
|
|
@ -42,7 +42,7 @@ pub fn gen_and_eval(src: &[u8], target: Triple, opt_level: OptLevel) -> Result<R
|
|||
&arena,
|
||||
filename,
|
||||
&module_src,
|
||||
stdlib,
|
||||
&stdlib,
|
||||
src_dir,
|
||||
exposed_types,
|
||||
ptr_bytes,
|
||||
|
|
|
@ -19,7 +19,7 @@ fn promote_expr_to_module(src: &str) -> String {
|
|||
pub fn helper<'a>(
|
||||
arena: &'a bumpalo::Bump,
|
||||
src: &str,
|
||||
stdlib: roc_builtins::std::StdLib,
|
||||
stdlib: &'a roc_builtins::std::StdLib,
|
||||
leak: bool,
|
||||
context: &'a inkwell::context::Context,
|
||||
) -> (&'static str, String, Library) {
|
||||
|
@ -295,40 +295,6 @@ pub fn helper<'a>(
|
|||
(main_fn_name, delayed_errors.join("\n"), lib)
|
||||
}
|
||||
|
||||
// TODO this is almost all code duplication with assert_llvm_evals_to
|
||||
// the only difference is that this calls uniq_expr instead of can_expr.
|
||||
// Should extract the common logic into test helpers.
|
||||
#[macro_export]
|
||||
macro_rules! assert_opt_evals_to {
|
||||
($src:expr, $expected:expr, $ty:ty, $transform:expr, $leak:expr) => {
|
||||
use bumpalo::Bump;
|
||||
use inkwell::context::Context;
|
||||
use roc_gen::run_jit_function;
|
||||
|
||||
let arena = Bump::new();
|
||||
|
||||
let context = Context::create();
|
||||
|
||||
// don't use uniqueness types any more
|
||||
// let stdlib = roc_builtins::unique::uniq_stdlib();
|
||||
let stdlib = roc_builtins::std::standard_stdlib();
|
||||
|
||||
let (main_fn_name, errors, lib) =
|
||||
$crate::helpers::eval::helper(&arena, $src, stdlib, $leak, &context);
|
||||
|
||||
let transform = |success| {
|
||||
let expected = $expected;
|
||||
let given = $transform(success);
|
||||
assert_eq!(&given, &expected);
|
||||
};
|
||||
run_jit_function!(lib, main_fn_name, $ty, transform, errors)
|
||||
};
|
||||
|
||||
($src:expr, $expected:expr, $ty:ty, $transform:expr) => {
|
||||
assert_opt_evals_to!($src, $expected, $ty, $transform, true)
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! assert_llvm_evals_to {
|
||||
($src:expr, $expected:expr, $ty:ty, $transform:expr, $leak:expr) => {
|
||||
|
@ -337,9 +303,10 @@ macro_rules! assert_llvm_evals_to {
|
|||
use roc_gen::run_jit_function;
|
||||
|
||||
let arena = Bump::new();
|
||||
|
||||
let context = Context::create();
|
||||
let stdlib = roc_builtins::std::standard_stdlib();
|
||||
|
||||
// NOTE the stdlib must be in the arena; just taking a reference will segfault
|
||||
let stdlib = arena.alloc(roc_builtins::std::standard_stdlib());
|
||||
|
||||
let (main_fn_name, errors, lib) =
|
||||
$crate::helpers::eval::helper(&arena, $src, stdlib, $leak, &context);
|
||||
|
@ -377,7 +344,8 @@ macro_rules! assert_evals_to {
|
|||
assert_llvm_evals_to!($src, $expected, $ty, $transform, $leak);
|
||||
}
|
||||
{
|
||||
assert_opt_evals_to!($src, $expected, $ty, $transform, $leak);
|
||||
// NOTE at the moment, the optimized tests do the same thing
|
||||
// assert_opt_evals_to!($src, $expected, $ty, $transform, $leak);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ pub fn helper<'a>(
|
|||
arena,
|
||||
filename,
|
||||
&module_src,
|
||||
stdlib,
|
||||
&stdlib,
|
||||
src_dir,
|
||||
exposed_types,
|
||||
8,
|
||||
|
|
|
@ -699,7 +699,7 @@ struct State<'a> {
|
|||
pub root_id: ModuleId,
|
||||
pub platform_id: Option<ModuleId>,
|
||||
pub goal_phase: Phase,
|
||||
pub stdlib: StdLib,
|
||||
pub stdlib: &'a StdLib,
|
||||
pub exposed_types: SubsByModule,
|
||||
pub output_path: Option<&'a str>,
|
||||
pub platform_path: Option<To<'a>>,
|
||||
|
@ -944,7 +944,7 @@ fn enqueue_task<'a>(
|
|||
pub fn load_and_typecheck(
|
||||
arena: &Bump,
|
||||
filename: PathBuf,
|
||||
stdlib: StdLib,
|
||||
stdlib: &StdLib,
|
||||
src_dir: &Path,
|
||||
exposed_types: SubsByModule,
|
||||
ptr_bytes: u32,
|
||||
|
@ -970,7 +970,7 @@ pub fn load_and_typecheck(
|
|||
pub fn load_and_monomorphize<'a>(
|
||||
arena: &'a Bump,
|
||||
filename: PathBuf,
|
||||
stdlib: StdLib,
|
||||
stdlib: &'a StdLib,
|
||||
src_dir: &Path,
|
||||
exposed_types: SubsByModule,
|
||||
ptr_bytes: u32,
|
||||
|
@ -997,7 +997,7 @@ pub fn load_and_monomorphize_from_str<'a>(
|
|||
arena: &'a Bump,
|
||||
filename: PathBuf,
|
||||
src: &'a str,
|
||||
stdlib: StdLib,
|
||||
stdlib: &'a StdLib,
|
||||
src_dir: &Path,
|
||||
exposed_types: SubsByModule,
|
||||
ptr_bytes: u32,
|
||||
|
@ -1146,7 +1146,7 @@ fn load<'a>(
|
|||
arena: &'a Bump,
|
||||
//filename: PathBuf,
|
||||
load_start: LoadStart<'a>,
|
||||
stdlib: StdLib,
|
||||
stdlib: &'a StdLib,
|
||||
src_dir: &Path,
|
||||
exposed_types: SubsByModule,
|
||||
goal_phase: Phase,
|
||||
|
|
|
@ -82,7 +82,7 @@ mod test_load {
|
|||
roc_load::file::load_and_typecheck(
|
||||
arena,
|
||||
full_file_path,
|
||||
stdlib,
|
||||
&stdlib,
|
||||
dir.path(),
|
||||
exposed_types,
|
||||
8,
|
||||
|
@ -124,7 +124,7 @@ mod test_load {
|
|||
let loaded = roc_load::file::load_and_typecheck(
|
||||
&arena,
|
||||
filename,
|
||||
roc_builtins::std::standard_stdlib(),
|
||||
&roc_builtins::std::standard_stdlib(),
|
||||
src_dir.as_path(),
|
||||
subs_by_module,
|
||||
8,
|
||||
|
@ -287,7 +287,7 @@ mod test_load {
|
|||
let loaded = roc_load::file::load_and_typecheck(
|
||||
&arena,
|
||||
filename,
|
||||
roc_builtins::std::standard_stdlib(),
|
||||
&roc_builtins::std::standard_stdlib(),
|
||||
src_dir.as_path(),
|
||||
subs_by_module,
|
||||
8,
|
||||
|
|
|
@ -58,7 +58,7 @@ mod test_mono {
|
|||
arena,
|
||||
filename,
|
||||
&module_src,
|
||||
stdlib,
|
||||
&stdlib,
|
||||
src_dir,
|
||||
exposed_types,
|
||||
8,
|
||||
|
|
|
@ -59,7 +59,7 @@ mod solve_expr {
|
|||
let result = roc_load::file::load_and_typecheck(
|
||||
arena,
|
||||
full_file_path,
|
||||
stdlib,
|
||||
&stdlib,
|
||||
dir.path(),
|
||||
exposed_types,
|
||||
8,
|
||||
|
|
|
@ -129,7 +129,7 @@ fn files_to_documentations(
|
|||
let mut loaded = roc_load::file::load_and_typecheck(
|
||||
&arena,
|
||||
filename,
|
||||
std_lib.clone(),
|
||||
&std_lib,
|
||||
src_dir,
|
||||
MutMap::default(),
|
||||
8, // TODO: Is it okay to hardcode ptr_bytes here? I think it should be fine since we'er only type checking (also, 8 => 32bit system)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue