mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 11:52:19 +00:00
Merge pull request #3510 from rtfeldman/fix-loading
Fix some file loading bugs
This commit is contained in:
commit
a812369299
14 changed files with 41 additions and 71 deletions
|
@ -10,15 +10,6 @@ pub fn load_module(src_file: &Path, threading: Threading) -> LoadedModule {
|
|||
let loaded = roc_load::load_and_typecheck(
|
||||
&arena,
|
||||
src_file.to_path_buf(),
|
||||
src_file
|
||||
.parent()
|
||||
.unwrap_or_else(|| {
|
||||
panic!(
|
||||
"src_file {:?} did not have a parent directory but I need to have one.",
|
||||
src_file
|
||||
)
|
||||
})
|
||||
.to_path_buf(),
|
||||
subs_by_module,
|
||||
TargetInfo::default_x86_64(),
|
||||
roc_reporting::report::RenderTarget::ColorTerminal,
|
||||
|
|
|
@ -10,7 +10,6 @@ use target_lexicon::Triple;
|
|||
|
||||
pub fn load_types(
|
||||
full_file_path: PathBuf,
|
||||
dir: PathBuf,
|
||||
threading: Threading,
|
||||
) -> Result<Vec<(Types, TargetInfo)>, io::Error> {
|
||||
let target_info = (&Triple::host()).into();
|
||||
|
@ -28,7 +27,6 @@ pub fn load_types(
|
|||
} = roc_load::load_and_typecheck(
|
||||
arena,
|
||||
full_file_path,
|
||||
dir,
|
||||
subs_by_module,
|
||||
target_info,
|
||||
RenderTarget::Generic,
|
||||
|
|
|
@ -33,7 +33,6 @@ enum OutputType {
|
|||
pub fn main() {
|
||||
let opts = Opts::parse();
|
||||
let input_path = opts.platform_module;
|
||||
let cwd = std::env::current_dir().unwrap();
|
||||
let output_path = opts.dest;
|
||||
let output_type = match output_path.extension().and_then(OsStr::to_str) {
|
||||
Some("rs") => OutputType::Rust,
|
||||
|
@ -56,7 +55,7 @@ pub fn main() {
|
|||
}
|
||||
};
|
||||
|
||||
match load_types(input_path.clone(), cwd, Threading::AllAvailable) {
|
||||
match load_types(input_path.clone(), Threading::AllAvailable) {
|
||||
Ok(types_and_targets) => {
|
||||
let mut file = File::create(output_path.clone()).unwrap_or_else(|err| {
|
||||
eprintln!(
|
||||
|
|
|
@ -33,7 +33,7 @@ pub fn generate_bindings(decl_src: &str) -> String {
|
|||
let mut file = File::create(file_path).unwrap();
|
||||
writeln!(file, "{}", &src).unwrap();
|
||||
|
||||
let result = load_types(full_file_path, dir.path().to_path_buf(), Threading::Single);
|
||||
let result = load_types(full_file_path, Threading::Single);
|
||||
|
||||
dir.close().expect("Unable to close tempdir");
|
||||
|
||||
|
|
|
@ -35,7 +35,6 @@ pub struct BuiltFile {
|
|||
pub fn build_file<'a>(
|
||||
arena: &'a Bump,
|
||||
target: &Triple,
|
||||
src_dir: PathBuf,
|
||||
app_module_path: PathBuf,
|
||||
opt_level: OptLevel,
|
||||
emit_debug_info: bool,
|
||||
|
@ -55,7 +54,6 @@ pub fn build_file<'a>(
|
|||
let loaded = roc_load::load_and_monomorphize(
|
||||
arena,
|
||||
app_module_path.clone(),
|
||||
src_dir,
|
||||
subs_by_module,
|
||||
target_info,
|
||||
// TODO: expose this from CLI?
|
||||
|
@ -419,7 +417,6 @@ fn spawn_rebuild_thread(
|
|||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn check_file(
|
||||
arena: &Bump,
|
||||
src_dir: PathBuf,
|
||||
roc_file_path: PathBuf,
|
||||
emit_timings: bool,
|
||||
threading: Threading,
|
||||
|
@ -436,7 +433,6 @@ pub fn check_file(
|
|||
let mut loaded = roc_load::load_and_typecheck(
|
||||
arena,
|
||||
roc_file_path,
|
||||
src_dir,
|
||||
subs_by_module,
|
||||
target_info,
|
||||
// TODO: expose this from CLI?
|
||||
|
|
|
@ -353,8 +353,6 @@ pub fn test(matches: &ArgMatches, triple: Triple) -> io::Result<i32> {
|
|||
);
|
||||
}
|
||||
|
||||
let src_dir = path.parent().unwrap().canonicalize().unwrap();
|
||||
|
||||
// let target_valgrind = matches.is_present(FLAG_VALGRIND);
|
||||
|
||||
let arena = &arena;
|
||||
|
@ -368,7 +366,6 @@ pub fn test(matches: &ArgMatches, triple: Triple) -> io::Result<i32> {
|
|||
let loaded = roc_load::load_and_monomorphize(
|
||||
arena,
|
||||
path,
|
||||
src_dir,
|
||||
subs_by_module,
|
||||
target_info,
|
||||
// TODO: expose this from CLI?
|
||||
|
@ -494,12 +491,10 @@ pub fn build(
|
|||
}
|
||||
});
|
||||
|
||||
let src_dir = path.parent().unwrap().canonicalize().unwrap();
|
||||
let target_valgrind = matches.is_present(FLAG_VALGRIND);
|
||||
let res_binary_path = build_file(
|
||||
&arena,
|
||||
&triple,
|
||||
src_dir,
|
||||
path,
|
||||
opt_level,
|
||||
emit_debug_info,
|
||||
|
|
|
@ -90,8 +90,6 @@ fn main() -> io::Result<()> {
|
|||
let emit_timings = matches.is_present(FLAG_TIME);
|
||||
let filename = matches.value_of_os(ROC_FILE).unwrap();
|
||||
let roc_file_path = PathBuf::from(filename);
|
||||
let src_dir = roc_file_path.parent().unwrap().to_owned();
|
||||
|
||||
let threading = match matches
|
||||
.value_of(roc_cli::FLAG_MAX_THREADS)
|
||||
.and_then(|s| s.parse::<usize>().ok())
|
||||
|
@ -102,7 +100,7 @@ fn main() -> io::Result<()> {
|
|||
Some(n) => Threading::AtMost(n),
|
||||
};
|
||||
|
||||
match check_file(&arena, src_dir, roc_file_path, emit_timings, threading) {
|
||||
match check_file(&arena, roc_file_path, emit_timings, threading) {
|
||||
Ok((problems, total_time)) => {
|
||||
println!(
|
||||
"\x1B[{}m{}\x1B[39m {} and \x1B[{}m{}\x1B[39m {} found in {} ms.",
|
||||
|
|
|
@ -92,7 +92,6 @@ pub fn load_and_monomorphize_from_str<'a>(
|
|||
pub fn load_and_monomorphize(
|
||||
arena: &Bump,
|
||||
filename: PathBuf,
|
||||
src_dir: PathBuf,
|
||||
exposed_types: ExposedByModule,
|
||||
target_info: TargetInfo,
|
||||
render: RenderTarget,
|
||||
|
@ -100,7 +99,7 @@ pub fn load_and_monomorphize(
|
|||
) -> Result<MonomorphizedModule<'_>, LoadingProblem<'_>> {
|
||||
use LoadResult::*;
|
||||
|
||||
let load_start = LoadStart::from_path(arena, src_dir, filename, render)?;
|
||||
let load_start = LoadStart::from_path(arena, filename, render)?;
|
||||
|
||||
match load(
|
||||
arena,
|
||||
|
@ -119,7 +118,6 @@ pub fn load_and_monomorphize(
|
|||
pub fn load_and_typecheck(
|
||||
arena: &Bump,
|
||||
filename: PathBuf,
|
||||
src_dir: PathBuf,
|
||||
exposed_types: ExposedByModule,
|
||||
target_info: TargetInfo,
|
||||
render: RenderTarget,
|
||||
|
@ -127,7 +125,7 @@ pub fn load_and_typecheck(
|
|||
) -> Result<LoadedModule, LoadingProblem<'_>> {
|
||||
use LoadResult::*;
|
||||
|
||||
let load_start = LoadStart::from_path(arena, src_dir, filename, render)?;
|
||||
let load_start = LoadStart::from_path(arena, filename, render)?;
|
||||
|
||||
match load(
|
||||
arena,
|
||||
|
|
|
@ -1114,13 +1114,13 @@ pub struct LoadStart<'a> {
|
|||
impl<'a> LoadStart<'a> {
|
||||
pub fn from_path(
|
||||
arena: &'a Bump,
|
||||
mut src_dir: PathBuf,
|
||||
filename: PathBuf,
|
||||
render: RenderTarget,
|
||||
) -> Result<Self, LoadingProblem<'a>> {
|
||||
let arc_modules = Arc::new(Mutex::new(PackageModuleIds::default()));
|
||||
let root_exposed_ident_ids = IdentIds::exposed_builtins(0);
|
||||
let ident_ids_by_module = Arc::new(Mutex::new(root_exposed_ident_ids));
|
||||
let mut src_dir = filename.parent().unwrap().to_path_buf();
|
||||
|
||||
// Load the root module synchronously; we can't proceed until we have its id.
|
||||
let (root_id, root_msg) = {
|
||||
|
@ -2839,7 +2839,7 @@ fn load_platform_module<'a>(
|
|||
// make a `platform` module that ultimately exposes `main` to the host
|
||||
let platform_module_msg = fabricate_platform_module(
|
||||
arena,
|
||||
shorthand,
|
||||
Some(shorthand),
|
||||
Some(app_module_id),
|
||||
filename.to_path_buf(),
|
||||
parser_state,
|
||||
|
@ -3237,19 +3237,17 @@ fn parse_header<'a>(
|
|||
To::NewPackage(_package_name) => Ok((module_id, app_module_header_msg)),
|
||||
}
|
||||
}
|
||||
Ok((ast::Module::Platform { header }, parse_state)) => {
|
||||
Ok(fabricate_platform_module(
|
||||
arena,
|
||||
"", // Use a shorthand of "" - it will be fine for `roc check` and bindgen
|
||||
None,
|
||||
filename,
|
||||
parse_state,
|
||||
module_ids.clone(),
|
||||
ident_ids_by_module,
|
||||
&header,
|
||||
module_timing,
|
||||
))
|
||||
}
|
||||
Ok((ast::Module::Platform { header }, parse_state)) => Ok(fabricate_platform_module(
|
||||
arena,
|
||||
None,
|
||||
None,
|
||||
filename,
|
||||
parse_state,
|
||||
module_ids.clone(),
|
||||
ident_ids_by_module,
|
||||
&header,
|
||||
module_timing,
|
||||
)),
|
||||
|
||||
Err(fail) => Err(LoadingProblem::ParsingFailed(
|
||||
fail.map_problem(SyntaxError::Header)
|
||||
|
@ -3534,7 +3532,7 @@ fn send_header<'a>(
|
|||
struct PlatformHeaderInfo<'a> {
|
||||
filename: PathBuf,
|
||||
is_root_module: bool,
|
||||
shorthand: &'a str,
|
||||
opt_shorthand: Option<&'a str>,
|
||||
opt_app_module_id: Option<ModuleId>,
|
||||
packages: &'a [Loc<PackageEntry<'a>>],
|
||||
provides: &'a [Loc<ExposedName<'a>>],
|
||||
|
@ -3554,7 +3552,7 @@ fn send_header_two<'a>(
|
|||
) -> (ModuleId, Msg<'a>) {
|
||||
let PlatformHeaderInfo {
|
||||
filename,
|
||||
shorthand,
|
||||
opt_shorthand,
|
||||
is_root_module,
|
||||
opt_app_module_id,
|
||||
packages,
|
||||
|
@ -3609,7 +3607,10 @@ fn send_header_two<'a>(
|
|||
let mut module_ids = (*module_ids).lock();
|
||||
let mut ident_ids_by_module = (*ident_ids_by_module).lock();
|
||||
|
||||
let name = PQModuleName::Qualified(shorthand, declared_name);
|
||||
let name = match opt_shorthand {
|
||||
Some(shorthand) => PQModuleName::Qualified(shorthand, declared_name),
|
||||
None => PQModuleName::Unqualified(declared_name),
|
||||
};
|
||||
home = module_ids.get_or_insert(&name);
|
||||
|
||||
// Ensure this module has an entry in the exposed_ident_ids map.
|
||||
|
@ -3623,8 +3624,13 @@ fn send_header_two<'a>(
|
|||
for (qualified_module_name, exposed_idents, region) in imported.into_iter() {
|
||||
let cloned_module_name = qualified_module_name.module.clone();
|
||||
let pq_module_name = match qualified_module_name.opt_package {
|
||||
None => PQModuleName::Qualified(shorthand, qualified_module_name.module),
|
||||
Some(package) => PQModuleName::Qualified(package, cloned_module_name.clone()),
|
||||
None => match opt_shorthand {
|
||||
Some(shorthand) => {
|
||||
PQModuleName::Qualified(shorthand, qualified_module_name.module)
|
||||
}
|
||||
None => PQModuleName::Unqualified(qualified_module_name.module),
|
||||
},
|
||||
Some(package) => PQModuleName::Qualified(package, cloned_module_name),
|
||||
};
|
||||
|
||||
let module_id = module_ids.get_or_insert(&pq_module_name);
|
||||
|
@ -3733,7 +3739,8 @@ fn send_header_two<'a>(
|
|||
};
|
||||
|
||||
let extra = HeaderFor::Platform {
|
||||
config_shorthand: shorthand,
|
||||
// A config_shorthand of "" should be fine
|
||||
config_shorthand: opt_shorthand.unwrap_or_default(),
|
||||
platform_main_type: requires[0].value,
|
||||
main_for_host,
|
||||
};
|
||||
|
@ -4187,7 +4194,7 @@ fn unspace<'a, T: Copy>(arena: &'a Bump, items: &[Loc<Spaced<'a, T>>]) -> &'a [L
|
|||
#[allow(clippy::too_many_arguments)]
|
||||
fn fabricate_platform_module<'a>(
|
||||
arena: &'a Bump,
|
||||
shorthand: &'a str,
|
||||
opt_shorthand: Option<&'a str>,
|
||||
opt_app_module_id: Option<ModuleId>,
|
||||
filename: PathBuf,
|
||||
parse_state: roc_parse::state::State<'a>,
|
||||
|
@ -4203,7 +4210,7 @@ fn fabricate_platform_module<'a>(
|
|||
let info = PlatformHeaderInfo {
|
||||
filename,
|
||||
is_root_module,
|
||||
shorthand,
|
||||
opt_shorthand,
|
||||
opt_app_module_id,
|
||||
packages: &[],
|
||||
provides: unspace(arena, header.provides.items),
|
||||
|
|
|
@ -35,13 +35,12 @@ use std::path::PathBuf;
|
|||
fn load_and_typecheck(
|
||||
arena: &Bump,
|
||||
filename: PathBuf,
|
||||
src_dir: PathBuf,
|
||||
exposed_types: ExposedByModule,
|
||||
target_info: TargetInfo,
|
||||
) -> Result<LoadedModule, LoadingProblem> {
|
||||
use LoadResult::*;
|
||||
|
||||
let load_start = LoadStart::from_path(arena, src_dir, filename, RenderTarget::Generic)?;
|
||||
let load_start = LoadStart::from_path(arena, filename, RenderTarget::Generic)?;
|
||||
|
||||
match roc_load_internal::file::load(
|
||||
arena,
|
||||
|
@ -163,13 +162,7 @@ fn multiple_modules_help<'a>(
|
|||
writeln!(file, "{}", source)?;
|
||||
file_handles.push(file);
|
||||
|
||||
load_and_typecheck(
|
||||
arena,
|
||||
full_file_path,
|
||||
dir.path().to_path_buf(),
|
||||
Default::default(),
|
||||
TARGET_INFO,
|
||||
)
|
||||
load_and_typecheck(arena, full_file_path, Default::default(), TARGET_INFO)
|
||||
};
|
||||
|
||||
Ok(result)
|
||||
|
@ -183,7 +176,7 @@ fn load_fixture(
|
|||
let src_dir = fixtures_dir().join(dir_name);
|
||||
let filename = src_dir.join(format!("{}.roc", module_name));
|
||||
let arena = Bump::new();
|
||||
let loaded = load_and_typecheck(&arena, filename, src_dir, subs_by_module, TARGET_INFO);
|
||||
let loaded = load_and_typecheck(&arena, filename, subs_by_module, TARGET_INFO);
|
||||
let mut loaded_module = match loaded {
|
||||
Ok(x) => x,
|
||||
Err(roc_load_internal::file::LoadingProblem::FormattedReport(report)) => {
|
||||
|
@ -339,7 +332,7 @@ 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, src_dir, subs_by_module, TARGET_INFO);
|
||||
let loaded = load_and_typecheck(&arena, filename, subs_by_module, TARGET_INFO);
|
||||
|
||||
let mut loaded_module = loaded.expect("Test module failed to load");
|
||||
let home = loaded_module.module_id;
|
||||
|
|
|
@ -432,13 +432,9 @@ pub fn load_modules_for_files(filenames: Vec<PathBuf>) -> Vec<LoadedModule> {
|
|||
let mut modules = Vec::with_capacity(filenames.len());
|
||||
|
||||
for filename in filenames {
|
||||
let mut src_dir = filename.clone();
|
||||
src_dir.pop();
|
||||
|
||||
match roc_load::load_and_typecheck(
|
||||
&arena,
|
||||
filename,
|
||||
src_dir,
|
||||
Default::default(),
|
||||
roc_target::TargetInfo::default_x86_64(), // This is just type-checking for docs, so "target" doesn't matter
|
||||
roc_reporting::report::RenderTarget::ColorTerminal,
|
||||
|
|
|
@ -86,7 +86,6 @@ mod test_reporting {
|
|||
let result = roc_load::load_and_typecheck(
|
||||
arena,
|
||||
full_file_path,
|
||||
dir.path().to_path_buf(),
|
||||
exposed_types,
|
||||
roc_target::TargetInfo::default_x86_64(),
|
||||
RenderTarget::Generic,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
interface InternalTask
|
||||
exposes [Task, fromEffect, toEffect]
|
||||
imports [pf.Effect.{ Effect }]
|
||||
imports [Effect.{ Effect }]
|
||||
|
||||
Task ok err fx := Effect (Result ok err)
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
interface Task
|
||||
exposes [Task, succeed, fail, await, map, onFail, attempt, forever, loop]
|
||||
imports [pf.Effect, pf.InternalTask]
|
||||
imports [Effect, InternalTask]
|
||||
|
||||
Task ok err fx : InternalTask.Task ok err fx
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue