Skip to content

Commit ef16034

Browse files
Merge pull request #14943 from dos65/bcode_wrap_errors
Better error messages in case of `TooLarge*` exceptions in GenBCode
2 parents dcb0d15 + 8c021c3 commit ef16034

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

compiler/src/dotty/tools/backend/jvm/GenBCode.scala

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import scala.tools.asm.tree._
3333
import tpd._
3434
import StdNames._
3535
import dotty.tools.io._
36+
import scala.tools.asm.MethodTooLargeException
37+
import scala.tools.asm.ClassTooLargeException
3638

3739
class GenBCode extends Phase {
3840

@@ -512,7 +514,7 @@ class GenBCodePipeline(val int: DottyBackendInterface, val primitives: DottyPrim
512514
* (c) tear down (closing the classfile-writer and clearing maps)
513515
*
514516
*/
515-
def run(t: Tree): Unit = {
517+
def run(t: Tree)(using Context): Unit = {
516518
this.tree = t
517519

518520
// val bcodeStart = Statistics.startTimer(BackendStats.bcodeTimer)
@@ -558,18 +560,29 @@ class GenBCodePipeline(val int: DottyBackendInterface, val primitives: DottyPrim
558560
* (c) dequeue one at a time from queue-2, convert it to byte-array, place in queue-3
559561
* (d) serialize to disk by draining queue-3.
560562
*/
561-
private def buildAndSendToDisk(needsOutFolder: Boolean) = {
562-
563-
feedPipeline1()
564-
// val genStart = Statistics.startTimer(BackendStats.bcodeGenStat)
565-
(new Worker1(needsOutFolder)).run()
566-
// Statistics.stopTimer(BackendStats.bcodeGenStat, genStart)
567-
568-
(new Worker2).run()
569-
570-
// val writeStart = Statistics.startTimer(BackendStats.bcodeWriteTimer)
571-
drainQ3()
572-
// Statistics.stopTimer(BackendStats.bcodeWriteTimer, writeStart)
563+
private def buildAndSendToDisk(needsOutFolder: Boolean)(using Context) = {
564+
try
565+
feedPipeline1()
566+
// val genStart = Statistics.startTimer(BackendStats.bcodeGenStat)
567+
(new Worker1(needsOutFolder)).run()
568+
// Statistics.stopTimer(BackendStats.bcodeGenStat, genStart)
569+
570+
(new Worker2).run()
571+
572+
// val writeStart = Statistics.startTimer(BackendStats.bcodeWriteTimer)
573+
drainQ3()
574+
// Statistics.stopTimer(BackendStats.bcodeWriteTimer, writeStart)
575+
catch
576+
case e: MethodTooLargeException =>
577+
val method =
578+
s"${e.getClassName.replaceAll("/", ".")}.${e.getMethodName}"
579+
val msg =
580+
s"Generated bytecode for method '$method' is too large. Size: ${e.getCodeSize} bytes. Limit is 64KB"
581+
report.error(msg)
582+
case e: ClassTooLargeException =>
583+
val msg =
584+
s"Class '${e.getClassName.replaceAll("/", ".")}' is too large. Constant pool size: ${e.getConstantPoolCount}. Limit is 64KB"
585+
report.error(msg)
573586

574587
}
575588

0 commit comments

Comments
 (0)