-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Look up members at erasure phase for generating static forwarders #12767
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
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,3 +34,4 @@ typeclass-derivation3.scala | |
varargs-abstract | ||
zero-arity-case-class.scala | ||
i12194.scala | ||
i12753 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
1 | ||
Dbr | ||
1 | ||
1 | ||
2 | ||
1 | ||
1 | ||
1 | ||
1 | ||
2 | ||
1 | ||
1 | ||
synthetic public static C D.foo(int) | ||
public static D D.foo(int) | ||
public static D D.t() | ||
synthetic public static java.lang.Object D.bar() | ||
public static java.lang.String D.bar() | ||
public static int O.a() | ||
public static int O.b() | ||
public static int O.c() | ||
public static int O.d() | ||
public static int O.i() | ||
public static int O.j() | ||
public static int O.k() | ||
public static int O.l() | ||
synthetic public static void O.T$_setter_$a_$eq(int) | ||
public static void O.b_$eq(int) | ||
public static void O.j_$eq(int) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
trait C[This <: C[This]] | ||
|
||
trait COps[This <: C[This]] { | ||
def t: This | ||
def foo(x: Int): This = t | ||
def bar: Object = "Cbr" | ||
} | ||
|
||
class D extends C[D] { | ||
def x = 1 | ||
} | ||
object D extends COps[D] { | ||
def t = new D | ||
override def foo(x: Int): D = super.foo(x) | ||
override def bar: String = "Dbr" | ||
} | ||
|
||
trait T { | ||
val a = 1 | ||
var b = 1 | ||
lazy val c = 1 | ||
def d = 1 | ||
|
||
val i: Int | ||
var j: Int | ||
lazy val k: Int = 1 | ||
def l: Int | ||
} | ||
object O extends T { | ||
val i: Int = 1 | ||
var j: Int = 1 | ||
override lazy val k: Int = 1 | ||
def l: Int = 1 | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
public class Test { | ||
public static void s(Object s) { | ||
System.out.println(s); | ||
} | ||
|
||
public static void statics(Class<?> c) { | ||
java.lang.reflect.Method[] ms = c.getDeclaredMethods(); | ||
java.util.Arrays.sort(ms, (a, b) -> a.toString().compareTo(b.toString())); | ||
for (java.lang.reflect.Method a : ms) { | ||
if (java.lang.reflect.Modifier.isStatic(a.getModifiers())) | ||
s((a.isSynthetic() ? "synthetic " : "") + a); | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
s(D.foo(1).x()); | ||
s(D.bar().trim()); | ||
|
||
s(O.a()); | ||
s(O.b()); | ||
O.b_$eq(2); | ||
s(O.b()); | ||
s(O.c()); | ||
s(O.d()); | ||
|
||
s(O.i()); | ||
s(O.j()); | ||
O.j_$eq(2); | ||
s(O.j()); | ||
s(O.k()); | ||
s(O.l()); | ||
|
||
statics(D.class); | ||
statics(O.class); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Given:
If I look at what we do before this PR, I see that sortedMembersBasedOnFlags returns two
get
methods, but only one of them.is(Bridge)
, can't we rely on that to know that its forwarder should be synthetic?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 gave that a try, but
looking up
O$
's members at the backend phase we get a methodO$.d
that's markedBridge
. Also, forthe lookup returns both a bridge
()Object
and the()String
method. However, 3.0.0 doesn't generate a static accessor for the bridge in this case, so it would be quite weird to start adding a new synthetic method now.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.
Ah, that's because we mark mixin forwarders as bridge too, so we could try excluding only bridges generated at erasure.
But if we only add this check in the place where the original code called
addForwarder
we shouldn't end up adding more forwarders.I've implemented this idea in #12860, let me know what you think.