@@ -119,16 +119,26 @@ object Periods {
119119 object Period {
120120
121121 /** The single-phase period consisting of given run id and phase id */
122- def apply (rid : RunId , pid : PhaseId ): Period =
122+ def apply (rid : RunId , pid : PhaseId ): Period = {
123+ assert(rid <= MaxPossibleRunId )
124+ assert(pid <= MaxPossiblePhaseId )
123125 new Period (((rid << PhaseWidth ) | pid) << PhaseWidth )
126+ }
124127
125128 /** The period consisting of given run id, and lo/hi phase ids */
126- def apply (rid : RunId , loPid : PhaseId , hiPid : PhaseId ): Period =
129+ def apply (rid : RunId , loPid : PhaseId , hiPid : PhaseId ): Period = {
130+ assert(rid <= MaxPossibleRunId )
131+ assert(loPid <= MaxPossiblePhaseId )
132+ assert(hiPid <= MaxPossiblePhaseId )
133+
127134 new Period (((rid << PhaseWidth ) | hiPid) << PhaseWidth | (hiPid - loPid))
135+ }
128136
129137 /** The interval consisting of all periods of given run id */
130- def allInRun (rid : RunId ) =
138+ def allInRun (rid : RunId ) = {
139+ assert(rid <= MaxPossibleRunId )
131140 apply(rid, 0 , PhaseMask )
141+ }
132142 }
133143
134144 final val Nowhere = new Period (0 )
@@ -141,6 +151,8 @@ object Periods {
141151 type RunId = Int
142152 final val NoRunId = 0
143153 final val InitialRunId = 1
154+ final val RunWidth = java.lang.Integer .SIZE - PhaseWidth * 2 - 1 /* sign */
155+ final val MaxPossibleRunId = (1 << RunWidth ) - 1
144156
145157 /** An ordinal number for phases. First phase has number 1. */
146158 type PhaseId = Int
0 commit comments