implement Str.from_utf8/16/32 with lossy variants #7514
+2,590
−1,859
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change adds the following new functions to the builtin
Str
module:from_utf8_lossy
,from_utf16
,from_utf16_lossy
,from_utf32
,from_utf32_lossy
. Onlyfrom_utf8_lossy
was implemented as a call to zig bitcode, all the rest are implemented as roc code.I originally implemented them all as zig bitcode, following the existing implementation of
from_utf8
. I ported it to roc code because it makes for a smaller change, and it feels like a good precedent to implement what I can in roc, and only port it to bitcode as necessary.There's an issue with the wasm backend where decoding surrogate pairs throws an integer multiplication overflow exception. If I replace the single multiply in the implementation with an equivalent
Num.shift_left_by
then it panics with integer subtraction overflow exception. I wasn't able to figure out why, so I added ashould_panic
to the test so it continues to run the test and any magic fixes get flagged as such.closes #7390