-
Notifications
You must be signed in to change notification settings - Fork 33
Make Serializer and Deserializer pub and expose incomplete_enum mechanism
#73
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
base: main
Are you sure you want to change the base?
Conversation
|
Interesting. We may want to mark the newly public function(s) as |
Introduces a third EnumProgress variant to mark enums as pending re-analysis. This now keeps them marked as incomplete but lets the Deserialize make progress. It upholds the promise the the registry can only be complete if incomplete_enums is empty. * add docs to Serializer::new, Deserializer::new * expose EnumProgress * make incomplete_enums only pub(crate) again
|
I think I found a decent way to keep up the invariant that only if |
Serializer and Deserializer pub, access incomplete_enum mechanismSerializer and Deserializer pub and expose incomplete_enum mechanism
|
@ma2bd anything I can do to advance this PR? |
* upstream/main: prepare release of serde-reflection 0.5.1 Add dynamic JSON converter module (zefchain#82) Fix parameter naming in generated code to resolve linter warnings (zefchain#80) attempt to fix get-solc in CI (zefchain#83) Prepare release of serde-generate 0.32.0 and serde-generate-bin 0.8.0 (zefchain#78) Several improvements to solidity support in `serde_reflection` (zefchain#77) prepare release of serde-generate 0.31.0 and serde-generate-bin 0.7.0 Improve the support for solidity (zefchain#74) Fix dart bytes hashcode (zefchain#76)
Hi @jordens, Thanks for your patience. Couple of questions:
|
Shows how one would use serde_reflection::Deserializer directly and explains the relevance of EnumProcess::Pending when doing so.
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.
@ma2bd thanks for looking at this!
-
To make use of an exposed
Deserializerthe user also needs access toincomplete_enumsto signal that further variants should be traced. If the user then removes an enum fromincomplete_enumsthe tracer state is inconsistent (until and unless it is re-traced):tracer.registry()at that point would succeed but be wrong. Before this PR that inconsistency only existed internally and for a short time:during the interval from L260 to the next trace in L255. To make it always consistent for a downstreamserde-reflection/serde-reflection/src/trace.rs
Lines 255 to 260 in df819c4
let (format, value) = self.trace_type_once::<T>(samples)?; values.push(value); if let Format::TypeName(name) = &format { if let Some(&progress) = self.incomplete_enums.get(name) { // Restart the analysis to find more variants of T. self.incomplete_enums.remove(name); Deserializeruser I need a way to distinguish the state "incomplete but marked for re-tracing" (i.e.EnumProgress::Pending) from the state "unknown or complete" (not present in incomplete_enums). I added a unittest showing the functionality and where the inconsistent state would show up. I tried to keep it readable. If you want, I can juggle the commits so that the test will actually show the wrong behavior before a subsequent commit fixes it. -
The infinite loop at that point was undetectable before. With the new
EnumProcess::Pendingit can now be detected. Since an Infinite loop here appears to imply wrong behavior in serde_reflection, I choose assert over returning an error. But I agree that the performance penalty is negligible and it should not be debug_assert. Changed.
Thanks for your answer. I tried your unit test and it doesn't seem to require the new value |
Summary
miniconfis a library we use to access (get/set over serial, mqtt, store in flash) settings on embedded devices. It is aserde-based hierarchical heterogeneous key-value access mechanism.We'd like to generate a schema for the settings trees and found
serde-reflectionvery useful for this (thanks!).We implement functionality similar to
trace_value/trace_typefromTracerusing our intermediateminiconf::TreeSerialize/TreeDeserializetraits. See below for what that looks like.For
trace_valueandtrace_type_oncewe would likeSerializerandDeserializerto bepub. Happy to split that out of this PR if it's uncontroversial.For
trace_typewe also need a way to mark the top level enum inincomplete_enumsbefore tracing again (seetrace_type).Downstream use case:
https://github.com/quartiq/miniconf/blob/c741c31b8fcd5e8769861c16081f0d6895e019a2/miniconf/src/trace.rs#L13-L63
Test Plan
CI