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:
Ayaz Hafiz 2023-01-11 14:20:47 -06:00
parent 7febddd1ea
commit 058644aa96
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
3 changed files with 53 additions and 44 deletions

View file

@ -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)