-
Notifications
You must be signed in to change notification settings - Fork 71
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
Ignore private constructors #778
Ignore private constructors #778
Conversation
This enables the doMethodOverloads in MimaUnpicker for constructors as well which was commented out with a todo.
…rivate constructors.
…on field on the case class. This also fixed binary compatibility of mima-core.
The build failed due to binary compatibility problems caused by an additional field in DefDef in the TastyUnpickler. I don't really see a way to avoid this. I've added the problems to the mima filters for now. |
…DefDef to the mima filters.
I'm sorry we haven't found a reviewer for this yet. I know it's discouraging to work on something and then get weeks of silence. Sadly, MiMa is without a primary owner at present. It has had a series of them in the past, but they've moved on to other things. If I can't find someone more knowledgeable than myself to review it before too much longer, I'll take a look and presumably optimistically-merge it before too much longer. (But not this week, busy with Scala Days.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @jeroentervoorde for the pull request!
I am not familiar with the codebase but the approach looks good to me, although I am not sure about the changes in TastyUnpickler.scala
. It would be good to get feedback from someone more experienced with the project.
I agree that adding a test with a case class and -Xsource:3
would be amazing!
core/src/main/scala/com/typesafe/tools/mima/core/TastyUnpickler.scala
Outdated
Show resolved
Hide resolved
def copyClassPrivate(tree: Tree, pkgInfo: PackageInfo): Unit = new ClassTraverser(pkgInfo) { | ||
override def forEachClass(clsDef: ClsDef, cls: ClassInfo): Unit = { | ||
} | ||
|
||
override def traverseTemplate(tmpl: Template): Unit = { | ||
super.traverseTemplate(tmpl) | ||
doMethods(tmpl) | ||
} | ||
|
||
def doMethods(tmpl: Template) = { | ||
val clazz = currentClass | ||
tmpl.meths.iterator | ||
.toSeq.groupBy(_.name).foreach { case (name, pickleMethods) => | ||
doMethodOverloads(clazz, name, pickleMethods) | ||
} | ||
} | ||
|
||
def doMethodOverloads(clazz: ClassInfo, name: Name, pickleMethods: Seq[DefDef]) = { | ||
val bytecodeMethods = clazz.methods.get(name.source).filter(!_.isBridge).toList | ||
if (pickleMethods.size == bytecodeMethods.size && pickleMethods.exists(_.classPrivate)) { | ||
bytecodeMethods.zip(pickleMethods).foreach { case (bytecodeMeth, pickleMeth) => | ||
bytecodeMeth.classPrivate = pickleMeth.classPrivate | ||
} | ||
} | ||
} | ||
}.traverse(tree) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please explain why it is not possible to do the job in copyPrivateWithin
? I am a bit lost.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked into it a bit more and actually was possible. The classPrivate flags are now also copied for ValDefs but I guess that's ok.
To make this work: - Added option to skip tests (using skip-${binaryVersion}.txt) - Added support for scala-options-${binaryVersion}.txt) which can be used to set -Xsource:3 (or other scalac options)
I did add a test for the private constructor change. I had to add some new functionality to the test runner though:
I also noticed that i did not get a warning for the unapply method in scala 3 as the signature doesn't actually change anymore (at least in my test). Is this always the case with scala 3? |
Yes. I think weird things could happen at run-time, but the type signature is the same. |
@dwijnand would you be interested in reviewing this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you @jeroentervoorde !
The comment is outdated as the issue was fixed in MiMa: lightbend-labs/mima#778
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [com.typesafe:sbt-mima-plugin](https://togithub.com/lightbend-labs/mima) | plugin | patch | `1.1.3` -> `1.1.4` | --- ### Release Notes <details> <summary>lightbend-labs/mima (com.typesafe:sbt-mima-plugin)</summary> ### [`v1.1.4`](https://togithub.com/lightbend-labs/mima/releases/tag/1.1.4) [Compare Source](https://togithub.com/lightbend-labs/mima/compare/1.1.3...1.1.4) #### Significant changes - Ignore private constructors by [@​jeroentervoorde](https://togithub.com/jeroentervoorde) in [https://github.com/lightbend-labs/mima/pull/778](https://togithub.com/lightbend-labs/mima/pull/778) #### Chores - this repo is under lightbend-labs org now by [@​SethTisue](https://togithub.com/SethTisue) in [https://github.com/lightbend-labs/mima/pull/810](https://togithub.com/lightbend-labs/mima/pull/810) - Update auxlib, clib, javalib, nativelib, ... to 0.5.4 by [@​scala-steward](https://togithub.com/scala-steward) in [https://github.com/lightbend-labs/mima/pull/818](https://togithub.com/lightbend-labs/mima/pull/818) - Update coursier to 2.1.10 by [@​scala-steward](https://togithub.com/scala-steward) in [https://github.com/lightbend-labs/mima/pull/811](https://togithub.com/lightbend-labs/mima/pull/811) - Update munit to 1.0.0 by [@​scala-steward](https://togithub.com/scala-steward) in [https://github.com/lightbend-labs/mima/pull/813](https://togithub.com/lightbend-labs/mima/pull/813) - Update nscplugin, sbt-scala-native to 0.5.1 by [@​scala-steward](https://togithub.com/scala-steward) in [https://github.com/lightbend-labs/mima/pull/805](https://togithub.com/lightbend-labs/mima/pull/805) - Update sbt to 1.10.1 by [@​scala-steward](https://togithub.com/scala-steward) in [https://github.com/lightbend-labs/mima/pull/819](https://togithub.com/lightbend-labs/mima/pull/819) - Update sbt-mima-plugin to 1.1.3 by [@​SethTisue](https://togithub.com/SethTisue) in [https://github.com/lightbend-labs/mima/pull/775](https://togithub.com/lightbend-labs/mima/pull/775) - Update scala-library, scala-reflect to 2.12.19 by [@​scala-steward](https://togithub.com/scala-steward) in [https://github.com/lightbend-labs/mima/pull/800](https://togithub.com/lightbend-labs/mima/pull/800) - Update scala-library, scala-reflect to 2.13.14 by [@​scala-steward](https://togithub.com/scala-steward) in [https://github.com/lightbend-labs/mima/pull/809](https://togithub.com/lightbend-labs/mima/pull/809) - Update scala3-library to 3.3.3 by [@​scala-steward](https://togithub.com/scala-steward) in [https://github.com/lightbend-labs/mima/pull/802](https://togithub.com/lightbend-labs/mima/pull/802) #### New Contributors - [@​jeroentervoorde](https://togithub.com/jeroentervoorde) made their first contribution in [https://github.com/lightbend-labs/mima/pull/778](https://togithub.com/lightbend-labs/mima/pull/778) **Full Changelog**: lightbend-labs/mima@1.1.3...1.1.4 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View the [repository job log](https://developer.mend.io/github/slick/slick). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC4yMC4xIiwidXBkYXRlZEluVmVyIjoiMzguMjAuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->
I've added a classPrivate flag in the same fashion as the scopedPrivate flag and got it value from the pickled flags.
This works for normal classes with private constructors as demonstrated by the test but I could use some input if there are other constructs that would require additional unit tests.
Case classes work as well but they need the -Xsource:3 option and private unapply (as documented here) to pass.
I could add a test for that, either by making it a nok test or by adding some way to enable the -Xsource:3 option for that specific test.
I also enabled the doMethodOverloads in MimaUnpicker for constructors as well which was commented out with a todo.
A side effect is that private[...] constructors are now also ignored (using the existing isScopedPrivate flag) but I'm not actually sure this is the wanted behaviour. If not I propose to add a doConstructorOverloads that only checks the classPrivate flag and either keep doMethodOverloads as is or also include the check for classPrivate is done in the PR.
References #738