diff options
author | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2015-02-10 13:52:19 +0100 |
---|---|---|
committer | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2015-02-11 11:37:48 +0100 |
commit | 5027f018be2879d0db5a13037abe4ac706ffbf42 (patch) | |
tree | f360289cae21257a507f71d8091ab533010588d0 /src/dotty/tools/dotc/core/Periods.scala | |
parent | 1892e77808b148eba34c409db98d15a886a74069 (diff) | |
download | dotty-5027f018be2879d0db5a13037abe4ac706ffbf42.tar.gz dotty-5027f018be2879d0db5a13037abe4ac706ffbf42.tar.bz2 dotty-5027f018be2879d0db5a13037abe4ac706ffbf42.zip |
Assert for overflows in Periods
Diffstat (limited to 'src/dotty/tools/dotc/core/Periods.scala')
-rw-r--r-- | src/dotty/tools/dotc/core/Periods.scala | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/dotty/tools/dotc/core/Periods.scala b/src/dotty/tools/dotc/core/Periods.scala index 66c26e381..cef85a07f 100644 --- a/src/dotty/tools/dotc/core/Periods.scala +++ b/src/dotty/tools/dotc/core/Periods.scala @@ -119,16 +119,26 @@ object Periods { object Period { /** The single-phase period consisting of given run id and phase id */ - def apply(rid: RunId, pid: PhaseId): Period = + def apply(rid: RunId, pid: PhaseId): Period = { + assert(rid <= MaxPossibleRunId) + assert(pid <= MaxPossiblePhaseId) new Period(((rid << PhaseWidth) | pid) << PhaseWidth) + } /** The period consisting of given run id, and lo/hi phase ids */ - def apply(rid: RunId, loPid: PhaseId, hiPid: PhaseId): Period = + def apply(rid: RunId, loPid: PhaseId, hiPid: PhaseId): Period = { + assert(rid <= MaxPossibleRunId) + assert(loPid <= MaxPossiblePhaseId) + assert(hiPid <= MaxPossiblePhaseId) + new Period(((rid << PhaseWidth) | hiPid) << PhaseWidth | (hiPid - loPid)) + } /** The interval consisting of all periods of given run id */ - def allInRun(rid: RunId) = + def allInRun(rid: RunId) = { + assert(rid <= MaxPossibleRunId) apply(rid, 0, PhaseMask) + } } final val Nowhere = new Period(0) @@ -141,6 +151,8 @@ object Periods { type RunId = Int final val NoRunId = 0 final val InitialRunId = 1 + final val RunWidth = java.lang.Integer.SIZE - PhaseWidth * 2 - 1/* sign */ + final val MaxPossibleRunId = (1 << RunWidth) - 1 /** An ordinal number for phases. First phase has number 1. */ type PhaseId = Int |