@@ -63,15 +63,15 @@ trait LiveVariables {
63
63
AsyncUtils .vprintln(s " fields never zero-ed out: ${noNull.mkString(" , " )}" )
64
64
65
65
/**
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.
67
67
*
68
68
* @param as a state of an `async` expression
69
69
* @return a set of lifted fields that are used within state `as`
70
70
*/
71
71
def fieldsUsedIn (as : AsyncState ): ReferencedFields = {
72
72
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 ]()
75
75
private def capturing [A ](body : => A ): A = {
76
76
val saved = capturing
77
77
try {
@@ -122,7 +122,7 @@ trait LiveVariables {
122
122
* A state `i` is contained in the list that is the value to which
123
123
* key `j` maps iff control can flow from state `j` to state `i`.
124
124
*/
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
126
126
127
127
/** Tests if `state1` is a predecessor of `state2`.
128
128
*/
@@ -145,8 +145,10 @@ trait LiveVariables {
145
145
146
146
val finalState = asyncStates.find(as => ! asyncStates.exists(other => isPred(as.state, other.state))).get
147
147
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
+ }
150
152
151
153
/* Backwards data-flow analysis. Computes live variables information at entry and exit
152
154
* of each async state.
@@ -201,9 +203,11 @@ trait LiveVariables {
201
203
currStates = exitChanged
202
204
}
203
205
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
+ }
207
211
}
208
212
209
213
def lastUsagesOf (field : Tree , at : AsyncState ): Set [Int ] = {
@@ -215,7 +219,7 @@ trait LiveVariables {
215
219
Set ()
216
220
}
217
221
else LVentry get at.state match {
218
- case Some (fields) if fields.exists(_ == field.symbol) =>
222
+ case Some (fields) if fields.contains( field.symbol) =>
219
223
Set (at.state)
220
224
case _ =>
221
225
avoid += at
@@ -228,10 +232,12 @@ trait LiveVariables {
228
232
}
229
233
230
234
val lastUsages : Map [Tree , Set [Int ]] =
231
- liftables.map(fld => ( fld -> lastUsagesOf(fld, finalState) )).toMap
235
+ liftables.map(fld => fld -> lastUsagesOf(fld, finalState)).toMap
232
236
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
+ }
235
241
236
242
val nullOutAt : Map [Tree , Set [Int ]] =
237
243
for ((fld, lastStates) <- lastUsages) yield {
@@ -242,14 +248,16 @@ trait LiveVariables {
242
248
val succNums = lastAsyncState.nextStates
243
249
// all successor states that are not indirect predecessors
244
250
// 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))
246
252
}
247
253
}
248
254
(fld, killAt)
249
255
}
250
256
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
+ }
253
261
254
262
nullOutAt
255
263
}
0 commit comments