mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 21:39:07 +00:00
Load and can new top-level imports
Previously, all imports were available in the header, so we could start processing dependencies as soon as we parsed it. However, the new imports are treated as defs, so we have to parse the whole module to find them. This commit essentially moves the dependency resolution from the `LoadHeader` phase to the `Parse` phase, and it updates canonicalization to introduce module symbols into scope when a `ValueDef::ModuleImport` is encountered. NOTE: - The `imports` header still parses, but it's no longer wired up. I will remove it in an upcoming commit. - Ingested files and imports that appear in nested expressions are not yet supported by load
This commit is contained in:
parent
11e0202eb9
commit
710d62f754
43 changed files with 683 additions and 771 deletions
|
@ -251,6 +251,12 @@ fn generate_entry_docs(
|
|||
ValueDef::ExpectFx { .. } => {
|
||||
// Don't generate docs for `expect-fx`s
|
||||
}
|
||||
ValueDef::ModuleImport { .. } => {
|
||||
// Don't generate docs for module imports
|
||||
}
|
||||
ValueDef::IngestedFileImport { .. } => {
|
||||
// Don't generate docs for ingested file imports
|
||||
}
|
||||
},
|
||||
Ok(type_index) => match &defs.type_defs[type_index.index()] {
|
||||
TypeDef::Alias {
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -13,7 +13,7 @@ use roc_module::symbol::{
|
|||
};
|
||||
use roc_mono::ir::{GlueLayouts, HostExposedLambdaSets, LambdaSetId, Proc, ProcLayout, ProcsBase};
|
||||
use roc_mono::layout::{LayoutCache, STLayoutInterner};
|
||||
use roc_parse::ast::{CommentOrNewline, Defs, TypeAnnotation, ValueDef};
|
||||
use roc_parse::ast::{CommentOrNewline, Defs, TypeAnnotation};
|
||||
use roc_parse::header::{HeaderType, PackageName};
|
||||
use roc_region::all::{Loc, Region};
|
||||
use roc_solve::module::Solved;
|
||||
|
@ -83,19 +83,12 @@ pub(crate) struct ModuleHeader<'a> {
|
|||
pub(crate) module_id: ModuleId,
|
||||
pub(crate) module_path: PathBuf,
|
||||
pub(crate) is_root_module: bool,
|
||||
pub(crate) exposed_ident_ids: IdentIds,
|
||||
pub(crate) deps_by_name: MutMap<PQModuleName<'a>, ModuleId>,
|
||||
pub(crate) packages: MutMap<&'a str, PackageName<'a>>,
|
||||
pub(crate) imported_modules: MutMap<ModuleId, Region>,
|
||||
pub(crate) package_qualified_imported_modules: MutSet<PackageQualified<'a, ModuleId>>,
|
||||
pub(crate) exposes: Vec<Symbol>,
|
||||
pub(crate) exposed_imports: MutMap<Ident, (Symbol, Region)>,
|
||||
pub(crate) parse_state: roc_parse::state::State<'a>,
|
||||
pub(crate) header_type: HeaderType<'a>,
|
||||
pub(crate) header_comments: &'a [CommentOrNewline<'a>],
|
||||
pub(crate) symbols_from_requires: Vec<(Loc<Symbol>, Loc<TypeAnnotation<'a>>)>,
|
||||
pub(crate) module_timing: ModuleTiming,
|
||||
pub(crate) defined_values: Vec<ValueDef<'a>>,
|
||||
pub(crate) opt_shorthand: Option<&'a str>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -190,13 +183,16 @@ pub struct ParsedModule<'a> {
|
|||
pub src: &'a str,
|
||||
pub module_timing: ModuleTiming,
|
||||
pub deps_by_name: MutMap<PQModuleName<'a>, ModuleId>,
|
||||
pub imported_modules: MutMap<ModuleId, Region>,
|
||||
pub exposed_ident_ids: IdentIds,
|
||||
pub exposed_imports: MutMap<Ident, (Symbol, Region)>,
|
||||
pub parsed_defs: Defs<'a>,
|
||||
pub symbols_from_requires: Vec<(Loc<Symbol>, Loc<TypeAnnotation<'a>>)>,
|
||||
pub header_type: HeaderType<'a>,
|
||||
pub header_comments: &'a [CommentOrNewline<'a>],
|
||||
pub imported_modules: MutMap<ModuleId, Region>,
|
||||
pub package_qualified_imported_modules: MutSet<PackageQualified<'a, ModuleId>>,
|
||||
pub packages: MutMap<&'a str, PackageName<'a>>,
|
||||
pub initial_scope: MutMap<Ident, (Symbol, Region)>,
|
||||
pub exposes: Vec<Symbol>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
|
@ -162,10 +162,6 @@ impl<'a> Dependencies<'a> {
|
|||
output.insert((dep, Phase::LoadHeader));
|
||||
}
|
||||
|
||||
// to parse and generate constraints, the headers of all dependencies must be loaded!
|
||||
// otherwise, we don't know whether an imported symbol is actually exposed
|
||||
self.add_dependency_help(module_id, dep, Phase::Parse, Phase::LoadHeader);
|
||||
|
||||
// to canonicalize a module, all its dependencies must be canonicalized
|
||||
self.add_dependency(module_id, dep, Phase::CanonicalizeAndConstrain);
|
||||
|
||||
|
@ -427,10 +423,10 @@ impl<'a> Dependencies<'a> {
|
|||
PrepareStartPhase::Recurse(new)
|
||||
}
|
||||
None => match phase {
|
||||
Phase::LoadHeader => {
|
||||
// this is fine, mark header loading as pending
|
||||
Phase::LoadHeader | Phase::Parse => {
|
||||
// this is fine, mark as pending
|
||||
self.status
|
||||
.insert(Job::Step(module_id, Phase::LoadHeader), Status::Pending);
|
||||
.insert(Job::Step(module_id, phase), Status::Pending);
|
||||
|
||||
PrepareStartPhase::Continue
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue