Skip to content

Fix #7212: Generate bridge for varargs annotation #9271

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

Merged
merged 12 commits into from
Jul 12, 2020

Conversation

TheElectronWill
Copy link
Contributor

@TheElectronWill TheElectronWill commented Jul 1, 2020

This shares most of the logic with the generation of bridges for overrides of java varargs methods.

I've added tests in pos-java-interop, but I'm not 100% confident that this is the right place 🤔 moved to run/tests/i7212 after smarter's review

@TheElectronWill TheElectronWill linked an issue Jul 1, 2020 that may be closed by this pull request
@TheElectronWill TheElectronWill requested a review from smarter July 1, 2020 17:34
Copy link
Member

@smarter smarter left a comment

Choose a reason for hiding this comment

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

If you grep for @varargs in https://github.com/scala/scala/tree/2.13.x/test you'll find a bunch of tests, can you try to port them over and see if they work with your implementation? One thing which probably still needs to be handled is when a scala method without @varargs overrides a scala method with @varargs, in that case we still need to generate the varargs bridge for the override I think.

@smarter
Copy link
Member

smarter commented Jul 1, 2020

you'll find a bunch of tests

Note that tests in test/files/jvm in scalac are just run tests and can go in tests/run in dotty.

@TheElectronWill
Copy link
Contributor Author

can you try to port them over and see if they work with your implementation?

I'll try that!

@TheElectronWill TheElectronWill force-pushed the varargs-annotation branch 5 times, most recently from e1304d6 to 8212750 Compare July 2, 2020 14:25
@TheElectronWill
Copy link
Contributor Author

TheElectronWill commented Jul 2, 2020

I've ported some tests but this one fails because the generic signatures aren't properly generated.
If the vararg uses a type parameter it doesn't show up in the signature, i.e. the backend emits [Ljava/lang/Object; instead of something like [TE;. It may not be in the scope of this PR.

@smarter
Copy link
Member

smarter commented Jul 3, 2020

If the vararg uses a type parameter it doesn't show up in the signature

This TODO is probably related: https://github.com/lampepfl/dotty/blob/ffd6a5892740d8038e85e0302d56591241135652/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala#L258
The corresponding code in scalac is: https://github.com/scala/scala/blob/9208bc449990cb9248837c3c841f651c121a4b66/src/compiler/scala/tools/nsc/transform/Erasure.scala#L378-L386
scalac relies on an attachement to remember the type parameter name, that's not very nice. Hopefully we don't need to do that in dotty because the varargs parameter has type Array[T & AnyRef] so the T is still present?

@TheElectronWill
Copy link
Contributor Author

TheElectronWill commented Jul 3, 2020

Yes the T is there (+1 for dotty :) ). I believe varargs are Array[? <: T & AnyRef] now.

I've just tried this test and it fails under -Ycheck:all with java.lang.AssertionError: assertion failed: Types differ while trying to compare T* and Seq[T]. Varargs + currying produce the same error:

object VarArgs {
  @annotation.varargs
  def two(a: Int)(b: String*): Nothing = ???
}
*** error while checking tests/pos/varargs-currying.scala after phase refchecks ***
exception occurred while compiling tests/pos/varargs-currying.scala
java.lang.AssertionError: assertion failed: Types differ
Original type : (b: String*): Nothing
After checking: (b: Seq[String]): Nothing
Original tree : VarArgs.two(a)
After checking: VarArgs.two(a)

I have yet to find the root cause of this.

@TheElectronWill TheElectronWill changed the title Fix #7212: Generate bridge for varargs annotation [wip] Fix #7212: Generate bridge for varargs annotation Jul 3, 2020
@TheElectronWill
Copy link
Contributor Author

TheElectronWill commented Jul 9, 2020

The ported tests seem to work now. I've added some cases.

sconfig fails to build because it defines a @varargs-annotated method and then overrides it with a repeatable parameter and defines a conflicting method with an array parameter (as a workaround for the previous lack of @varargs handling). An error is expected. What should we do then? Remove (temporarily) sconfig from the community build?

@TheElectronWill TheElectronWill changed the title [wip] Fix #7212: Generate bridge for varargs annotation Fix #7212: Generate bridge for varargs annotation Jul 9, 2020
@TheElectronWill TheElectronWill requested a review from smarter July 9, 2020 20:47
@smarter
Copy link
Member

smarter commented Jul 9, 2020

What should we do then? Remove (temporarily) sconfig from the community build?

No need hopefully: all the projects in our community build are submodules in https://github.com/dotty-staging, so we can fix them without waiting on upstream. I've just given you access to that organization, so you should be able to push a new branch to github.com/dotty-staging/scodec/ with the fix in, and update this PR to make the scodec submodule point to that commit.

TheElectronWill added a commit to dotty-staging/sconfig that referenced this pull request Jul 10, 2020
This was a hack for the lack of `@varargs` implementation, which is fixed by scala/scala3#9271
@TheElectronWill
Copy link
Contributor Author

TheElectronWill commented Jul 10, 2020

No need hopefully: all the projects in our community build are submodules in https://github.com/dotty-staging, so we can fix them without waiting on upstream. I've just given you access to that organization, so you should be able to push a new branch to github.com/dotty-staging/scodec/ with the fix in, and update this PR to make the scodec submodule point to that commit.

Done! SConfig was the only submodule not in dotty-staging so I forked it.

@TheElectronWill
Copy link
Contributor Author

rebased

Copy link
Member

@smarter smarter left a comment

Choose a reason for hiding this comment

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

Awesome work, thanks! That was harder than I thought it would be :).

@smarter smarter assigned TheElectronWill and unassigned smarter Jul 11, 2020
Copy link
Member

@smarter smarter left a comment

Choose a reason for hiding this comment

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

Otherwise LGTM!

@smarter smarter merged commit 38553ce into scala:master Jul 12, 2020
@TheElectronWill TheElectronWill deleted the varargs-annotation branch August 10, 2020 14:05
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.

@vararg annotation when called from Java does not compile
2 participants