8000 [backport] SI-10071 and SI-8786 by dragos · Pull Request #5557 · scala/scala · GitHub
[go: up one dir, main page]

Skip to content

[backport] SI-10071 and SI-8786 #5557

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 4 commits into from

Conversation

dragos
Copy link
Contributor
@dragos dragos commented Nov 25, 2016

The fix in #5556 depends on 70f11f1, which refactored the relevant code parts in UnCurry. A backport without that commit would be essentially a rewrite and IMO more risky than just back-porting both.

lrytz and others added 4 commits November 25, 2016 20:00
When generating a varargs forwarder for

    def foo[T](a: T*)

the parameter type of the forwarder needs to be Array[Object]. If we
gnerate Array[T] in UnCurry, that would be erased to plain Object, and
the method would not be a valid varargs.

Unfortunately, setting the parameter type to Array[Object] lead to
an invalid generic signature - the generic signature should reflect the
real signature.

This change adds an attachment to the parameter symbol in the varargs
forwarder method and special-cases signature generation.

Also cleanes up the code to produce the varargs forwarder. For example,
type parameter and parameter symbols in the forwarder's method type were
not clones, but the same symbols from the original method were re-used.
Make sure that methods annotated with varargs are properly mixed-in. This commit
splits the transformation into an info transformer (that works on all symbols, whether
they come from source or binary) and a tree transformer.

The gist of this is that the symbol-creation part of the code was moved to the UnCurry
info transformer, while tree operations remained in the tree transformer. The newly
created symbol is attached to the original method so that the tree transformer can still
retrieve the symbol.

A few fall outs:

- I removed a local map that was identical to TypeParamsVarargsAttachment
- moved the said attachment to StdAttachments so it’s visible between reflect.internal
  and nsc.transform
- a couple more comments in UnCurry to honour the boy-scout rule
Cloning the original symbol in its entirety, rather than cloning
its type/value parameters individually. `cloneSymbol` takes care of
all the tricky substitutions for us!
@dragos dragos added this to the 2.11.9 milestone Nov 25, 2016
@@ -77,6 +101,60 @@ trait UnCurry {
}
}

private def varargForwarderSym(currentClass: Symbol, origSym: Symbol, newInfo: Type): Symbol = {
val forwSym = currentClass.newMethod(origSym.name.toTermName, origSym.pos, VARARGS | SYNTHETIC | origSym.flags & ~DEFERRED)
Copy link
Member

Choose a reason for hiding this comment

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

note that this also includes the fix for SI-10059 / #5534 which was not previously backported to 2.11.x. maybe add its test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I'll have a look. I'm a bit surprised about the failing test, since this seemed to pass on my system. Also, there are some compiler crashes, weird... :-/

@dragos
Copy link
Contributor Author
dragos commented Nov 26, 2016

I just tried again and that commit at least builds on my system, I am wondering what could be the problem with the bot... It crashes, I have no idea if this is a real error or just a failure of the bot. Can you please advise? I'm talking about the first two commits, 70f11f1 and a31673b.

@dragos
Copy link
Contributor Author
dragos commented Nov 26, 2016

70f11f1 passes all tests on my machine (using the ant build).

test.stability:
Comparing build/quick/classes and build/strap/classes
 library:  3867 classfiles verified identical
 reflect:  3054 classfiles verified identical
compiler:  7860 classfiles verified identical

test.done:

test:

BUILD SUCCESSFUL
Total time: 40 minutes 38 seconds

And for the tip of the branch, Jason's commit:

test.stability:
Comparing build/quick/classes and build/strap/classes
 library:  3867 classfiles verified identical
 reflect:  3066 classfiles verified identical
compiler:  7858 classfiles verified identical

test.done:

test:

BUILD SUCCESSFUL
Total time: 42 minutes 39 seconds

@lrytz
Copy link
Member
lrytz commented Nov 26, 2016

the 2.11.x build has a spurious failure that we haven't managed to nail down yet: scala/scala-dev#251. but it's happening so much lately that it's becoming really hard to get a 2.11.x PR green :-(

for the failure of jvm/t8786-sig.scala, this seems to be a real issue - maybe related to the optimizer being enabled on CI? cannot check right now..

@lrytz
Copy link
Member
lrytz commented Nov 27, 2016

I re-ran the build on the first commit, no spurious failures this time. The failure of jvm/t8786-sig.scala looks legit.

@dragos
Copy link
Contributor Author
dragos commented Nov 28, 2016

How should I build? Using ant or sbt? It seems the CI is using Sbt, but the docs say ant is the official build. At any rate, the tests should pass with or without optimizations, right?

@dragos
Copy link
Contributor Author
dragos commented Nov 28, 2016
8000

I built with optimizations on (ant build-opt) and tests still pass on my system. Any ideas?

@lrytz
Copy link
Member
lrytz commented Nov 28, 2016

I also didn't manage to reproduce it - until just now, by switching to JDK 6.

Here's the log file:

java.lang.AssertionError: assertion failed: found: public <T> T A.m1(T[])
expected: public <T> T A.m1(T...)
	at Test$.check(t8786-sig.scala:37)

@lrytz
Copy link
Member
lrytz commented Nov 28, 2016

so maybe the toString simply changed between JDK 6 and 8?

@dragos
Copy link
Contributor Author
dragos commented Nov 28, 2016

Oh, thanks! I will try Java 6...

@lrytz
Copy link
Member
lrytz commented Nov 28, 2016

brew cask install java6 (i actually had to do reinstall)

@dragos
Copy link
Contributor Author
dragos commented Dec 10, 2016

I didn't forget about this, but got caught up in work prior to Scala Exchange. I'll get back to it next week.

@adriaanm
Copy link
Contributor
adriaanm commented Jan 5, 2017

Ping! 2.11.9 PRs are due soon. We'd like to cut the tag in two weeks (Jan 20th).

@adriaanm
Copy link
Contributor
adriaanm commented Jan 9, 2017

(FYI, to use brew cask for older versions, you also first need to run brew tap caskroom/versions. I'll look into this one.)

@adriaanm
Copy link
Contributor
adriaanm commented Jan 9, 2017

Java bug?

public interface Foo {
  public <T> void tempMethod(T... ia) throws Exception;
}
$ javac -version
javac 1.6.0_65
➜  /tmp ~/scala/scala-2.11.8/bin/scala
Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_65).
Type in expressions for evaluation. Or try :help.

scala> classOf[Foo].getDeclaredMethod("tempMethod", classOf[Array[Object]]).isVarArgs
res0: Boolean = true

scala> classOf[Foo].getDeclaredMethod("tempMethod", classOf[Array[Object]]).toGenericString
res1: String = public abstract <T> void Foo.tempMethod(T[]) throws java.lang.Exception

➜  /tmp java_home 1.8               
➜  /tmp scala
Welcome to Scala 2.12.0 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_112).
Type in expressions for evaluation. Or try :help.

scala> classOf[Foo].getDeclaredMethod("tempMethod", classOf[Array[Object]]).toGenericString
res0: String = public abstract <T> void Foo.tempMethod(T...) throws java.lang.Exception

@adriaanm
Copy link
Contributor
adriaanm commented Jan 9, 2017

I guess it's not really a bug per se -- the docs https://docs.oracle.com/javase/6/docs/api/java/lang/reflect/Method.html#toGenericString() don't mention the ... pretty printing, whereas they do at https://docs.oracle.com/javase/7/docs/api/java/lang/reflect/Method.html#toGenericString()

@adriaanm
Copy link
Contributor
adriaanm commented Jan 9, 2017

Rebased and test fixed in #5630

@adriaanm adriaanm closed this Jan 9, 2017
@dragos
Copy link
Contributor Author
dragos commented Jan 24, 2017

Thanks a lot @adriaanm. Sorry I lagged so much.

@adriaanm
Copy link
Contributor
adriaanm commented Jan 24, 2017 via email

@SethTisue SethTisue removed this from the 2.11.9 milestone Feb 22, 2017
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
0