Repository navigation
fix(optimizer): exclude abstract polymorphic variants - #319
Conversation
Bergmann89
left a comment
There was a problem hiding this comment.
Hey @sundermann,
Thanks, the core fix looks right to me: abstract complex types and abstract elements are both caught, concrete leaves under an abstract intermediate survive, and computing the abstract set up front really makes the conversion order-independent. The onix snapshot changes are all explained by the removed abstract XHTML heads.
A few things before merging:
- Missing test for the generated serializer/deserializer. The new tests use
Config::test_default(), which only renders the types, so the quick_xml code for the new empty enums is never generated or compiled. In the flattened casenext_eventrendersmatch *self.value {}followed by more code, which will most likely triggerunreachable_code. Please add a feature test undertests/feature/withschema.xsd+ compiledexpected/default.rs/expected/quick_xml.rs, with and withoutFLATTEN_CONTENT, plus a read test that a concrete member round-trips and an abstract tag is rejected. - Converting a single type affects other dynamic types.
remove_abstract_derived_types(dynamic_to_choice.rs) strips abstract entries from every dynamic type, not just the one being converted. For a type that stays dynamic, this drops trait impls and supertraits from the boxed-dyn output. Please touch only the types being converted.
Nits: add an empty /// line before the new doc lines in dynamic_to_choice.rs:20, and the comment at complex.rs:292 mostly repeats the condition.
9fc5a5d to
6e2099e
Compare
|
@Bergmann89 Thanks! I revisited the PR and adressed the feedback, should be good now |
Bergmann89
left a comment
There was a problem hiding this comment.
Thanks, that looks great now! The new feature test with the read tests is exactly what I was looking for, and the conversion only touches the converted types now.
I added the last small things as suggestions, then it's ready to merge.
Dynamic-to-choice conversion exposes abstract type records and abstract substitution group members as constructible enum variants. Cache abstract identifiers before conversion and filter only the choice being built, leaving unconverted boxed-dyn types and their inheritance traits intact. Keep results without concrete alternatives as empty choices and retain their uninhabited enum content when flattening is disabled. Generate exhaustive XML serializers and deserializers for those empty enums, without unused helper bindings or XML root context. Forward element names, namespaces and root state through unflattened dynamic content so concrete values serialize consistently in both layouts. Generated enums no longer expose abstract variants, and types without concrete alternatives can no longer be instantiated as empty structs. Required fields of these uninhabited types make their parents uninhabited as well.
6e2099e to
dc3cd25
Compare
Fixes
CONVERT_DYNAMIC_TO_CHOICEexposing abstract schema types and elements as constructible enum variants.Changes
FLATTEN_CONTENT, withunreachable_codedenied. Cover nested and standalone concrete XML round trips, rejection of abstract tags and types, and empty choices. Metadata regressions cover conversion order and preserving unconverted dynamic types.Generated API changes: enums lose invalid abstract variants, and abstract types without concrete descendants can no longer be instantiated as empty structs. A required field of an uninhabited type also makes its containing type impossible to construct.
Checklist
update-expectationsand reviewedcargo fmt,cargo clippyandcargo testpass (see CONTRIBUTING.md)cargo build -p benchmark --releaseand release runs ofread_write,bpmn, andvsmepass