mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 04:08:19 +00:00
Treat untyped suffixed functions as effectful
This commit is contained in:
parent
af6fc6306f
commit
cfc4be5254
25 changed files with 139 additions and 21 deletions
|
@ -15,6 +15,7 @@ use roc_module::symbol::{Interns, ModuleId, Symbol};
|
|||
pub static WILDCARD: &str = "*";
|
||||
static EMPTY_RECORD: &str = "{}";
|
||||
static EMPTY_TAG_UNION: &str = "[]";
|
||||
static EFFECTFUL_FUNC: &str = "! : ... => ?";
|
||||
|
||||
/// Requirements for parentheses.
|
||||
///
|
||||
|
@ -217,6 +218,7 @@ fn find_names_needed(
|
|||
find_under_alias,
|
||||
);
|
||||
}
|
||||
Structure(EffectfulFunc) => {}
|
||||
Structure(Record(sorted_fields, ext_var)) => {
|
||||
for index in sorted_fields.iter_variables() {
|
||||
let var = subs[index];
|
||||
|
@ -1139,6 +1141,7 @@ fn write_flat_type<'a>(
|
|||
parens,
|
||||
pol,
|
||||
),
|
||||
EffectfulFunc => buf.push_str(EFFECTFUL_FUNC),
|
||||
Record(fields, ext_var) => {
|
||||
use crate::types::{gather_fields, RecordStructure};
|
||||
|
||||
|
|
|
@ -833,6 +833,7 @@ fn subs_fmt_flat_type(this: &FlatType, subs: &Subs, f: &mut fmt::Formatter) -> f
|
|||
}
|
||||
FlatType::EmptyRecord => write!(f, "EmptyRecord"),
|
||||
FlatType::EmptyTagUnion => write!(f, "EmptyTagUnion"),
|
||||
FlatType::EffectfulFunc => write!(f, "EffectfulFunc"),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2584,6 +2585,8 @@ impl TagExt {
|
|||
pub enum FlatType {
|
||||
Apply(Symbol, VariableSubsSlice),
|
||||
Func(VariableSubsSlice, Variable, Variable, Variable),
|
||||
/// A function that we know nothing about yet except that it's effectful
|
||||
EffectfulFunc,
|
||||
Record(RecordFields, Variable),
|
||||
Tuple(TupleElems, Variable),
|
||||
TagUnion(UnionTags, TagExt),
|
||||
|
@ -3492,7 +3495,7 @@ fn occurs(
|
|||
|
||||
short_circuit_help(subs, root_var, ctx, ext_var)
|
||||
}
|
||||
EmptyRecord | EmptyTagUnion => Ok(()),
|
||||
EmptyRecord | EmptyTagUnion | EffectfulFunc => Ok(()),
|
||||
},
|
||||
Alias(_, args, _, _) => {
|
||||
// THEORY: we only need to explore the args, as that is the surface of all
|
||||
|
@ -3686,7 +3689,7 @@ fn explicit_substitute(
|
|||
subs.set_content(in_var, Structure(Tuple(vars_by_elem, new_ext)));
|
||||
}
|
||||
|
||||
EmptyRecord | EmptyTagUnion => {}
|
||||
EmptyRecord | EmptyTagUnion | EffectfulFunc => {}
|
||||
}
|
||||
|
||||
in_var
|
||||
|
@ -3872,7 +3875,9 @@ fn get_var_names(
|
|||
accum
|
||||
}
|
||||
|
||||
FlatType::EmptyRecord | FlatType::EmptyTagUnion => taken_names,
|
||||
FlatType::EmptyRecord | FlatType::EmptyTagUnion | FlatType::EffectfulFunc => {
|
||||
taken_names
|
||||
}
|
||||
|
||||
FlatType::Record(vars_by_field, ext) => {
|
||||
let mut accum = get_var_names(subs, ext, taken_names);
|
||||
|
@ -4236,6 +4241,7 @@ fn flat_type_to_err_type(
|
|||
ErrorType::Function(args, Box::new(closure), fx, Box::new(ret))
|
||||
}
|
||||
|
||||
EffectfulFunc => ErrorType::EffectfulFunc,
|
||||
EmptyRecord => ErrorType::Record(SendMap::default(), TypeExt::Closed),
|
||||
EmptyTagUnion => ErrorType::TagUnion(SendMap::default(), TypeExt::Closed, pol),
|
||||
|
||||
|
@ -4694,6 +4700,7 @@ impl StorageSubs {
|
|||
),
|
||||
FlatType::EmptyRecord => FlatType::EmptyRecord,
|
||||
FlatType::EmptyTagUnion => FlatType::EmptyTagUnion,
|
||||
FlatType::EffectfulFunc => FlatType::EffectfulFunc,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5084,6 +5091,8 @@ fn storage_copy_var_to_help(env: &mut StorageCopyVarToEnv<'_>, var: Variable) ->
|
|||
|
||||
RecursiveTagUnion(new_rec_var, union_tags, new_ext)
|
||||
}
|
||||
|
||||
EffectfulFunc => EffectfulFunc,
|
||||
};
|
||||
|
||||
env.target
|
||||
|
@ -5552,6 +5561,7 @@ fn copy_import_to_help(env: &mut CopyImportEnv<'_>, max_rank: Rank, var: Variabl
|
|||
|
||||
RecursiveTagUnion(new_rec_var, union_tags, new_ext)
|
||||
}
|
||||
EffectfulFunc => EffectfulFunc,
|
||||
};
|
||||
|
||||
env.target
|
||||
|
@ -5890,6 +5900,8 @@ fn instantiate_rigids_help(subs: &mut Subs, max_rank: Rank, initial: Variable) {
|
|||
stack.push(ext.var());
|
||||
stack.push(rec_var);
|
||||
}
|
||||
|
||||
EffectfulFunc => {}
|
||||
},
|
||||
Alias(_, args, var, _) => {
|
||||
let var = *var;
|
||||
|
@ -5997,7 +6009,7 @@ pub fn get_member_lambda_sets_at_region(subs: &Subs, var: Variable, target_regio
|
|||
);
|
||||
stack.push(ext.var());
|
||||
}
|
||||
FlatType::EmptyRecord | FlatType::EmptyTagUnion => {}
|
||||
FlatType::EffectfulFunc | FlatType::EmptyRecord | FlatType::EmptyTagUnion => {}
|
||||
},
|
||||
Content::Alias(_, _, real_var, _) => {
|
||||
stack.push(*real_var);
|
||||
|
@ -6073,6 +6085,7 @@ fn is_inhabited(subs: &Subs, var: Variable) -> bool {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
FlatType::EffectfulFunc => {}
|
||||
FlatType::FunctionOrTagUnion(_, _, _) => {}
|
||||
FlatType::EmptyRecord => {}
|
||||
FlatType::EmptyTagUnion => {
|
||||
|
|
|
@ -3660,6 +3660,7 @@ pub enum ErrorType {
|
|||
/// If the name was auto-generated, it will start with a `#`.
|
||||
FlexVar(Lowercase),
|
||||
RigidVar(Lowercase),
|
||||
EffectfulFunc,
|
||||
/// If the name was auto-generated, it will start with a `#`.
|
||||
FlexAbleVar(Lowercase, AbilitySet),
|
||||
RigidAbleVar(Lowercase, AbilitySet),
|
||||
|
@ -3750,6 +3751,7 @@ impl ErrorType {
|
|||
t.add_names(taken);
|
||||
});
|
||||
}
|
||||
EffectfulFunc => {}
|
||||
Error => {}
|
||||
}
|
||||
}
|
||||
|
@ -3902,6 +3904,7 @@ fn write_debug_error_type_help(error_type: ErrorType, buf: &mut String, parens:
|
|||
buf.push(')');
|
||||
}
|
||||
}
|
||||
EffectfulFunc => buf.push_str("EffectfulFunc"),
|
||||
Type(symbol, arguments) => {
|
||||
let write_parens = parens == Parens::InTypeParam && !arguments.is_empty();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue