-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tracking issue for RFC 23 - byte string literals #14646
Comments
Note to myself: the |
Feature branch: https://github.com/SimonSapin/rust/compare/byte-literals Sub-tasks:
|
SimonSapin@cc17dd6 is a first pass at byte string literals, re-using the existing
I had a look at |
@pcwalton (You’re the winner in |
@SimonSapin In patterns, the right thing to do may be to desugar a byte literal into a vector pattern so that you can interchange byte literal patterns with vector patterns like this: match x {
b"foo" => ...,
[2u, 10u, 5u] => ...
} So the above would effectively expand into: match x {
[102u, 111u, 111u] => ...,
[2u, 10u, 5u] => ...
} What's not ideal about this is that the actual IR generated for this will be quite naive so you'd rely on LLVM to compile it down to a memcmp. |
https://github.com/mozilla/rust/blob/3316b1eb7c3eb520896af489dd45c4d17190d0a8/src/libsyntax/parse/parser.rs#L2886 would probably be the place to add the logic that expands a LitBinary into PatVec. |
@jakub- Does the compiler have a data structure that represents specifically a vector pattern? Do you know how it’s called? As to optimizing matching to a |
@jakub- this looks promising. Thanks! |
@SimonSapin No worries! About the memcmp, that's true. The difference with vector patterns is that the above actually compiles down to a byte-by-byte comparison with bound checks for each element. I'm pretty sure we can eliminate the bound checks so maybe at that point it'll end up being a memcmp. |
The issue above was resolved with a lot of help from @jakub- and @luqmana on IRC. Thanks both! |
See #14646 (tracking issue) and rust-lang/rfcs#69. This does not close the tracking issue, as the `bytes!()` macro still needs to be removed. It will be later, after a snapshot is made with the changes in this PR, so that the new syntax can be used when bootstrapping the compiler.
@SimonSapin Awesome work! Thanks. |
rust-lang/rfcs#69
The text was updated successfully, but these errors were encountered: