-
Notifications
You must be signed in to change notification settings - Fork 87
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
Follow-up for canonical se/de after an additional round of review #588
Conversation
- Removed all enum attributes. The manual implementation of the traits can do the same. - Removed `clone` for each `Input` required to call `into_full`. It is possible because of a new `Empty<Type>` type that implements canonical se/de with minimal implementation. - Removed `SIZE_NO_DYNAMIC` because it is not used in the codebase. - Removed `SerializedSizeFixed` because we don't have any specific logic that uses it. - Moved all methods from `SerializedSize` to `Serialize`. It looks unnatural that `#[derive(Serialize)]` implements 3 traits. Instead, it implements on trait now. - Removed `SIZE_STATIC` because it is impossible to calculate in the case of enums(or if the `struct` has an enum field). Supporting something like this requires another way of doing that, plus it doesn't provide a lot of wins for us right now because `#[inline(always]` handle that well enough. - Removed panics during size calculation. Instead we use `saturating_add`. If the size is incorrect we will fail in another place. - Removed usage of `num_enum` and replaced with canonical se/de. - Removed calculation of the discriminant on macro level. Replaced with native rust calculation that covers all cases.
@@ -451,6 +453,81 @@ impl From<Mint> for Transaction { | |||
} | |||
} | |||
|
|||
impl Serialize for Transaction { |
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.
What's the benefit of implementing this kind of boilerplate logic manually? Does it just add unnecessary complexity to the macros by trying to automate this?
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.
We can use the peek
function, which removes the Clone
requirement from the trait Input: Clone
. Skipping of the discriminant is a very "magic" thing and I prefer to do that manually because we need it only in one place for Transaction
.
# Conflicts: # CHANGELOG.md # fuel-tx/Cargo.toml
I dislike the added copy-paste, as that makes it possible to accidentally apply a change to only a part of the branches.
The empty type changes I really like, and this is a nice additional benefit.
Sure.
I though there was an attempt to get
I dislike this, as it has a possibility to silently fail, and could hide implementation bugs. Shouldn't matter much, but if we change the serialization itself at some point, this makes it a bit harder.
Sure.
The new code seems good enough. |
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.
I disagree with some design decisions here, as mentioned above.
Still, I don't think it matters enough to keep discussing this, so lets just go ahead and merge.
Addresses breaking fuel-vm changes from FuelLabs/fuel-vm#582, FuelLabs/fuel-vm#578, FuelLabs/fuel-vm#588 and FuelLabs/fuel-vm#587. Waiting for a new fuel-vm release. --------- Co-authored-by: Green Baneling <XgreenX9999@gmail.com>
Addresses breaking fuel-vm changes from FuelLabs/fuel-vm#582, FuelLabs/fuel-vm#578, FuelLabs/fuel-vm#588 and FuelLabs/fuel-vm#587. Waiting for a new fuel-vm release. --------- Co-authored-by: Green Baneling <XgreenX9999@gmail.com>
clone
for eachInput
required to callinto_full
. It is possible because of a newEmpty<Type>
type that implements canonical se/de with minimal implementation.SIZE_NO_DYNAMIC
because it is not used in the codebase.SerializedSizeFixed
because we don't have any specific logic that uses it.SerializedSize
toSerialize
. It looks unnatural that#[derive(Serialize)]
implements 3 traits. Instead, it implements on trait now.SIZE_STATIC
because it is impossible to calculate in the case of enums(or if thestruct
has an enum field). Supporting something like this requires another way of doing that, plus it doesn't provide a lot of wins for us right now because#[inline(always]
handle that well enough.saturating_add
. If the size is incorrect we will fail in another place.num_enum
and replaced with canonical se/de.