-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #3675: don't unnecessarily wrap arrays when eliminating java varargs #3869
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
Changes from 2 commits
46a9783
7e18110
09dbfc2
9c2f9c2
5482916
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -187,4 +187,32 @@ class TestBCode extends DottyBytecodeTest { | |
diffInstructions(instructions1, instructions2)) | ||
} | ||
} | ||
|
||
/** Verifies that arrays are not unnecessarily wrapped when passed to Java varargs methods */ | ||
@Test def dontWrapArraysInJavaVarargs = { | ||
val source = | ||
""" | ||
|import java.nio.file._ | ||
|class Test { | ||
| def test(xs: Array[String]) = { | ||
| val p4 = Paths.get("Hello", xs: _*) | ||
| } | ||
|} | ||
""".stripMargin | ||
|
||
checkBCode(source) { dir => | ||
val moduleIn = dir.lookupName("Test.class", directory = false) | ||
val moduleNode = loadClassNode(moduleIn.input) | ||
val method = getMethod(moduleNode, "test") | ||
|
||
val arrayWrapped = instructionsFromMethod(method).exists { instr: Instruction => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can do: val arrayWrapped = instructionsFromMethod(method).exists {
case inv: Invoke => inv.name.contains("wrapRefArray")
case _ => false
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
instr match { | ||
case inv: Invoke => inv.name.contains("wrapRefArray") | ||
case _ => false | ||
} | ||
} | ||
|
||
assert(!arrayWrapped, "Arrays should not be wrapped when passed to a Java varargs method\n") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I verified that this fails if I comment out the changes to ElimRepeated. |
||
} | ||
} | ||
} |
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.
@allanrenucci That's much nicer! Thanks! PTAL
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 think the name of the method and doc are confusing. This tests that the tree is a method call to
Predef.wrappedXArray
, not that the tree represents a wrapped array. I would prefer: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.
Done.