Skip to content

Conversation

arlyon
Copy link

@arlyon arlyon commented Sep 15, 2025

This is a breaking change.

This PR achieves two things:

  • change the logic to allow for combinations of named an unnamed (VariantN) variants in enums, rather than an all-or-nothing approach
  • improve the name-finding heuristic to give reasonable defaults for the 7 instance types

You can see the outcome on the codegen from the snapshot tests, and I have included a new snapshot test that exercises the partially-named case.

I decided to keep the Variant number as its index in the overall type list, not as its index amongst unnamed types such that its name is stable under the addition or removal of metadata earlier in the schema that would add or remove inferred names.

This also changes the behaviour upon encountering duplicates. Previously, there was a later check to assert the code did not produce them. Now, in the case that the inferred name is the same for two or more variants, we just eject the affected enum back to VariantN

@arlyon arlyon force-pushed the arlyon/instance-type-inference branch from ac77c4b to a76393e Compare September 15, 2025 16:05
@@ -863,7 +863,7 @@ impl<'de> ::serde::Deserialize<'de> for Ipv6Net {
pub enum JankNames {
Variant0(::std::string::String),
Variant1(::std::collections::HashMap<::std::string::String, ::std::string::String>),
Copy link
Author

@arlyon arlyon Sep 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These clash and so stay as Variant0 and Variant1, however the object variant will be given a descriptive name.

There is an argument to be made to call them <INFERRED_NAME>0 and <INFERRED_NAME>1 instead. It is fairly easy to add. Will let you make the call.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is surprising. Variants 0 and 1 have the same title; variants 1 and 2 have the same type (object).

Copy link
Author

@arlyon arlyon Sep 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The clash is resolved at the name level, and the heuristic currently only produces a single name (rather than a ranked list of Variant1 or else Object for example) and so there is a clash for the first 2 but not the third.

Will be irrelevant when I revert the best-effort name resolution in favour of all-or-nothing.

Copy link
Collaborator

@ahl ahl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks very much for this submission. Please see my other comments; happy to discuss.

Comment on lines 621 to 623
// Store seen, un-stripped names here. Any item for which their
// name appears more than once, ALL the items with that clashing
// name will be converted to the `VariantN` scheme.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize this is a matter of aesthetics, but I don't think we should mix naming schemes: either we have a "good" name that we derive from the schema or the type and is unique, or we use Variant{n}. I think that mix and match is worse.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your call. I will revert that part of the functionality but leave it in a separate commit in case the opinion changes.

@@ -863,7 +863,7 @@ impl<'de> ::serde::Deserialize<'de> for Ipv6Net {
pub enum JankNames {
Variant0(::std::string::String),
Variant1(::std::collections::HashMap<::std::string::String, ::std::string::String>),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is surprising. Variants 0 and 1 have the same title; variants 1 and 2 have the same type (object).

@arlyon
Copy link
Author

arlyon commented Sep 16, 2025

Feedback addressed. Thank you for the prompt reply 🥇

@arlyon arlyon force-pushed the arlyon/instance-type-inference branch from a76393e to 83a6da7 Compare September 16, 2025 10:36
@arlyon arlyon requested a review from ahl September 16, 2025 10:38
@arlyon arlyon force-pushed the arlyon/instance-type-inference branch from 83a6da7 to 347a338 Compare September 16, 2025 10:48
Copy link
Collaborator

@ahl ahl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some nits to consider.

@arlyon arlyon force-pushed the arlyon/instance-type-inference branch 2 times, most recently from 40669ea to f8b3c71 Compare September 17, 2025 19:41
@arlyon arlyon requested a review from ahl September 17, 2025 19:42
@arlyon
Copy link
Author

arlyon commented Sep 17, 2025

Ok, pared back the impl and added support for format which as added DateTime, Uuid, and Uri. 🎉

@arlyon arlyon force-pushed the arlyon/instance-type-inference branch from f8b3c71 to a5f0ed8 Compare September 17, 2025 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants