From 561f3d9711645f511a055d5dba56e95803ffa31c Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Wed, 1 Jan 2025 23:12:35 -0600 Subject: [PATCH] Store lambda set variables as flex inference variables This is actually correct - the rigid approach is not. Lambda set variables should be inferred in-scope. --- crates/compiler/constrain/src/expr.rs | 15 ++++++--------- .../calls_result_in_unique_specializations.txt | 2 +- ...ursive_annotation_independently_issue_5256.txt | 4 ++-- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/crates/compiler/constrain/src/expr.rs b/crates/compiler/constrain/src/expr.rs index 0e7254d950c..f628ba42b13 100644 --- a/crates/compiler/constrain/src/expr.rs +++ b/crates/compiler/constrain/src/expr.rs @@ -3808,9 +3808,9 @@ 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 @@ -3818,9 +3818,8 @@ fn instantiate_rigids( .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() { @@ -3900,12 +3899,8 @@ 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> = introduced_vars.inferred.clone(); - // ext-infer vars are always freshly introduced in this annotation new_infer_variables.extend( introduced_vars @@ -3913,6 +3908,8 @@ fn instantiate_rigids_simple( .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() { diff --git a/crates/compiler/uitest/tests/recursion/calls_result_in_unique_specializations.txt b/crates/compiler/uitest/tests/recursion/calls_result_in_unique_specializations.txt index 94dc9e3d5d0..5f8d20fae3f 100644 --- a/crates/compiler/uitest/tests/recursion/calls_result_in_unique_specializations.txt +++ b/crates/compiler/uitest/tests/recursion/calls_result_in_unique_specializations.txt @@ -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 diff --git a/crates/compiler/uitest/tests/recursion/constrain_recursive_annotation_independently_issue_5256.txt b/crates/compiler/uitest/tests/recursion/constrain_recursive_annotation_independently_issue_5256.txt index 537ed97f2a9..433d4aef27a 100644 --- a/crates/compiler/uitest/tests/recursion/constrain_recursive_annotation_independently_issue_5256.txt +++ b/crates/compiler/uitest/tests/recursion/constrain_recursive_annotation_independently_issue_5256.txt @@ -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 }