Merge branch 'add-load-internal' into builtins-in-roc

This commit is contained in:
Folkert 2022-03-23 17:35:49 +01:00
commit aefb536bc4
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
55 changed files with 101 additions and 74 deletions

7
Cargo.lock generated
View file

@ -3682,6 +3682,13 @@ dependencies = [
[[package]] [[package]]
name = "roc_load" name = "roc_load"
version = "0.1.0" version = "0.1.0"
dependencies = [
"roc_load_internal",
]
[[package]]
name = "roc_load_internal"
version = "0.1.0"
dependencies = [ dependencies = [
"bumpalo", "bumpalo",
"crossbeam", "crossbeam",

View file

@ -18,6 +18,7 @@ members = [
"compiler/alias_analysis", "compiler/alias_analysis",
"compiler/test_mono", "compiler/test_mono",
"compiler/load", "compiler/load",
"compiler/load_internal",
"compiler/gen_llvm", "compiler/gen_llvm",
"compiler/gen_dev", "compiler/gen_dev",
"compiler/gen_wasm", "compiler/gen_wasm",

View file

@ -1,14 +1,14 @@
use std::path::Path; use std::path::Path;
use bumpalo::Bump; use bumpalo::Bump;
use roc_load::file::LoadedModule; use roc_load::LoadedModule;
use roc_target::TargetInfo; use roc_target::TargetInfo;
pub fn load_module(src_file: &Path) -> LoadedModule { pub fn load_module(src_file: &Path) -> LoadedModule {
let subs_by_module = Default::default(); let subs_by_module = Default::default();
let arena = Bump::new(); let arena = Bump::new();
let loaded = roc_load::file::load_and_typecheck( let loaded = roc_load::load_and_typecheck(
&arena, &arena,
src_file.to_path_buf(), src_file.to_path_buf(),
src_file.parent().unwrap_or_else(|| { src_file.parent().unwrap_or_else(|| {
@ -23,7 +23,7 @@ pub fn load_module(src_file: &Path) -> LoadedModule {
match loaded { match loaded {
Ok(x) => x, Ok(x) => x,
Err(roc_load::file::LoadingProblem::FormattedReport(report)) => { Err(roc_load::LoadingProblem::FormattedReport(report)) => {
panic!( panic!(
"Failed to load module from src_file {:?}. Report: {}", "Failed to load module from src_file {:?}. Report: {}",
src_file, report src_file, report

View file

@ -4,7 +4,7 @@ use roc_build::{
program, program,
}; };
use roc_builtins::bitcode; use roc_builtins::bitcode;
use roc_load::file::LoadingProblem; use roc_load::LoadingProblem;
use roc_mono::ir::OptLevel; use roc_mono::ir::OptLevel;
use roc_target::TargetInfo; use roc_target::TargetInfo;
use std::path::PathBuf; use std::path::PathBuf;
@ -62,7 +62,7 @@ pub fn build_file<'a>(
// Step 1: compile the app and generate the .o file // Step 1: compile the app and generate the .o file
let subs_by_module = Default::default(); let subs_by_module = Default::default();
let loaded = roc_load::file::load_and_monomorphize( let loaded = roc_load::load_and_monomorphize(
arena, arena,
roc_file_path.clone(), roc_file_path.clone(),
src_dir.as_path(), src_dir.as_path(),
@ -363,7 +363,7 @@ pub fn check_file(
// Step 1: compile the app and generate the .o file // Step 1: compile the app and generate the .o file
let subs_by_module = Default::default(); let subs_by_module = Default::default();
let mut loaded = roc_load::file::load_and_typecheck( let mut loaded = roc_load::load_and_typecheck(
arena, arena,
roc_file_path, roc_file_path,
src_dir.as_path(), src_dir.as_path(),

View file

@ -6,7 +6,7 @@ use bumpalo::Bump;
use clap::{App, AppSettings, Arg, ArgMatches}; use clap::{App, AppSettings, Arg, ArgMatches};
use roc_build::link::LinkType; use roc_build::link::LinkType;
use roc_error_macros::user_error; use roc_error_macros::user_error;
use roc_load::file::LoadingProblem; use roc_load::LoadingProblem;
use roc_mono::ir::OptLevel; use roc_mono::ir::OptLevel;
use std::env; use std::env;
use std::io; use std::io;

View file

@ -3,7 +3,7 @@ use roc_cli::{
build_app, docs, format, BuildConfig, FormatMode, CMD_BUILD, CMD_CHECK, CMD_DOCS, CMD_EDIT, build_app, docs, format, BuildConfig, FormatMode, CMD_BUILD, CMD_CHECK, CMD_DOCS, CMD_EDIT,
CMD_FORMAT, CMD_REPL, CMD_VERSION, DIRECTORY_OR_FILES, FLAG_CHECK, FLAG_TIME, ROC_FILE, CMD_FORMAT, CMD_REPL, CMD_VERSION, DIRECTORY_OR_FILES, FLAG_CHECK, FLAG_TIME, ROC_FILE,
}; };
use roc_load::file::LoadingProblem; use roc_load::LoadingProblem;
use std::fs::{self, FileType}; use std::fs::{self, FileType};
use std::io; use std::io;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};

View file

@ -2,7 +2,7 @@
use roc_gen_llvm::llvm::build::module_from_builtins; use roc_gen_llvm::llvm::build::module_from_builtins;
#[cfg(feature = "llvm")] #[cfg(feature = "llvm")]
pub use roc_gen_llvm::llvm::build::FunctionIterator; pub use roc_gen_llvm::llvm::build::FunctionIterator;
use roc_load::file::{LoadedModule, MonomorphizedModule}; use roc_load::{LoadedModule, MonomorphizedModule};
use roc_module::symbol::{Interns, ModuleId}; use roc_module::symbol::{Interns, ModuleId};
use roc_mono::ir::OptLevel; use roc_mono::ir::OptLevel;
use roc_region::all::LineInfo; use roc_region::all::LineInfo;

View file

@ -6,32 +6,7 @@ license = "UPL-1.0"
edition = "2018" edition = "2018"
[dependencies] [dependencies]
roc_collections = { path = "../collections" } roc_load_internal = { path = "../load_internal" }
roc_error_macros = { path = "../../error_macros" }
roc_region = { path = "../region" }
roc_module = { path = "../module" }
roc_types = { path = "../types" }
roc_can = { path = "../can" }
roc_constrain = { path = "../constrain" }
roc_builtins = { path = "../builtins" }
roc_problem = { path = "../problem" }
roc_unify = { path = "../unify" }
roc_parse = { path = "../parse" }
roc_solve = { path = "../solve" }
roc_mono = { path = "../mono" }
roc_target = { path = "../roc_target" }
roc_reporting = { path = "../../reporting" }
morphic_lib = { path = "../../vendor/morphic_lib" }
ven_pretty = { path = "../../vendor/pretty" }
bumpalo = { version = "3.8.0", features = ["collections"] }
parking_lot = "0.11.2"
crossbeam = "0.8.1"
num_cpus = "1.13.0"
memmap = "0.7.0"
[dev-dependencies] [build-dependencies]
tempfile = "3.2.0" roc_load_internal = { path = "../load_internal" }
pretty_assertions = "1.0.0"
maplit = "1.0.2"
indoc = "1.0.3"
strip-ansi-escapes = "0.1.1"

View file

@ -1,9 +1,6 @@
#![warn(clippy::dbg_macro)] pub use roc_load_internal::file::{
// See github.com/rtfeldman/roc/issues/800 for discussion of the large_enum_variant check. load_and_monomorphize, load_and_monomorphize_from_str, load_and_typecheck, LoadedModule,
#![allow(clippy::large_enum_variant)] LoadingProblem, MonomorphizedModule,
pub mod docs; };
pub mod file;
mod work;
#[cfg(target_family = "wasm")] pub use roc_load_internal::docs;
mod wasm_system_time;

View file

@ -0,0 +1,37 @@
[package]
name = "roc_load_internal"
version = "0.1.0"
authors = ["The Roc Contributors"]
license = "UPL-1.0"
edition = "2018"
[dependencies]
roc_collections = { path = "../collections" }
roc_error_macros = { path = "../../error_macros" }
roc_region = { path = "../region" }
roc_module = { path = "../module" }
roc_types = { path = "../types" }
roc_can = { path = "../can" }
roc_constrain = { path = "../constrain" }
roc_builtins = { path = "../builtins" }
roc_problem = { path = "../problem" }
roc_unify = { path = "../unify" }
roc_parse = { path = "../parse" }
roc_solve = { path = "../solve" }
roc_mono = { path = "../mono" }
roc_target = { path = "../roc_target" }
roc_reporting = { path = "../../reporting" }
morphic_lib = { path = "../../vendor/morphic_lib" }
ven_pretty = { path = "../../vendor/pretty" }
bumpalo = { version = "3.8.0", features = ["collections"] }
parking_lot = "0.11.2"
crossbeam = "0.8.1"
num_cpus = "1.13.0"
memmap = "0.7.0"
[dev-dependencies]
tempfile = "3.2.0"
pretty_assertions = "1.0.0"
maplit = "1.0.2"
indoc = "1.0.3"
strip-ansi-escapes = "0.1.1"

View file

@ -0,0 +1,9 @@
#![warn(clippy::dbg_macro)]
// See github.com/rtfeldman/roc/issues/800 for discussion of the large_enum_variant check.
#![allow(clippy::large_enum_variant)]
pub mod docs;
pub mod file;
mod work;
#[cfg(target_family = "wasm")]
mod wasm_system_time;

View file

@ -7,7 +7,7 @@ extern crate maplit;
extern crate bumpalo; extern crate bumpalo;
extern crate roc_collections; extern crate roc_collections;
extern crate roc_load; extern crate roc_load_internal;
extern crate roc_module; extern crate roc_module;
mod helpers; mod helpers;
@ -19,7 +19,7 @@ mod test_load {
use roc_can::def::Declaration::*; use roc_can::def::Declaration::*;
use roc_can::def::Def; use roc_can::def::Def;
use roc_constrain::module::ExposedByModule; use roc_constrain::module::ExposedByModule;
use roc_load::file::LoadedModule; use roc_load_internal::file::{load_and_typecheck, LoadedModule};
use roc_module::ident::ModuleName; use roc_module::ident::ModuleName;
use roc_module::symbol::{Interns, ModuleId}; use roc_module::symbol::{Interns, ModuleId};
use roc_problem::can::Problem; use roc_problem::can::Problem;
@ -62,7 +62,7 @@ mod test_load {
} }
fn multiple_modules(files: Vec<(&str, &str)>) -> Result<LoadedModule, String> { fn multiple_modules(files: Vec<(&str, &str)>) -> Result<LoadedModule, String> {
use roc_load::file::LoadingProblem; use roc_load_internal::file::LoadingProblem;
let arena = Bump::new(); let arena = Bump::new();
let arena = &arena; let arena = &arena;
@ -102,7 +102,8 @@ mod test_load {
fn multiple_modules_help<'a>( fn multiple_modules_help<'a>(
arena: &'a Bump, arena: &'a Bump,
mut files: Vec<(&str, &str)>, mut files: Vec<(&str, &str)>,
) -> Result<Result<LoadedModule, roc_load::file::LoadingProblem<'a>>, std::io::Error> { ) -> Result<Result<LoadedModule, roc_load_internal::file::LoadingProblem<'a>>, std::io::Error>
{
use std::fs::{self, File}; use std::fs::{self, File};
use std::io::Write; use std::io::Write;
use tempfile::tempdir; use tempfile::tempdir;
@ -137,7 +138,7 @@ mod test_load {
writeln!(file, "{}", source)?; writeln!(file, "{}", source)?;
file_handles.push(file); file_handles.push(file);
roc_load::file::load_and_typecheck( load_and_typecheck(
arena, arena,
full_file_path, full_file_path,
dir.path(), dir.path(),
@ -159,7 +160,7 @@ mod test_load {
let src_dir = fixtures_dir().join(dir_name); let src_dir = fixtures_dir().join(dir_name);
let filename = src_dir.join(format!("{}.roc", module_name)); let filename = src_dir.join(format!("{}.roc", module_name));
let arena = Bump::new(); let arena = Bump::new();
let loaded = roc_load::file::load_and_typecheck( let loaded = load_and_typecheck(
&arena, &arena,
filename, filename,
src_dir.as_path(), src_dir.as_path(),
@ -168,7 +169,7 @@ mod test_load {
); );
let mut loaded_module = match loaded { let mut loaded_module = match loaded {
Ok(x) => x, Ok(x) => x,
Err(roc_load::file::LoadingProblem::FormattedReport(report)) => { Err(roc_load_internal::file::LoadingProblem::FormattedReport(report)) => {
println!("{}", report); println!("{}", report);
panic!("{}", report); panic!("{}", report);
} }
@ -323,7 +324,7 @@ mod test_load {
let src_dir = fixtures_dir().join("interface_with_deps"); let src_dir = fixtures_dir().join("interface_with_deps");
let filename = src_dir.join("Primary.roc"); let filename = src_dir.join("Primary.roc");
let arena = Bump::new(); let arena = Bump::new();
let loaded = roc_load::file::load_and_typecheck( let loaded = load_and_typecheck(
&arena, &arena,
filename, filename,
src_dir.as_path(), src_dir.as_path(),
@ -391,7 +392,7 @@ mod test_load {
} }
#[test] #[test]
fn load_and_typecheck() { fn test_load_and_typecheck() {
let subs_by_module = Default::default(); let subs_by_module = Default::default();
let loaded_module = load_fixture("interface_with_deps", "WithBuiltins", subs_by_module); let loaded_module = load_fixture("interface_with_deps", "WithBuiltins", subs_by_module);

View file

@ -52,7 +52,7 @@ mod solve_expr {
let mut file = File::create(file_path)?; let mut file = File::create(file_path)?;
writeln!(file, "{}", module_src)?; writeln!(file, "{}", module_src)?;
drop(file); drop(file);
let result = roc_load::file::load_and_typecheck( let result = roc_load::load_and_typecheck(
arena, arena,
full_file_path, full_file_path,
dir.path(), dir.path(),
@ -67,7 +67,7 @@ mod solve_expr {
let loaded = loaded.expect("failed to load module"); let loaded = loaded.expect("failed to load module");
use roc_load::file::LoadedModule; use roc_load::LoadedModule;
let LoadedModule { let LoadedModule {
module_id: home, module_id: home,
mut can_problems, mut can_problems,

View file

@ -47,7 +47,7 @@ pub fn helper(
module_src = &temp; module_src = &temp;
} }
let loaded = roc_load::file::load_and_monomorphize_from_str( let loaded = roc_load::load_and_monomorphize_from_str(
arena, arena,
filename, filename,
module_src, module_src,
@ -58,7 +58,7 @@ pub fn helper(
let mut loaded = loaded.expect("failed to load module"); let mut loaded = loaded.expect("failed to load module");
use roc_load::file::MonomorphizedModule; use roc_load::MonomorphizedModule;
let MonomorphizedModule { let MonomorphizedModule {
module_id, module_id,
procedures, procedures,

View file

@ -50,7 +50,7 @@ fn create_llvm_module<'a>(
module_src = &temp; module_src = &temp;
} }
let loaded = roc_load::file::load_and_monomorphize_from_str( let loaded = roc_load::load_and_monomorphize_from_str(
arena, arena,
filename, filename,
module_src, module_src,
@ -61,14 +61,14 @@ fn create_llvm_module<'a>(
let mut loaded = match loaded { let mut loaded = match loaded {
Ok(x) => x, Ok(x) => x,
Err(roc_load::file::LoadingProblem::FormattedReport(report)) => { Err(roc_load::LoadingProblem::FormattedReport(report)) => {
println!("{}", report); println!("{}", report);
panic!(); panic!();
} }
Err(e) => panic!("{:?}", e), Err(e) => panic!("{:?}", e),
}; };
use roc_load::file::MonomorphizedModule; use roc_load::MonomorphizedModule;
let MonomorphizedModule { let MonomorphizedModule {
procedures, procedures,
entry_point, entry_point,

View file

@ -84,7 +84,7 @@ fn compile_roc_to_wasm_bytes<'a, T: Wasm32Result>(
module_src = &temp; module_src = &temp;
} }
let loaded = roc_load::file::load_and_monomorphize_from_str( let loaded = roc_load::load_and_monomorphize_from_str(
arena, arena,
filename, filename,
module_src, module_src,
@ -95,7 +95,7 @@ fn compile_roc_to_wasm_bytes<'a, T: Wasm32Result>(
let loaded = loaded.expect("failed to load module"); let loaded = loaded.expect("failed to load module");
use roc_load::file::MonomorphizedModule; use roc_load::MonomorphizedModule;
let MonomorphizedModule { let MonomorphizedModule {
module_id, module_id,
procedures, procedures,

View file

@ -94,7 +94,7 @@ fn compiles_to_ir(test_name: &str, src: &str) {
module_src = &temp; module_src = &temp;
} }
let loaded = roc_load::file::load_and_monomorphize_from_str( let loaded = roc_load::load_and_monomorphize_from_str(
arena, arena,
filename, filename,
module_src, module_src,
@ -105,14 +105,14 @@ fn compiles_to_ir(test_name: &str, src: &str) {
let mut loaded = match loaded { let mut loaded = match loaded {
Ok(x) => x, Ok(x) => x,
Err(roc_load::file::LoadingProblem::FormattedReport(report)) => { Err(roc_load::LoadingProblem::FormattedReport(report)) => {
println!("{}", report); println!("{}", report);
panic!(); panic!();
} }
Err(e) => panic!("{:?}", e), Err(e) => panic!("{:?}", e),
}; };
use roc_load::file::MonomorphizedModule; use roc_load::MonomorphizedModule;
let MonomorphizedModule { let MonomorphizedModule {
module_id: home, module_id: home,
procedures, procedures,

View file

@ -11,7 +11,7 @@ use roc_highlight::highlight_parser::{highlight_defs, highlight_expr};
use roc_load::docs::DocEntry::DocDef; use roc_load::docs::DocEntry::DocDef;
use roc_load::docs::{DocEntry, TypeAnnotation}; use roc_load::docs::{DocEntry, TypeAnnotation};
use roc_load::docs::{ModuleDocumentation, RecordField}; use roc_load::docs::{ModuleDocumentation, RecordField};
use roc_load::file::{LoadedModule, LoadingProblem}; use roc_load::{LoadedModule, LoadingProblem};
use roc_module::symbol::{IdentIds, Interns, ModuleId}; use roc_module::symbol::{IdentIds, Interns, ModuleId};
use roc_parse::ident::{parse_ident, Ident}; use roc_parse::ident::{parse_ident, Ident};
use roc_parse::state::State; use roc_parse::state::State;
@ -418,7 +418,7 @@ pub fn load_modules_for_files(filenames: Vec<PathBuf>) -> Vec<LoadedModule> {
let mut src_dir = filename.clone(); let mut src_dir = filename.clone();
src_dir.pop(); src_dir.pop();
match roc_load::file::load_and_typecheck( match roc_load::load_and_typecheck(
&arena, &arena,
filename, filename,
src_dir.as_path(), src_dir.as_path(),

View file

@ -19,7 +19,7 @@ use roc_code_markup::markup::convert::from_ast::ast_to_mark_nodes;
use roc_code_markup::markup::mark_id_ast_id_map::MarkIdAstIdMap; use roc_code_markup::markup::mark_id_ast_id_map::MarkIdAstIdMap;
use roc_code_markup::markup::nodes; use roc_code_markup::markup::nodes;
use roc_code_markup::slow_pool::{MarkNodeId, SlowPool}; use roc_code_markup::slow_pool::{MarkNodeId, SlowPool};
use roc_load::file::LoadedModule; use roc_load::LoadedModule;
use roc_module::symbol::Interns; use roc_module::symbol::Interns;
use std::path::Path; use std::path::Path;
@ -232,7 +232,7 @@ pub mod test_ed_model {
use roc_ast::lang::env::Env; use roc_ast::lang::env::Env;
use roc_ast::mem_pool::pool::Pool; use roc_ast::mem_pool::pool::Pool;
use roc_ast::module::load_module; use roc_ast::module::load_module;
use roc_load::file::LoadedModule; use roc_load::LoadedModule;
use roc_module::symbol::IdentIds; use roc_module::symbol::IdentIds;
use roc_module::symbol::ModuleIds; use roc_module::symbol::ModuleIds;
use roc_types::subs::VarStore; use roc_types::subs::VarStore;

View file

@ -13,7 +13,7 @@ use roc_build::link::module_to_dylib;
use roc_collections::all::MutSet; use roc_collections::all::MutSet;
use roc_gen_llvm::llvm::externs::add_default_roc_externs; use roc_gen_llvm::llvm::externs::add_default_roc_externs;
use roc_gen_llvm::{run_jit_function, run_jit_function_dynamic_type}; use roc_gen_llvm::{run_jit_function, run_jit_function_dynamic_type};
use roc_load::file::MonomorphizedModule; use roc_load::MonomorphizedModule;
use roc_mono::ir::OptLevel; use roc_mono::ir::OptLevel;
use roc_parse::ast::Expr; use roc_parse::ast::Expr;
use roc_parse::parser::{EExpr, ELambda, SyntaxError}; use roc_parse::parser::{EExpr, ELambda, SyntaxError};

View file

@ -4,7 +4,7 @@ use std::path::{Path, PathBuf};
use roc_fmt::annotation::Formattable; use roc_fmt::annotation::Formattable;
use roc_fmt::annotation::{Newlines, Parens}; use roc_fmt::annotation::{Newlines, Parens};
use roc_load::file::{LoadingProblem, MonomorphizedModule}; use roc_load::{LoadingProblem, MonomorphizedModule};
use roc_parse::ast::Expr; use roc_parse::ast::Expr;
use roc_region::all::LineInfo; use roc_region::all::LineInfo;
use roc_reporting::report::{can_problem, mono_problem, type_problem, RocDocAllocator}; use roc_reporting::report::{can_problem, mono_problem, type_problem, RocDocAllocator};
@ -53,7 +53,7 @@ pub fn compile_to_mono<'a>(
let module_src = arena.alloc(promote_expr_to_module(src)); let module_src = arena.alloc(promote_expr_to_module(src));
let exposed_types = Default::default(); let exposed_types = Default::default();
let loaded = roc_load::file::load_and_monomorphize_from_str( let loaded = roc_load::load_and_monomorphize_from_str(
arena, arena,
filename, filename,
module_src, module_src,

View file

@ -3,7 +3,7 @@ use std::mem::size_of;
use roc_collections::all::MutSet; use roc_collections::all::MutSet;
use roc_gen_wasm::wasm32_result; use roc_gen_wasm::wasm32_result;
use roc_load::file::MonomorphizedModule; use roc_load::MonomorphizedModule;
use roc_parse::ast::Expr; use roc_parse::ast::Expr;
use roc_repl_eval::{ use roc_repl_eval::{
eval::jit_to_ast, eval::jit_to_ast,