Skip to content

Commit

Permalink
Store lambda set variables as flex inference variables
Browse files Browse the repository at this point in the history
This is actually correct - the rigid approach is not. Lambda set
variables should be inferred in-scope.
  • Loading branch information
ayazhafiz committed Jan 6, 2025
1 parent 54cc5e4 commit 561f3d9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
15 changes: 6 additions & 9 deletions crates/compiler/constrain/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3808,19 +3808,18 @@ fn instantiate_rigids(
// wildcards are always freshly introduced in this annotation
new_rigid_variables.extend(introduced_vars.wildcards.iter().copied());

// lambda set vars are always freshly introduced in this annotation
new_rigid_variables.extend(introduced_vars.lambda_sets.iter().map(|&v| Loc::at_zero(v)));
let has_explicit_inference_variables = !introduced_vars.inferred.is_empty();

new_infer_variables.extend(introduced_vars.inferred.iter().copied());
// ext-infer vars are always freshly introduced in this annotation
new_infer_variables.extend(
introduced_vars
.infer_ext_in_output
.iter()
.map(|&v| Loc::at_zero(v)),
);

let has_explicit_inference_variables = !introduced_vars.inferred.is_empty();
new_infer_variables.extend(introduced_vars.inferred.iter().copied());
// lambda set vars are always freshly introduced in this annotation
new_infer_variables.extend(introduced_vars.lambda_sets.iter().map(|&v| Loc::at_zero(v)));

// Instantiate rigid variables
if !rigid_substitution.is_empty() {
Expand Down Expand Up @@ -3900,19 +3899,17 @@ fn instantiate_rigids_simple(
// wildcards are always freshly introduced in this annotation
new_rigid_variables.extend(introduced_vars.wildcards.iter().copied());

// lambda set vars are always freshly introduced in this annotation
new_rigid_variables.extend(introduced_vars.lambda_sets.iter().map(|&v| Loc::at_zero(v)));

let has_explicit_inference_variables = !introduced_vars.inferred.is_empty();
let mut new_infer_variables: Vec<Loc<Variable>> = introduced_vars.inferred.clone();

// ext-infer vars are always freshly introduced in this annotation
new_infer_variables.extend(
introduced_vars
.infer_ext_in_output
.iter()
.map(|&v| Loc::at_zero(v)),
);
// lambda set vars are always freshly introduced in this annotation
new_infer_variables.extend(introduced_vars.lambda_sets.iter().map(|&v| Loc::at_zero(v)));

// Instantiate rigid variables
if !rigid_substitution.is_empty() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ main =
# ^^^ a, Bool -[[foo(1)]]-> Str

bar = \_ -> foo {} Bool.true
# ^^^ {}, Bool -[[]]-> Str
# ^^^ {}, Bool -[[foo(1)]]-> Str

foo "" Bool.false
# ^^^{inst} Str, Bool -[[foo(1)]]-> Str
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ main =

map : { f1: (I64 -> I64) } -> List I64
map = \{ f1 } -> List.concat [f1 1] (map { f1 })
# ^^^ { f1 : I64 -[[]]-> I64 } -[[map(2)]]-> List I64
# ^^^ { f1 : I64 -[[]]-> I64 } -[[map(2)]]-> List I64
# ^^^ { f1 : I64 -[[f(1)]]-> I64 } -[[map(2)]]-> List I64
# ^^^ { f1 : I64 -[[f(1)]]-> I64 } -[[map(2)]]-> List I64


map { f1: f }
Expand Down

0 comments on commit 561f3d9

Please sign in to comment.