From 2dfce54a7c7370cf0f4d5f2140b00446890d99f0 Mon Sep 17 00:00:00 2001 From: shua Date: Sat, 7 Dec 2024 22:52:36 +0100 Subject: [PATCH 1/3] update Str.fromUtf8 error type --- crates/compiler/builtins/roc/Str.roc | 4 ++-- crates/compiler/solve/tests/solve_expr.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/compiler/builtins/roc/Str.roc b/crates/compiler/builtins/roc/Str.roc index 3e2569ef19a..331540439ea 100644 --- a/crates/compiler/builtins/roc/Str.roc +++ b/crates/compiler/builtins/roc/Str.roc @@ -538,14 +538,14 @@ toUtf8 : Str -> List U8 ## expect Str.fromUtf8 [] == Ok "" ## expect Str.fromUtf8 [255] |> Result.isErr ## ``` -fromUtf8 : List U8 -> Result Str [BadUtf8 Utf8ByteProblem U64] +fromUtf8 : List U8 -> Result Str [BadUtf8 { problem : Utf8ByteProblem, index : U64 }] fromUtf8 = \bytes -> result = fromUtf8Lowlevel bytes if result.cIsOk then Ok result.bString else - Err (BadUtf8 result.dProblemCode result.aByteIndex) + Err (BadUtf8 { problem: result.dProblemCode, index: result.aByteIndex }) expect (Str.fromUtf8 [82, 111, 99]) == Ok "Roc" expect (Str.fromUtf8 [224, 174, 154, 224, 174, 191]) == Ok "சி" diff --git a/crates/compiler/solve/tests/solve_expr.rs b/crates/compiler/solve/tests/solve_expr.rs index 58330cbe949..015508f0312 100644 --- a/crates/compiler/solve/tests/solve_expr.rs +++ b/crates/compiler/solve/tests/solve_expr.rs @@ -165,7 +165,7 @@ mod solve_expr { Str.fromUtf8 " ), - "List U8 -> Result Str [BadUtf8 Utf8ByteProblem U64]", + "List U8 -> Result Str [BadUtf8 { index : U64, problem : Utf8ByteProblem }]", ); } From bf2895237d055db4abfc7ca2c00d2501e04d5d72 Mon Sep 17 00:00:00 2001 From: shua Date: Sat, 7 Dec 2024 22:52:43 +0100 Subject: [PATCH 2/3] update mono tests --- .../encode_derived_nested_record_string.txt | 28 +++++++++---------- ...encode_derived_record_one_field_string.txt | 28 +++++++++---------- ...ncode_derived_record_two_field_strings.txt | 28 +++++++++---------- .../generated/encode_derived_string.txt | 28 +++++++++---------- .../encode_derived_tag_one_field_string.txt | 28 +++++++++---------- ...encode_derived_tag_two_payloads_string.txt | 28 +++++++++---------- 6 files changed, 84 insertions(+), 84 deletions(-) diff --git a/crates/compiler/test_mono/generated/encode_derived_nested_record_string.txt b/crates/compiler/test_mono/generated/encode_derived_nested_record_string.txt index cbe4549671c..b5e7db27d9e 100644 --- a/crates/compiler/test_mono/generated/encode_derived_nested_record_string.txt +++ b/crates/compiler/test_mono/generated/encode_derived_nested_record_string.txt @@ -164,31 +164,31 @@ procedure Num.96 (#Attr.2): ret Num.285; procedure Str.12 (#Attr.2): - let Str.258 : List U8 = lowlevel StrToUtf8 #Attr.2; - ret Str.258; + let Str.259 : List U8 = lowlevel StrToUtf8 #Attr.2; + ret Str.259; procedure Str.36 (#Attr.2): - let Str.259 : U64 = lowlevel StrCountUtf8Bytes #Attr.2; - ret Str.259; + let Str.260 : U64 = lowlevel StrCountUtf8Bytes #Attr.2; + ret Str.260; procedure Str.43 (#Attr.2): - let Str.253 : {U64, Str, Int1, U8} = lowlevel StrFromUtf8 #Attr.2; - ret Str.253; + let Str.254 : {U64, Str, Int1, U8} = lowlevel StrFromUtf8 #Attr.2; + ret Str.254; procedure Str.9 (Str.73): let Str.74 : {U64, Str, Int1, U8} = CallByName Str.43 Str.73; - let Str.250 : Int1 = StructAtIndex 2 Str.74; - if Str.250 then - let Str.252 : Str = StructAtIndex 1 Str.74; - let Str.251 : [C {U64, U8}, C Str] = TagId(1) Str.252; - ret Str.251; + let Str.251 : Int1 = StructAtIndex 2 Str.74; + if Str.251 then + let Str.253 : Str = StructAtIndex 1 Str.74; + let Str.252 : [C {U64, U8}, C Str] = TagId(1) Str.253; + ret Str.252; else - let Str.248 : U8 = StructAtIndex 3 Str.74; let Str.249 : U64 = StructAtIndex 0 Str.74; + let Str.250 : U8 = StructAtIndex 3 Str.74; let #Derived_gen.45 : Str = StructAtIndex 1 Str.74; dec #Derived_gen.45; - let Str.247 : {U64, U8} = Struct {Str.249, Str.248}; - let Str.246 : [C {U64, U8}, C Str] = TagId(0) Str.247; + let Str.248 : {U64, U8} = Struct {Str.249, Str.250}; + let Str.246 : [C {U64, U8}, C Str] = TagId(0) Str.248; ret Str.246; procedure Test.20 (Test.56): diff --git a/crates/compiler/test_mono/generated/encode_derived_record_one_field_string.txt b/crates/compiler/test_mono/generated/encode_derived_record_one_field_string.txt index f97f1c8bdc8..e465b76c498 100644 --- a/crates/compiler/test_mono/generated/encode_derived_record_one_field_string.txt +++ b/crates/compiler/test_mono/generated/encode_derived_record_one_field_string.txt @@ -105,31 +105,31 @@ procedure Num.96 (#Attr.2): ret Num.281; procedure Str.12 (#Attr.2): - let Str.255 : List U8 = lowlevel StrToUtf8 #Attr.2; - ret Str.255; + let Str.256 : List U8 = lowlevel StrToUtf8 #Attr.2; + ret Str.256; procedure Str.36 (#Attr.2): - let Str.256 : U64 = lowlevel StrCountUtf8Bytes #Attr.2; - ret Str.256; + let Str.257 : U64 = lowlevel StrCountUtf8Bytes #Attr.2; + ret Str.257; procedure Str.43 (#Attr.2): - let Str.253 : {U64, Str, Int1, U8} = lowlevel StrFromUtf8 #Attr.2; - ret Str.253; + let Str.254 : {U64, Str, Int1, U8} = lowlevel StrFromUtf8 #Attr.2; + ret Str.254; procedure Str.9 (Str.73): let Str.74 : {U64, Str, Int1, U8} = CallByName Str.43 Str.73; - let Str.250 : Int1 = StructAtIndex 2 Str.74; - if Str.250 then - let Str.252 : Str = StructAtIndex 1 Str.74; - let Str.251 : [C {U64, U8}, C Str] = TagId(1) Str.252; - ret Str.251; + let Str.251 : Int1 = StructAtIndex 2 Str.74; + if Str.251 then + let Str.253 : Str = StructAtIndex 1 Str.74; + let Str.252 : [C {U64, U8}, C Str] = TagId(1) Str.253; + ret Str.252; else - let Str.248 : U8 = StructAtIndex 3 Str.74; let Str.249 : U64 = StructAtIndex 0 Str.74; + let Str.250 : U8 = StructAtIndex 3 Str.74; let #Derived_gen.24 : Str = StructAtIndex 1 Str.74; dec #Derived_gen.24; - let Str.247 : {U64, U8} = Struct {Str.249, Str.248}; - let Str.246 : [C {U64, U8}, C Str] = TagId(0) Str.247; + let Str.248 : {U64, U8} = Struct {Str.249, Str.250}; + let Str.246 : [C {U64, U8}, C Str] = TagId(0) Str.248; ret Str.246; procedure Test.20 (Test.56): diff --git a/crates/compiler/test_mono/generated/encode_derived_record_two_field_strings.txt b/crates/compiler/test_mono/generated/encode_derived_record_two_field_strings.txt index 311b88e7b25..e0b52ea113d 100644 --- a/crates/compiler/test_mono/generated/encode_derived_record_two_field_strings.txt +++ b/crates/compiler/test_mono/generated/encode_derived_record_two_field_strings.txt @@ -112,31 +112,31 @@ procedure Num.96 (#Attr.2): ret Num.281; procedure Str.12 (#Attr.2): - let Str.255 : List U8 = lowlevel StrToUtf8 #Attr.2; - ret Str.255; + let Str.256 : List U8 = lowlevel StrToUtf8 #Attr.2; + ret Str.256; procedure Str.36 (#Attr.2): - let Str.256 : U64 = lowlevel StrCountUtf8Bytes #Attr.2; - ret Str.256; + let Str.257 : U64 = lowlevel StrCountUtf8Bytes #Attr.2; + ret Str.257; procedure Str.43 (#Attr.2): - let Str.253 : {U64, Str, Int1, U8} = lowlevel StrFromUtf8 #Attr.2; - ret Str.253; + let Str.254 : {U64, Str, Int1, U8} = lowlevel StrFromUtf8 #Attr.2; + ret Str.254; procedure Str.9 (Str.73): let Str.74 : {U64, Str, Int1, U8} = CallByName Str.43 Str.73; - let Str.250 : Int1 = StructAtIndex 2 Str.74; - if Str.250 then - let Str.252 : Str = StructAtIndex 1 Str.74; - let Str.251 : [C {U64, U8}, C Str] = TagId(1) Str.252; - ret Str.251; + let Str.251 : Int1 = StructAtIndex 2 Str.74; + if Str.251 then + let Str.253 : Str = StructAtIndex 1 Str.74; + let Str.252 : [C {U64, U8}, C Str] = TagId(1) Str.253; + ret Str.252; else - let Str.248 : U8 = StructAtIndex 3 Str.74; let Str.249 : U64 = StructAtIndex 0 Str.74; + let Str.250 : U8 = StructAtIndex 3 Str.74; let #Derived_gen.28 : Str = StructAtIndex 1 Str.74; dec #Derived_gen.28; - let Str.247 : {U64, U8} = Struct {Str.249, Str.248}; - let Str.246 : [C {U64, U8}, C Str] = TagId(0) Str.247; + let Str.248 : {U64, U8} = Struct {Str.249, Str.250}; + let Str.246 : [C {U64, U8}, C Str] = TagId(0) Str.248; ret Str.246; procedure Test.20 (Test.56): diff --git a/crates/compiler/test_mono/generated/encode_derived_string.txt b/crates/compiler/test_mono/generated/encode_derived_string.txt index 787973e3a10..2f4a168b91b 100644 --- a/crates/compiler/test_mono/generated/encode_derived_string.txt +++ b/crates/compiler/test_mono/generated/encode_derived_string.txt @@ -38,31 +38,31 @@ procedure Num.96 (#Attr.2): ret Num.281; procedure Str.12 (#Attr.2): - let Str.255 : List U8 = lowlevel StrToUtf8 #Attr.2; - ret Str.255; + let Str.256 : List U8 = lowlevel StrToUtf8 #Attr.2; + ret Str.256; procedure Str.36 (#Attr.2): - let Str.256 : U64 = lowlevel StrCountUtf8Bytes #Attr.2; - ret Str.256; + let Str.257 : U64 = lowlevel StrCountUtf8Bytes #Attr.2; + ret Str.257; procedure Str.43 (#Attr.2): - let Str.253 : {U64, Str, Int1, U8} = lowlevel StrFromUtf8 #Attr.2; - ret Str.253; + let Str.254 : {U64, Str, Int1, U8} = lowlevel StrFromUtf8 #Attr.2; + ret Str.254; procedure Str.9 (Str.73): let Str.74 : {U64, Str, Int1, U8} = CallByName Str.43 Str.73; - let Str.250 : Int1 = StructAtIndex 2 Str.74; - if Str.250 then - let Str.252 : Str = StructAtIndex 1 Str.74; - let Str.251 : [C {U64, U8}, C Str] = TagId(1) Str.252; - ret Str.251; + let Str.251 : Int1 = StructAtIndex 2 Str.74; + if Str.251 then + let Str.253 : Str = StructAtIndex 1 Str.74; + let Str.252 : [C {U64, U8}, C Str] = TagId(1) Str.253; + ret Str.252; else - let Str.248 : U8 = StructAtIndex 3 Str.74; let Str.249 : U64 = StructAtIndex 0 Str.74; + let Str.250 : U8 = StructAtIndex 3 Str.74; let #Derived_gen.3 : Str = StructAtIndex 1 Str.74; dec #Derived_gen.3; - let Str.247 : {U64, U8} = Struct {Str.249, Str.248}; - let Str.246 : [C {U64, U8}, C Str] = TagId(0) Str.247; + let Str.248 : {U64, U8} = Struct {Str.249, Str.250}; + let Str.246 : [C {U64, U8}, C Str] = TagId(0) Str.248; ret Str.246; procedure Test.20 (Test.56): diff --git a/crates/compiler/test_mono/generated/encode_derived_tag_one_field_string.txt b/crates/compiler/test_mono/generated/encode_derived_tag_one_field_string.txt index eaef60877aa..943f560050e 100644 --- a/crates/compiler/test_mono/generated/encode_derived_tag_one_field_string.txt +++ b/crates/compiler/test_mono/generated/encode_derived_tag_one_field_string.txt @@ -110,31 +110,31 @@ procedure Num.96 (#Attr.2): ret Num.281; procedure Str.12 (#Attr.2): - let Str.255 : List U8 = lowlevel StrToUtf8 #Attr.2; - ret Str.255; + let Str.256 : List U8 = lowlevel StrToUtf8 #Attr.2; + ret Str.256; procedure Str.36 (#Attr.2): - let Str.256 : U64 = lowlevel StrCountUtf8Bytes #Attr.2; - ret Str.256; + let Str.257 : U64 = lowlevel StrCountUtf8Bytes #Attr.2; + ret Str.257; procedure Str.43 (#Attr.2): - let Str.253 : {U64, Str, Int1, U8} = lowlevel StrFromUtf8 #Attr.2; - ret Str.253; + let Str.254 : {U64, Str, Int1, U8} = lowlevel StrFromUtf8 #Attr.2; + ret Str.254; procedure Str.9 (Str.73): let Str.74 : {U64, Str, Int1, U8} = CallByName Str.43 Str.73; - let Str.250 : Int1 = StructAtIndex 2 Str.74; - if Str.250 then - let Str.252 : Str = StructAtIndex 1 Str.74; - let Str.251 : [C {U64, U8}, C Str] = TagId(1) Str.252; - ret Str.251; + let Str.251 : Int1 = StructAtIndex 2 Str.74; + if Str.251 then + let Str.253 : Str = StructAtIndex 1 Str.74; + let Str.252 : [C {U64, U8}, C Str] = TagId(1) Str.253; + ret Str.252; else - let Str.248 : U8 = StructAtIndex 3 Str.74; let Str.249 : U64 = StructAtIndex 0 Str.74; + let Str.250 : U8 = StructAtIndex 3 Str.74; let #Derived_gen.27 : Str = StructAtIndex 1 Str.74; dec #Derived_gen.27; - let Str.247 : {U64, U8} = Struct {Str.249, Str.248}; - let Str.246 : [C {U64, U8}, C Str] = TagId(0) Str.247; + let Str.248 : {U64, U8} = Struct {Str.249, Str.250}; + let Str.246 : [C {U64, U8}, C Str] = TagId(0) Str.248; ret Str.246; procedure Test.20 (Test.56): diff --git a/crates/compiler/test_mono/generated/encode_derived_tag_two_payloads_string.txt b/crates/compiler/test_mono/generated/encode_derived_tag_two_payloads_string.txt index e08ecc31d55..c4b39a1709e 100644 --- a/crates/compiler/test_mono/generated/encode_derived_tag_two_payloads_string.txt +++ b/crates/compiler/test_mono/generated/encode_derived_tag_two_payloads_string.txt @@ -113,31 +113,31 @@ procedure Num.96 (#Attr.2): ret Num.281; procedure Str.12 (#Attr.2): - let Str.255 : List U8 = lowlevel StrToUtf8 #Attr.2; - ret Str.255; + let Str.256 : List U8 = lowlevel StrToUtf8 #Attr.2; + ret Str.256; procedure Str.36 (#Attr.2): - let Str.256 : U64 = lowlevel StrCountUtf8Bytes #Attr.2; - ret Str.256; + let Str.257 : U64 = lowlevel StrCountUtf8Bytes #Attr.2; + ret Str.257; procedure Str.43 (#Attr.2): - let Str.253 : {U64, Str, Int1, U8} = lowlevel StrFromUtf8 #Attr.2; - ret Str.253; + let Str.254 : {U64, Str, Int1, U8} = lowlevel StrFromUtf8 #Attr.2; + ret Str.254; procedure Str.9 (Str.73): let Str.74 : {U64, Str, Int1, U8} = CallByName Str.43 Str.73; - let Str.250 : Int1 = StructAtIndex 2 Str.74; - if Str.250 then - let Str.252 : Str = StructAtIndex 1 Str.74; - let Str.251 : [C {U64, U8}, C Str] = TagId(1) Str.252; - ret Str.251; + let Str.251 : Int1 = StructAtIndex 2 Str.74; + if Str.251 then + let Str.253 : Str = StructAtIndex 1 Str.74; + let Str.252 : [C {U64, U8}, C Str] = TagId(1) Str.253; + ret Str.252; else - let Str.248 : U8 = StructAtIndex 3 Str.74; let Str.249 : U64 = StructAtIndex 0 Str.74; + let Str.250 : U8 = StructAtIndex 3 Str.74; let #Derived_gen.28 : Str = StructAtIndex 1 Str.74; dec #Derived_gen.28; - let Str.247 : {U64, U8} = Struct {Str.249, Str.248}; - let Str.246 : [C {U64, U8}, C Str] = TagId(0) Str.247; + let Str.248 : {U64, U8} = Struct {Str.249, Str.250}; + let Str.246 : [C {U64, U8}, C Str] = TagId(0) Str.248; ret Str.246; procedure Test.20 (Test.56): From f90e63b484a95880a0eba70c7da524773b4dec01 Mon Sep 17 00:00:00 2001 From: shua Date: Mon, 9 Dec 2024 20:17:13 +0100 Subject: [PATCH 3/3] update test_gen str tests --- crates/compiler/test_gen/src/gen_str.rs | 12 ++++++------ crates/compiler/test_gen/src/wasm_str.rs | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/crates/compiler/test_gen/src/gen_str.rs b/crates/compiler/test_gen/src/gen_str.rs index f50e72104c5..1ea116fe739 100644 --- a/crates/compiler/test_gen/src/gen_str.rs +++ b/crates/compiler/test_gen/src/gen_str.rs @@ -692,7 +692,7 @@ fn str_from_utf8_fail_invalid_start_byte() { indoc!( r#" when Str.fromUtf8 [97, 98, 0x80, 99] is - Err (BadUtf8 InvalidStartByte byteIndex) -> + Err (BadUtf8 {problem: InvalidStartByte, index: byteIndex}) -> if byteIndex == 2 then "a" else @@ -712,7 +712,7 @@ fn str_from_utf8_fail_unexpected_end_of_sequence() { indoc!( r#" when Str.fromUtf8 [97, 98, 99, 0xC2] is - Err (BadUtf8 UnexpectedEndOfSequence byteIndex) -> + Err (BadUtf8 {problem: UnexpectedEndOfSequence, index: byteIndex}) -> if byteIndex == 3 then "a" else @@ -732,7 +732,7 @@ fn str_from_utf8_fail_expected_continuation() { indoc!( r#" when Str.fromUtf8 [97, 98, 99, 0xC2, 0x00] is - Err (BadUtf8 ExpectedContinuation byteIndex) -> + Err (BadUtf8 {problem: ExpectedContinuation, index: byteIndex}) -> if byteIndex == 3 then "a" else @@ -752,7 +752,7 @@ fn str_from_utf8_fail_overlong_encoding() { indoc!( r#" when Str.fromUtf8 [97, 0xF0, 0x80, 0x80, 0x80] is - Err (BadUtf8 OverlongEncoding byteIndex) -> + Err (BadUtf8 {problem: OverlongEncoding, index: byteIndex}) -> if byteIndex == 1 then "a" else @@ -772,7 +772,7 @@ fn str_from_utf8_fail_codepoint_too_large() { indoc!( r#" when Str.fromUtf8 [97, 0xF4, 0x90, 0x80, 0x80] is - Err (BadUtf8 CodepointTooLarge byteIndex) -> + Err (BadUtf8 {problem: CodepointTooLarge, index: byteIndex}) -> if byteIndex == 1 then "a" else @@ -792,7 +792,7 @@ fn str_from_utf8_fail_surrogate_half() { indoc!( r#" when Str.fromUtf8 [97, 98, 0xED, 0xA0, 0x80] is - Err (BadUtf8 EncodesSurrogateHalf byteIndex) -> + Err (BadUtf8 {problem: EncodesSurrogateHalf, index: byteIndex}) -> if byteIndex == 2 then "a" else diff --git a/crates/compiler/test_gen/src/wasm_str.rs b/crates/compiler/test_gen/src/wasm_str.rs index 37fe5512387..0f7b35aa287 100644 --- a/crates/compiler/test_gen/src/wasm_str.rs +++ b/crates/compiler/test_gen/src/wasm_str.rs @@ -522,7 +522,7 @@ fn str_from_utf8_fail_invalid_start_byte() { indoc!( r#" when Str.fromUtf8 [97, 98, 0x80, 99] is - Err (BadUtf8 InvalidStartByte byteIndex) -> + Err (BadUtf8 {problem: InvalidStartByte, index: byteIndex}) -> if byteIndex == 2 then "a" else @@ -541,7 +541,7 @@ fn str_from_utf8_fail_unexpected_end_of_sequence() { indoc!( r#" when Str.fromUtf8 [97, 98, 99, 0xC2] is - Err (BadUtf8 UnexpectedEndOfSequence byteIndex) -> + Err (BadUtf8 {problem: UnexpectedEndOfSequence, index: byteIndex}) -> if byteIndex == 3 then "a" else @@ -560,7 +560,7 @@ fn str_from_utf8_fail_expected_continuation() { indoc!( r#" when Str.fromUtf8 [97, 98, 99, 0xC2, 0x00] is - Err (BadUtf8 ExpectedContinuation byteIndex) -> + Err (BadUtf8 {problem: ExpectedContinuation, index: byteIndex}) -> if byteIndex == 3 then "a" else @@ -579,7 +579,7 @@ fn str_from_utf8_fail_overlong_encoding() { indoc!( r#" when Str.fromUtf8 [97, 0xF0, 0x80, 0x80, 0x80] is - Err (BadUtf8 OverlongEncoding byteIndex) -> + Err (BadUtf8 {problem: OverlongEncoding, index: byteIndex}) -> if byteIndex == 1 then "a" else @@ -598,7 +598,7 @@ fn str_from_utf8_fail_codepoint_too_large() { indoc!( r#" when Str.fromUtf8 [97, 0xF4, 0x90, 0x80, 0x80] is - Err (BadUtf8 CodepointTooLarge byteIndex) -> + Err (BadUtf8 {problem: CodepointTooLarge, index: byteIndex}) -> if byteIndex == 1 then "a" else @@ -617,7 +617,7 @@ fn str_from_utf8_fail_surrogate_half() { indoc!( r#" when Str.fromUtf8 [97, 98, 0xED, 0xA0, 0x80] is - Err (BadUtf8 EncodesSurrogateHalf byteIndex) -> + Err (BadUtf8 {problem: EncodesSurrogateHalf, index: byteIndex}) -> if byteIndex == 2 then "a" else