Use BytesView instead of Bytes (+add Utf8 hint type)#50
Open
Use BytesView instead of Bytes (+add Utf8 hint type)#50
BytesView instead of Bytes (+add Utf8 hint type)#50Conversation
Member
Not good :( At least if I get it right. Most of the strings are static strings. Also, returning (for instance, from |
Collaborator
Author
|
To be clear, I meant "no way to get string literals on custom structs" You do get the implicit conversion on type aliases, like we have in this PR. However in this snippet: firefly-moon/example/random/main.mbt Lines 12 to 17 in 700fc8a ^I had to add the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Changes to use
BytesViewmore, as it seems to be a better convention for function parameters asBytesimplicitly converts to aBytesView.I also added "hint alias types" for
Utf8andUtf8Viewto try better hint where UTF-8 input is required. Sadly the LSP currently only view the aliased typeBytes/BytesView, and doesn't even allow "jump to definition" for type aliases. And there's currently no way to get string literals to implicitly convert to custom types. Bummer. But maybe that will be fixed in the future?One issue here is that using views will force import the stdlib's
abortimplementation, which does some string andSourceLocshenaginans which brings in ~5kB of code: https://github.com/moonbitlang/core/blob/05aaf6a8164093e22247519255cccdcabd7870c6/builtin/intrinsics.mbt#L64-L78No additional code is imported if the app already uses any other standard library function that calls
@builtin.abort, which for more complicated projects is somewhat unavoidable.