From 9877224678259dced912bce144f179d1e1d65ae3 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Mon, 1 Aug 2022 16:49:27 -0500 Subject: [PATCH 1/3] Turn on deriver tests that work again Blocked on #3643 --- crates/compiler/test_derive/src/encoding.rs | 86 +++++++++++++-------- 1 file changed, 52 insertions(+), 34 deletions(-) diff --git a/crates/compiler/test_derive/src/encoding.rs b/crates/compiler/test_derive/src/encoding.rs index 023a996ac0..839dc99e79 100644 --- a/crates/compiler/test_derive/src/encoding.rs +++ b/crates/compiler/test_derive/src/encoding.rs @@ -588,7 +588,6 @@ fn one_field_record() { } #[test] -#[ignore = "TODO #3421 unification of unspecialized variables in lambda sets currently causes this to be derived incorrectly"] fn two_field_record() { derive_test(v!({ a: v!(U8), b: v!(STR), }), |golden| { assert_snapshot!(golden, @r###" @@ -600,11 +599,16 @@ fn two_field_record() { # @<2>: [[custom(2) { a : val, b : a }]] | a has Encoding, val has Encoding #Derived.toEncoder_{a,b} = \#Derived.rcd -> - Encode.custom \#Derived.bytes, #Derived.fmt -> - Encode.appendWith #Derived.bytes (Encode.record [ - { value: Encode.toEncoder #Derived.rcd.a, key: "a", }, - { value: Encode.toEncoder #Derived.rcd.b, key: "b", }, - ]) #Derived.fmt + Encode.custom + \#Derived.bytes, #Derived.fmt -> + Encode.appendWith + #Derived.bytes + (Encode.record + [ + { value: Encode.toEncoder #Derived.rcd.a, key: "a", }, + { value: Encode.toEncoder #Derived.rcd.b, key: "b", }, + ]) + #Derived.fmt "### ) }) @@ -647,7 +651,6 @@ fn tag_one_label_zero_args() { } #[test] -#[ignore = "TODO #3421 unification of unspecialized variables in lambda sets currently causes this to be derived incorrectly"] fn tag_one_label_two_args() { derive_test(v!([A v!(U8) v!(STR)]), |golden| { assert_snapshot!(golden, @r###" @@ -659,20 +662,25 @@ fn tag_one_label_two_args() { # @<2>: [[custom(4) [A val a]]] | a has Encoding, val has Encoding #Derived.toEncoder_[A 2] = \#Derived.tag -> - Encode.custom \#Derived.bytes, #Derived.fmt -> - Encode.appendWith #Derived.bytes (when #Derived.tag is - A #Derived.2 #Derived.3 -> - Encode.tag "A" [ - Encode.toEncoder #Derived.2, - Encode.toEncoder #Derived.3, - ]) #Derived.fmt + Encode.custom + \#Derived.bytes, #Derived.fmt -> + Encode.appendWith + #Derived.bytes + (when #Derived.tag is + A #Derived.2 #Derived.3 -> + Encode.tag + "A" + [ + Encode.toEncoder #Derived.2, + Encode.toEncoder #Derived.3, + ]) + #Derived.fmt "### ) }) } #[test] -#[ignore = "TODO #3421 unification of unspecialized variables in lambda sets currently causes this to be derived incorrectly"] fn tag_two_labels() { derive_test(v!([A v!(U8) v!(STR) v!(U16), B v!(STR)]), |golden| { assert_snapshot!(golden, @r###" @@ -684,23 +692,27 @@ fn tag_two_labels() { # @<2>: [[custom(6) [A val a b, B c]]] | a has Encoding, b has Encoding, c has Encoding, val has Encoding #Derived.toEncoder_[A 3,B 1] = \#Derived.tag -> - Encode.custom \#Derived.bytes, #Derived.fmt -> - Encode.appendWith #Derived.bytes (when #Derived.tag is - A #Derived.2 #Derived.3 #Derived.4 -> - Encode.tag "A" [ - Encode.toEncoder #Derived.2, - Encode.toEncoder #Derived.3, - Encode.toEncoder #Derived.4, - ] - B #Derived.5 -> Encode.tag "B" [Encode.toEncoder #Derived.5]) - #Derived.fmt + Encode.custom + \#Derived.bytes, #Derived.fmt -> + Encode.appendWith + #Derived.bytes + (when #Derived.tag is + A #Derived.2 #Derived.3 #Derived.4 -> + Encode.tag + "A" + [ + Encode.toEncoder #Derived.2, + Encode.toEncoder #Derived.3, + Encode.toEncoder #Derived.4, + ] + B #Derived.5 -> Encode.tag "B" [Encode.toEncoder #Derived.5]) + #Derived.fmt "### ) }) } #[test] -#[ignore = "TODO #3421 unification of unspecialized variables in lambda sets currently causes this to be derived incorrectly"] fn recursive_tag_union() { derive_test(v!([Nil, Cons v!(U8) v!(*lst) ] as lst), |golden| { assert_snapshot!(golden, @r###" @@ -712,14 +724,20 @@ fn recursive_tag_union() { # @<2>: [[custom(4) [Cons val a, Nil]]] | a has Encoding, val has Encoding #Derived.toEncoder_[Cons 2,Nil 0] = \#Derived.tag -> - Encode.custom \#Derived.bytes, #Derived.fmt -> - Encode.appendWith #Derived.bytes (when #Derived.tag is - Cons #Derived.2 #Derived.3 -> - Encode.tag "Cons" [ - Encode.toEncoder #Derived.2, - Encode.toEncoder #Derived.3, - ] - Nil -> Encode.tag "Nil" []) #Derived.fmt + Encode.custom + \#Derived.bytes, #Derived.fmt -> + Encode.appendWith + #Derived.bytes + (when #Derived.tag is + Cons #Derived.2 #Derived.3 -> + Encode.tag + "Cons" + [ + Encode.toEncoder #Derived.2, + Encode.toEncoder #Derived.3, + ] + Nil -> Encode.tag "Nil" []) + #Derived.fmt "### ) }) From 6ebb0bfa6df181d68f93f70a3163546958b0ee32 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 2 Aug 2022 14:27:53 -0500 Subject: [PATCH 2/3] Fix solve tests --- crates/compiler/solve/tests/solve_expr.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/compiler/solve/tests/solve_expr.rs b/crates/compiler/solve/tests/solve_expr.rs index 59b8550cf7..6bacc74603 100644 --- a/crates/compiler/solve/tests/solve_expr.rs +++ b/crates/compiler/solve/tests/solve_expr.rs @@ -7370,10 +7370,10 @@ mod solve_expr { E#k(10) : E -[[k(10)]]-> {} a : j | j has J b : j | j has J - it : k -[[] + j:j(2):2 + a:j(2):2]-> {} | a has J, j has J, k has K - J#j(2) : j -[[] + j:j(2):1]-> (k -[[] + j:j(2):2 + a:j(2):2]-> {}) | a has J, j has J, k has K - J#j(2) : j -[[] + j:j(2):1]-> (k -[[] + a:j(2):2 + j:j(2):2]-> {}) | a has J, j has J, k has K - it : k -[[] + j:j(2):2 + a:j(2):2]-> {} | a has J, j has J, k has K + it : k -[[] + j:j(2):2 + j1:j(2):2]-> {} | j has J, j1 has J, k has K + J#j(2) : j -[[] + j:j(2):1]-> (k -[[] + j:j(2):2 + j1:j(2):2]-> {}) | j has J, j1 has J, k has K + J#j(2) : j -[[] + j:j(2):1]-> (k -[[] + j1:j(2):2 + j:j(2):2]-> {}) | j has J, j1 has J, k has K + it : k -[[] + j:j(2):2 + j1:j(2):2]-> {} | j has J, j1 has J, k has K f : [A, B], C, D -[[f(11)]]-> (E -[[k(10)]]-> {}) f A (@C {}) (@D {}) : E -[[k(10)]]-> {} main : {} @@ -7439,10 +7439,10 @@ mod solve_expr { kF : F -[[kF(12)]]-> {} a : j | j has J b : j | j has J - it : k -[[] + j:j(2):2 + a:j(2):2]-> {} | a has J, j has J, k has K - J#j(2) : j -[[] + j:j(2):1]-> (k -[[] + j:j(2):2 + a:j(2):2]-> {}) | a has J, j has J, k has K - J#j(2) : j -[[] + j:j(2):1]-> (k -[[] + a:j(2):2 + j:j(2):2]-> {}) | a has J, j has J, k has K - it : k -[[] + j:j(2):2 + a:j(2):2]-> {} | a has J, j has J, k has K + it : k -[[] + j:j(2):2 + j1:j(2):2]-> {} | j has J, j1 has J, k has K + J#j(2) : j -[[] + j:j(2):1]-> (k -[[] + j:j(2):2 + j1:j(2):2]-> {}) | j has J, j1 has J, k has K + J#j(2) : j -[[] + j:j(2):1]-> (k -[[] + j1:j(2):2 + j:j(2):2]-> {}) | j has J, j1 has J, k has K + it : k -[[] + j:j(2):2 + j1:j(2):2]-> {} | j has J, j1 has J, k has K main : {} it : k -[[] + k:k(4):1]-> {} | k has K f : [A, B], C, D -[[f(13)]]-> (k -[[] + k:k(4):1]-> {}) | k has K From 3ec68fb3ef86145cb2521373ae92870a31cc3671 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 2 Aug 2022 16:16:12 -0500 Subject: [PATCH 3/3] Update type variables in derive tests --- crates/compiler/test_derive/src/encoding.rs | 24 ++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/crates/compiler/test_derive/src/encoding.rs b/crates/compiler/test_derive/src/encoding.rs index 839dc99e79..bb24b94f17 100644 --- a/crates/compiler/test_derive/src/encoding.rs +++ b/crates/compiler/test_derive/src/encoding.rs @@ -592,11 +592,11 @@ fn two_field_record() { derive_test(v!({ a: v!(U8), b: v!(STR), }), |golden| { assert_snapshot!(golden, @r###" # derived for { a : U8, b : Str } - # { a : val, b : a } -[[toEncoder_{a,b}(0)]]-> Encoder fmt | a has Encoding, fmt has EncoderFormatting, val has Encoding - # { a : val, b : a } -[[toEncoder_{a,b}(0)]]-> (List U8, fmt -[[custom(2) { a : val, b : a }]]-> List U8) | a has Encoding, fmt has EncoderFormatting, val has Encoding + # { a : val, b : val1 } -[[toEncoder_{a,b}(0)]]-> Encoder fmt | fmt has EncoderFormatting, val has Encoding, val1 has Encoding + # { a : val, b : val1 } -[[toEncoder_{a,b}(0)]]-> (List U8, fmt -[[custom(2) { a : val, b : val1 }]]-> List U8) | fmt has EncoderFormatting, val has Encoding, val1 has Encoding # Specialization lambda sets: # @<1>: [[toEncoder_{a,b}(0)]] - # @<2>: [[custom(2) { a : val, b : a }]] | a has Encoding, val has Encoding + # @<2>: [[custom(2) { a : val, b : val1 }]] | val has Encoding, val1 has Encoding #Derived.toEncoder_{a,b} = \#Derived.rcd -> Encode.custom @@ -655,11 +655,11 @@ fn tag_one_label_two_args() { derive_test(v!([A v!(U8) v!(STR)]), |golden| { assert_snapshot!(golden, @r###" # derived for [A U8 Str] - # [A val a] -[[toEncoder_[A 2](0)]]-> Encoder fmt | a has Encoding, fmt has EncoderFormatting, val has Encoding - # [A val a] -[[toEncoder_[A 2](0)]]-> (List U8, fmt -[[custom(4) [A val a]]]-> List U8) | a has Encoding, fmt has EncoderFormatting, val has Encoding + # [A val val1] -[[toEncoder_[A 2](0)]]-> Encoder fmt | fmt has EncoderFormatting, val has Encoding, val1 has Encoding + # [A val val1] -[[toEncoder_[A 2](0)]]-> (List U8, fmt -[[custom(4) [A val val1]]]-> List U8) | fmt has EncoderFormatting, val has Encoding, val1 has Encoding # Specialization lambda sets: # @<1>: [[toEncoder_[A 2](0)]] - # @<2>: [[custom(4) [A val a]]] | a has Encoding, val has Encoding + # @<2>: [[custom(4) [A val val1]]] | val has Encoding, val1 has Encoding #Derived.toEncoder_[A 2] = \#Derived.tag -> Encode.custom @@ -685,11 +685,11 @@ fn tag_two_labels() { derive_test(v!([A v!(U8) v!(STR) v!(U16), B v!(STR)]), |golden| { assert_snapshot!(golden, @r###" # derived for [A U8 Str U16, B Str] - # [A val a b, B c] -[[toEncoder_[A 3,B 1](0)]]-> Encoder fmt | a has Encoding, b has Encoding, c has Encoding, fmt has EncoderFormatting, val has Encoding - # [A val a b, B c] -[[toEncoder_[A 3,B 1](0)]]-> (List U8, fmt -[[custom(6) [A val a b, B c]]]-> List U8) | a has Encoding, b has Encoding, c has Encoding, fmt has EncoderFormatting, val has Encoding + # [A val val1 val1, B val1] -[[toEncoder_[A 3,B 1](0)]]-> Encoder fmt | fmt has EncoderFormatting, val has Encoding, val1 has Encoding + # [A val val1 val1, B val1] -[[toEncoder_[A 3,B 1](0)]]-> (List U8, fmt -[[custom(6) [A val val1 val1, B val1]]]-> List U8) | fmt has EncoderFormatting, val has Encoding, val1 has Encoding # Specialization lambda sets: # @<1>: [[toEncoder_[A 3,B 1](0)]] - # @<2>: [[custom(6) [A val a b, B c]]] | a has Encoding, b has Encoding, c has Encoding, val has Encoding + # @<2>: [[custom(6) [A val val1 val1, B val1]]] | val has Encoding, val1 has Encoding #Derived.toEncoder_[A 3,B 1] = \#Derived.tag -> Encode.custom @@ -717,11 +717,11 @@ fn recursive_tag_union() { derive_test(v!([Nil, Cons v!(U8) v!(*lst) ] as lst), |golden| { assert_snapshot!(golden, @r###" # derived for [Cons U8 $rec, Nil] as $rec - # [Cons val a, Nil] -[[toEncoder_[Cons 2,Nil 0](0)]]-> Encoder fmt | a has Encoding, fmt has EncoderFormatting, val has Encoding - # [Cons val a, Nil] -[[toEncoder_[Cons 2,Nil 0](0)]]-> (List U8, fmt -[[custom(4) [Cons val a, Nil]]]-> List U8) | a has Encoding, fmt has EncoderFormatting, val has Encoding + # [Cons val val1, Nil] -[[toEncoder_[Cons 2,Nil 0](0)]]-> Encoder fmt | fmt has EncoderFormatting, val has Encoding, val1 has Encoding + # [Cons val val1, Nil] -[[toEncoder_[Cons 2,Nil 0](0)]]-> (List U8, fmt -[[custom(4) [Cons val val1, Nil]]]-> List U8) | fmt has EncoderFormatting, val has Encoding, val1 has Encoding # Specialization lambda sets: # @<1>: [[toEncoder_[Cons 2,Nil 0](0)]] - # @<2>: [[custom(4) [Cons val a, Nil]]] | a has Encoding, val has Encoding + # @<2>: [[custom(4) [Cons val val1, Nil]]] | val has Encoding, val1 has Encoding #Derived.toEncoder_[Cons 2,Nil 0] = \#Derived.tag -> Encode.custom