mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 20:28:02 +00:00
Mark flex fx vars as pure after solving body
This commit is contained in:
parent
89a918cebe
commit
2859829ea8
3 changed files with 33 additions and 0 deletions
|
@ -623,6 +623,7 @@ impl Constraints {
|
|||
| Constraint::Pattern(..)
|
||||
| Constraint::EffectfulStmt(..)
|
||||
| Constraint::FxCall(_)
|
||||
| Constraint::FlexToPure(_)
|
||||
| Constraint::True
|
||||
| Constraint::IsOpenType(_)
|
||||
| Constraint::IncludesTag(_)
|
||||
|
@ -797,6 +798,8 @@ pub enum Constraint {
|
|||
),
|
||||
/// Check call fx against enclosing function fx
|
||||
FxCall(Index<FxCallConstraint>),
|
||||
/// Mark a function that doesn't call any effectful functions as pure
|
||||
FlexToPure(Variable),
|
||||
/// Expect statement to be effectful
|
||||
EffectfulStmt(Variable, Region),
|
||||
/// Used for things that always unify, e.g. blanks and runtime errors
|
||||
|
@ -913,6 +916,9 @@ impl std::fmt::Debug for Constraint {
|
|||
Self::EffectfulStmt(arg0, arg1) => {
|
||||
write!(f, "EffectfulStmt({arg0:?}, {arg1:?})")
|
||||
}
|
||||
Self::FlexToPure(arg0) => {
|
||||
write!(f, "FlexToPure({arg0:?})")
|
||||
}
|
||||
Self::True => write!(f, "True"),
|
||||
Self::SaveTheEnvironment => write!(f, "SaveTheEnvironment"),
|
||||
Self::Let(arg0, arg1) => f.debug_tuple("Let").field(arg0).field(arg1).finish(),
|
||||
|
|
|
@ -243,6 +243,7 @@ fn constrain_untyped_closure(
|
|||
),
|
||||
early_returns_constraint,
|
||||
closure_constraint,
|
||||
Constraint::FlexToPure(fx_var),
|
||||
];
|
||||
|
||||
constraints.exists_many(vars, cons)
|
||||
|
@ -3042,6 +3043,7 @@ fn constrain_typed_def(
|
|||
constraints.store(signature_index, *fn_var, std::file!(), std::line!()),
|
||||
constraints.store(signature_index, expr_var, std::file!(), std::line!()),
|
||||
closure_constraint,
|
||||
Constraint::FlexToPure(fx_var),
|
||||
];
|
||||
|
||||
let expr_con = constraints.exists_many(vars, cons);
|
||||
|
@ -4022,6 +4024,7 @@ fn constraint_recursive_function(
|
|||
constraints.store(signature_index, expr_var, std::file!(), std::line!()),
|
||||
constraints.store(ret_type_index, ret_var, std::file!(), std::line!()),
|
||||
closure_constraint,
|
||||
Constraint::FlexToPure(fx_var),
|
||||
];
|
||||
|
||||
let and_constraint = constraints.and_constraint(cons);
|
||||
|
|
|
@ -851,6 +851,30 @@ fn solve(
|
|||
}
|
||||
}
|
||||
}
|
||||
FlexToPure(variable) => {
|
||||
let content = env.subs.get_content_without_compacting(*variable);
|
||||
|
||||
match content {
|
||||
Content::FlexVar(_) => {
|
||||
let desc = env.subs.get(Variable::PURE);
|
||||
env.subs.union(*variable, Variable::PURE, desc);
|
||||
|
||||
state
|
||||
}
|
||||
Content::Pure | Content::Effectful | Content::Error => state,
|
||||
Content::RigidVar(_)
|
||||
| Content::FlexAbleVar(_, _)
|
||||
| Content::RigidAbleVar(_, _)
|
||||
| Content::RecursionVar { .. }
|
||||
| Content::LambdaSet(_)
|
||||
| Content::ErasedLambda
|
||||
| Content::Structure(_)
|
||||
| Content::Alias(_, _, _, _)
|
||||
| Content::RangedNumber(_) => {
|
||||
internal_error!("FlexToPure: unexpected content: {:?}", content)
|
||||
}
|
||||
}
|
||||
}
|
||||
Let(index, pool_slice) => {
|
||||
let let_con = &env.constraints.let_constraints[index.index()];
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue