From 6b82a6f18a71e5e958d3693dcba23dcc9f2d190a Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 3 Aug 2017 14:53:12 +0200 Subject: [PATCH 1/3] Fix #2636: Move last phase period assertion --- compiler/src/dotty/tools/dotc/Compiler.scala | 7 ++++++- compiler/src/dotty/tools/dotc/Run.scala | 1 - 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/Compiler.scala b/compiler/src/dotty/tools/dotc/Compiler.scala index 84d49502dc54..0347c40f2910 100644 --- a/compiler/src/dotty/tools/dotc/Compiler.scala +++ b/compiler/src/dotty/tools/dotc/Compiler.scala @@ -108,9 +108,14 @@ class Compiler { new CollectSuperCalls, // Find classes that are called with super new DropInlined, // Drop Inlined nodes, since backend has no use for them new LabelDefs), // Converts calls to labels to jumps - List(new GenBCode) // Generate JVM bytecode + List(checkedIdOverflow(new GenBCode)) // Generate JVM bytecode ) + private def checkedIdOverflow(phase: Phase): Phase = { + assert(phase.id <= Periods.MaxPossiblePhaseId) + phase + } + var runId = 1 def nextRunId = { runId += 1; runId diff --git a/compiler/src/dotty/tools/dotc/Run.scala b/compiler/src/dotty/tools/dotc/Run.scala index acd885dd3afe..e9ec9dd3d96b 100644 --- a/compiler/src/dotty/tools/dotc/Run.scala +++ b/compiler/src/dotty/tools/dotc/Run.scala @@ -24,7 +24,6 @@ import scala.util.control.NonFatal /** A compiler run. Exports various methods to compile source files */ class Run(comp: Compiler)(implicit ctx: Context) { - assert(comp.phases.last.last.id <= Periods.MaxPossiblePhaseId) assert(ctx.runId <= Periods.MaxPossibleRunId) var units: List[CompilationUnit] = _ From 863650867d915191f6135b362bd365beb18ff67a Mon Sep 17 00:00:00 2001 From: Dmitry Petrashko Date: Thu, 3 Aug 2017 15:19:51 +0200 Subject: [PATCH 2/3] Phases: test for too many phases --- compiler/src/dotty/tools/dotc/core/Phases.scala | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/src/dotty/tools/dotc/core/Phases.scala b/compiler/src/dotty/tools/dotc/core/Phases.scala index 16f281a42ee9..409827f39ad6 100644 --- a/compiler/src/dotty/tools/dotc/core/Phases.scala +++ b/compiler/src/dotty/tools/dotc/core/Phases.scala @@ -348,6 +348,7 @@ object Phases { protected[Phases] def init(base: ContextBase, start: Int, end:Int): Unit = { if (start >= FirstPhaseId) assert(myPeriod == Periods.InvalidPeriod, s"phase $this has already been used once; cannot be reused") + assert(start <= Periods.MaxPossiblePhaseId, s"Too many phases, Period bits overflow") myBase = base myPeriod = Period(NoRunId, start, end) myErasedTypes = prev.getClass == classOf[Erasure] || prev.erasedTypes From 23aceb1a7379d28c812fb02e1e284a21bce8a54f Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 3 Aug 2017 15:51:27 +0200 Subject: [PATCH 3/3] Remove duplicated asserion --- compiler/src/dotty/tools/dotc/Compiler.scala | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/Compiler.scala b/compiler/src/dotty/tools/dotc/Compiler.scala index 0347c40f2910..84d49502dc54 100644 --- a/compiler/src/dotty/tools/dotc/Compiler.scala +++ b/compiler/src/dotty/tools/dotc/Compiler.scala @@ -108,14 +108,9 @@ class Compiler { new CollectSuperCalls, // Find classes that are called with super new DropInlined, // Drop Inlined nodes, since backend has no use for them new LabelDefs), // Converts calls to labels to jumps - List(checkedIdOverflow(new GenBCode)) // Generate JVM bytecode + List(new GenBCode) // Generate JVM bytecode ) - private def checkedIdOverflow(phase: Phase): Phase = { - assert(phase.id <= Periods.MaxPossiblePhaseId) - phase - } - var runId = 1 def nextRunId = { runId += 1; runId