-
Notifications
You must be signed in to change notification settings - Fork 15
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
when using #[serde(untagged)] it compiles with Floats #43
Comments
Found same issue, so will explain why and offer alternative approach as a workaround. What happened?Here is the generated code for #[doc(hidden)]
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
const _: () = {
#[allow(unused_extern_crates, clippy::useless_attribute)]
extern crate serde as _serde;
#[automatically_derived]
impl<'de> _serde::Deserialize<'de> for TransactionFilterValue {
fn deserialize<__D>(
__deserializer: __D,
) -> _serde::__private::Result<Self, __D::Error>
where
__D: _serde::Deserializer<'de>,
{
// [1] `_serde::__private::de::Content` is where the problem lies
let __content = match <_serde::__private::de::Content as _serde::Deserialize>::deserialize(
__deserializer,
) {
_serde::__private::Ok(__val) => __val,
_serde::__private::Err(__err) => {
return _serde::__private::Err(__err);
}
};
if let _serde::__private::Ok(__ok)
= _serde::__private::Result::map(
<String as _serde::Deserialize>::deserialize(
_serde::__private::de::ContentRefDeserializer::<
__D::Error,
>::new(&__content),
),
TransactionFilterValue::String,
) {
return _serde::__private::Ok(__ok);
}
if let _serde::__private::Ok(__ok)
= _serde::__private::Result::map(
<u128 as _serde::Deserialize>::deserialize(
_serde::__private::de::ContentRefDeserializer::<
// [2] Error is also where the problem lies
__D::Error,
>::new(&__content),
),
TransactionFilterValue::Int,
) {
return _serde::__private::Ok(__ok);
}
_serde::__private::Err(
_serde::de::Error::custom(
"data did not match any variant of untagged enum TransactionFilterValue",
),
)
}
}
}; So for for WorkaroundFollowing the same logic as generated code but use https://github.com/CosmWasm/serde-cw-value instead of
|
@hashedone would it be possible to create a macro like @iboss-ptk explains how to make such code, but if his approach works, auto-generating with a macro would be awesome. |
@ethanfrey so |
Not urgent, but I'd love to see that added to the backlog |
It seems that in rust 1.65, |
Awesome! Time to update our minimum supported rust version and close this issue (with a test or two) |
I just tried updating to 1.65 and removing the workaround here. But no luck :/ |
I also ran this on 1.65 and still got floats in the result. @iboss-ptk maybe the optimization worked specifically for your use case but can't be generalized? I tried with with:
|
interesting, can you share the compiler optimization profile. here's mine [profile.release]
codegen-units = 1
debug = false
debug-assertions = false
incremental = false
lto = true
opt-level = 3
overflow-checks = true
panic = 'abort'
rpath = false |
I have the same values |
for @nicolaslara DM-ed him and found that
enum SomeEnum {
Variant(SomeType),
}
enum SomeEnum {
Variant { something: SomeType },
} wonder what's your case @luca992 |
finally made an example. I made a branch that causes the error here: https://github.com/eqoty-labs/snip721-migrate-example/tree/serde-untagged-floats-error Take a look at ExecuteMsg and QueryMsg |
Still happens in rust 1.68.0 |
@ethanfrey @luca992 I'm afraid #53 it doesn't fix Easy way to try it in your own projects is adding this to the root
|
Just tried. Unfortunately it didn't work for |
I ended up using @iboss-ptk's workaround for
Here's the |
What do you guys think of this approach? I really want to get rid of the serde_cw_value dependency in my project, it adds way too much size to the wasm output. If instead deserialize_bytes was supported for use with your own Visitor implementing visit_bytes you can deserialize an untagged enum by trial and error. I tested it out and it works well and my wasm output size is down by a couple hundred kb |
Hey, thanks for your example, but I still end up having f64.load in my contract that's generated by |
When I use serde(untagged) for parsing mixed types into enum, something like this
it compiles but on WASM execution it panics with
The text was updated successfully, but these errors were encountered: