diff --git a/Cargo.lock b/Cargo.lock index 38bacbfed9..249611d60c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3351,6 +3351,7 @@ dependencies = [ "roc_parse", "roc_region", "roc_reporting", + "roc_solve", "roc_target", "roc_types", "snafu", @@ -3591,6 +3592,7 @@ dependencies = [ "roc_mono", "roc_packaging", "roc_reporting", + "roc_solve", "roc_target", "serde", "serial_test", @@ -3611,6 +3613,7 @@ dependencies = [ "roc_module", "roc_packaging", "roc_reporting", + "roc_solve", "roc_target", "roc_types", ] @@ -3794,6 +3797,7 @@ dependencies = [ "roc_problem", "roc_region", "roc_reporting", + "roc_solve", "roc_std", "roc_target", "roc_types", @@ -3849,6 +3853,7 @@ dependencies = [ "roc_parse", "roc_repl_eval", "roc_reporting", + "roc_solve", "roc_target", "roc_types", "tempfile", diff --git a/crates/ast/src/module.rs b/crates/ast/src/module.rs index f88649ad7d..942e6d4d5b 100644 --- a/crates/ast/src/module.rs +++ b/crates/ast/src/module.rs @@ -12,6 +12,7 @@ pub fn load_module( ) -> LoadedModule { let load_config = LoadConfig { target_info: TargetInfo::default_x86_64(), // editor only needs type info, so this is unused + function_kind: roc_solve::FunctionKind::LambdaSet, // TODO the editor may need to dynamically change this render: roc_reporting::report::RenderTarget::ColorTerminal, palette: DEFAULT_PALETTE, threading, diff --git a/crates/cli/src/lib.rs b/crates/cli/src/lib.rs index 50fa9b60f8..bd32dfcc19 100644 --- a/crates/cli/src/lib.rs +++ b/crates/cli/src/lib.rs @@ -385,7 +385,7 @@ pub fn test(_matches: &ArgMatches, _triple: Triple) -> io::Result { #[cfg(not(windows))] pub fn test(matches: &ArgMatches, triple: Triple) -> io::Result { use roc_build::program::report_problems_monomorphized; - use roc_load::{ExecutionMode, LoadConfig, LoadMonomorphizedError}; + use roc_load::{ExecutionMode, FunctionKind, LoadConfig, LoadMonomorphizedError}; use roc_packaging::cache; use roc_target::TargetInfo; @@ -427,10 +427,13 @@ pub fn test(matches: &ArgMatches, triple: Triple) -> io::Result { let target = &triple; let opt_level = opt_level; let target_info = TargetInfo::from(target); + // TODO may need to determine this dynamically based on dev builds. + let function_kind = FunctionKind::LambdaSet; // Step 1: compile the app and generate the .o file let load_config = LoadConfig { target_info, + function_kind, // TODO: expose this from CLI? render: roc_reporting::report::RenderTarget::ColorTerminal, palette: roc_reporting::report::DEFAULT_PALETTE, diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index 997d6ab043..705be3ef98 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -11,7 +11,7 @@ use roc_docs::generate_docs_html; use roc_error_macros::user_error; use roc_gen_dev::AssemblyBackendMode; use roc_gen_llvm::llvm::build::LlvmBackendMode; -use roc_load::{LoadingProblem, Threading}; +use roc_load::{FunctionKind, LoadingProblem, Threading}; use roc_packaging::cache::{self, RocCacheDir}; use roc_target::Target; use std::fs::{self, FileType}; @@ -123,10 +123,12 @@ fn main() -> io::Result<()> { .get_one::(FLAG_TARGET) .and_then(|s| Target::from_str(s).ok()) .unwrap_or_default(); + let function_kind = FunctionKind::LambdaSet; roc_linker::generate_stub_lib( input_path, RocCacheDir::Persistent(cache::roc_cache_dir().as_path()), &target.to_triple(), + function_kind, ) } Some((CMD_BUILD, matches)) => { diff --git a/crates/compiler/build/src/program.rs b/crates/compiler/build/src/program.rs index 083b07cbba..d057ae23b1 100644 --- a/crates/compiler/build/src/program.rs +++ b/crates/compiler/build/src/program.rs @@ -8,8 +8,8 @@ use roc_gen_dev::AssemblyBackendMode; use roc_gen_llvm::llvm::build::{module_from_builtins, LlvmBackendMode}; use roc_gen_llvm::llvm::externs::add_default_roc_externs; use roc_load::{ - EntryPoint, ExecutionMode, ExpectMetadata, LoadConfig, LoadMonomorphizedError, LoadedModule, - LoadingProblem, MonomorphizedModule, Threading, + EntryPoint, ExecutionMode, ExpectMetadata, FunctionKind, LoadConfig, LoadMonomorphizedError, + LoadedModule, LoadingProblem, MonomorphizedModule, Threading, }; use roc_mono::ir::{OptLevel, SingleEntryPoint}; use roc_packaging::cache::RocCacheDir; @@ -742,6 +742,7 @@ pub fn standard_load_config( LoadConfig { target_info, + function_kind: FunctionKind::LambdaSet, render: RenderTarget::ColorTerminal, palette: DEFAULT_PALETTE, threading, @@ -1205,6 +1206,8 @@ pub fn check_file<'a>( let load_config = LoadConfig { target_info, + // TODO: we may not want this for just checking. + function_kind: FunctionKind::LambdaSet, // TODO: expose this from CLI? render: RenderTarget::ColorTerminal, palette: DEFAULT_PALETTE, diff --git a/crates/compiler/load/Cargo.toml b/crates/compiler/load/Cargo.toml index eae006f711..f86f1ef2a4 100644 --- a/crates/compiler/load/Cargo.toml +++ b/crates/compiler/load/Cargo.toml @@ -14,6 +14,7 @@ roc_load_internal = { path = "../load_internal" } roc_module = { path = "../module" } roc_packaging = { path = "../../packaging" } roc_reporting = { path = "../../reporting" } +roc_solve = { path = "../solve" } roc_target = { path = "../roc_target" } roc_types = { path = "../types" } @@ -25,6 +26,7 @@ roc_can = { path = "../can" } roc_module = { path = "../module" } roc_packaging = { path = "../../packaging" } roc_reporting = { path = "../../reporting" } +roc_solve = { path = "../solve" } roc_target = { path = "../roc_target" } roc_error_macros = { path = "../../error_macros" } diff --git a/crates/compiler/load/build.rs b/crates/compiler/load/build.rs index 570c8a6f2e..5119007da6 100644 --- a/crates/compiler/load/build.rs +++ b/crates/compiler/load/build.rs @@ -77,6 +77,7 @@ fn write_types_for_module_real(module_id: ModuleId, filename: &str, output_path: let cwd = std::env::current_dir().unwrap(); let source = roc_builtins::roc::module_source(module_id); let target_info = roc_target::TargetInfo::default_x86_64(); + let function_kind = roc_solve::FunctionKind::LambdaSet; let res_module = roc_load_internal::file::load_and_typecheck_str( &arena, @@ -85,6 +86,7 @@ fn write_types_for_module_real(module_id: ModuleId, filename: &str, output_path: cwd, Default::default(), target_info, + function_kind, roc_reporting::report::RenderTarget::ColorTerminal, roc_reporting::report::DEFAULT_PALETTE, RocCacheDir::Disallowed, diff --git a/crates/compiler/load/src/lib.rs b/crates/compiler/load/src/lib.rs index ff7e4ec574..0777b01f2a 100644 --- a/crates/compiler/load/src/lib.rs +++ b/crates/compiler/load/src/lib.rs @@ -24,6 +24,7 @@ pub use roc_load_internal::file::{ pub use roc_load_internal::module::{ EntryPoint, Expectations, ExposedToHost, LoadedModule, MonomorphizedModule, }; +pub use roc_solve::FunctionKind; #[allow(clippy::too_many_arguments)] fn load<'a>( @@ -51,6 +52,7 @@ pub fn load_single_threaded<'a>( arena: &'a Bump, load_start: LoadStart<'a>, target_info: TargetInfo, + function_kind: FunctionKind, render: RenderTarget, palette: Palette, roc_cache_dir: RocCacheDir<'_>, @@ -64,6 +66,7 @@ pub fn load_single_threaded<'a>( load_start, exposed_types, target_info, + function_kind, cached_subs, render, palette, @@ -170,6 +173,7 @@ pub fn load_and_typecheck_str<'a>( source: &'a str, src_dir: PathBuf, target_info: TargetInfo, + function_kind: FunctionKind, render: RenderTarget, roc_cache_dir: RocCacheDir<'_>, palette: Palette, @@ -185,6 +189,7 @@ pub fn load_and_typecheck_str<'a>( arena, load_start, target_info, + function_kind, render, palette, roc_cache_dir, diff --git a/crates/compiler/load_internal/src/file.rs b/crates/compiler/load_internal/src/file.rs index 8f1a4437c1..a1ddac510c 100644 --- a/crates/compiler/load_internal/src/file.rs +++ b/crates/compiler/load_internal/src/file.rs @@ -63,6 +63,7 @@ use roc_region::all::{LineInfo, Loc, Region}; use roc_reporting::report::to_https_problem_report_string; use roc_reporting::report::{to_file_problem_report_string, Palette, RenderTarget}; use roc_solve::module::{extract_module_owned_implementations, SolveConfig, Solved, SolvedModule}; +use roc_solve::FunctionKind; use roc_solve_problem::TypeError; use roc_target::TargetInfo; use roc_types::subs::{CopiedImport, ExposedTypesStorageSubs, Subs, VarStore, Variable}; @@ -113,6 +114,7 @@ pub struct LoadConfig { pub palette: Palette, pub threading: Threading, pub exec_mode: ExecutionMode, + pub function_kind: FunctionKind, } #[derive(Debug, Clone, Copy)] @@ -679,6 +681,8 @@ struct State<'a> { pub output_path: Option<&'a str>, pub platform_path: PlatformPath<'a>, pub target_info: TargetInfo, + #[allow(unused)] // for now + pub(self) function_kind: FunctionKind, /// Note: only packages and platforms actually expose any modules; /// for all others, this will be empty. @@ -740,6 +744,7 @@ impl<'a> State<'a> { root_id: ModuleId, opt_platform_shorthand: Option<&'a str>, target_info: TargetInfo, + function_kind: FunctionKind, exposed_types: ExposedByModule, arc_modules: Arc>>, ident_ids_by_module: SharedIdentIdsByModule, @@ -759,6 +764,7 @@ impl<'a> State<'a> { opt_platform_shorthand, cache_dir, target_info, + function_kind, platform_data: None, output_path: None, platform_path: PlatformPath::NotSpecified, @@ -969,6 +975,7 @@ pub fn load_and_typecheck_str<'a>( src_dir: PathBuf, exposed_types: ExposedByModule, target_info: TargetInfo, + function_kind: FunctionKind, render: RenderTarget, palette: Palette, roc_cache_dir: RocCacheDir<'_>, @@ -988,6 +995,7 @@ pub fn load_and_typecheck_str<'a>( palette, threading, exec_mode: ExecutionMode::Check, + function_kind, }; match load( @@ -1243,6 +1251,7 @@ pub fn load<'a>( load_start, exposed_types, load_config.target_info, + load_config.function_kind, cached_types, load_config.render, load_config.palette, @@ -1254,6 +1263,7 @@ pub fn load<'a>( load_start, exposed_types, load_config.target_info, + load_config.function_kind, cached_types, load_config.render, load_config.palette, @@ -1270,6 +1280,7 @@ pub fn load_single_threaded<'a>( load_start: LoadStart<'a>, exposed_types: ExposedByModule, target_info: TargetInfo, + function_kind: FunctionKind, cached_types: MutMap, render: RenderTarget, palette: Palette, @@ -1297,6 +1308,7 @@ pub fn load_single_threaded<'a>( root_id, opt_platform_shorthand, target_info, + function_kind, exposed_types, arc_modules, ident_ids_by_module, @@ -1584,6 +1596,7 @@ fn load_multi_threaded<'a>( load_start: LoadStart<'a>, exposed_types: ExposedByModule, target_info: TargetInfo, + function_kind: FunctionKind, cached_types: MutMap, render: RenderTarget, palette: Palette, @@ -1627,6 +1640,7 @@ fn load_multi_threaded<'a>( root_id, opt_platform_shorthand, target_info, + function_kind, exposed_types, arc_modules, ident_ids_by_module, diff --git a/crates/compiler/load_internal/tests/test_load.rs b/crates/compiler/load_internal/tests/test_load.rs index f788e6aed8..c52ee7a674 100644 --- a/crates/compiler/load_internal/tests/test_load.rs +++ b/crates/compiler/load_internal/tests/test_load.rs @@ -29,6 +29,7 @@ use roc_region::all::LineInfo; use roc_reporting::report::RenderTarget; use roc_reporting::report::RocDocAllocator; use roc_reporting::report::{can_problem, DEFAULT_PALETTE}; +use roc_solve::FunctionKind; use roc_target::TargetInfo; use roc_types::pretty_print::name_and_print_var; use roc_types::pretty_print::DebugPrint; @@ -40,6 +41,7 @@ fn load_and_typecheck( filename: PathBuf, exposed_types: ExposedByModule, target_info: TargetInfo, + function_kind: FunctionKind, ) -> Result { use LoadResult::*; @@ -52,6 +54,7 @@ fn load_and_typecheck( )?; let load_config = LoadConfig { target_info, + function_kind, render: RenderTarget::Generic, palette: DEFAULT_PALETTE, threading: Threading::Single, @@ -176,7 +179,13 @@ fn multiple_modules_help<'a>( writeln!(file, "{source}")?; file_handles.push(file); - load_and_typecheck(arena, full_file_path, Default::default(), TARGET_INFO) + load_and_typecheck( + arena, + full_file_path, + Default::default(), + TARGET_INFO, + FunctionKind::LambdaSet, + ) }; Ok(result) @@ -190,7 +199,13 @@ fn load_fixture( let src_dir = fixtures_dir().join(dir_name); let filename = src_dir.join(format!("{module_name}.roc")); let arena = Bump::new(); - let loaded = load_and_typecheck(&arena, filename, subs_by_module, TARGET_INFO); + let loaded = load_and_typecheck( + &arena, + filename, + subs_by_module, + TARGET_INFO, + FunctionKind::LambdaSet, + ); let mut loaded_module = match loaded { Ok(x) => x, Err(roc_load_internal::file::LoadingProblem::FormattedReport(report)) => { @@ -347,7 +362,13 @@ fn interface_with_deps() { let src_dir = fixtures_dir().join("interface_with_deps"); let filename = src_dir.join("Primary.roc"); let arena = Bump::new(); - let loaded = load_and_typecheck(&arena, filename, subs_by_module, TARGET_INFO); + let loaded = load_and_typecheck( + &arena, + filename, + subs_by_module, + TARGET_INFO, + FunctionKind::LambdaSet, + ); let mut loaded_module = loaded.expect("Test module failed to load"); let home = loaded_module.module_id; diff --git a/crates/compiler/solve/src/kinds.rs b/crates/compiler/solve/src/kinds.rs new file mode 100644 index 0000000000..761f2e519d --- /dev/null +++ b/crates/compiler/solve/src/kinds.rs @@ -0,0 +1,8 @@ +/// How function kinds should be represented in the type system. +#[derive(Debug)] +pub enum FunctionKind { + /// Function values are solved to lambda sets; lambda sets are the kind. + LambdaSet, + /// Function values are erased, no kind is introduced. + Erased, +} diff --git a/crates/compiler/solve/src/lib.rs b/crates/compiler/solve/src/lib.rs index d43fc7bff4..6424775c77 100644 --- a/crates/compiler/solve/src/lib.rs +++ b/crates/compiler/solve/src/lib.rs @@ -14,9 +14,11 @@ pub mod specialize; mod aliases; mod deep_copy; mod env; +mod kinds; mod pools; mod to_var; pub use aliases::Aliases; pub use env::{DerivedEnv, Env}; +pub use kinds::FunctionKind; pub use pools::Pools; diff --git a/crates/compiler/test_derive/src/util.rs b/crates/compiler/test_derive/src/util.rs index d6e8d5fa10..8f755bd84d 100644 --- a/crates/compiler/test_derive/src/util.rs +++ b/crates/compiler/test_derive/src/util.rs @@ -3,7 +3,10 @@ use std::path::PathBuf; use bumpalo::Bump; use roc_packaging::cache::RocCacheDir; -use roc_solve::module::{SolveConfig, SolveOutput}; +use roc_solve::{ + module::{SolveConfig, SolveOutput}, + FunctionKind, +}; use ven_pretty::DocAllocator; use roc_can::{ @@ -520,6 +523,7 @@ where path.parent().unwrap().to_path_buf(), Default::default(), target_info, + FunctionKind::LambdaSet, roc_reporting::report::RenderTarget::ColorTerminal, roc_reporting::report::DEFAULT_PALETTE, RocCacheDir::Disallowed, diff --git a/crates/compiler/test_gen/src/helpers/llvm.rs b/crates/compiler/test_gen/src/helpers/llvm.rs index ee2e172308..34c73925c0 100644 --- a/crates/compiler/test_gen/src/helpers/llvm.rs +++ b/crates/compiler/test_gen/src/helpers/llvm.rs @@ -8,7 +8,9 @@ use roc_collections::all::MutSet; use roc_command_utils::zig; use roc_gen_llvm::llvm::externs::add_default_roc_externs; use roc_gen_llvm::{llvm::build::LlvmBackendMode, run_roc::RocCallResult}; -use roc_load::{EntryPoint, ExecutionMode, LoadConfig, LoadMonomorphizedError, Threading}; +use roc_load::{ + EntryPoint, ExecutionMode, FunctionKind, LoadConfig, LoadMonomorphizedError, Threading, +}; use roc_mono::ir::{CrashTag, OptLevel, SingleEntryPoint}; use roc_packaging::cache::RocCacheDir; use roc_region::all::LineInfo; @@ -52,6 +54,8 @@ fn create_llvm_module<'a>( target: &Triple, ) -> (&'static str, String, &'a Module<'a>) { let target_info = roc_target::TargetInfo::from(target); + // TODO parameterize + let function_kind = FunctionKind::LambdaSet; let filename = PathBuf::from("Test.roc"); let src_dir = PathBuf::from("fake/test/path"); @@ -69,6 +73,7 @@ fn create_llvm_module<'a>( let load_config = LoadConfig { target_info, + function_kind, render: RenderTarget::ColorTerminal, palette: DEFAULT_PALETTE, threading: Threading::Single, diff --git a/crates/compiler/test_mono/src/tests.rs b/crates/compiler/test_mono/src/tests.rs index 80c8ad48c6..c53629723c 100644 --- a/crates/compiler/test_mono/src/tests.rs +++ b/crates/compiler/test_mono/src/tests.rs @@ -16,6 +16,7 @@ const EXPANDED_STACK_SIZE: usize = 8 * 1024 * 1024; use bumpalo::Bump; use roc_collections::all::MutMap; use roc_load::ExecutionMode; +use roc_load::FunctionKind; use roc_load::LoadConfig; use roc_load::LoadMonomorphizedError; use roc_load::Threading; @@ -104,6 +105,8 @@ fn compiles_to_ir(test_name: &str, src: &str, mode: &str, allow_type_errors: boo let load_config = LoadConfig { target_info: TARGET_INFO, + // TODO parameterize + function_kind: FunctionKind::LambdaSet, threading: Threading::Single, render: roc_reporting::report::RenderTarget::Generic, palette: roc_reporting::report::DEFAULT_PALETTE, diff --git a/crates/compiler/test_solve_helpers/src/lib.rs b/crates/compiler/test_solve_helpers/src/lib.rs index 563b38588b..88b660b654 100644 --- a/crates/compiler/test_solve_helpers/src/lib.rs +++ b/crates/compiler/test_solve_helpers/src/lib.rs @@ -79,6 +79,8 @@ pub fn run_load_and_infer<'a>( module_src, dir.path().to_path_buf(), roc_target::TargetInfo::default_x86_64(), + // TODO parameterize me! + roc_solve::FunctionKind::LambdaSet, roc_reporting::report::RenderTarget::Generic, RocCacheDir::Disallowed, roc_reporting::report::DEFAULT_PALETTE, diff --git a/crates/compiler/uitest/src/mono.rs b/crates/compiler/uitest/src/mono.rs index 06f4f42196..6a9772424e 100644 --- a/crates/compiler/uitest/src/mono.rs +++ b/crates/compiler/uitest/src/mono.rs @@ -8,6 +8,7 @@ use roc_mono::{ ir::{Proc, ProcLayout}, layout::STLayoutInterner, }; +use roc_solve::FunctionKind; use tempfile::tempdir; use test_solve_helpers::format_problems; @@ -41,6 +42,8 @@ pub fn write_compiled_ir<'a>( let load_config = LoadConfig { target_info: roc_target::TargetInfo::default_x86_64(), + // TODO parameterize + function_kind: FunctionKind::LambdaSet, threading: Threading::Single, render: roc_reporting::report::RenderTarget::Generic, palette: roc_reporting::report::DEFAULT_PALETTE, diff --git a/crates/docs/Cargo.toml b/crates/docs/Cargo.toml index b29d35a0a7..85721ed2cc 100644 --- a/crates/docs/Cargo.toml +++ b/crates/docs/Cargo.toml @@ -20,6 +20,7 @@ roc_packaging = { path = "../packaging" } roc_parse = { path = "../compiler/parse" } roc_region = { path = "../compiler/region" } roc_reporting = { path = "../reporting" } +roc_solve = { path = "../compiler/solve" } roc_target = { path = "../compiler/roc_target" } roc_types = { path = "../compiler/types" } diff --git a/crates/docs/src/lib.rs b/crates/docs/src/lib.rs index ff911aa92a..85e6affe8f 100644 --- a/crates/docs/src/lib.rs +++ b/crates/docs/src/lib.rs @@ -454,6 +454,7 @@ pub fn load_module_for_docs(filename: PathBuf) -> LoadedModule { let arena = Bump::new(); let load_config = LoadConfig { target_info: roc_target::TargetInfo::default_x86_64(), // This is just type-checking for docs, so "target" doesn't matter + function_kind: roc_solve::FunctionKind::LambdaSet, render: roc_reporting::report::RenderTarget::ColorTerminal, palette: roc_reporting::report::DEFAULT_PALETTE, threading: Threading::AllAvailable, diff --git a/crates/glue/src/load.rs b/crates/glue/src/load.rs index aa58bf5edd..51360eb0d1 100644 --- a/crates/glue/src/load.rs +++ b/crates/glue/src/load.rs @@ -10,7 +10,7 @@ use roc_build::{ }, }; use roc_collections::MutMap; -use roc_load::{ExecutionMode, LoadConfig, LoadedModule, LoadingProblem, Threading}; +use roc_load::{ExecutionMode, FunctionKind, LoadConfig, LoadedModule, LoadingProblem, Threading}; use roc_mono::ir::{generate_glue_procs, GlueProc, OptLevel}; use roc_mono::layout::{GlobalLayoutInterner, LayoutCache, LayoutInterner}; use roc_packaging::cache::{self, RocCacheDir}; @@ -334,6 +334,8 @@ pub fn load_types( ignore_errors: IgnoreErrors, ) -> Result, io::Error> { let target_info = (&Triple::host()).into(); + // TODO the function kind may need to be parameterizable. + let function_kind = FunctionKind::LambdaSet; let arena = &Bump::new(); let LoadedModule { module_id: home, @@ -350,6 +352,7 @@ pub fn load_types( RocCacheDir::Persistent(cache::roc_cache_dir().as_path()), LoadConfig { target_info, + function_kind, render: RenderTarget::Generic, palette: DEFAULT_PALETTE, threading, diff --git a/crates/linker/Cargo.toml b/crates/linker/Cargo.toml index ea6d76ea14..dac662a678 100644 --- a/crates/linker/Cargo.toml +++ b/crates/linker/Cargo.toml @@ -20,6 +20,7 @@ roc_load = { path = "../compiler/load" } roc_mono = { path = "../compiler/mono" } roc_packaging = { path = "../packaging" } roc_reporting = { path = "../reporting" } +roc_solve = { path = "../compiler/solve" } roc_target = { path = "../compiler/roc_target" } bincode.workspace = true diff --git a/crates/linker/src/lib.rs b/crates/linker/src/lib.rs index 9f53ac42b4..bec65cbfa2 100644 --- a/crates/linker/src/lib.rs +++ b/crates/linker/src/lib.rs @@ -10,6 +10,7 @@ use roc_load::{EntryPoint, ExecutionMode, ExposedToHost, LoadConfig, Threading}; use roc_module::symbol::Interns; use roc_packaging::cache::RocCacheDir; use roc_reporting::report::{RenderTarget, DEFAULT_PALETTE}; +use roc_solve::FunctionKind; use roc_target::get_target_triple_str; use std::cmp::Ordering; use std::mem; @@ -88,6 +89,7 @@ pub fn generate_stub_lib( input_path: &Path, roc_cache_dir: RocCacheDir<'_>, triple: &Triple, + function_kind: FunctionKind, ) -> std::io::Result { // Note: this should theoretically just be able to load the host, I think. // Instead, I am loading an entire app because that was simpler and had example code. @@ -101,6 +103,7 @@ pub fn generate_stub_lib( roc_cache_dir, LoadConfig { target_info, + function_kind, render: RenderTarget::Generic, palette: DEFAULT_PALETTE, threading: Threading::AllAvailable, diff --git a/crates/repl_cli/src/cli_gen.rs b/crates/repl_cli/src/cli_gen.rs index 95236209ab..accd1359d9 100644 --- a/crates/repl_cli/src/cli_gen.rs +++ b/crates/repl_cli/src/cli_gen.rs @@ -7,7 +7,7 @@ use roc_error_macros::internal_error; use roc_gen_llvm::llvm::build::LlvmBackendMode; use roc_gen_llvm::llvm::externs::add_default_roc_externs; use roc_gen_llvm::{run_jit_function, run_jit_function_dynamic_type}; -use roc_load::{EntryPoint, MonomorphizedModule}; +use roc_load::{EntryPoint, FunctionKind, MonomorphizedModule}; use roc_mono::ir::OptLevel; use roc_mono::layout::STLayoutInterner; use roc_parse::ast::Expr; @@ -29,11 +29,19 @@ pub fn gen_and_eval_llvm<'a, I: Iterator>( ) -> (Option, Problems) { let arena = Bump::new(); let target_info = TargetInfo::from(&target); + let function_kind = FunctionKind::LambdaSet; let mut loaded; let problems; - match compile_to_mono(&arena, defs, src, target_info, DEFAULT_PALETTE) { + match compile_to_mono( + &arena, + defs, + src, + target_info, + function_kind, + DEFAULT_PALETTE, + ) { (Some(mono), probs) => { loaded = mono; problems = probs; diff --git a/crates/repl_eval/Cargo.toml b/crates/repl_eval/Cargo.toml index eb14b97b7b..9a41356a07 100644 --- a/crates/repl_eval/Cargo.toml +++ b/crates/repl_eval/Cargo.toml @@ -20,6 +20,7 @@ roc_parse = { path = "../compiler/parse" } roc_problem = { path = "../compiler/problem" } roc_region = { path = "../compiler/region" } roc_reporting = { path = "../reporting" } +roc_solve = { path = "../compiler/solve" } roc_std = { path = "../roc_std" } roc_target = { path = "../compiler/roc_target" } roc_types = { path = "../compiler/types" } diff --git a/crates/repl_eval/src/gen.rs b/crates/repl_eval/src/gen.rs index d7cbf3d06f..830d056f68 100644 --- a/crates/repl_eval/src/gen.rs +++ b/crates/repl_eval/src/gen.rs @@ -11,6 +11,7 @@ use roc_load::{LoadingProblem, MonomorphizedModule}; use roc_parse::ast::Expr; use roc_region::all::LineInfo; use roc_reporting::report::{can_problem, type_problem, RocDocAllocator}; +use roc_solve::FunctionKind; use roc_target::TargetInfo; #[derive(Debug)] @@ -49,6 +50,7 @@ pub fn compile_to_mono<'a, 'i, I: Iterator>( defs: I, expr: &str, target_info: TargetInfo, + function_kind: FunctionKind, palette: Palette, ) -> (Option>, Problems) { let filename = PathBuf::from(""); @@ -62,6 +64,7 @@ pub fn compile_to_mono<'a, 'i, I: Iterator>( RocCacheDir::Persistent(cache::roc_cache_dir().as_path()), LoadConfig { target_info, + function_kind, render: roc_reporting::report::RenderTarget::ColorTerminal, palette, threading: Threading::Single, diff --git a/crates/repl_expect/src/lib.rs b/crates/repl_expect/src/lib.rs index e08a23d7ad..752d0d8c0c 100644 --- a/crates/repl_expect/src/lib.rs +++ b/crates/repl_expect/src/lib.rs @@ -95,7 +95,7 @@ mod test { use pretty_assertions::assert_eq; use roc_error_macros::internal_error; use roc_gen_llvm::{llvm::build::LlvmBackendMode, run_roc::RocCallResult, run_roc_dylib}; - use roc_load::{ExecutionMode, LoadConfig, LoadMonomorphizedError, Threading}; + use roc_load::{ExecutionMode, FunctionKind, LoadConfig, LoadMonomorphizedError, Threading}; use roc_packaging::cache::RocCacheDir; use roc_reporting::report::{RenderTarget, DEFAULT_PALETTE}; use target_lexicon::Triple; @@ -113,6 +113,7 @@ mod test { let opt_level = roc_mono::ir::OptLevel::Normal; let target_info = TargetInfo::from(target); + let function_kind = FunctionKind::LambdaSet; // Step 1: compile the app and generate the .o file let src_dir = tempfile::tempdir().unwrap(); @@ -122,6 +123,7 @@ mod test { let load_config = LoadConfig { target_info, + function_kind, render: RenderTarget::ColorTerminal, palette: DEFAULT_PALETTE, threading: Threading::Single, diff --git a/crates/repl_wasm/Cargo.toml b/crates/repl_wasm/Cargo.toml index 59e245f0f7..a6c4eed509 100644 --- a/crates/repl_wasm/Cargo.toml +++ b/crates/repl_wasm/Cargo.toml @@ -32,6 +32,7 @@ roc_load = { path = "../compiler/load" } roc_parse = { path = "../compiler/parse" } roc_repl_eval = { path = "../repl_eval" } roc_reporting = { path = "../reporting" } +roc_solve = { path = "../compiler/solve" } roc_target = { path = "../compiler/roc_target" } roc_types = { path = "../compiler/types" } diff --git a/crates/repl_wasm/src/repl.rs b/crates/repl_wasm/src/repl.rs index b1703985d6..5aa5c29766 100644 --- a/crates/repl_wasm/src/repl.rs +++ b/crates/repl_wasm/src/repl.rs @@ -180,6 +180,7 @@ pub async fn entrypoint_from_js(src: String) -> Result { // Compile the app let target_info = TargetInfo::default_wasm32(); + let function_kind = roc_solve::FunctionKind::LambdaSet; // TODO use this to filter out problems and warnings in wrapped defs. // See the variable by the same name in the CLI REPL for how to do this! let mono = match compile_to_mono( @@ -187,6 +188,7 @@ pub async fn entrypoint_from_js(src: String) -> Result { std::iter::empty(), &src, target_info, + function_kind, DEFAULT_PALETTE_HTML, ) { (Some(m), problems) if problems.is_empty() => m, // TODO render problems and continue if possible diff --git a/crates/reporting/tests/test_reporting.rs b/crates/reporting/tests/test_reporting.rs index 46702abcac..08f04a0e8a 100644 --- a/crates/reporting/tests/test_reporting.rs +++ b/crates/reporting/tests/test_reporting.rs @@ -26,6 +26,7 @@ mod test_reporting { DEFAULT_PALETTE, }; use roc_reporting::report::{RocDocAllocator, RocDocBuilder}; + use roc_solve::FunctionKind; use roc_solve_problem::TypeError; use roc_types::subs::Subs; use std::path::PathBuf; @@ -127,6 +128,7 @@ mod test_reporting { palette: DEFAULT_PALETTE, threading: Threading::Single, exec_mode: ExecutionMode::Check, + function_kind: FunctionKind::LambdaSet, }; let result = roc_load::load_and_typecheck( arena,