Skip to content
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

Fix class ordering when propagating type annotations, take two #352

Merged
merged 1 commit into from
Feb 12, 2024

Conversation

Ladicek
Copy link
Collaborator

@Ladicek Ladicek commented Feb 12, 2024

To propagate type annotations across nested classes, we sort the entire set of indexed classes so that outer classes come before their inner classes. We don't really care about ordering between classes that are not members of the same nest (using the JEP 181 terminology). That is, we only need a partial order on classes.

However, to perform that sort, we use the sorting routine in the JDK, which uses the order defined by a Comparator, and that order must be total.

To define a total order, this commit takes a completely opposite approach. We compute a nesting level for each class (where a top-level class has a nesting level of 0, a class nested in a top-level class has a nesting level of 1, etc.) and sort by the nesting level. For equal nesting levels, we sort by the class name. This means that all top-level classes come first, all classes nested in top-level classes come second, etc.

To verify that a given Comparator establishes a total order for a given set of values, this commit includes a simple utility class TotalOrderChecker, which was used to reproduce (and understand) the problem of previous implementation of this ordering.

Fixes #349
Follows up on #290

To propagate type annotations across nested classes, we sort the entire
set of indexed classes so that outer classes come before their inner
classes. We don't really care about ordering between classes that are
not members of the same nest (using the JEP 181 terminology). That is,
we only need a partial order on classes.

However, to perform that sort, we use the sorting routine in the JDK, which
uses the order defined by a `Comparator`, and that order must be total.

To define a total order, this commit takes a completely opposite approach.
We compute a nesting level for each class (where a top-level class has
a nesting level of 0, a class nested in a top-level class has a nesting
level of 1, etc.) and sort by the nesting level. For equal nesting levels,
we sort by the class name. This means that all top-level classes come first,
all classes nested in top-level classes come second, etc.

To verify that a given `Comparator` establishes a total order for a given
set of values, this commit includes a simple utility class `TotalOrderChecker`,
which was used to reproduce (and understand) the problem of previous
implementation of this ordering.
@Ladicek Ladicek merged commit a50c850 into smallrye:main Feb 12, 2024
39 checks passed
@Ladicek Ladicek deleted the index-postprocessing-sort branch February 12, 2024 16:05
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.

Comparison method violates its general contract!
1 participant