Merge branch 'trunk' into list-map-ownership

This commit is contained in:
Folkert de Vries 2022-05-07 11:59:51 +02:00 committed by GitHub
commit 201d09d9bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
71 changed files with 2250 additions and 2560 deletions

View file

@ -30,7 +30,7 @@ use roc_mono::ir::{
UpdateModeIds,
};
use roc_mono::layout::{Layout, LayoutCache, LayoutProblem};
use roc_parse::ast::{self, ExtractSpaces, Spaced, StrLiteral};
use roc_parse::ast::{self, ExtractSpaces, Spaced, StrLiteral, TypeAnnotation};
use roc_parse::header::{ExposedName, ImportsEntry, PackageEntry, PlatformHeader, To, TypedIdent};
use roc_parse::header::{HeaderFor, ModuleNameEnum, PackageName};
use roc_parse::ident::UppercaseIdent;
@ -512,8 +512,9 @@ struct ModuleHeader<'a> {
exposes: Vec<Symbol>,
exposed_imports: MutMap<Ident, (Symbol, Region)>,
parse_state: roc_parse::state::State<'a>,
module_timing: ModuleTiming,
header_for: HeaderFor<'a>,
symbols_from_requires: Vec<(Loc<Symbol>, Loc<TypeAnnotation<'a>>)>,
module_timing: ModuleTiming,
}
#[derive(Debug)]
@ -603,6 +604,7 @@ struct ParsedModule<'a> {
exposed_imports: MutMap<Ident, (Symbol, Region)>,
parsed_defs: &'a [Loc<roc_parse::ast::Def<'a>>],
module_name: ModuleNameEnum<'a>,
symbols_from_requires: Vec<(Loc<Symbol>, Loc<TypeAnnotation<'a>>)>,
header_for: HeaderFor<'a>,
}
@ -948,6 +950,7 @@ fn enqueue_task<'a>(
Ok(())
}
#[allow(clippy::too_many_arguments)]
pub fn load_and_typecheck_str<'a>(
arena: &'a Bump,
filename: PathBuf,
@ -956,6 +959,7 @@ pub fn load_and_typecheck_str<'a>(
exposed_types: ExposedByModule,
target_info: TargetInfo,
render: RenderTarget,
threading: Threading,
) -> Result<LoadedModule, LoadingProblem<'a>> {
use LoadResult::*;
@ -974,6 +978,7 @@ pub fn load_and_typecheck_str<'a>(
target_info,
cached_subs,
render,
threading,
)? {
Monomorphized(_) => unreachable!(""),
TypeChecked(module) => Ok(module),
@ -1091,6 +1096,12 @@ pub enum LoadResult<'a> {
Monomorphized(MonomorphizedModule<'a>),
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum Threading {
Single,
Multi,
}
/// The loading process works like this, starting from the given filename (e.g. "main.roc"):
///
/// 1. Open the file.
@ -1144,10 +1155,11 @@ pub fn load<'a>(
target_info: TargetInfo,
cached_subs: MutMap<ModuleId, (Subs, Vec<(Symbol, Variable)>)>,
render: RenderTarget,
threading: Threading,
) -> Result<LoadResult<'a>, LoadingProblem<'a>> {
// When compiling to wasm, we cannot spawn extra threads
// so we have a single-threaded implementation
if cfg!(target_family = "wasm") {
if threading == Threading::Single || cfg!(target_family = "wasm") {
load_single_threaded(
arena,
load_start,
@ -3234,8 +3246,9 @@ fn send_header<'a>(
exposes: exposed,
parse_state,
exposed_imports: scope,
module_timing,
symbols_from_requires: Vec::new(),
header_for: extra,
module_timing,
}),
)
}
@ -3275,6 +3288,7 @@ fn send_header_two<'a>(
} = info;
let declared_name: ModuleName = "".into();
let mut symbols_from_requires = Vec::with_capacity(requires.len());
let mut imported: Vec<(QualifiedModuleName, Vec<Ident>, Region)> =
Vec::with_capacity(imports.len());
@ -3378,6 +3392,7 @@ fn send_header_two<'a>(
debug_assert!(!scope.contains_key(&ident.clone()));
scope.insert(ident, (symbol, entry.ident.region));
symbols_from_requires.push((Loc::at(entry.ident.region, symbol), entry.ann));
}
for entry in requires_types {
@ -3477,6 +3492,7 @@ fn send_header_two<'a>(
parse_state,
exposed_imports: scope,
module_timing,
symbols_from_requires,
header_for: extra,
}),
)
@ -3820,6 +3836,7 @@ fn canonicalize_and_constrain<'a>(
exposed_imports,
imported_modules,
mut module_timing,
symbols_from_requires,
..
} = parsed;
@ -3837,6 +3854,7 @@ fn canonicalize_and_constrain<'a>(
aliases,
exposed_imports,
&exposed_symbols,
&symbols_from_requires,
&mut var_store,
);
@ -3881,6 +3899,7 @@ fn canonicalize_and_constrain<'a>(
} else {
constrain_module(
&mut constraints,
module_output.symbols_from_requires,
&module_output.scope.abilities_store,
&module_output.declarations,
module_id,
@ -3992,6 +4011,7 @@ fn parse<'a>(arena: &'a Bump, header: ModuleHeader<'a>) -> Result<Msg<'a>, Loadi
exposed_imports,
module_path,
header_for,
symbols_from_requires,
..
} = header;
@ -4006,6 +4026,7 @@ fn parse<'a>(arena: &'a Bump, header: ModuleHeader<'a>) -> Result<Msg<'a>, Loadi
exposed_ident_ids,
exposed_imports,
parsed_defs,
symbols_from_requires,
header_for,
};