clone less

This commit is contained in:
Folkert 2022-10-05 23:45:31 +02:00
parent f838a94c00
commit fe9da8316d
No known key found for this signature in database
GPG Key ID: 1F17F6FFD112B97C
5 changed files with 75 additions and 99 deletions

View File

@ -4,13 +4,10 @@ use roc_build::{
program::{self, CodeGenOptions, Problems},
};
use roc_builtins::bitcode;
use roc_collections::VecMap;
use roc_intern::SingleThreadedInterner;
use roc_load::{
EntryPoint, ExecutionMode, Expectations, LoadConfig, LoadMonomorphizedError, LoadedModule,
EntryPoint, ExecutionMode, ExpectMetadata, LoadConfig, LoadMonomorphizedError, LoadedModule,
LoadingProblem, Threading,
};
use roc_module::symbol::{Interns, ModuleId};
use roc_mono::ir::OptLevel;
use roc_reporting::report::RenderTarget;
use roc_target::TargetInfo;
@ -35,9 +32,7 @@ pub struct BuiltFile<'a> {
pub binary_path: PathBuf,
pub problems: Problems,
pub total_time: Duration,
pub expectations: VecMap<ModuleId, Expectations>,
pub interns: Interns,
pub layout_interner: SingleThreadedInterner<'a, roc_mono::layout::Layout<'a>>,
pub expect_metadata: ExpectMetadata<'a>,
}
pub enum BuildOrdering {
@ -242,12 +237,8 @@ pub fn build_file<'a>(
// inside a nested scope without causing a borrow error!
let mut loaded = loaded;
let problems = program::report_problems_monomorphized(&mut loaded);
let expectations = std::mem::take(&mut loaded.expectations);
let layout_interner = loaded.layout_interner.clone();
let loaded = loaded;
let interns = loaded.interns.clone();
enum HostRebuildTiming {
BeforeApp(u128),
ConcurrentWithApp(JoinHandle<u128>),
@ -266,7 +257,7 @@ pub fn build_file<'a>(
HostRebuildTiming::ConcurrentWithApp(rebuild_thread)
};
let (roc_app_bytes, code_gen_timing) = program::gen_from_mono_module(
let (roc_app_bytes, code_gen_timing, expect_metadata) = program::gen_from_mono_module(
arena,
loaded,
&app_module_path,
@ -387,9 +378,7 @@ pub fn build_file<'a>(
binary_path,
problems,
total_time,
interns,
expectations,
layout_interner,
expect_metadata,
})
}

View File

@ -6,13 +6,9 @@ use bumpalo::Bump;
use clap::{Arg, ArgMatches, Command, ValueSource};
use roc_build::link::{LinkType, LinkingStrategy};
use roc_build::program::{CodeGenBackend, CodeGenOptions, Problems};
use roc_collections::VecMap;
use roc_error_macros::{internal_error, user_error};
use roc_intern::SingleThreadedInterner;
use roc_load::{Expectations, LoadingProblem, Threading};
use roc_module::symbol::{Interns, ModuleId};
use roc_load::{ExpectMetadata, LoadingProblem, Threading};
use roc_mono::ir::OptLevel;
use roc_mono::layout::Layout;
use std::env;
use std::ffi::{CString, OsStr};
use std::io;
@ -581,9 +577,7 @@ pub fn build(
binary_path,
problems,
total_time,
expectations,
interns,
layout_interner,
expect_metadata,
}) => {
match config {
BuildOnly => {
@ -619,16 +613,7 @@ pub fn build(
// ManuallyDrop will leak the bytes because we don't drop manually
let bytes = &ManuallyDrop::new(std::fs::read(&binary_path).unwrap());
roc_run(
&arena,
opt_level,
triple,
args,
bytes,
expectations,
interns,
layout_interner,
)
roc_run(&arena, opt_level, triple, args, bytes, expect_metadata)
}
BuildAndRunIfNoErrors => {
debug_assert!(
@ -649,16 +634,7 @@ pub fn build(
// ManuallyDrop will leak the bytes because we don't drop manually
let bytes = &ManuallyDrop::new(std::fs::read(&binary_path).unwrap());
roc_run(
&arena,
opt_level,
triple,
args,
bytes,
expectations,
interns,
layout_interner,
)
roc_run(&arena, opt_level, triple, args, bytes, expect_metadata)
}
}
}
@ -729,9 +705,7 @@ fn roc_run<'a, I: IntoIterator<Item = &'a OsStr>>(
triple: Triple,
args: I,
binary_bytes: &[u8],
expectations: VecMap<ModuleId, Expectations>,
interns: Interns,
layout_interner: SingleThreadedInterner<Layout>,
expect_metadata: ExpectMetadata,
) -> io::Result<i32> {
match triple.architecture {
Architecture::Wasm32 => {
@ -770,15 +744,7 @@ fn roc_run<'a, I: IntoIterator<Item = &'a OsStr>>(
Ok(0)
}
_ => roc_run_native(
arena,
opt_level,
args,
binary_bytes,
expectations,
interns,
layout_interner,
),
_ => roc_run_native(arena, opt_level, args, binary_bytes, expect_metadata),
}
}
@ -836,9 +802,7 @@ fn roc_run_native<I: IntoIterator<Item = S>, S: AsRef<OsStr>>(
opt_level: OptLevel,
args: I,
binary_bytes: &[u8],
expectations: VecMap<ModuleId, Expectations>,
interns: Interns,
layout_interner: SingleThreadedInterner<Layout>,
expect_metadata: ExpectMetadata,
) -> std::io::Result<i32> {
use bumpalo::collections::CollectIn;
@ -859,15 +823,7 @@ fn roc_run_native<I: IntoIterator<Item = S>, S: AsRef<OsStr>>(
.collect_in(arena);
match opt_level {
OptLevel::Development => roc_run_native_debug(
arena,
executable,
argv,
envp,
expectations,
interns,
layout_interner,
),
OptLevel::Development => roc_dev_native(arena, executable, argv, envp, expect_metadata),
OptLevel::Normal | OptLevel::Size | OptLevel::Optimize => {
roc_run_native_fast(executable, &argv, &envp);
}
@ -944,18 +900,22 @@ impl ExecutableFile {
// with Expect
#[cfg(target_family = "unix")]
fn roc_run_native_debug(
fn roc_dev_native(
arena: &Bump,
executable: ExecutableFile,
argv: bumpalo::collections::Vec<*const c_char>,
envp: bumpalo::collections::Vec<*const c_char>,
mut expectations: VecMap<ModuleId, Expectations>,
interns: Interns,
layout_interner: SingleThreadedInterner<Layout>,
expect_metadata: ExpectMetadata,
) -> ! {
use roc_repl_expect::run::ExpectMemory;
use signal_hook::{consts::signal::SIGCHLD, consts::signal::SIGUSR1, iterator::Signals};
let ExpectMetadata {
mut expectations,
interns,
layout_interner,
} = expect_metadata;
let mut signals = Signals::new(&[SIGCHLD, SIGUSR1]).unwrap();
// let shm_name = format!("/roc_expect_buffer_{}", std::process::id());

View File

@ -2,7 +2,7 @@ use inkwell::memory_buffer::MemoryBuffer;
pub use roc_gen_llvm::llvm::build::FunctionIterator;
use roc_gen_llvm::llvm::build::{module_from_builtins, LlvmBackendMode};
use roc_gen_llvm::llvm::externs::add_default_roc_externs;
use roc_load::{EntryPoint, LoadedModule, MonomorphizedModule};
use roc_load::{EntryPoint, ExpectMetadata, LoadedModule, MonomorphizedModule};
use roc_module::symbol::{Interns, ModuleId};
use roc_mono::ir::OptLevel;
use roc_region::all::LineInfo;
@ -187,16 +187,18 @@ pub struct CodeGenOptions {
pub emit_debug_info: bool,
}
type GenFromMono<'a> = (CodeObject, CodeGenTiming, ExpectMetadata<'a>);
#[allow(clippy::too_many_arguments)]
pub fn gen_from_mono_module(
arena: &bumpalo::Bump,
loaded: MonomorphizedModule,
pub fn gen_from_mono_module<'a>(
arena: &'a bumpalo::Bump,
loaded: MonomorphizedModule<'a>,
roc_file_path: &Path,
target: &target_lexicon::Triple,
code_gen_options: CodeGenOptions,
preprocessed_host_path: &Path,
wasm_dev_stack_bytes: Option<u32>,
) -> (CodeObject, CodeGenTiming) {
) -> GenFromMono<'a> {
match code_gen_options.backend {
CodeGenBackend::Assembly => gen_from_mono_module_dev(
arena,
@ -220,14 +222,14 @@ pub fn gen_from_mono_module(
// TODO how should imported modules factor into this? What if those use builtins too?
// TODO this should probably use more helper functions
// TODO make this polymorphic in the llvm functions so it can be reused for another backend.
fn gen_from_mono_module_llvm(
arena: &bumpalo::Bump,
loaded: MonomorphizedModule,
fn gen_from_mono_module_llvm<'a>(
arena: &'a bumpalo::Bump,
loaded: MonomorphizedModule<'a>,
roc_file_path: &Path,
target: &target_lexicon::Triple,
opt_level: OptLevel,
emit_debug_info: bool,
) -> (CodeObject, CodeGenTiming) {
) -> GenFromMono<'a> {
use crate::target::{self, convert_opt_level};
use inkwell::attributes::{Attribute, AttributeLoc};
use inkwell::context::Context;
@ -443,17 +445,22 @@ fn gen_from_mono_module_llvm(
(
CodeObject::MemoryBuffer(memory_buffer),
CodeGenTiming { code_gen },
ExpectMetadata {
interns: env.interns,
layout_interner: loaded.layout_interner,
expectations: loaded.expectations,
},
)
}
#[cfg(feature = "target-wasm32")]
fn gen_from_mono_module_dev(
arena: &bumpalo::Bump,
loaded: MonomorphizedModule,
fn gen_from_mono_module_dev<'a>(
arena: &'a bumpalo::Bump,
loaded: MonomorphizedModule<'a>,
target: &target_lexicon::Triple,
preprocessed_host_path: &Path,
wasm_dev_stack_bytes: Option<u32>,
) -> (CodeObject, CodeGenTiming) {
) -> GenFromMono<'a> {
use target_lexicon::Architecture;
match target.architecture {
@ -471,13 +478,13 @@ fn gen_from_mono_module_dev(
}
#[cfg(not(feature = "target-wasm32"))]
pub fn gen_from_mono_module_dev(
arena: &bumpalo::Bump,
loaded: MonomorphizedModule,
pub fn gen_from_mono_module_dev<'a>(
arena: &'a bumpalo::Bump,
loaded: MonomorphizedModule<'a>,
target: &target_lexicon::Triple,
_host_input_path: &Path,
_wasm_dev_stack_bytes: Option<u32>,
) -> (CodeObject, CodeGenTiming) {
) -> GenFromMono<'a> {
use target_lexicon::Architecture;
match target.architecture {
@ -489,12 +496,12 @@ pub fn gen_from_mono_module_dev(
}
#[cfg(feature = "target-wasm32")]
fn gen_from_mono_module_dev_wasm32(
arena: &bumpalo::Bump,
loaded: MonomorphizedModule,
fn gen_from_mono_module_dev_wasm32<'a>(
arena: &'a bumpalo::Bump,
loaded: MonomorphizedModule<'a>,
preprocessed_host_path: &Path,
wasm_dev_stack_bytes: Option<u32>,
) -> (CodeObject, CodeGenTiming) {
) -> GenFromMono<'a> {
let code_gen_start = Instant::now();
let MonomorphizedModule {
module_id,
@ -543,14 +550,19 @@ fn gen_from_mono_module_dev_wasm32(
(
CodeObject::Vector(final_binary_bytes),
CodeGenTiming { code_gen },
ExpectMetadata {
interns,
layout_interner,
expectations: loaded.expectations,
},
)
}
fn gen_from_mono_module_dev_assembly(
arena: &bumpalo::Bump,
loaded: MonomorphizedModule,
fn gen_from_mono_module_dev_assembly<'a>(
arena: &'a bumpalo::Bump,
loaded: MonomorphizedModule<'a>,
target: &target_lexicon::Triple,
) -> (CodeObject, CodeGenTiming) {
) -> GenFromMono<'a> {
let code_gen_start = Instant::now();
let lazy_literals = true;
@ -582,5 +594,13 @@ fn gen_from_mono_module_dev_assembly(
.write()
.expect("failed to build output object");
(CodeObject::Vector(module_out), CodeGenTiming { code_gen })
(
CodeObject::Vector(module_out),
CodeGenTiming { code_gen },
ExpectMetadata {
interns,
layout_interner,
expectations: loaded.expectations,
},
)
}

View File

@ -16,8 +16,8 @@ const SKIP_SUBS_CACHE: bool = {
pub use roc_load_internal::docs;
pub use roc_load_internal::file::{
EntryPoint, ExecutionMode, Expectations, LoadConfig, LoadResult, LoadStart, LoadedModule,
LoadingProblem, MonomorphizedModule, Phase, Threading,
EntryPoint, ExecutionMode, ExpectMetadata, Expectations, LoadConfig, LoadResult, LoadStart,
LoadedModule, LoadingProblem, MonomorphizedModule, Phase, Threading,
};
#[allow(clippy::too_many_arguments)]

View File

@ -702,6 +702,13 @@ pub struct MonomorphizedModule<'a> {
pub expectations: VecMap<ModuleId, Expectations>,
}
/// Values used to render expect output
pub struct ExpectMetadata<'a> {
pub interns: Interns,
pub layout_interner: SingleThreadedInterner<'a, Layout<'a>>,
pub expectations: VecMap<ModuleId, Expectations>,
}
#[derive(Debug)]
pub enum EntryPoint<'a> {
Executable {