-
Notifications
You must be signed in to change notification settings - Fork 98
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
[WIP] TryFromBuild derive support for enums #371
Closed
joshlf
wants to merge
5
commits into
try-from-bytes-raw-argument-to-is-bit-valid--derive-validator
from
try-from-bytes-raw-argument-to-is-bit-valid--derive-enums
Closed
[WIP] TryFromBuild derive support for enums #371
joshlf
wants to merge
5
commits into
try-from-bytes-raw-argument-to-is-bit-valid--derive-validator
from
try-from-bytes-raw-argument-to-is-bit-valid--derive-enums
Conversation
This file contains 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
joshlf
commented
Sep 11, 2023
|
||
let cases = var.fields.fields().into_iter().map(foo); | ||
Some(quote!(|| { | ||
struct Variant { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Give this an explicit repr -- oops!
joshlf
force-pushed
the
try-from-bytes-raw-argument-to-is-bit-valid--derive-enums
branch
from
September 11, 2023 22:28
3c07e88
to
ba55c12
Compare
joshlf
force-pushed
the
try-from-bytes-raw-argument-to-is-bit-valid--derive-validator
branch
from
September 11, 2023 22:28
c2db8b1
to
342026f
Compare
joshlf
force-pushed
the
try-from-bytes-raw-argument-to-is-bit-valid--derive-enums
branch
from
September 11, 2023 22:52
ba55c12
to
6f7276b
Compare
joshlf
force-pushed
the
try-from-bytes-raw-argument-to-is-bit-valid--derive-validator
branch
from
September 11, 2023 22:52
342026f
to
7286c44
Compare
joshlf
force-pushed
the
try-from-bytes-raw-argument-to-is-bit-valid--derive-enums
branch
from
September 11, 2023 23:05
6f7276b
to
4ad50c6
Compare
joshlf
force-pushed
the
try-from-bytes-raw-argument-to-is-bit-valid--derive-validator
branch
from
September 11, 2023 23:05
7286c44
to
bff9a97
Compare
joshlf
force-pushed
the
try-from-bytes-raw-argument-to-is-bit-valid--derive-enums
branch
from
September 11, 2023 23:31
4ad50c6
to
7898e14
Compare
joshlf
force-pushed
the
try-from-bytes-raw-argument-to-is-bit-valid--derive-validator
branch
from
September 11, 2023 23:31
bff9a97
to
d463caf
Compare
joshlf
force-pushed
the
try-from-bytes-raw-argument-to-is-bit-valid--derive-enums
branch
2 times, most recently
from
September 12, 2023 00:34
58a3786
to
1277a6e
Compare
joshlf
force-pushed
the
try-from-bytes-raw-argument-to-is-bit-valid--derive-validator
branch
from
September 12, 2023 00:34
d463caf
to
90c2aed
Compare
joshlf
force-pushed
the
try-from-bytes-raw-argument-to-is-bit-valid--derive-enums
branch
from
September 12, 2023 00:48
1277a6e
to
34d48a2
Compare
joshlf
force-pushed
the
try-from-bytes-raw-argument-to-is-bit-valid--derive-validator
branch
from
September 12, 2023 00:48
90c2aed
to
7707fb1
Compare
joshlf
force-pushed
the
try-from-bytes-raw-argument-to-is-bit-valid--derive-enums
branch
from
September 12, 2023 00:48
34d48a2
to
f912032
Compare
joshlf
force-pushed
the
try-from-bytes-raw-argument-to-is-bit-valid--derive-validator
branch
from
September 12, 2023 00:48
7707fb1
to
de82f0e
Compare
joshlf
force-pushed
the
try-from-bytes-raw-argument-to-is-bit-valid--derive-enums
branch
from
September 12, 2023 01:19
f912032
to
f7ad4d1
Compare
joshlf
force-pushed
the
try-from-bytes-raw-argument-to-is-bit-valid--derive-validator
branch
from
September 12, 2023 01:19
de82f0e
to
575c570
Compare
joshlf
force-pushed
the
try-from-bytes-raw-argument-to-is-bit-valid--derive-enums
branch
from
September 12, 2023 01:40
f7ad4d1
to
18ed997
Compare
joshlf
force-pushed
the
try-from-bytes-raw-argument-to-is-bit-valid--derive-validator
branch
from
September 12, 2023 01:40
575c570
to
ceb1983
Compare
joshlf
force-pushed
the
try-from-bytes-raw-argument-to-is-bit-valid--derive-enums
branch
from
September 12, 2023 02:22
18ed997
to
8185e85
Compare
joshlf
force-pushed
the
try-from-bytes-raw-argument-to-is-bit-valid--derive-validator
branch
from
September 12, 2023 02:22
ceb1983
to
98ca637
Compare
joshlf
force-pushed
the
try-from-bytes-raw-argument-to-is-bit-valid--derive-enums
branch
from
September 12, 2023 02:49
8185e85
to
94b0458
Compare
joshlf
force-pushed
the
try-from-bytes-raw-argument-to-is-bit-valid--derive-validator
branch
from
September 12, 2023 02:49
98ca637
to
8eff3b0
Compare
joshlf
force-pushed
the
try-from-bytes-raw-argument-to-is-bit-valid--derive-enums
branch
from
September 12, 2023 03:19
94b0458
to
be161c6
Compare
joshlf
force-pushed
the
try-from-bytes-raw-argument-to-is-bit-valid--derive-validator
branch
from
September 12, 2023 03:20
8eff3b0
to
4004cbe
Compare
joshlf
force-pushed
the
try-from-bytes-raw-argument-to-is-bit-valid--derive-enums
branch
2 times, most recently
from
September 12, 2023 03:43
5fbe8b4
to
06f8296
Compare
joshlf
force-pushed
the
try-from-bytes-raw-argument-to-is-bit-valid--derive-validator
branch
from
September 12, 2023 03:43
4004cbe
to
8595f94
Compare
joshlf
force-pushed
the
try-from-bytes-raw-argument-to-is-bit-valid--derive-enums
branch
from
September 12, 2023 06:02
06f8296
to
06b5db5
Compare
joshlf
force-pushed
the
try-from-bytes-raw-argument-to-is-bit-valid--derive-validator
branch
from
September 12, 2023 06:02
8595f94
to
843e2ee
Compare
joshlf
force-pushed
the
try-from-bytes-raw-argument-to-is-bit-valid--derive-enums
branch
from
September 12, 2023 06:16
06b5db5
to
8b0983c
Compare
joshlf
force-pushed
the
try-from-bytes-raw-argument-to-is-bit-valid--derive-validator
branch
from
September 12, 2023 06:16
843e2ee
to
a46bdc1
Compare
joshlf
force-pushed
the
try-from-bytes-raw-argument-to-is-bit-valid--derive-enums
branch
from
September 12, 2023 15:41
8b0983c
to
286537d
Compare
joshlf
force-pushed
the
try-from-bytes-raw-argument-to-is-bit-valid--derive-validator
branch
from
September 12, 2023 15:41
a46bdc1
to
e1cd6a7
Compare
joshlf
force-pushed
the
try-from-bytes-raw-argument-to-is-bit-valid--derive-enums
branch
from
September 12, 2023 15:44
286537d
to
d4cd61b
Compare
joshlf
force-pushed
the
try-from-bytes-raw-argument-to-is-bit-valid--derive-validator
branch
from
September 12, 2023 15:44
e1cd6a7
to
55aee47
Compare
`TryFromBytes` can be implemented for types which are not `FromZeroes` or `FromBytes`; it supports performing a runtime check to determine whether a given byte sequence contains a valid instance of `Self`. This is the first step of #5. Future commits will add support for a custom derive and for implementing `TryFromBytes` on unsized types. TODO: - More thorough tests for non-FromBytes types (bool, char, etc) - Tests that go through the `TryFromBytes` public methods rather than testing `is_bit_valid` directly - Pick public TryFromBytes method names that are more consistent with FromBytes? In particular: - try_from_ref -> try_from_bytes - try_from_mut -> try_from_bytes_mut Makes progress on #5
TODO: Commit message body TODO: - In `try_transmute!`, should the argument be dropped or forgotten (ie, `mem::forget`) when the transmute fails? We could also return the original value in a `Result::Error`, but that would be inconsistent with `TryFrom`. Then again, `TryFrom` provides a custom error type, so in theory implementers could do that if they wanted to. Most of the types that don't consume Copy types. Makes progress on #5
TODO: - Should DataExt::fields have a different shape? Extracting field names for enums doesn't really make sense - Lots and lots of tests - If we manage to land derive(KnownLayout) first, replace manual impls of KnownLayout with the derive - Is there any way to make sure the code we emit doesn't emit warnings? I tested with an earlier version of the code that had lots of code smells like pointer coercions that emitted warnings, and even after emitting `#[deny(...)]` attributes, I couldn't get code which made use of the derive to complain at all - the compiler just happily accepted it. Makes progress on #5
TODO: - Cleaner way to pass name of validator to `impl_block`? - Cleaner way to parse validator attribute? - Safety comment in emitted call to `validate` - Tests (especially including tests for the error message resulting from passing a validator with the wrong type signature - test for both argument types and return types) - Also test for invalid zerocopy attributes - Also test for hygiene - that the validator can't access variables from the `is_bit_valid` function body scope - Other misc TODO comments in code
TODO: - Clean up repr computation - Support enums with fields - If we don't support enums with fields, enforce that - Should enum variants be considered "used" in the sense of dead code? It's possible to never construct an enum variant from Rust's perspective even though it is constructed via TryFromBytes. - Confirm that we reject uninhabited enums. Currently Rust doesn't let you put a repr on these enums, so we would reject them for lack of a repr, but we should probably have a more reliable check than that.
joshlf
force-pushed
the
try-from-bytes-raw-argument-to-is-bit-valid--derive-enums
branch
from
September 12, 2023 16:47
d4cd61b
to
42e44c5
Compare
joshlf
force-pushed
the
try-from-bytes-raw-argument-to-is-bit-valid--derive-validator
branch
4 times, most recently
from
September 19, 2023 16:43
5c45ea8
to
3271ca4
Compare
joshlf
force-pushed
the
try-from-bytes-raw-argument-to-is-bit-valid--derive-validator
branch
3 times, most recently
from
September 19, 2023 22:33
1439d4b
to
fe3118f
Compare
joshlf
force-pushed
the
try-from-bytes-raw-argument-to-is-bit-valid--derive-validator
branch
from
October 12, 2023 21:41
fe3118f
to
1f8ff06
Compare
joshlf
deleted the
try-from-bytes-raw-argument-to-is-bit-valid--derive-enums
branch
September 10, 2024 13:38
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.
TODO: