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

Ignore private constructors #778

Merged
merged 10 commits into from
Dec 11, 2023

Conversation

jeroentervoorde
Copy link
Contributor

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

This enables the doMethodOverloads in MimaUnpicker for constructors as well which was commented out with a todo.
@jeroentervoorde jeroentervoorde changed the title Private constructors Ignore private constructors Aug 9, 2023
…on field on the case class.

This also fixed binary compatibility of mima-core.
@jeroentervoorde jeroentervoorde marked this pull request as draft August 10, 2023 14:22
@jeroentervoorde
Copy link
Contributor Author

jeroentervoorde commented Aug 11, 2023

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.
Not sure if DefDef is/should be part of the public api.

@jeroentervoorde jeroentervoorde marked this pull request as ready for review August 17, 2023 09:46
@SethTisue
Copy link
Collaborator

SethTisue commented Sep 10, 2023

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.)

Copy link
Contributor

@julienrf julienrf left a 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!

Comment on lines 105 to 130
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)
Copy link
Contributor

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.

Copy link
Contributor Author

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)
@jeroentervoorde
Copy link
Contributor Author

I did add a test for the private constructor change. I had to add some new functionality to the test runner though:

  • Tests can now be skipped by adding a "skip-${version}.txt" file.
  • Scalac options can be set using a "scalac-options-${version}.txt" file.

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?

@julienrf
Copy link
Contributor

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.

@julienrf
Copy link
Contributor

julienrf commented Dec 7, 2023

@dwijnand would you be interested in reviewing this PR?

Copy link
Collaborator

@dwijnand dwijnand left a 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 !

@dwijnand dwijnand merged commit 68f6dc6 into lightbend-labs:main Dec 11, 2023
11 checks passed
daddykotex added a commit to daddykotex/docs.scala-lang that referenced this pull request Jan 23, 2024
The comment is outdated as the issue was fixed in MiMa: lightbend-labs/mima#778
@SethTisue SethTisue mentioned this pull request Jun 20, 2024
mergify bot referenced this pull request in slick/slick Aug 9, 2024
[![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
[@&#8203;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
[@&#8203;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
[@&#8203;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
[@&#8203;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
[@&#8203;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
[@&#8203;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
[@&#8203;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
[@&#8203;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
[@&#8203;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
[@&#8203;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
[@&#8203;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

- [@&#8203;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==-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants