mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 05:49:08 +00:00
Fix formatting and clippy issues
This commit is contained in:
parent
49f5ea88fc
commit
28ceb0e93f
3 changed files with 78 additions and 55 deletions
|
@ -96,7 +96,7 @@ pub struct Run {
|
||||||
stdin_vals: Vec<&'static str>,
|
stdin_vals: Vec<&'static str>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'run> Run {
|
impl Run {
|
||||||
pub fn new<S>(exe: S) -> Self
|
pub fn new<S>(exe: S) -> Self
|
||||||
where
|
where
|
||||||
S: AsRef<OsStr>,
|
S: AsRef<OsStr>,
|
||||||
|
@ -189,7 +189,7 @@ impl<'run> Run {
|
||||||
where
|
where
|
||||||
I: IntoIterator<Item = &'static str>,
|
I: IntoIterator<Item = &'static str>,
|
||||||
{
|
{
|
||||||
self.stdin_vals.extend(stdin_vals.into_iter());
|
self.stdin_vals.extend(stdin_vals);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
use crate::link::{
|
use crate::link::{link, preprocess_host_wasm32, rebuild_host, LinkType, LinkingStrategy};
|
||||||
link, preprocess_host_wasm32, rebuild_host, LinkType, LinkingStrategy,
|
|
||||||
};
|
|
||||||
use bumpalo::Bump;
|
use bumpalo::Bump;
|
||||||
use inkwell::memory_buffer::MemoryBuffer;
|
use inkwell::memory_buffer::MemoryBuffer;
|
||||||
use roc_error_macros::internal_error;
|
use roc_error_macros::internal_error;
|
||||||
|
@ -434,22 +432,34 @@ fn gen_from_mono_module_dev<'a>(
|
||||||
backend_mode: AssemblyBackendMode,
|
backend_mode: AssemblyBackendMode,
|
||||||
) -> GenFromMono<'a> {
|
) -> GenFromMono<'a> {
|
||||||
match (preprocessed_host_path, target.architecture()) {
|
match (preprocessed_host_path, target.architecture()) {
|
||||||
(PrebuiltHost::Additive(host_path), Architecture::Wasm32) => gen_from_mono_module_dev_wasm32(
|
(PrebuiltHost::Additive(host_path), Architecture::Wasm32) => {
|
||||||
arena,
|
gen_from_mono_module_dev_wasm32(arena, loaded, host_path, wasm_dev_stack_bytes)
|
||||||
loaded,
|
}
|
||||||
host_path,
|
(PrebuiltHost::None, Architecture::Wasm32) => {
|
||||||
wasm_dev_stack_bytes,
|
todo!("Cannot compile wasm32 without a host on the dev compiler backend")
|
||||||
|
}
|
||||||
|
(PrebuiltHost::Legacy(host_path), Architecture::Wasm32) => todo!(
|
||||||
|
"Unsupported host files found for use with wasm32 dev compiler backend\n {}",
|
||||||
|
host_path.display()
|
||||||
),
|
),
|
||||||
(PrebuiltHost::None, Architecture::Wasm32) =>
|
(
|
||||||
todo!("Cannot compile wasm32 without a host on the dev compiler backend"),
|
PrebuiltHost::Surgical(SurgicalHostArtifacts {
|
||||||
(PrebuiltHost::Legacy(host_path), Architecture::Wasm32) =>
|
preprocessed_host, ..
|
||||||
todo!("Unsupported host files found for use with wasm32 dev compiler backend\n {}", host_path.display()),
|
}),
|
||||||
(PrebuiltHost::Surgical(SurgicalHostArtifacts {preprocessed_host, ..}), Architecture::Wasm32) =>
|
Architecture::Wasm32,
|
||||||
todo!("Unsupported host files found for use with wasm32 dev compiler backend\n {}", preprocessed_host.display()),
|
) => todo!(
|
||||||
(_, Architecture::X86_64 | Architecture::Aarch64) =>
|
"Unsupported host files found for use with wasm32 dev compiler backend\n {}",
|
||||||
gen_from_mono_module_dev_assembly(arena, loaded, target, backend_mode),
|
preprocessed_host.display()
|
||||||
(_, Architecture::Aarch32) => todo!("Dev compiler backend does not support 32 bit ARM architectures"),
|
),
|
||||||
(_, Architecture::X86_32) => todo!("Dev compiler backend does not support 32 bit x86 architectures"),
|
(_, Architecture::X86_64 | Architecture::Aarch64) => {
|
||||||
|
gen_from_mono_module_dev_assembly(arena, loaded, target, backend_mode)
|
||||||
|
}
|
||||||
|
(_, Architecture::Aarch32) => {
|
||||||
|
todo!("Dev compiler backend does not support 32 bit ARM architectures")
|
||||||
|
}
|
||||||
|
(_, Architecture::X86_32) => {
|
||||||
|
todo!("Dev compiler backend does not support 32 bit x86 architectures")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -745,8 +755,6 @@ pub enum PrebuiltHost {
|
||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fn build_and_preprocess_host(
|
fn build_and_preprocess_host(
|
||||||
code_gen_options: CodeGenOptions,
|
code_gen_options: CodeGenOptions,
|
||||||
dll_stub_symbols: Vec<String>,
|
dll_stub_symbols: Vec<String>,
|
||||||
|
@ -757,14 +765,12 @@ fn build_and_preprocess_host(
|
||||||
target: Target,
|
target: Target,
|
||||||
) -> PrebuiltHost {
|
) -> PrebuiltHost {
|
||||||
let rebuild_thread = match linking_strategy {
|
let rebuild_thread = match linking_strategy {
|
||||||
LinkingStrategy::Additive => {
|
LinkingStrategy::Additive => spawn_wasm32_host_build_thread(
|
||||||
spawn_wasm32_host_build_thread(
|
|
||||||
code_gen_options.opt_level,
|
code_gen_options.opt_level,
|
||||||
target,
|
target,
|
||||||
platform_main_roc.to_owned(),
|
platform_main_roc.to_owned(),
|
||||||
preprocessed_host_path.to_owned(),
|
preprocessed_host_path.to_owned(),
|
||||||
)
|
),
|
||||||
},
|
|
||||||
LinkingStrategy::Surgical => {
|
LinkingStrategy::Surgical => {
|
||||||
let preprocessed_path =
|
let preprocessed_path =
|
||||||
platform_main_roc.with_file_name(target.prebuilt_surgical_host());
|
platform_main_roc.with_file_name(target.prebuilt_surgical_host());
|
||||||
|
@ -779,13 +785,11 @@ fn build_and_preprocess_host(
|
||||||
metadata_path,
|
metadata_path,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
LinkingStrategy::Legacy => {
|
LinkingStrategy::Legacy => spawn_legacy_host_build_thread(
|
||||||
spawn_legacy_host_build_thread(
|
|
||||||
code_gen_options.opt_level,
|
code_gen_options.opt_level,
|
||||||
target,
|
target,
|
||||||
platform_main_roc.to_owned(),
|
platform_main_roc.to_owned(),
|
||||||
)
|
),
|
||||||
}
|
|
||||||
};
|
};
|
||||||
let (rebuild_duration, path) = rebuild_thread.join().expect("Failed to build host.");
|
let (rebuild_duration, path) = rebuild_thread.join().expect("Failed to build host.");
|
||||||
if emit_timings {
|
if emit_timings {
|
||||||
|
@ -836,7 +840,7 @@ fn build_loaded_file<'a>(
|
||||||
legacy_host_path,
|
legacy_host_path,
|
||||||
surgical_artifacts,
|
surgical_artifacts,
|
||||||
build_host_requested,
|
build_host_requested,
|
||||||
link_type
|
link_type,
|
||||||
) {
|
) {
|
||||||
// The following 4 cases represent the possible valid host states for the compiler once
|
// The following 4 cases represent the possible valid host states for the compiler once
|
||||||
// host rebuilding has been removed.
|
// host rebuilding has been removed.
|
||||||
|
@ -847,7 +851,7 @@ fn build_loaded_file<'a>(
|
||||||
(Err(legacy_paths), Err(surgical_paths), false, LinkType::Executable) => {
|
(Err(legacy_paths), Err(surgical_paths), false, LinkType::Executable) => {
|
||||||
report_missing_prebuilt_host(&format!("{legacy_paths}\n {surgical_paths}"));
|
report_missing_prebuilt_host(&format!("{legacy_paths}\n {surgical_paths}"));
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
},
|
}
|
||||||
|
|
||||||
// The following 3 cases we currently support for host rebuilding. Emit a deprecation
|
// The following 3 cases we currently support for host rebuilding. Emit a deprecation
|
||||||
// warning and rebuild the host.
|
// warning and rebuild the host.
|
||||||
|
@ -863,7 +867,14 @@ fn build_loaded_file<'a>(
|
||||||
target,
|
target,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
(_, Ok(SurgicalHostArtifacts {preprocessed_host, ..}), true, LinkType::Executable) => {
|
(
|
||||||
|
_,
|
||||||
|
Ok(SurgicalHostArtifacts {
|
||||||
|
preprocessed_host, ..
|
||||||
|
}),
|
||||||
|
true,
|
||||||
|
LinkType::Executable,
|
||||||
|
) => {
|
||||||
report_rebuilding_existing_host(&preprocessed_host.to_string_lossy());
|
report_rebuilding_existing_host(&preprocessed_host.to_string_lossy());
|
||||||
build_and_preprocess_host(
|
build_and_preprocess_host(
|
||||||
code_gen_options,
|
code_gen_options,
|
||||||
|
@ -894,7 +905,15 @@ fn build_loaded_file<'a>(
|
||||||
report_refusing_to_rebuild_host(&host_path.to_string_lossy());
|
report_refusing_to_rebuild_host(&host_path.to_string_lossy());
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
(_, Ok(SurgicalHostArtifacts {preprocessed_host, metadata}), true, LinkType::Dylib | LinkType::None) => {
|
(
|
||||||
|
_,
|
||||||
|
Ok(SurgicalHostArtifacts {
|
||||||
|
preprocessed_host,
|
||||||
|
metadata,
|
||||||
|
}),
|
||||||
|
true,
|
||||||
|
LinkType::Dylib | LinkType::None,
|
||||||
|
) => {
|
||||||
report_refusing_to_rebuild_host(&format!(
|
report_refusing_to_rebuild_host(&format!(
|
||||||
"{}\n {}",
|
"{}\n {}",
|
||||||
preprocessed_host.to_string_lossy(),
|
preprocessed_host.to_string_lossy(),
|
||||||
|
@ -906,12 +925,12 @@ fn build_loaded_file<'a>(
|
||||||
report_rebuilding_missing_host(&format!("{legacy_paths}\n {surgical_paths}"));
|
report_rebuilding_missing_host(&format!("{legacy_paths}\n {surgical_paths}"));
|
||||||
eprintln!("You asked me to build the host, but I don't know how to rebuild a host for a dynamic library.");
|
eprintln!("You asked me to build the host, but I don't know how to rebuild a host for a dynamic library.");
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
},
|
}
|
||||||
(Err(legacy_paths), Err(surgical_paths), true, LinkType::None) => {
|
(Err(legacy_paths), Err(surgical_paths), true, LinkType::None) => {
|
||||||
report_rebuilding_missing_host(&format!("{legacy_paths}\n {surgical_paths}"));
|
report_rebuilding_missing_host(&format!("{legacy_paths}\n {surgical_paths}"));
|
||||||
eprintln!("You asked me to build the host, but I don't know how to rebuild a host for an unlinked object.");
|
eprintln!("You asked me to build the host, but I don't know how to rebuild a host for an unlinked object.");
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let buf = &mut String::with_capacity(1024);
|
let buf = &mut String::with_capacity(1024);
|
||||||
|
@ -1116,7 +1135,6 @@ fn get_exe_path(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn report_rebuilding_existing_host(host_path: &str) {
|
fn report_rebuilding_existing_host(host_path: &str) {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
indoc::indoc!(
|
indoc::indoc!(
|
||||||
|
@ -1203,7 +1221,10 @@ fn spawn_wasm32_host_build_thread(
|
||||||
|
|
||||||
preprocess_host_wasm32(host_dest.as_path(), &output_path);
|
preprocess_host_wasm32(host_dest.as_path(), &output_path);
|
||||||
|
|
||||||
(start.elapsed().as_millis(), PrebuiltHost::Additive(output_path))
|
(
|
||||||
|
start.elapsed().as_millis(),
|
||||||
|
PrebuiltHost::Additive(output_path),
|
||||||
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1254,10 +1275,13 @@ fn spawn_surgical_host_build_thread(
|
||||||
// The surgical linker will modify that copy in-place.
|
// The surgical linker will modify that copy in-place.
|
||||||
//std::fs::copy(&preprocessed_path, &output_exe_path).unwrap();
|
//std::fs::copy(&preprocessed_path, &output_exe_path).unwrap();
|
||||||
|
|
||||||
(start.elapsed().as_millis(), PrebuiltHost::Surgical(SurgicalHostArtifacts {
|
(
|
||||||
|
start.elapsed().as_millis(),
|
||||||
|
PrebuiltHost::Surgical(SurgicalHostArtifacts {
|
||||||
metadata: metadata_path,
|
metadata: metadata_path,
|
||||||
preprocessed_host: preprocessed_path,
|
preprocessed_host: preprocessed_path,
|
||||||
}))
|
}),
|
||||||
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
// See github.com/roc-lang/roc/issues/800 for discussion of the large_enum_variant check.
|
// See github.com/roc-lang/roc/issues/800 for discussion of the large_enum_variant check.
|
||||||
#![allow(clippy::large_enum_variant)]
|
#![allow(clippy::large_enum_variant)]
|
||||||
|
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::path::{PathBuf, Path};
|
|
||||||
|
|
||||||
use roc_error_macros::user_error;
|
use roc_error_macros::user_error;
|
||||||
use strum_macros::{EnumCount, EnumIter};
|
use strum_macros::{EnumCount, EnumIter};
|
||||||
|
@ -87,14 +87,12 @@ pub enum Target {
|
||||||
Wasm32,
|
Wasm32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct SurgicalHostArtifacts {
|
pub struct SurgicalHostArtifacts {
|
||||||
pub metadata: PathBuf,
|
pub metadata: PathBuf,
|
||||||
pub preprocessed_host: PathBuf,
|
pub preprocessed_host: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl Target {
|
impl Target {
|
||||||
pub const fn architecture(&self) -> Architecture {
|
pub const fn architecture(&self) -> Architecture {
|
||||||
use Target::*;
|
use Target::*;
|
||||||
|
@ -257,7 +255,10 @@ impl Target {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Search for a prebuilt surgical host in the platform main directory.
|
/// Search for a prebuilt surgical host in the platform main directory.
|
||||||
pub fn find_surgical_host(&self, platform_main_roc: &Path) -> Result<SurgicalHostArtifacts, String> {
|
pub fn find_surgical_host(
|
||||||
|
&self,
|
||||||
|
platform_main_roc: &Path,
|
||||||
|
) -> Result<SurgicalHostArtifacts, String> {
|
||||||
let surgical_metadata = platform_main_roc.with_file_name(self.metadata_file_name());
|
let surgical_metadata = platform_main_roc.with_file_name(self.metadata_file_name());
|
||||||
let surgical_host_path = platform_main_roc.with_file_name(self.prebuilt_surgical_host());
|
let surgical_host_path = platform_main_roc.with_file_name(self.prebuilt_surgical_host());
|
||||||
|
|
||||||
|
@ -283,8 +284,6 @@ impl Target {
|
||||||
.to_string())
|
.to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum ParseError {
|
pub enum ParseError {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue