Skip to content

Commit ff6bee5

Browse files
authored
Merge pull request scala#10410 from som-snytt/tweak/inliner-message
Tweak inliner error message
2 parents 7992103 + 8b878ec commit ff6bee5

File tree

4 files changed

+54
-49
lines changed

4 files changed

+54
-49
lines changed

src/compiler/scala/tools/nsc/backend/jvm/BackendReporting.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,14 @@ object BackendReporting {
191191
s"\nthat would cause an IllegalAccessError when inlined into class $callsiteClass."
192192

193193
case IllegalAccessCheckFailed(_, _, _, _, callsiteClass, instruction, cause) =>
194-
s"Failed to check if $calleeMethodSig can be safely inlined to $callsiteClass without causing an IllegalAccessError. Checking instruction ${AsmUtils.textify(instruction)} failed:\n" + cause
194+
sm"""|Failed to check if $calleeMethodSig can be safely inlined to $callsiteClass without causing an IllegalAccessError.
195+
|Checking failed for instruction ${AsmUtils.textify(instruction)}:
196+
|$cause"""
195197

196198
case MethodWithHandlerCalledOnNonEmptyStack(_, _, _, _, callsiteClass, callsiteName, callsiteDesc) =>
197-
s"""The operand stack at the callsite in ${BackendReporting.methodSignature(callsiteClass, callsiteName, callsiteDesc)} contains more values than the
198-
|arguments expected by the callee $calleeMethodSig. These values would be discarded
199-
|when entering an exception handler declared in the inlined method.""".stripMargin
199+
sm"""|The operand stack at the callsite in ${BackendReporting.methodSignature(callsiteClass, callsiteName, callsiteDesc)} contains more values than the
200+
|arguments expected by the callee $calleeMethodSig. These values would be discarded
201+
|when entering an exception handler declared in the inlined method."""
200202

201203
case SynchronizedMethod(_, _, _, _) =>
202204
s"Method $calleeMethodSig cannot be inlined because it is synchronized."
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
newSource1.scala:1: warning: A_1::test()Ljava/lang/String; could not be inlined:
2-
Failed to check if A_1::test()Ljava/lang/String; can be safely inlined to T without causing an IllegalAccessError. Checking instruction INVOKEDYNAMIC m()LA_1$Fun; [
2+
Failed to check if A_1::test()Ljava/lang/String; can be safely inlined to T without causing an IllegalAccessError.
3+
Checking failed for instruction INVOKEDYNAMIC m()LA_1$Fun; [
34
// handle kind 0x6 : INVOKESTATIC
45
not/java/lang/SomeLambdaMetafactory.notAMetaFactoryMethod(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;
56
// arguments:
67
(Ljava/lang/String;)Ljava/lang/String;,
78
// handle kind 0x6 : INVOKESTATIC
89
A_1.lambda$test$0(Ljava/lang/String;)Ljava/lang/String;,
910
(Ljava/lang/String;)Ljava/lang/String;
10-
] failed:
11+
]:
1112
The callee contains an InvokeDynamic instruction with an unknown bootstrap method (not a LambdaMetaFactory).
1213
class T { def foo = A_1.test }
1314
^

test/junit/scala/tools/nsc/backend/jvm/opt/InlineWarningTest.scala

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ package scala.tools.nsc
22
package backend.jvm
33
package opt
44

5+
import org.junit.Assert._
56
import org.junit.Test
67
import org.junit.runner.RunWith
78
import org.junit.runners.JUnit4
89

9-
import scala.tools.testkit.BytecodeTesting
10-
import scala.tools.testkit.BytecodeTesting._
10+
import scala.collection.mutable
11+
import scala.tools.testkit.BytecodeTesting, BytecodeTesting._
1112

1213
@RunWith(classOf[JUnit4])
1314
class InlineWarningTest extends BytecodeTesting {
@@ -170,37 +171,37 @@ class InlineWarningTest extends BytecodeTesting {
170171
}
171172

172173
@Test // scala-dev#20
173-
def mixedCompilationSpuriousWarning(): Unit = {
174+
def mixedCompilationSpuriousWarning: Unit = {
174175
val jCode =
175-
"""public class A {
176-
| public static final int bar() { return 100; }
177-
| public final int baz() { return 100; }
178-
|}
179-
""".stripMargin
176+
sm"""|public class A {
177+
| public static final int bar() { return 100; }
178+
| public final int baz() { return 100; }
179+
|}
180+
"""
180181

181182
val sCode =
182-
"""class C {
183-
| @inline final def foo = A.bar()
184-
| @inline final def fii(a: A) = a.baz()
185-
| def t = foo + fii(new A)
186-
|}
187-
""".stripMargin
183+
sm"""|class C {
184+
| @inline final def foo = A.bar()
185+
| @inline final def fii(a: A) = a.baz()
186+
| def t = foo + fii(new A)
187+
|}
188+
"""
188189

189190
val warns = List(
190-
"""C::foo()I is annotated @inline but could not be inlined:
191-
|Failed to check if C::foo()I can be safely inlined to C without causing an IllegalAccessError. Checking instruction INVOKESTATIC A.bar ()I failed:
192-
|The method bar()I could not be found in the class A or any of its parents.
193-
|Note that class A is defined in a Java source (mixed compilation), no bytecode is available.""".stripMargin,
194-
195-
"""C::fii(LA;)I is annotated @inline but could not be inlined:
196-
|Failed to check if C::fii(LA;)I can be safely inlined to C without causing an IllegalAccessError. Checking instruction INVOKEVIRTUAL A.baz ()I failed:
197-
|The method baz()I could not be found in the class A or any of its parents.
198-
|Note that class A is defined in a Java source (mixed compilation), no bytecode is available.""".stripMargin
191+
sm"""|C::foo()I is annotated @inline but could not be inlined:
192+
|Failed to check if C::foo()I can be safely inlined to C without causing an IllegalAccessError.
193+
|Checking failed for instruction INVOKESTATIC A.bar ()I:
194+
|The method bar()I could not be found in the class A or any of its parents.
195+
|Note that class A is defined in a Java source (mixed compilation), no bytecode is available.""",
196+
197+
sm"""|C::fii(LA;)I is annotated @inline but could not be inlined:
198+
|Failed to check if C::fii(LA;)I can be safely inlined to C without causing an IllegalAccessError.
199+
|Checking failed for instruction INVOKEVIRTUAL A.baz ()I:
200+
|The method baz()I could not be found in the class A or any of its parents.
201+
|Note that class A is defined in a Java source (mixed compilation), no bytecode is available.""",
199202
)
200-
var c = 0
201-
compileClasses(sCode, javaCode = List((jCode, "A.java")), allowMessage = i => { c += 1;
202-
warns.exists(i.msg.contains)
203-
})
204-
assert(c == 2)
203+
val allowed = mutable.Set.from(warns)
204+
compileClasses(sCode, javaCode = List(jCode -> "A.java"), allowMessage = i => allowed.remove(i.msg))
205+
assertTrue(s"${allowed.size} unseen warnings:\n$allowed", allowed.isEmpty)
205206
}
206207
}

test/junit/scala/tools/nsc/backend/jvm/opt/InlinerTest.scala

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -398,27 +398,28 @@ class InlinerTest extends BytecodeTesting {
398398
// A, so `flop` cannot be inlined, we cannot check if it's safe.
399399

400400
val javaCode =
401-
"""public class A {
402-
| public static final int bar() { return 100; }
403-
|}
404-
""".stripMargin
401+
sm"""|public class A {
402+
| public static final int bar() { return 100; }
403+
|}
404+
"""
405405

406406
val scalaCode =
407-
"""class B {
408-
| @inline final def flop = A.bar
409-
| def g = flop
410-
|}
411-
""".stripMargin
407+
sm"""|class B {
408+
| @inline final def flop = A.bar
409+
| def g = flop
410+
|}
411+
"""
412412

413413
val warn =
414-
"""B::flop()I is annotated @inline but could not be inlined:
415-
|Failed to check if B::flop()I can be safely inlined to B without causing an IllegalAccessError. Checking instruction INVOKESTATIC A.bar ()I failed:
416-
|The method bar()I could not be found in the class A or any of its parents.
417-
|Note that class A is defined in a Java source (mixed compilation), no bytecode is available.""".stripMargin
414+
sm"""|B::flop()I is annotated @inline but could not be inlined:
415+
|Failed to check if B::flop()I can be safely inlined to B without causing an IllegalAccessError.
416+
|Checking failed for instruction INVOKESTATIC A.bar ()I:
417+
|The method bar()I could not be found in the class A or any of its parents.
418+
|Note that class A is defined in a Java source (mixed compilation), no bytecode is available."""
418419

419420
var c = 0
420-
val b = compileClass(scalaCode, List((javaCode, "A.java")), allowMessage = i => {c += 1; i.msg contains warn})
421-
assert(c == 1, c)
421+
val b = compileClass(scalaCode, List(javaCode -> "A.java"), allowMessage = i => { c += 1; i.msg.contains(warn) })
422+
assertEquals(1, c)
422423
val ins = getInstructions(b, "g")
423424
val invokeFlop = Invoke(INVOKEVIRTUAL, "B", "flop", "()I", false)
424425
assert(ins contains invokeFlop, ins.stringLines)

0 commit comments

Comments
 (0)