mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
Implement weakening of variables introduced in branch patterns
Variables introduced in branch patterns should never be generalized in the new weakening model. This implements that. The strategy is: - when we have a let-binding that should be weakened, do not introduce its bound variables in a new (higher) rank - instead, introduce them at the current rank, and also solve the let-binding at the current rank - if any of those variables should then be generalized relative to the current rank, they will be so when the current rank is popped and generalized
This commit is contained in:
parent
7febddd1ea
commit
058644aa96
3 changed files with 53 additions and 44 deletions
|
@ -1055,18 +1055,8 @@ pub fn constrain_expr(
|
|||
pattern_headers,
|
||||
pattern_constraints,
|
||||
body_constraints,
|
||||
// NB(weakening): ideally we never explicitly mark generalizability here, but we
|
||||
// must currently do so to handle cases like
|
||||
//
|
||||
// ```
|
||||
// \x -> when x is
|
||||
// Red -> Red
|
||||
// ```
|
||||
//
|
||||
// because we ultimately want `[Red]*` to be generalized at the level the function
|
||||
// argument `x` is and not pulled down into a lower rank. However we don't yet have
|
||||
// a way to express that requirement.
|
||||
Generalizable(true),
|
||||
// Never generalize identifiers introduced in branch-patterns
|
||||
Generalizable(false),
|
||||
);
|
||||
|
||||
let result_con =
|
||||
|
@ -2293,18 +2283,8 @@ fn constrain_when_branch_help(
|
|||
[],
|
||||
guard_constraint,
|
||||
ret_constraint,
|
||||
// NB(weakening): ideally we never explicitly mark generalizability here, but we
|
||||
// must currently do so to handle cases like
|
||||
//
|
||||
// ```
|
||||
// \x -> when x is
|
||||
// Red -> Red
|
||||
// ```
|
||||
//
|
||||
// because we ultimately want `[Red]*` to be generalized at the level the function
|
||||
// argument `x` is and not pulled down into a lower rank. However we don't yet have
|
||||
// a way to express that requirement.
|
||||
Generalizable(true),
|
||||
// Never generalize identifiers introduced in branch guards
|
||||
Generalizable(false),
|
||||
);
|
||||
|
||||
(state_constraints, delayed_is_open_constraints, inner)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue