@@ -138,7 +138,7 @@ object Checking {
138
138
}
139
139
}
140
140
141
- private def checkEffectsIn (effs : Effects , cls : ClassSymbol )(implicit state : State ): Unit = {
141
+ private def checkEffectsIn (effs : Effects , cls : ClassSymbol )(implicit state : State ): Unit = traceOp( " checking effects " + Effects .show(effs), init) {
142
142
val rebased = Effects .asSeenFrom(effs, ThisRef (state.thisClass)(null ), cls, Potentials .empty)
143
143
for {
144
144
eff <- rebased
@@ -172,8 +172,9 @@ object Checking {
172
172
Errors .empty
173
173
174
174
case pot =>
175
- val pots = expand(pot)
176
- pots.flatMap { pot => check(Promote (pot)(eff.source)) }
175
+ val (pots, effs) = expand(pot)
176
+ val effs2 = pots.map(Promote (_)(eff.source))
177
+ (effs2 ++ effs).flatMap(check(_))
177
178
}
178
179
179
180
case FieldAccess (pot, field) =>
@@ -208,8 +209,10 @@ object Checking {
208
209
throw new Exception (" Unexpected effect " + eff.show)
209
210
210
211
case pot =>
211
- val pots = expand(pot)
212
- pots.flatMap { pot => check(FieldAccess (pot, field)(eff.source)) }
212
+ val (pots, effs) = expand(pot)
213
+ val effs2 = pots.map(FieldAccess (_, field)(eff.source))
214
+ (effs2 ++ effs).flatMap(check(_))
215
+
213
216
}
214
217
215
218
case MethodCall (pot, sym) =>
@@ -258,55 +261,55 @@ object Checking {
258
261
// curried, tupled, toString are harmless
259
262
260
263
case pot =>
261
- val pots = expand(pot)
262
- pots.flatMap { pot =>
263
- check(MethodCall (pot, sym)(eff.source))
264
- }
264
+ val (pots, effs) = expand(pot)
265
+ val effs2 = pots.map(MethodCall (_, sym)(eff.source))
266
+ (effs2 ++ effs).flatMap(check(_))
265
267
}
266
268
}
267
269
}
268
270
269
- private def expand (pot : Potential )(implicit state : State ): Potentials = trace(" expand " + pot.show, init, pots => Potentials .show(pots .asInstanceOf [Potentials ])) {
271
+ private def expand (pot : Potential )(implicit state : State ): Summary = trace(" expand " + pot.show, init, sum => Summary .show(sum .asInstanceOf [Summary ])) {
270
272
pot match {
271
273
case MethodReturn (pot1, sym) =>
272
274
pot1 match {
273
275
case thisRef @ ThisRef (cls) =>
274
276
assert(cls == state.thisClass, " unexpected potential " + pot.show)
275
277
276
278
val target = resolve(cls, sym)
277
- if (target.isInternal) thisRef.potentialsOf(target)
278
- else Potentials .empty // warning already issued in call effect
279
+ if (target.isInternal) ( thisRef.potentialsOf(target), Effects .empty )
280
+ else Summary .empty // warning already issued in call effect
279
281
280
282
case SuperRef (thisRef @ ThisRef (cls), supercls) =>
281
283
assert(cls == state.thisClass, " unexpected potential " + pot.show)
282
284
283
285
val target = resolveSuper(cls, supercls, sym)
284
- if (target.isInternal) thisRef.potentialsOf(target)
285
- else Potentials .empty // warning already issued in call effect
286
+ if (target.isInternal) ( thisRef.potentialsOf(target), Effects .empty )
287
+ else Summary .empty // warning already issued in call effect
286
288
287
289
288
290
case Fun (pots, effs) =>
289
291
val name = sym.name.toString
290
- if (name == " apply" ) pots
291
- else if (name == " tupled" ) Set (pot1)
292
+ if (name == " apply" ) ( pots, Effects .empty)
293
+ else if (name == " tupled" ) ( Set (pot1), Effects .empty )
292
294
else if (name == " curried" ) {
293
295
val arity = defn.functionArity(sym.info.finalResultType)
294
- (1 until arity).foldLeft(Set (pot1)) { (acc, i) => Set (Fun (acc, Effects .empty)(pot1.source)) }
296
+ val pots = (1 until arity).foldLeft(Set (pot1)) { (acc, i) => Set (Fun (acc, Effects .empty)(pot1.source)) }
297
+ (pots, Effects .empty)
295
298
}
296
- else Potentials .empty
299
+ else Summary .empty
297
300
298
301
case warm : Warm =>
299
302
val target = resolve(warm.classSymbol, sym)
300
- if (target.isInternal) warm.potentialsOf(target)
301
- else Potentials .empty // warning already issued in call effect
303
+ if (target.isInternal) ( warm.potentialsOf(target), Effects .empty )
304
+ else Summary .empty // warning already issued in call effect
302
305
303
306
case _ : Cold =>
304
- Potentials .empty // error already reported, ignore
307
+ Summary .empty // error already reported, ignore
305
308
306
309
case _ =>
307
- val (pots, effs) = expand(pot1).select(sym, pot.source)
308
- effs.foreach(check(_) )
309
- pots
310
+ val (pots, effs) = expand(pot1)
311
+ val (pots2, effs2) = pots.select(sym, pot.source )
312
+ (pots2, effs ++ effs2)
310
313
}
311
314
312
315
case FieldReturn (pot1, sym) =>
@@ -315,58 +318,62 @@ object Checking {
315
318
assert(cls == state.thisClass, " unexpected potential " + pot.show)
316
319
317
320
val target = resolve(cls, sym)
318
- if (sym.isInternal) thisRef.potentialsOf(target)
319
- else Cold ()(pot.source).toPots
321
+ if (sym.isInternal) ( thisRef.potentialsOf(target), Effects .empty )
322
+ else ( Cold ()(pot.source).toPots, Effects .empty)
320
323
321
324
case SuperRef (thisRef @ ThisRef (cls), supercls) =>
322
325
assert(cls == state.thisClass, " unexpected potential " + pot.show)
323
326
324
327
val target = resolveSuper(cls, supercls, sym)
325
- if (target.isInternal) thisRef.potentialsOf(target)
326
- else Cold ()(pot.source).toPots
328
+ if (target.isInternal) ( thisRef.potentialsOf(target), Effects .empty )
329
+ else ( Cold ()(pot.source).toPots, Effects .empty)
327
330
328
331
case _ : Fun =>
329
332
throw new Exception (" Unexpected code reached" )
330
333
331
334
case warm : Warm =>
332
335
val target = resolve(warm.classSymbol, sym)
333
- if (target.isInternal) warm.potentialsOf(target)
334
- else Cold ()(pot.source).toPots
336
+ if (target.isInternal) ( warm.potentialsOf(target), Effects .empty )
337
+ else ( Cold ()(pot.source).toPots, Effects .empty)
335
338
336
339
case _ : Cold =>
337
- Potentials .empty // error already reported, ignore
340
+ Summary .empty // error already reported, ignore
338
341
339
342
case _ =>
340
- val (pots, effs) = expand(pot1).select(sym, pot.source)
341
- effs.foreach(check(_) )
342
- pots
343
+ val (pots, effs) = expand(pot1)
344
+ val (pots2, effs2) = pots.select(sym, pot.source )
345
+ (pots2, effs ++ effs2)
343
346
}
344
347
345
348
case Outer (pot1, cls) =>
346
349
pot1 match {
347
350
case ThisRef (cls) =>
348
351
assert(cls == state.thisClass, " unexpected potential " + pot.show)
349
352
350
- Potentials .empty
353
+ Summary .empty
351
354
352
355
case _ : Fun =>
353
356
throw new Exception (" Unexpected code reached" )
354
357
355
358
case warm : Warm =>
356
- warm.outerFor(cls)
359
+ ( warm.outerFor(cls), Effects .empty )
357
360
358
361
case _ : Cold =>
359
362
throw new Exception (" Unexpected code reached" )
360
363
361
364
case _ =>
362
- expand(pot1).map { Outer (_, cls)(pot.source) }
365
+ val (pots, effs) = expand(pot1)
366
+ val pots2 = pots.map { Outer (_, cls)(pot.source): Potential }
367
+ (pots2, effs)
363
368
}
364
369
365
370
case _ : ThisRef | _ : Fun | _ : Warm | _ : Cold =>
366
- Set (pot)
371
+ ( Set (pot), Effects .empty )
367
372
368
373
case SuperRef (pot1, supercls) =>
369
- expand(pot1).map { SuperRef (_, supercls)(pot.source) }
374
+ val (pots, effs) = expand(pot1)
375
+ val pots2 = pots.map { SuperRef (_, supercls)(pot.source): Potential }
376
+ (pots2, effs)
370
377
}
371
378
}
372
379
}
0 commit comments