-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
deriving(Encodable) does not use emit_enum_struct_variant or emit_tuple_struct #19756
Comments
See also #15659, which touches on the |
Encode was moved out of tree, so if this is still an issue, please pursue it over at https://github.com/rust-lang/rustc-serialize |
steveklabnik: This was a still a problem the last time I looked, and it is in the compiler tree. Specifically, the There's a strong case to be made that the in-tree stuff is severely suboptimal, and I really wanted to propose a fix before the alpha. But I've been hit with one crisis or another all month. I'm happy to explain this in more detail, but I'm not sure if I can spearhead a fix before it's too late. :-/ |
The in-tree one is private to |
Are you sure? As far as I can tell, the in-tree In other words, I think that the in-tree plugins are used directly by the out-of-tree code, and the in-tree plugins have some moderately serious issues. This can be worked around in I don't necessarily think that we can or should fix the in-tree stuff at this point. But I do think that the in-tree stuff could have used one more pass of API fixes, assuming it really is used by Sorry for the terse and possibly confused messages; I'm juggling way too much stuff this week. |
@alexcrichton , am I in the right or in the wrong here? |
Yeah |
OK, here are the other related issues on the decode side:
I'm not sure whether this is 100% backwards-compatible. I'm not seeing an obvious solution. I might be able to find some time next week to work on this, if people think that's desirable and appropriate. If we can't fix this in the compiler, my tentative recommendation is to remove all the struct variant and tuple struct from Anyway, I'm very open to suggestions, and I might be able to find a day to work on this if that helps. |
We're still in a period where it's still mostly ok to make breaking changes, so I think it's fine to make these changes (even the breaking ones) for now. The changes would likely only break decoders of which there are relatively few in the wild :) |
OK, sounds good. I'll try to somehow find the time if that's the best way forward. The one piece I would need from you is feedback on the intended relationship between Thank you very much for your help and your advice! And my apologies for not getting to this sooner. |
Hm, it looks like Also no worries! There's certainly no rush here :) |
OK. In that case, does it even make sense to have a separate I'm quite happy to proceed with whatever design makes sense, but I've only worked on one idiosyncratic encoder/decoder pair, so I'm especially eager for feedback on the design. |
Also, should we write up an RFC or something like that, and solicit input from people using serialization? Thank you for helping guide me through this process! |
This seems minor enough that it probably doesn't warrant an RFC, but your proposed solution seems like a good idea to me! |
Any news on that? Or are we just waiting for serde? |
RustcEncodable is deprecated. Serde handles these cases in a more consistent way. |
This issue is closely related to #17158, but affects the proposed
RustcEncodable
trait which will be stabilized as part of the compiler for Rust 1.0.Currently, the code which derives
Encodable
has a few weird design decisions:1. Rust always uses
emit_enum_variant
instead ofemit_enum_struct_variant
.If we have a structure
ExEnum
as follows:…then both
Bar
andBaz
will emit code to callemit_enum_variant
. For example, JSON encoding will yield:This would probably look a lot nicer with
x:
andy:
in theBaz
case.2. Rust will always use
emit_struct
instead ofemit_tuple_struct
This will encode to JSON as:
This is particularly unfortunate—the resulting data would look nicer if it went through
emit_tuple_struct
and used some sort of array-based encoding.Proposed fixes
I can see two ways forward:
emit_enum_struct_variant
andemit_tuple_struct
and always useemit_enum_variant
andemit_struct
.Encoder
(or the newRustcEncoder
) to useemit_enum_struct_variant
andemit_tuple_struct
.The current behavior feels like an oversight, and (2) would allow for finer-grained control over the serialization and nicer JSON. If people agree that this should happen before 1.0, and that (2) is the better design, I'd be interested in tackling this as my first rustc contribution.
The text was updated successfully, but these errors were encountered: