mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 21:39:07 +00:00
Go back to old opt_main_for_host
This commit is contained in:
parent
bff3204727
commit
63e9f5da8c
7 changed files with 74 additions and 59 deletions
|
@ -11,7 +11,7 @@ use roc_module::symbol::Symbol;
|
||||||
|
|
||||||
use roc_mono::ir::{
|
use roc_mono::ir::{
|
||||||
Call, CallType, Expr, HigherOrderLowLevel, HostExposedLayouts, ListLiteralElement, Literal,
|
Call, CallType, Expr, HigherOrderLowLevel, HostExposedLayouts, ListLiteralElement, Literal,
|
||||||
ModifyRc, OptLevel, Proc, ProcLayout, Stmt,
|
ModifyRc, OptLevel, Proc, Stmt,
|
||||||
};
|
};
|
||||||
use roc_mono::layout::{
|
use roc_mono::layout::{
|
||||||
Builtin, CapturesNiche, Layout, RawFunctionLayout, STLayoutInterner, UnionLayout,
|
Builtin, CapturesNiche, Layout, RawFunctionLayout, STLayoutInterner, UnionLayout,
|
||||||
|
@ -136,15 +136,12 @@ pub fn spec_program<'a, I>(
|
||||||
arena: &'a Bump,
|
arena: &'a Bump,
|
||||||
interner: &STLayoutInterner<'a>,
|
interner: &STLayoutInterner<'a>,
|
||||||
opt_level: OptLevel,
|
opt_level: OptLevel,
|
||||||
entry_points: &'a [(Symbol, ProcLayout<'a>)],
|
opt_entry_point: Option<roc_mono::ir::EntryPoint<'a>>,
|
||||||
procs: I,
|
procs: I,
|
||||||
) -> Result<morphic_lib::Solutions>
|
) -> Result<morphic_lib::Solutions>
|
||||||
where
|
where
|
||||||
I: Iterator<Item = &'a Proc<'a>>,
|
I: Iterator<Item = &'a Proc<'a>>,
|
||||||
{
|
{
|
||||||
// TODO support multiple entry points here!
|
|
||||||
let opt_entry_point = entry_points.first();
|
|
||||||
|
|
||||||
let main_module = {
|
let main_module = {
|
||||||
let mut m = ModDefBuilder::new();
|
let mut m = ModDefBuilder::new();
|
||||||
|
|
||||||
|
@ -229,13 +226,13 @@ where
|
||||||
m.add_func(func_name, spec)?;
|
m.add_func(func_name, spec)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some((symbol, proc_layout)) = opt_entry_point {
|
if let Some(entry_point) = opt_entry_point {
|
||||||
// the entry point wrapper
|
// the entry point wrapper
|
||||||
let roc_main_bytes = func_name_bytes_help(
|
let roc_main_bytes = func_name_bytes_help(
|
||||||
*symbol,
|
entry_point.symbol,
|
||||||
proc_layout.arguments.iter().copied(),
|
entry_point.layout.arguments.iter().copied(),
|
||||||
CapturesNiche::no_niche(),
|
CapturesNiche::no_niche(),
|
||||||
&proc_layout.result,
|
&entry_point.layout.result,
|
||||||
);
|
);
|
||||||
let roc_main = FuncName(&roc_main_bytes);
|
let roc_main = FuncName(&roc_main_bytes);
|
||||||
|
|
||||||
|
@ -244,7 +241,7 @@ where
|
||||||
let entry_point_function = build_entry_point(
|
let entry_point_function = build_entry_point(
|
||||||
&mut env,
|
&mut env,
|
||||||
interner,
|
interner,
|
||||||
*proc_layout,
|
entry_point.layout,
|
||||||
roc_main,
|
roc_main,
|
||||||
&host_exposed_functions,
|
&host_exposed_functions,
|
||||||
)?;
|
)?;
|
||||||
|
|
|
@ -188,18 +188,25 @@ fn gen_from_mono_module_llvm<'a>(
|
||||||
// expects that would confuse the surgical linker
|
// expects that would confuse the surgical linker
|
||||||
add_default_roc_externs(&env);
|
add_default_roc_externs(&env);
|
||||||
|
|
||||||
let exposed_to_host = match loaded.entry_point {
|
let opt_entry_point = match loaded.entry_point {
|
||||||
EntryPoint::Executable {
|
EntryPoint::Executable {
|
||||||
exposed_to_host, ..
|
exposed_to_host,
|
||||||
} => exposed_to_host,
|
platform_path: _,
|
||||||
EntryPoint::Test => &[],
|
} => {
|
||||||
|
// TODO support multiple of these!
|
||||||
|
debug_assert_eq!(exposed_to_host.len(), 1);
|
||||||
|
let (symbol, layout) = exposed_to_host[0];
|
||||||
|
|
||||||
|
Some(roc_mono::ir::EntryPoint { symbol, layout })
|
||||||
|
}
|
||||||
|
EntryPoint::Test => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
roc_gen_llvm::llvm::build::build_procedures(
|
roc_gen_llvm::llvm::build::build_procedures(
|
||||||
&env,
|
&env,
|
||||||
opt_level,
|
opt_level,
|
||||||
loaded.procedures,
|
loaded.procedures,
|
||||||
exposed_to_host,
|
opt_entry_point,
|
||||||
Some(&app_ll_file),
|
Some(&app_ll_file),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,8 @@ use roc_debug_flags::ROC_PRINT_LLVM_FN_VERIFICATION;
|
||||||
use roc_error_macros::internal_error;
|
use roc_error_macros::internal_error;
|
||||||
use roc_module::symbol::{Interns, ModuleId, Symbol};
|
use roc_module::symbol::{Interns, ModuleId, Symbol};
|
||||||
use roc_mono::ir::{
|
use roc_mono::ir::{
|
||||||
BranchInfo, CallType, CrashTag, JoinPointId, ListLiteralElement, ModifyRc, OptLevel, ProcLayout,
|
BranchInfo, CallType, CrashTag, EntryPoint, JoinPointId, ListLiteralElement, ModifyRc,
|
||||||
|
OptLevel, ProcLayout,
|
||||||
};
|
};
|
||||||
use roc_mono::layout::{
|
use roc_mono::layout::{
|
||||||
Builtin, CapturesNiche, LambdaName, LambdaSet, Layout, LayoutIds, RawFunctionLayout,
|
Builtin, CapturesNiche, LambdaName, LambdaSet, Layout, LayoutIds, RawFunctionLayout,
|
||||||
|
@ -4163,60 +4164,50 @@ pub fn build_procedures<'a, 'ctx, 'env>(
|
||||||
env: &Env<'a, 'ctx, 'env>,
|
env: &Env<'a, 'ctx, 'env>,
|
||||||
opt_level: OptLevel,
|
opt_level: OptLevel,
|
||||||
procedures: MutMap<(Symbol, ProcLayout<'a>), roc_mono::ir::Proc<'a>>,
|
procedures: MutMap<(Symbol, ProcLayout<'a>), roc_mono::ir::Proc<'a>>,
|
||||||
entry_points: &[(Symbol, ProcLayout<'a>)],
|
opt_entry_point: Option<EntryPoint<'a>>,
|
||||||
debug_output_file: Option<&Path>,
|
debug_output_file: Option<&Path>,
|
||||||
) {
|
) {
|
||||||
build_procedures_help(env, opt_level, procedures, entry_points, debug_output_file);
|
build_procedures_help(
|
||||||
|
env,
|
||||||
|
opt_level,
|
||||||
|
procedures,
|
||||||
|
opt_entry_point,
|
||||||
|
debug_output_file,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_wasm_test_wrapper<'a, 'ctx, 'env>(
|
pub fn build_wasm_test_wrapper<'a, 'ctx, 'env>(
|
||||||
env: &Env<'a, 'ctx, 'env>,
|
env: &Env<'a, 'ctx, 'env>,
|
||||||
opt_level: OptLevel,
|
opt_level: OptLevel,
|
||||||
procedures: MutMap<(Symbol, ProcLayout<'a>), roc_mono::ir::Proc<'a>>,
|
procedures: MutMap<(Symbol, ProcLayout<'a>), roc_mono::ir::Proc<'a>>,
|
||||||
entry_points: &'a [(Symbol, ProcLayout<'a>)],
|
entry_point: EntryPoint<'a>,
|
||||||
) -> (&'static str, FunctionValue<'ctx>) {
|
) -> (&'static str, FunctionValue<'ctx>) {
|
||||||
assert_eq!(
|
|
||||||
entry_points.len(),
|
|
||||||
1,
|
|
||||||
"Currently, build_wasm_test_wrapper() only supports receiving one entrypoint."
|
|
||||||
);
|
|
||||||
|
|
||||||
let mod_solutions = build_procedures_help(
|
let mod_solutions = build_procedures_help(
|
||||||
env,
|
env,
|
||||||
opt_level,
|
opt_level,
|
||||||
procedures,
|
procedures,
|
||||||
entry_points,
|
Some(entry_point),
|
||||||
Some(&std::env::temp_dir().join("test.ll")),
|
Some(&std::env::temp_dir().join("test.ll")),
|
||||||
);
|
);
|
||||||
|
|
||||||
let (symbol, proc_layout) = entry_points[0];
|
promote_to_wasm_test_wrapper(env, mod_solutions, entry_point.symbol, entry_point.layout)
|
||||||
|
|
||||||
promote_to_wasm_test_wrapper(env, mod_solutions, symbol, proc_layout)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_procedures_return_main<'a, 'ctx, 'env>(
|
pub fn build_procedures_return_main<'a, 'ctx, 'env>(
|
||||||
env: &Env<'a, 'ctx, 'env>,
|
env: &Env<'a, 'ctx, 'env>,
|
||||||
opt_level: OptLevel,
|
opt_level: OptLevel,
|
||||||
procedures: MutMap<(Symbol, ProcLayout<'a>), roc_mono::ir::Proc<'a>>,
|
procedures: MutMap<(Symbol, ProcLayout<'a>), roc_mono::ir::Proc<'a>>,
|
||||||
entry_points: &'a [(Symbol, ProcLayout<'a>)],
|
entry_point: EntryPoint<'a>,
|
||||||
) -> (&'static str, FunctionValue<'ctx>) {
|
) -> (&'static str, FunctionValue<'ctx>) {
|
||||||
assert_eq!(
|
|
||||||
entry_points.len(),
|
|
||||||
1,
|
|
||||||
"Currently, build_procedures_return_main() only supports receiving one entrypoint."
|
|
||||||
);
|
|
||||||
|
|
||||||
let mod_solutions = build_procedures_help(
|
let mod_solutions = build_procedures_help(
|
||||||
env,
|
env,
|
||||||
opt_level,
|
opt_level,
|
||||||
procedures,
|
procedures,
|
||||||
entry_points,
|
Some(entry_point),
|
||||||
Some(&std::env::temp_dir().join("test.ll")),
|
Some(&std::env::temp_dir().join("test.ll")),
|
||||||
);
|
);
|
||||||
|
|
||||||
let (symbol, proc_layout) = entry_points[0];
|
promote_to_main_function(env, mod_solutions, entry_point.symbol, entry_point.layout)
|
||||||
|
|
||||||
promote_to_main_function(env, mod_solutions, symbol, proc_layout)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_procedures_expose_expects<'a, 'ctx, 'env>(
|
pub fn build_procedures_expose_expects<'a, 'ctx, 'env>(
|
||||||
|
@ -4224,13 +4215,13 @@ pub fn build_procedures_expose_expects<'a, 'ctx, 'env>(
|
||||||
opt_level: OptLevel,
|
opt_level: OptLevel,
|
||||||
expects: &[Symbol],
|
expects: &[Symbol],
|
||||||
procedures: MutMap<(Symbol, ProcLayout<'a>), roc_mono::ir::Proc<'a>>,
|
procedures: MutMap<(Symbol, ProcLayout<'a>), roc_mono::ir::Proc<'a>>,
|
||||||
entry_points: &'a [(Symbol, ProcLayout<'a>)],
|
opt_entry_point: Option<EntryPoint<'a>>,
|
||||||
) -> Vec<'a, &'a str> {
|
) -> Vec<'a, &'a str> {
|
||||||
let mod_solutions = build_procedures_help(
|
let mod_solutions = build_procedures_help(
|
||||||
env,
|
env,
|
||||||
opt_level,
|
opt_level,
|
||||||
procedures,
|
procedures,
|
||||||
entry_points,
|
opt_entry_point,
|
||||||
Some(&std::env::temp_dir().join("test.ll")),
|
Some(&std::env::temp_dir().join("test.ll")),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -4292,7 +4283,7 @@ fn build_procedures_help<'a, 'ctx, 'env>(
|
||||||
env: &Env<'a, 'ctx, 'env>,
|
env: &Env<'a, 'ctx, 'env>,
|
||||||
opt_level: OptLevel,
|
opt_level: OptLevel,
|
||||||
procedures: MutMap<(Symbol, ProcLayout<'a>), roc_mono::ir::Proc<'a>>,
|
procedures: MutMap<(Symbol, ProcLayout<'a>), roc_mono::ir::Proc<'a>>,
|
||||||
entry_points: &[(Symbol, ProcLayout<'a>)],
|
opt_entry_point: Option<EntryPoint<'a>>,
|
||||||
debug_output_file: Option<&Path>,
|
debug_output_file: Option<&Path>,
|
||||||
) -> &'a ModSolutions {
|
) -> &'a ModSolutions {
|
||||||
let mut layout_ids = roc_mono::layout::LayoutIds::default();
|
let mut layout_ids = roc_mono::layout::LayoutIds::default();
|
||||||
|
@ -4304,7 +4295,7 @@ fn build_procedures_help<'a, 'ctx, 'env>(
|
||||||
env.arena,
|
env.arena,
|
||||||
env.layout_interner,
|
env.layout_interner,
|
||||||
opt_level,
|
opt_level,
|
||||||
entry_points,
|
opt_entry_point,
|
||||||
it,
|
it,
|
||||||
) {
|
) {
|
||||||
Err(e) => panic!("Error in alias analysis: {}", e),
|
Err(e) => panic!("Error in alias analysis: {}", e),
|
||||||
|
|
|
@ -118,6 +118,12 @@ pub enum OptLevel {
|
||||||
Optimize,
|
Optimize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
pub struct EntryPoint<'a> {
|
||||||
|
pub symbol: Symbol,
|
||||||
|
pub layout: ProcLayout<'a>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub struct PartialProcId(usize);
|
pub struct PartialProcId(usize);
|
||||||
|
|
||||||
|
|
|
@ -238,10 +238,10 @@ fn create_llvm_module<'a>(
|
||||||
// platform to provide them.
|
// platform to provide them.
|
||||||
add_default_roc_externs(&env);
|
add_default_roc_externs(&env);
|
||||||
|
|
||||||
let entry_points = match entry_point {
|
let entry_point = match entry_point {
|
||||||
EntryPoint::Executable {
|
EntryPoint::Executable { symbol, layout, .. } => {
|
||||||
exposed_to_host, ..
|
roc_mono::ir::EntryPoint { symbol, layout }
|
||||||
} => exposed_to_host,
|
}
|
||||||
EntryPoint::Test => {
|
EntryPoint::Test => {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
|
@ -254,13 +254,13 @@ fn create_llvm_module<'a>(
|
||||||
&env,
|
&env,
|
||||||
config.opt_level,
|
config.opt_level,
|
||||||
procedures,
|
procedures,
|
||||||
entry_points,
|
entry_point,
|
||||||
),
|
),
|
||||||
LlvmBackendMode::GenTest => roc_gen_llvm::llvm::build::build_procedures_return_main(
|
LlvmBackendMode::GenTest => roc_gen_llvm::llvm::build::build_procedures_return_main(
|
||||||
&env,
|
&env,
|
||||||
config.opt_level,
|
config.opt_level,
|
||||||
procedures,
|
procedures,
|
||||||
entry_points,
|
entry_point,
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -233,10 +233,17 @@ fn mono_module_to_dylib<'a>(
|
||||||
// platform to provide them.
|
// platform to provide them.
|
||||||
add_default_roc_externs(&env);
|
add_default_roc_externs(&env);
|
||||||
|
|
||||||
let entry_points = match entry_point {
|
let entry_point = match entry_point {
|
||||||
EntryPoint::Executable {
|
EntryPoint::Executable {
|
||||||
exposed_to_host, ..
|
exposed_to_host,
|
||||||
} => exposed_to_host,
|
platform_path: _,
|
||||||
|
} => {
|
||||||
|
// TODO support multiple of these!
|
||||||
|
debug_assert_eq!(exposed_to_host.len(), 1);
|
||||||
|
let (symbol, layout) = exposed_to_host[0];
|
||||||
|
|
||||||
|
roc_mono::ir::EntryPoint { symbol, layout }
|
||||||
|
}
|
||||||
EntryPoint::Test => {
|
EntryPoint::Test => {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
|
@ -246,7 +253,7 @@ fn mono_module_to_dylib<'a>(
|
||||||
&env,
|
&env,
|
||||||
opt_level,
|
opt_level,
|
||||||
procedures,
|
procedures,
|
||||||
entry_points,
|
entry_point,
|
||||||
);
|
);
|
||||||
|
|
||||||
env.dibuilder.finalize();
|
env.dibuilder.finalize();
|
||||||
|
|
|
@ -708,11 +708,18 @@ pub fn expect_mono_module_to_dylib<'a>(
|
||||||
// platform to provide them.
|
// platform to provide them.
|
||||||
add_default_roc_externs(&env);
|
add_default_roc_externs(&env);
|
||||||
|
|
||||||
let entry_points = match entry_point {
|
let opt_entry_point = match entry_point {
|
||||||
EntryPoint::Executable {
|
EntryPoint::Executable {
|
||||||
exposed_to_host, ..
|
exposed_to_host,
|
||||||
} => exposed_to_host,
|
platform_path: _,
|
||||||
EntryPoint::Test => &[],
|
} => {
|
||||||
|
// TODO support multiple of these!
|
||||||
|
debug_assert_eq!(exposed_to_host.len(), 1);
|
||||||
|
let (symbol, layout) = exposed_to_host[0];
|
||||||
|
|
||||||
|
Some(roc_mono::ir::EntryPoint { symbol, layout })
|
||||||
|
}
|
||||||
|
EntryPoint::Test => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let capacity = toplevel_expects.pure.len() + toplevel_expects.fx.len();
|
let capacity = toplevel_expects.pure.len() + toplevel_expects.fx.len();
|
||||||
|
@ -726,7 +733,7 @@ pub fn expect_mono_module_to_dylib<'a>(
|
||||||
opt_level,
|
opt_level,
|
||||||
&expect_symbols,
|
&expect_symbols,
|
||||||
procedures,
|
procedures,
|
||||||
entry_points,
|
opt_entry_point,
|
||||||
);
|
);
|
||||||
|
|
||||||
let expects_fx = bumpalo::collections::Vec::from_iter_in(
|
let expects_fx = bumpalo::collections::Vec::from_iter_in(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue