Switch fx mode based on platform main too

This commit is contained in:
Agus Zubiaga 2024-10-16 15:30:49 -03:00
parent 2c8571537e
commit b80f44738f
No known key found for this signature in database
4 changed files with 19 additions and 15 deletions

View file

@ -34,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,
@ -2235,6 +2235,7 @@ fn update<'a>(
config_shorthand,
provides,
exposes_ids,
requires,
..
} => {
work.extend(state.dependencies.notify_package(config_shorthand));
@ -2269,6 +2270,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 {
@ -2286,17 +2293,6 @@ fn update<'a>(
.iter()
.any(|exposed| exposed.value.is_effectful_fn())
{
if exposes
.iter()
.any(|exposed| !exposed.value.is_effectful_fn())
{
// Temporary error message while we transition platforms
return Err(LoadingProblem::FormattedReport(
"Hosted module must not mix effectful and Task functions"
.to_string(),
));
}
state.fx_mode = FxMode::PurityInference;
}
}

View file

@ -386,7 +386,14 @@ impl IdentSuffix {
}
}
pub fn is_suffixed(&self) -> bool {
pub fn is_none(&self) -> bool {
match self {
IdentSuffix::None => true,
IdentSuffix::Bang => false,
}
}
pub fn is_bang(&self) -> bool {
match self {
IdentSuffix::None => false,
IdentSuffix::Bang => true,

View file

@ -1068,7 +1068,7 @@ macro_rules! define_builtins {
// or `if false` and will get optimized out.
debug_assert_eq!($exposed_apply_type, $ident_name.chars().next().unwrap().is_uppercase());
// Types should not be suffixed
debug_assert!(!IdentSuffix::from_name($ident_name).is_suffixed());
debug_assert!(IdentSuffix::from_name($ident_name).is_none());
if $exposed_apply_type {
scope.insert($ident_name.into(), (Symbol::new(ModuleId::$module_const, IdentId::from_index($ident_id, IdentSuffix::None)), Region::zero()));

View file

@ -19,6 +19,7 @@ use crate::pattern::record_pattern_fields;
use crate::state::State;
use crate::string_literal::{self, parse_str_literal};
use crate::type_annotation;
use roc_module::ident::IdentSuffix;
use roc_module::symbol::ModuleId;
use roc_region::all::{Loc, Position, Region};
@ -1134,7 +1135,7 @@ impl<'a> ExposedName<'a> {
}
pub fn is_effectful_fn(&self) -> bool {
self.0.ends_with('!')
IdentSuffix::from_name(self.0).is_bang()
}
}