You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Quotes reflect: sort the typeMembers output list and filter out non-members (#22876)
The typeMember currently returns a List (implying some kind of
ordering), even though the order of the elements can be unpredictable.
This is because the underlying methods operate on Sets, before wrapping
those into a Seq. I believe the simplest solution is to just sort the
obtained List as part of the quotes reflect implementation: first
depending on the location (which classlike contains it), then depending
on if it is a type parameter (and the declaration order of it), then for
non-type params lexicographically (ideally it would also be sorted by
declaration order, but I can't really find the use case for that and it
would easily be the costliest part). The reasons for choosing to sort
are:
* rewriting the memberDenot to remember the ordering of items (like
suggested in the linked issue thread) is dangerous. LinkedHashMap the
only hashmap which keeps the insertion order, but it currently has no
immutable version (so a simple mistake could spiral across the whole
compiler, esp. easy to happen as the collected names are cached there)
and it would add an ever so slight performance cost to a critical part
of the compiler.
* This all might suggest that a quotes reflect specific rewrite would be
better (since we end up redoing some of the calculations done as part of
the `lookupPrefix.typeMembers`), but the costliest part, filtering
through all of the declarations from all of the parents, we do not have
to touch as part of this sort. We can also reuse the caches (while
making sure we do not miss any type members which were included in the
previous implementation), since we just sort that part
lexicographically.
We also now filter out the non-existent Symbols, which can appear like
in #22483. The whole reason why that happens is because after collecting
the member names in `memberDenots` we wrap them in `member` to get their
Denotation/Symbol. If that returns a NoSymbol, it's because we cannot
access them as part of the symbol (so any kind of selection there will
not work either). Because of this, I am comfortable with just filtering
them out.
Fixes#22472Fixes#22483
0 commit comments