@@ -164,18 +164,18 @@ private[streams] trait Strategies
164
164
false
165
165
}
166
166
167
- def isStreamSafe = {
168
- // Note: we count the number of closures / ops that have side effects, not the
169
- // number of side-effects themselves: we assume that within a closure the
170
- // side effects are still done in the same order, and likewise for preserved
171
- // sub-trees that they're still evaluated in the same order within the same
172
- // originating op. For instance with mkString(prefix, sep, suffix), prefix,
173
- // sep and suffix will still be evaluated in the same order after the rewrite.
174
- val unsafeClosureSideEffectCount =
175
- stream.closureSideEffectss.count(hasUnsafeEffect)
176
- def unsafePreservedTreesSideEffectsCount =
177
- stream.preservedSubTreesSideEffectss.count(hasUnsafeEffect)
167
+ // Note: we count the number of closures / ops that have side effects, not the
168
+ // number of side-effects themselves: we assume that within a closure the
169
+ // side effects are still done in the same order, and likewise for preserved
170
+ // sub-trees that they're still evaluated in the same order within the same
171
+ // originating op. For instance with mkString(prefix, sep, suffix), prefix,
172
+ // sep and suffix will still be evaluated in the same order after the rewrite.
173
+ val unsafeClosureSideEffectCount =
174
+ stream.closureSideEffectss.count(hasUnsafeEffect)
175
+ def unsafePreservedTreesSideEffectsCount =
176
+ stream.preservedSubTreesSideEffectss.count(hasUnsafeEffect)
178
177
178
+ def isStreamSafe = {
179
179
unsafeClosureSideEffectCount <= 1 &&
180
180
(unsafeClosureSideEffectCount + unsafePreservedTreesSideEffectsCount) <= 1 &&
181
181
! couldSkipSideEffects
@@ -205,7 +205,22 @@ private[streams] trait Strategies
205
205
}
206
206
}
207
207
208
- // println(s"tree = ${stream.tree}\n\tstream = ${stream.describe()}\n\tstrategy = $strategy\n\tlambdaCount = ${stream.lambdaCount}\n\tclosureSideEffectss = ${stream.closureSideEffectss}\n\tcouldSkipSideEffects = $couldSkipSideEffects\n\thasMoreThanOneLambdaWithUnsafeSideEffect = $hasMoreThanOneLambdaWithUnsafeSideEffect\n\tisWorthOptimizing = $worthOptimizing")
208
+ // if (flags.debug) {
209
+ // // info(stream.tree.pos,
210
+ // println(s"""
211
+ // tree = ${stream.tree}
212
+ // stream = ${stream.describe()}
213
+ // strategy = $strategy
214
+ // lambdaCount = ${stream.lambdaCount}
215
+ // closureSideEffectss = ${stream.closureSideEffectss}
216
+ // couldSkipSideEffects = $couldSkipSideEffects
217
+ // isWorthOptimizing = $worthOptimizing
218
+ // isFaster = $isFaster
219
+ // unsafeClosureSideEffectCount = $unsafeClosureSideEffectCount
220
+ // unsafePreservedTreesSideEffectsCount = $unsafePreservedTreesSideEffectsCount
221
+ // isStreamSafe = $isStreamSafe
222
+ // """)//, force = true)
223
+ // }
209
224
210
225
worthOptimizing
211
226
}
0 commit comments