mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-12 14:56:18 +00:00
add basic checking for if an ingested file exists
This commit is contained in:
parent
f4411afbbc
commit
0c366949cb
3 changed files with 49 additions and 21 deletions
|
@ -3636,7 +3636,7 @@ fn load_package_from_disk<'a>(
|
||||||
&header,
|
&header,
|
||||||
comments,
|
comments,
|
||||||
pkg_module_timing,
|
pkg_module_timing,
|
||||||
);
|
)?;
|
||||||
|
|
||||||
Ok(Msg::Header(package_module_msg))
|
Ok(Msg::Header(package_module_msg))
|
||||||
}
|
}
|
||||||
|
@ -3667,7 +3667,7 @@ fn load_package_from_disk<'a>(
|
||||||
&header,
|
&header,
|
||||||
comments,
|
comments,
|
||||||
pkg_module_timing,
|
pkg_module_timing,
|
||||||
);
|
)?;
|
||||||
|
|
||||||
Ok(Msg::Header(platform_module_msg))
|
Ok(Msg::Header(platform_module_msg))
|
||||||
}
|
}
|
||||||
|
@ -3763,7 +3763,7 @@ fn load_builtin_module<'a>(
|
||||||
module_timing: ModuleTiming,
|
module_timing: ModuleTiming,
|
||||||
module_id: ModuleId,
|
module_id: ModuleId,
|
||||||
module_name: &str,
|
module_name: &str,
|
||||||
) -> (ModuleId, Msg<'a>) {
|
) -> Result<(ModuleId, Msg<'a>), LoadingProblem<'a>> {
|
||||||
let src_bytes = module_source(module_id);
|
let src_bytes = module_source(module_id);
|
||||||
|
|
||||||
let (info, parse_state) = load_builtin_module_help(arena, module_name, src_bytes);
|
let (info, parse_state) = load_builtin_module_help(arena, module_name, src_bytes);
|
||||||
|
@ -3775,8 +3775,8 @@ fn load_builtin_module<'a>(
|
||||||
module_ids,
|
module_ids,
|
||||||
ident_ids_by_module,
|
ident_ids_by_module,
|
||||||
module_timing,
|
module_timing,
|
||||||
);
|
)?;
|
||||||
(module_id, Msg::Header(header))
|
Ok((module_id, Msg::Header(header)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Load a module by its module name, rather than by its filename
|
/// Load a module by its module name, rather than by its filename
|
||||||
|
@ -3812,7 +3812,7 @@ fn load_module<'a>(
|
||||||
module_timing,
|
module_timing,
|
||||||
$module_id,
|
$module_id,
|
||||||
concat!($name, ".roc")
|
concat!($name, ".roc")
|
||||||
);
|
)?;
|
||||||
|
|
||||||
return Ok(HeaderOutput { module_id, msg, opt_platform_shorthand: None });
|
return Ok(HeaderOutput { module_id, msg, opt_platform_shorthand: None });
|
||||||
}
|
}
|
||||||
|
@ -4056,7 +4056,7 @@ fn parse_header<'a>(
|
||||||
module_ids,
|
module_ids,
|
||||||
ident_ids_by_module,
|
ident_ids_by_module,
|
||||||
module_timing,
|
module_timing,
|
||||||
);
|
)?;
|
||||||
|
|
||||||
if let Some(expected_module_name) = opt_expected_module_name {
|
if let Some(expected_module_name) = opt_expected_module_name {
|
||||||
if expected_module_name != module_name {
|
if expected_module_name != module_name {
|
||||||
|
@ -4111,7 +4111,7 @@ fn parse_header<'a>(
|
||||||
module_ids,
|
module_ids,
|
||||||
ident_ids_by_module,
|
ident_ids_by_module,
|
||||||
module_timing,
|
module_timing,
|
||||||
);
|
)?;
|
||||||
|
|
||||||
Ok(HeaderOutput {
|
Ok(HeaderOutput {
|
||||||
module_id,
|
module_id,
|
||||||
|
@ -4173,7 +4173,7 @@ fn parse_header<'a>(
|
||||||
module_ids.clone(),
|
module_ids.clone(),
|
||||||
ident_ids_by_module.clone(),
|
ident_ids_by_module.clone(),
|
||||||
module_timing,
|
module_timing,
|
||||||
);
|
)?;
|
||||||
|
|
||||||
let mut messages = Vec::with_capacity(packages.len() + 1);
|
let mut messages = Vec::with_capacity(packages.len() + 1);
|
||||||
|
|
||||||
|
@ -4232,7 +4232,7 @@ fn parse_header<'a>(
|
||||||
&header,
|
&header,
|
||||||
comments,
|
comments,
|
||||||
module_timing,
|
module_timing,
|
||||||
);
|
)?;
|
||||||
|
|
||||||
Ok(HeaderOutput {
|
Ok(HeaderOutput {
|
||||||
module_id,
|
module_id,
|
||||||
|
@ -4267,7 +4267,7 @@ fn parse_header<'a>(
|
||||||
&header,
|
&header,
|
||||||
comments,
|
comments,
|
||||||
module_timing,
|
module_timing,
|
||||||
);
|
)?;
|
||||||
|
|
||||||
Ok(HeaderOutput {
|
Ok(HeaderOutput {
|
||||||
module_id,
|
module_id,
|
||||||
|
@ -4441,7 +4441,7 @@ fn build_header<'a>(
|
||||||
module_ids: Arc<Mutex<PackageModuleIds<'a>>>,
|
module_ids: Arc<Mutex<PackageModuleIds<'a>>>,
|
||||||
ident_ids_by_module: SharedIdentIdsByModule,
|
ident_ids_by_module: SharedIdentIdsByModule,
|
||||||
module_timing: ModuleTiming,
|
module_timing: ModuleTiming,
|
||||||
) -> (ModuleId, PQModuleName<'a>, ModuleHeader<'a>) {
|
) -> Result<(ModuleId, PQModuleName<'a>, ModuleHeader<'a>), LoadingProblem<'a>> {
|
||||||
let HeaderInfo {
|
let HeaderInfo {
|
||||||
filename,
|
filename,
|
||||||
is_root_module,
|
is_root_module,
|
||||||
|
@ -4503,7 +4503,7 @@ fn build_header<'a>(
|
||||||
|
|
||||||
imported.push((qualified_module_name, exposed, loc_entry.region));
|
imported.push((qualified_module_name, exposed, loc_entry.region));
|
||||||
}
|
}
|
||||||
if let Some(value) = value_def_from_imports(arena, loc_entry) {
|
if let Some(value) = value_def_from_imports(arena, loc_entry)? {
|
||||||
defined_values.push(value);
|
defined_values.push(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4732,7 +4732,7 @@ fn build_header<'a>(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
(
|
Ok((
|
||||||
home,
|
home,
|
||||||
name,
|
name,
|
||||||
ModuleHeader {
|
ModuleHeader {
|
||||||
|
@ -4753,7 +4753,7 @@ fn build_header<'a>(
|
||||||
module_timing,
|
module_timing,
|
||||||
defined_values,
|
defined_values,
|
||||||
},
|
},
|
||||||
)
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> BuildTask<'a> {
|
impl<'a> BuildTask<'a> {
|
||||||
|
@ -5280,7 +5280,7 @@ fn build_package_header<'a>(
|
||||||
header: &PackageHeader<'a>,
|
header: &PackageHeader<'a>,
|
||||||
comments: &'a [CommentOrNewline<'a>],
|
comments: &'a [CommentOrNewline<'a>],
|
||||||
module_timing: ModuleTiming,
|
module_timing: ModuleTiming,
|
||||||
) -> (ModuleId, PQModuleName<'a>, ModuleHeader<'a>) {
|
) -> Result<(ModuleId, PQModuleName<'a>, ModuleHeader<'a>), LoadingProblem<'a>> {
|
||||||
let exposes = bumpalo::collections::Vec::from_iter_in(
|
let exposes = bumpalo::collections::Vec::from_iter_in(
|
||||||
unspace(arena, header.exposes.item.items).iter().copied(),
|
unspace(arena, header.exposes.item.items).iter().copied(),
|
||||||
arena,
|
arena,
|
||||||
|
@ -5331,7 +5331,7 @@ fn build_platform_header<'a>(
|
||||||
header: &PlatformHeader<'a>,
|
header: &PlatformHeader<'a>,
|
||||||
comments: &'a [CommentOrNewline<'a>],
|
comments: &'a [CommentOrNewline<'a>],
|
||||||
module_timing: ModuleTiming,
|
module_timing: ModuleTiming,
|
||||||
) -> (ModuleId, PQModuleName<'a>, ModuleHeader<'a>) {
|
) -> Result<(ModuleId, PQModuleName<'a>, ModuleHeader<'a>), LoadingProblem<'a>> {
|
||||||
// If we have an app module, then it's the root module;
|
// If we have an app module, then it's the root module;
|
||||||
// otherwise, we must be the root.
|
// otherwise, we must be the root.
|
||||||
let is_root_module = opt_app_module_id.is_none();
|
let is_root_module = opt_app_module_id.is_none();
|
||||||
|
@ -5681,13 +5681,38 @@ fn exposed_from_import<'a>(
|
||||||
fn value_def_from_imports<'a>(
|
fn value_def_from_imports<'a>(
|
||||||
arena: &'a Bump,
|
arena: &'a Bump,
|
||||||
entry: &Loc<ImportsEntry<'a>>,
|
entry: &Loc<ImportsEntry<'a>>,
|
||||||
) -> Option<ValueDef<'a>> {
|
) -> Result<Option<ValueDef<'a>>, LoadingProblem<'a>> {
|
||||||
use roc_parse::header::ImportsEntry::*;
|
use roc_parse::header::ImportsEntry::*;
|
||||||
|
|
||||||
match entry.value {
|
let value = match entry.value {
|
||||||
Module(_, _) => None,
|
Module(_, _) => None,
|
||||||
Package(_, _, _) => None,
|
Package(_, _, _) => None,
|
||||||
IngestedFile(file_name, typed_ident) => {
|
IngestedFile(file_name, typed_ident) => {
|
||||||
|
if let StrLiteral::PlainLine(file_name) = file_name {
|
||||||
|
// TODO: This check should be relative to the current module location.
|
||||||
|
let file_path = Path::new(file_name);
|
||||||
|
match fs::metadata(file_path) {
|
||||||
|
Ok(md) => {
|
||||||
|
if !md.is_file() {
|
||||||
|
// TODO: is there a better loading problem to return when not a file.
|
||||||
|
return Err(LoadingProblem::FileProblem {
|
||||||
|
filename: file_path.to_path_buf(),
|
||||||
|
error: io::ErrorKind::InvalidInput,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
return Err(LoadingProblem::FileProblem {
|
||||||
|
filename: file_path.to_path_buf(),
|
||||||
|
error: e.kind(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
todo!(
|
||||||
|
"Only plain strings are supported. Other cases should be made impossible here"
|
||||||
|
);
|
||||||
|
}
|
||||||
let typed_ident = typed_ident.extract_spaces().item;
|
let typed_ident = typed_ident.extract_spaces().item;
|
||||||
let ident = arena.alloc(typed_ident.ident.map_owned(Pattern::Identifier));
|
let ident = arena.alloc(typed_ident.ident.map_owned(Pattern::Identifier));
|
||||||
Some(ValueDef::AnnotatedBody {
|
Some(ValueDef::AnnotatedBody {
|
||||||
|
@ -5698,7 +5723,9 @@ fn value_def_from_imports<'a>(
|
||||||
body_expr: arena.alloc(entry.with_value(Expr::IngestedFile(file_name.to_owned()))),
|
body_expr: arena.alloc(entry.with_value(Expr::IngestedFile(file_name.to_owned()))),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
|
Ok(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ident_from_exposed(entry: &Spaced<'_, ExposedName<'_>>) -> Ident {
|
fn ident_from_exposed(entry: &Spaced<'_, ExposedName<'_>>) -> Ident {
|
||||||
|
|
|
@ -664,6 +664,7 @@ fn imports_entry<'a>() -> impl Parser<'a, Spaced<'a, ImportsEntry<'a>>, EImports
|
||||||
specialize(|_, pos| EImports::TypedIdent(pos), typed_ident())
|
specialize(|_, pos| EImports::TypedIdent(pos), typed_ident())
|
||||||
),
|
),
|
||||||
|((file_name, _), typed_ident)| {
|
|((file_name, _), typed_ident)| {
|
||||||
|
// TODO: look at blacking block strings during parsing.
|
||||||
Spaced::Item(ImportsEntry::IngestedFile(file_name, typed_ident))
|
Spaced::Item(ImportsEntry::IngestedFile(file_name, typed_ident))
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -4,4 +4,4 @@ app "helloWorld"
|
||||||
provides [main] to pf
|
provides [main] to pf
|
||||||
|
|
||||||
main =
|
main =
|
||||||
Stdout.line file
|
Stdout.line "Hello, World!"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue