@@ -33,6 +33,8 @@ import scala.tools.asm.tree._
33
33
import tpd ._
34
34
import StdNames ._
35
35
import dotty .tools .io ._
36
+ import scala .tools .asm .MethodTooLargeException
37
+ import scala .tools .asm .ClassTooLargeException
36
38
37
39
class GenBCode extends Phase {
38
40
@@ -512,7 +514,7 @@ class GenBCodePipeline(val int: DottyBackendInterface, val primitives: DottyPrim
512
514
* (c) tear down (closing the classfile-writer and clearing maps)
513
515
*
514
516
*/
515
- def run (t : Tree ): Unit = {
517
+ def run (t : Tree )( using Context ) : Unit = {
516
518
this .tree = t
517
519
518
520
// val bcodeStart = Statistics.startTimer(BackendStats.bcodeTimer)
@@ -558,18 +560,29 @@ class GenBCodePipeline(val int: DottyBackendInterface, val primitives: DottyPrim
558
560
* (c) dequeue one at a time from queue-2, convert it to byte-array, place in queue-3
559
561
* (d) serialize to disk by draining queue-3.
560
562
*/
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)
573
586
574
587
}
575
588
0 commit comments