Skip to content

Replace Set with UniqList in memberNames #13973

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

Closed
wants to merge 2 commits into from

Conversation

dwijnand
Copy link
Member

This is intended to be a fix for the filename-based behaviour change observed in the nightly java 8 failure #13878.

But I'm unable to recreate the problem because of a stupid "Cyclic Error" involving $throws.scala and object Predef...

But it's doing something reasonable, IMHO.

[test_java8]
[test_non_bootstrapped]
[test_windows_full]

@dwijnand dwijnand marked this pull request as ready for review November 17, 2021 18:02
Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

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

Set is there for a reason. UniqList would introduce too many duplicates. We should not admit changes that have the potential for significant slowdowns, even if it is only in specific situations.

I am still not convinced we should fix it. And if we should we should have a very good argument that no performance could possibly be lost.

@dwijnand
Copy link
Member Author

Duplicates how? I believe it to be behaving like Set, removing any duplicates. Perhaps the name UniqList imply something else to you? Do you have a better name for it?

@odersky
Copy link
Contributor

odersky commented Nov 22, 2021

So it removes the duplicates at linear cost. good. That's still unacceptable.

@nicolasstucki
Copy link
Contributor

Can we use a LinkedHashSet?

@odersky
Copy link
Contributor

odersky commented Nov 22, 2021 via email

@dwijnand
Copy link
Member Author

dwijnand commented Nov 22, 2021

So there aren't many uses of the various duplicate-removing APIs (+ is only for RefinedType for example). I tried to do something reasonable in the construction, using a builder and calling distinct only at the end. Similarly we can revise &, | and filter.

The motivation is compiler determinism: avoid that the names of the input source files vary the order in which names are iterated (which is determined by the name hashes, but also from the order in which names are forced onto the names table). The difference in hash-based iteration order was one of the key contributors to the reoccurring nightly failures we had some 10 days ago.

I was initially worried that this set was heavily used for membership testing, but that didn't turn out to be true, so I went with a sequence-based structure. I care more about the intent than how it's done, so if a LinkedHashSet is preferred, I can look to switch to that, or any other ideas.

@dwijnand
Copy link
Member Author

Perhaps I can keep it as an immutable Set, but hide it behind an opaque type so we can sort the names according to Name's Ordering on any iterating operations (foreach, iterator, etc)?

@dwijnand
Copy link
Member Author

I guess that's similar to a SortedSet, except with the ordering only used for iteration rather than also storage.

@dwijnand
Copy link
Member Author

Apart from another use of memberNames in RefChecks (for default methods), the main point in which names are iterated is in:

     def memberDenots(keepOnly: NameFilter, f: (Name, mutable.Buffer[SingleDenotation]) => Unit)(using Context): Seq[SingleDenotation] = {
       val buf = mutable.ListBuffer[SingleDenotation]()
-      for (name <- memberNames(keepOnly)) f(name, buf)
+      for (name <- memberNames(keepOnly).toList.sorted) f(name, buf)
       buf.toList
     }

But I think that's going to be objectively worst, as that sorting isn't even persisted...

@dwijnand dwijnand requested a review from odersky November 28, 2021 18:23
Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

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

SortedSet is also very inefficient. Since the original issue #13878 is already closed, let's just keep things as they are.

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.

3 participants