Go back to old opt_main_for_host

This commit is contained in:
Richard Feldman 2022-12-09 22:04:36 -05:00
parent bff3204727
commit 63e9f5da8c
No known key found for this signature in database
GPG key ID: F1F21AA5B1D9E43B
7 changed files with 74 additions and 59 deletions

View file

@ -11,7 +11,7 @@ use roc_module::symbol::Symbol;
use roc_mono::ir::{
Call, CallType, Expr, HigherOrderLowLevel, HostExposedLayouts, ListLiteralElement, Literal,
ModifyRc, OptLevel, Proc, ProcLayout, Stmt,
ModifyRc, OptLevel, Proc, Stmt,
};
use roc_mono::layout::{
Builtin, CapturesNiche, Layout, RawFunctionLayout, STLayoutInterner, UnionLayout,
@ -136,15 +136,12 @@ pub fn spec_program<'a, I>(
arena: &'a Bump,
interner: &STLayoutInterner<'a>,
opt_level: OptLevel,
entry_points: &'a [(Symbol, ProcLayout<'a>)],
opt_entry_point: Option<roc_mono::ir::EntryPoint<'a>>,
procs: I,
) -> Result<morphic_lib::Solutions>
where
I: Iterator<Item = &'a Proc<'a>>,
{
// TODO support multiple entry points here!
let opt_entry_point = entry_points.first();
let main_module = {
let mut m = ModDefBuilder::new();
@ -229,13 +226,13 @@ where
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
let roc_main_bytes = func_name_bytes_help(
*symbol,
proc_layout.arguments.iter().copied(),
entry_point.symbol,
entry_point.layout.arguments.iter().copied(),
CapturesNiche::no_niche(),
&proc_layout.result,
&entry_point.layout.result,
);
let roc_main = FuncName(&roc_main_bytes);
@ -244,7 +241,7 @@ where
let entry_point_function = build_entry_point(
&mut env,
interner,
*proc_layout,
entry_point.layout,
roc_main,
&host_exposed_functions,
)?;

View file

@ -188,18 +188,25 @@ fn gen_from_mono_module_llvm<'a>(
// expects that would confuse the surgical linker
add_default_roc_externs(&env);
let exposed_to_host = match loaded.entry_point {
let opt_entry_point = match loaded.entry_point {
EntryPoint::Executable {
exposed_to_host, ..
} => exposed_to_host,
EntryPoint::Test => &[],
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];
Some(roc_mono::ir::EntryPoint { symbol, layout })
}
EntryPoint::Test => None,
};
roc_gen_llvm::llvm::build::build_procedures(
&env,
opt_level,
loaded.procedures,
exposed_to_host,
opt_entry_point,
Some(&app_ll_file),
);

View file

@ -40,7 +40,8 @@ use roc_debug_flags::ROC_PRINT_LLVM_FN_VERIFICATION;
use roc_error_macros::internal_error;
use roc_module::symbol::{Interns, ModuleId, Symbol};
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::{
Builtin, CapturesNiche, LambdaName, LambdaSet, Layout, LayoutIds, RawFunctionLayout,
@ -4163,60 +4164,50 @@ pub fn build_procedures<'a, 'ctx, 'env>(
env: &Env<'a, 'ctx, 'env>,
opt_level: OptLevel,
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>,
) {
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>(
env: &Env<'a, 'ctx, 'env>,
opt_level: OptLevel,
procedures: MutMap<(Symbol, ProcLayout<'a>), roc_mono::ir::Proc<'a>>,
entry_points: &'a [(Symbol, ProcLayout<'a>)],
entry_point: EntryPoint<'a>,
) -> (&'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(
env,
opt_level,
procedures,
entry_points,
Some(entry_point),
Some(&std::env::temp_dir().join("test.ll")),
);
let (symbol, proc_layout) = entry_points[0];
promote_to_wasm_test_wrapper(env, mod_solutions, symbol, proc_layout)
promote_to_wasm_test_wrapper(env, mod_solutions, entry_point.symbol, entry_point.layout)
}
pub fn build_procedures_return_main<'a, 'ctx, 'env>(
env: &Env<'a, 'ctx, 'env>,
opt_level: OptLevel,
procedures: MutMap<(Symbol, ProcLayout<'a>), roc_mono::ir::Proc<'a>>,
entry_points: &'a [(Symbol, ProcLayout<'a>)],
entry_point: EntryPoint<'a>,
) -> (&'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(
env,
opt_level,
procedures,
entry_points,
Some(entry_point),
Some(&std::env::temp_dir().join("test.ll")),
);
let (symbol, proc_layout) = entry_points[0];
promote_to_main_function(env, mod_solutions, symbol, proc_layout)
promote_to_main_function(env, mod_solutions, entry_point.symbol, entry_point.layout)
}
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,
expects: &[Symbol],
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> {
let mod_solutions = build_procedures_help(
env,
opt_level,
procedures,
entry_points,
opt_entry_point,
Some(&std::env::temp_dir().join("test.ll")),
);
@ -4292,7 +4283,7 @@ fn build_procedures_help<'a, 'ctx, 'env>(
env: &Env<'a, 'ctx, 'env>,
opt_level: OptLevel,
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>,
) -> &'a ModSolutions {
let mut layout_ids = roc_mono::layout::LayoutIds::default();
@ -4304,7 +4295,7 @@ fn build_procedures_help<'a, 'ctx, 'env>(
env.arena,
env.layout_interner,
opt_level,
entry_points,
opt_entry_point,
it,
) {
Err(e) => panic!("Error in alias analysis: {}", e),

View file

@ -118,6 +118,12 @@ pub enum OptLevel {
Optimize,
}
#[derive(Debug, Clone, Copy)]
pub struct EntryPoint<'a> {
pub symbol: Symbol,
pub layout: ProcLayout<'a>,
}
#[derive(Clone, Copy, Debug)]
pub struct PartialProcId(usize);

View file

@ -238,10 +238,10 @@ fn create_llvm_module<'a>(
// platform to provide them.
add_default_roc_externs(&env);
let entry_points = match entry_point {
EntryPoint::Executable {
exposed_to_host, ..
} => exposed_to_host,
let entry_point = match entry_point {
EntryPoint::Executable { symbol, layout, .. } => {
roc_mono::ir::EntryPoint { symbol, layout }
}
EntryPoint::Test => {
unreachable!()
}
@ -254,13 +254,13 @@ fn create_llvm_module<'a>(
&env,
config.opt_level,
procedures,
entry_points,
entry_point,
),
LlvmBackendMode::GenTest => roc_gen_llvm::llvm::build::build_procedures_return_main(
&env,
config.opt_level,
procedures,
entry_points,
entry_point,
),
};