@@ -63,15 +63,15 @@ trait LiveVariables {
6363 AsyncUtils .vprintln(s " fields never zero-ed out: ${noNull.mkString(" , " )}" )
6464
6565 /**
66- * Traverse statements of an `AsyncState`, collect `Ident`-s refering to lifted fields.
66+ * Traverse statements of an `AsyncState`, collect `Ident`-s referring to lifted fields.
6767 *
6868 * @param as a state of an `async` expression
6969 * @return a set of lifted fields that are used within state `as`
7070 */
7171 def fieldsUsedIn (as : AsyncState ): ReferencedFields = {
7272 class FindUseTraverser extends AsyncTraverser {
73- var usedFields = Set [Symbol ]()
74- var capturedFields = Set [Symbol ]()
73+ var usedFields : Set [ Symbol ] = Set [Symbol ]()
74+ var capturedFields : Set [ Symbol ] = Set [Symbol ]()
7575 private def capturing [A ](body : => A ): A = {
7676 val saved = capturing
7777 try {
@@ -122,7 +122,7 @@ trait LiveVariables {
122122 * A state `i` is contained in the list that is the value to which
123123 * key `j` maps iff control can flow from state `j` to state `i`.
124124 */
125- val cfg : Map [Int , List [Int ]] = asyncStates.map(as => ( as.state -> as.nextStates) ).toMap
125+ val cfg : Map [Int , List [Int ]] = asyncStates.map(as => as.state -> as.nextStates).toMap
126126
127127 /** Tests if `state1` is a predecessor of `state2`.
128128 */
@@ -145,8 +145,10 @@ trait LiveVariables {
145145
146146 val finalState = asyncStates.find(as => ! asyncStates.exists(other => isPred(as.state, other.state))).get
147147
148- for (as <- asyncStates)
149- AsyncUtils .vprintln(s " fields used in state # ${as.state}: ${fieldsUsedIn(as)}" )
148+ if (AsyncUtils .verbose) {
149+ for (as <- asyncStates)
150+ AsyncUtils .vprintln(s " fields used in state # ${as.state}: ${fieldsUsedIn(as)}" )
151+ }
150152
151153 /* Backwards data-flow analysis. Computes live variables information at entry and exit
152154 * of each async state.
@@ -201,9 +203,11 @@ trait LiveVariables {
201203 currStates = exitChanged
202204 }
203205
204- for (as <- asyncStates) {
205- AsyncUtils .vprintln(s " LVentry at state # ${as.state}: ${LVentry (as.state).mkString(" , " )}" )
206- AsyncUtils .vprintln(s " LVexit at state # ${as.state}: ${LVexit (as.state).mkString(" , " )}" )
206+ if (AsyncUtils .verbose) {
207+ for (as <- asyncStates) {
208+ AsyncUtils .vprintln(s " LVentry at state # ${as.state}: ${LVentry (as.state).mkString(" , " )}" )
209+ AsyncUtils .vprintln(s " LVexit at state # ${as.state}: ${LVexit (as.state).mkString(" , " )}" )
210+ }
207211 }
208212
209213 def lastUsagesOf (field : Tree , at : AsyncState ): Set [Int ] = {
@@ -215,7 +219,7 @@ trait LiveVariables {
215219 Set ()
216220 }
217221 else LVentry get at.state match {
218- case Some (fields) if fields.exists(_ == field.symbol) =>
222+ case Some (fields) if fields.contains( field.symbol) =>
219223 Set (at.state)
220224 case _ =>
221225 avoid += at
@@ -228,10 +232,12 @@ trait LiveVariables {
228232 }
229233
230234 val lastUsages : Map [Tree , Set [Int ]] =
231- liftables.map(fld => ( fld -> lastUsagesOf(fld, finalState) )).toMap
235+ liftables.map(fld => fld -> lastUsagesOf(fld, finalState)).toMap
232236
233- for ((fld, lastStates) <- lastUsages)
234- AsyncUtils .vprintln(s " field ${fld.symbol.name} is last used in states ${lastStates.mkString(" , " )}" )
237+ if (AsyncUtils .verbose) {
238+ for ((fld, lastStates) <- lastUsages)
239+ AsyncUtils .vprintln(s " field ${fld.symbol.name} is last used in states ${lastStates.mkString(" , " )}" )
240+ }
235241
236242 val nullOutAt : Map [Tree , Set [Int ]] =
237243 for ((fld, lastStates) <- lastUsages) yield {
@@ -242,14 +248,16 @@ trait LiveVariables {
242248 val succNums = lastAsyncState.nextStates
243249 // all successor states that are not indirect predecessors
244250 // filter out successor states where the field is live at the entry
245- succNums.filter(num => ! isPred(num, s)).filterNot(num => LVentry (num).exists(_ == fld.symbol))
251+ succNums.filter(num => ! isPred(num, s)).filterNot(num => LVentry (num).contains( fld.symbol))
246252 }
247253 }
248254 (fld, killAt)
249255 }
250256
251- for ((fld, killAt) <- nullOutAt)
252- AsyncUtils .vprintln(s " field ${fld.symbol.name} should be nulled out in states ${killAt.mkString(" , " )}" )
257+ if (AsyncUtils .verbose) {
258+ for ((fld, killAt) <- nullOutAt)
259+ AsyncUtils .vprintln(s " field ${fld.symbol.name} should be nulled out in states ${killAt.mkString(" , " )}" )
260+ }
253261
254262 nullOutAt
255263 }
0 commit comments