zefchain / serde-reflection

Rust libraries and tools to help with interoperability and testing of serialization formats based on Serde.
Apache License 2.0
139 stars 26 forks source link

[Feature Request] Improved tracing algorithm in serde_reflection::trace_type #21

Closed jerel closed 1 year ago

jerel commented 2 years ago

🚀 Feature Request

serde_reflection::trace_type relies on a few ideas and heuristics that it might be time to revisit.

Notably, we use the current table of formats tracer.registry to guide the tracing in most decision points -- with the exception of tracer.incomplete_enums that is also used to decide how to trace enum variants.

This approach was a natural starting point but it is not ideal in the long run for a few reasons:

Calling trace_value before trace_type may update the registry in an incomplete way and defeat further tracing with trace_type. We don't have an easy way to detect non-termination if the base case of enums is not the first variant. We cannot call trace_type_once<T> repeatedly and hope to make progress in finding variants that are deeper that T. (For instance, after one tracing call on struct T(option<S>) we are not going to look into S ever again because it has a format: https://github.com/novifinancial/serde-reflection/blob/master/serde-reflection/src/de.rs#L199)

Moving this issue across from https://github.com/novifinancial/serde-reflection/issues/104

jerel commented 1 year ago

@ma2bd do you have any further thoughts on this algorithm? The workaround that I've been using to explicitly trace enums is getting quite unwieldy in our large codebase so I have motivation to make serde-reflection trace enums fully. I wanted to check if you had any plans for implementation before I took a shot at it.

ma2bd commented 1 year ago

Hi @jerel , Sorry for the lag. I eventually kinda gave up on improving tracing. From the top of my head, the main difficulties are: