ron-rs / ron

Rusty Object Notation
https://docs.rs/ron
Apache License 2.0
3.31k stars 122 forks source link

Untagged enum roundtrip issues #500

Closed juntyr closed 1 year ago

juntyr commented 1 year ago

The following cases do not roundtrip:

juntyr commented 1 year ago

I have given this a bit more thought. The untagged struct variant issue is caused by

We could technically fix this with significant changes to ron, e.g. making the struct_names format option a explicit_type_names extension instead which forces struct names to be serialised and changes variants to a Enum::Variant form instead. During deserialising and if the extension is enabled, we would then only report an enum to serde's Content type if it is in Enum::Variant form. Without the extension enabled, we would proceed as now, i.e. assume that any named item is a variant.

While possible, I don't think that this is a very sustainable direction for ron to take. After all, optional struct names, required variant names, and no enum names are specific features of the format, none of which cause any problems when deserialize_any is not involved.

In the end, format-specific buffering support in serde would fix this and many other issues. Unfortunately, even though this could be implemented in serde today (see https://github.com/serde-rs/serde/pull/1354), dtolnay has indicated that serde will instead wait for associated type default to be stabilized, which might be quite a while.

I'm not quite sure where we go from here. Do we just document these limitations (and publish v0.9 with them)? Do we change the ron format? Do we unionise with other serde formats and demand a timeline for format-specific buffering /hj?

@torkleyy

torkleyy commented 1 year ago

I would leave the format as-is and document it, this seems like a very specific problem and we can't do anything about the root cause (other than waiting).

juntyr commented 1 year ago

I would leave the format as-is and document it, this seems like a very specific problem and we can't do anything about the root cause (other than waiting).

Ok, that sounds reasonable! Since discovering and fixing more issues with serde's enum representations is definitely a longer project (see https://github.com/juntyr/ron/tree/fuzz-untagged for a rough start), I'd propose to push that after the v0.9 release. For now, I'll document what we know to be problematic, e.g. "ron strives to support most #[serde(untagged)] use cases. However, the following cases are known to not roundtrip: ... . Please file an issue if you come across a use case which is not listed here but still breaks."