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

Refactor hasOnlyLocalInstantiation to use isLocalToCompilationUnit #19886

Merged
merged 2 commits into from
Mar 16, 2024

Conversation

mbovel
Copy link
Member

@mbovel mbovel commented Mar 5, 2024

Follow-up on #19803.

@mbovel mbovel requested a review from odersky March 5, 2024 14:27
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.

LGTM

@mbovel mbovel enabled auto-merge (rebase) March 5, 2024 14:30
@mbovel
Copy link
Member Author

mbovel commented Mar 5, 2024

In scala-parallel-collections, MiMa complains about AddingHashTable not preserving binary compatibility:

private[mutable] abstract class ParHashMapCombiner[K, V](private val tableLoadFactor: Int)
  ...
  private[ParHashMapCombiner] class AddingHashTable(numelems: Int, lf: Int, _seedvalue: Int) extends HashTable[K, V, DefaultEntry[K, V]]
  ...

Source

scala-parallel-collections: Failed binary compatibility check against org.scala-lang.modules:scala-parallel-collections_3:1.0.4! Found 1 potential problems (filtered 287)
[error]  * method this(scala.collection.parallel.mutable.ParHashMapCombiner,Int,Int,Int)Unit in class scala.collection.parallel.mutable.ParHashMapCombiner#AddingHashTable does not have a correspondent in current version
[error]    filter with: ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.parallel.mutable.ParHashMapCombiner#AddingHashTable.this")
[error] Module scala-parallel-collections:1.0.4+28-7d0e41ae-SNAPSHOT is not binary compatible with version 1.0.4. You have to relax your compatibility intention by changing the value of versionPolicyIntention.
[error] java.lang.RuntimeException: Failed binary compatibility check against org.scala-lang.modules:scala-parallel-collections_3:1.0.4! Found 1 potential problems (filtered 287)

Logs

@hamzaremmal
Copy link
Member

@mbovel I've disabled automerge for now to avoid having unexpected CI issues tomorrow morning.

@odersky
Copy link
Contributor

odersky commented Mar 6, 2024

This might be a blocker, unfortunately. We do get a different public interface.

@dwijnand
Copy link
Member

dwijnand commented Mar 6, 2024

I think it might be a bug in isLocalToCompilationUnit, it should be:

-      || accessBoundary(defn.RootClass).isContainedIn(symbol.topLevelClass)
+      || {
+        val boundary = accessBoundary(defn.RootClass)
+        val topLevelCls = symbol.topLevelClass
+        boundary != topLevelCls && boundary.isContainedIn(topLevelCls)
+      }

@dwijnand
Copy link
Member

dwijnand commented Mar 6, 2024

And if you want to be really ambitious, I think we should move the module logic into isLocalToCompilationUnit too.

So I looked at cls.is(Private, butNot = Module) to understand if the module part is redundant. I think the reason is that when a class mixes in the trait, it needs to instantiate the module even if it's private. So I assume there's some trait in the standard library (with Scala 2 emitted bytecode) that contains a private object that we need to correctly instantiate. And in Scala 2 it had an outer pointer, so we need to pass an outer-pointer to its constructor. So I think the logic is correct there, the only progression we could do is start dropping outer pointers when it's defined in Scala 3 instead of Scala 2 - but probably that's not worth it.

Co-Authored-By: Dale Wijnand <dale.wijnand@gmail.com>
@mbovel mbovel requested a review from dwijnand March 16, 2024 00:47
@dwijnand dwijnand merged commit 9ef24bf into scala:main Mar 16, 2024
19 checks passed
@mbovel mbovel deleted the mb/hasOnlyLocalInstantiation branch March 16, 2024 11:51
@Kordyjan Kordyjan added this to the 3.4.2 milestone Mar 28, 2024
WojciechMazur added a commit that referenced this pull request Jul 4, 2024
…ionUnit" to LTS (#20993)

Backports #19886 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
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.

5 participants