This commit is contained in:
Luke Boswell 2024-11-11 10:22:58 +11:00
parent 743030fc99
commit 8a566dc339
No known key found for this signature in database
GPG key ID: F6DB3C9DB47377B0
260 changed files with 6344 additions and 2958 deletions

View file

@ -15,6 +15,7 @@ use parking_lot::Mutex;
use roc_builtins::roc::module_source;
use roc_can::abilities::{AbilitiesStore, PendingAbilitiesStore, ResolvedImpl};
use roc_can::constraint::{Constraint as ConstraintSoa, Constraints, TypeOrVar};
use roc_can::env::FxMode;
use roc_can::expr::{DbgLookup, Declarations, ExpectLookup, PendingDerives};
use roc_can::module::{
canonicalize_module_defs, ExposedByModule, ExposedForModule, ExposedModuleTypes, Module,
@ -33,7 +34,7 @@ use roc_debug_flags::{
use roc_derive::SharedDerivedModule;
use roc_error_macros::internal_error;
use roc_late_solve::{AbilitiesView, WorldAbilities};
use roc_module::ident::{Ident, ModuleName, QualifiedModuleName};
use roc_module::ident::{Ident, IdentSuffix, ModuleName, QualifiedModuleName};
use roc_module::symbol::{
IdentIds, IdentIdsByModule, Interns, ModuleId, ModuleIds, PQModuleName, PackageModuleIds,
PackageQualified, Symbol,
@ -318,6 +319,7 @@ fn start_phase<'a>(
exposed_module_ids: state.exposed_modules,
exec_mode: state.exec_mode,
imported_module_params,
fx_mode: state.fx_mode,
}
}
@ -710,6 +712,7 @@ struct State<'a> {
pub platform_path: PlatformPath<'a>,
pub target: Target,
pub(self) function_kind: FunctionKind,
pub fx_mode: FxMode,
/// Note: only packages and platforms actually expose any modules;
/// for all others, this will be empty.
@ -797,6 +800,7 @@ impl<'a> State<'a> {
cache_dir,
target,
function_kind,
fx_mode: FxMode::Task,
platform_data: None,
platform_path: PlatformPath::NotSpecified,
module_cache: ModuleCache::default(),
@ -900,6 +904,7 @@ enum BuildTask<'a> {
skip_constraint_gen: bool,
exec_mode: ExecutionMode,
imported_module_params: VecMap<ModuleId, ModuleParams>,
fx_mode: FxMode,
},
Solve {
module: Module,
@ -2235,6 +2240,7 @@ fn update<'a>(
config_shorthand,
provides,
exposes_ids,
requires,
..
} => {
work.extend(state.dependencies.notify_package(config_shorthand));
@ -2269,6 +2275,12 @@ fn update<'a>(
if header.is_root_module {
state.exposed_modules = exposes_ids;
}
if requires.iter().any(|requires| {
IdentSuffix::from_name(requires.value.ident.value).is_bang()
}) {
state.fx_mode = FxMode::PurityInference;
}
}
Builtin { .. } | Module { .. } => {
if header.is_root_module {
@ -2276,11 +2288,18 @@ fn update<'a>(
state.platform_path = PlatformPath::RootIsModule;
}
}
Hosted { .. } => {
Hosted { exposes, .. } => {
if header.is_root_module {
debug_assert!(matches!(state.platform_path, PlatformPath::NotSpecified));
state.platform_path = PlatformPath::RootIsHosted;
}
if exposes
.iter()
.any(|exposed| exposed.value.is_effectful_fn())
{
state.fx_mode = FxMode::PurityInference;
}
}
}
@ -4394,7 +4413,12 @@ fn synth_list_len_type(subs: &mut Subs) -> Variable {
let fn_args_slice = slice_extend_new(&mut subs.variables, [list_a]);
subs.set_content(
fn_var,
Content::Structure(FlatType::Func(fn_args_slice, clos_list_len, Variable::U64)),
Content::Structure(FlatType::Func(
fn_args_slice,
clos_list_len,
Variable::U64,
Variable::PURE,
)),
);
fn_var
}
@ -5050,6 +5074,7 @@ fn canonicalize_and_constrain<'a>(
exposed_module_ids: &[ModuleId],
exec_mode: ExecutionMode,
imported_module_params: VecMap<ModuleId, ModuleParams>,
fx_mode: FxMode,
) -> CanAndCon {
let canonicalize_start = Instant::now();
@ -5093,6 +5118,7 @@ fn canonicalize_and_constrain<'a>(
&symbols_from_requires,
&mut var_store,
opt_shorthand,
fx_mode,
);
let mut types = Types::new();
@ -6276,6 +6302,7 @@ fn run_task<'a>(
exposed_module_ids,
exec_mode,
imported_module_params,
fx_mode,
} => {
let can_and_con = canonicalize_and_constrain(
arena,
@ -6289,6 +6316,7 @@ fn run_task<'a>(
exposed_module_ids,
exec_mode,
imported_module_params,
fx_mode,
);
Ok(Msg::CanonicalizedAndConstrained(can_and_con))