Skip to content

Commit 33b3d25

Browse files
committed
Refactor expand
It should return a tuple of effects and potentials due to length limit. Previously, the effects are checked but the errors are thrown away.
1 parent 93702cc commit 33b3d25

File tree

1 file changed

+46
-39
lines changed

1 file changed

+46
-39
lines changed

compiler/src/dotty/tools/dotc/transform/init/Checking.scala

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ object Checking {
138138
}
139139
}
140140

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) {
142142
val rebased = Effects.asSeenFrom(effs, ThisRef(state.thisClass)(null), cls, Potentials.empty)
143143
for {
144144
eff <- rebased
@@ -172,8 +172,9 @@ object Checking {
172172
Errors.empty
173173

174174
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(_))
177178
}
178179

179180
case FieldAccess(pot, field) =>
@@ -208,8 +209,10 @@ object Checking {
208209
throw new Exception("Unexpected effect " + eff.show)
209210

210211
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+
213216
}
214217

215218
case MethodCall(pot, sym) =>
@@ -258,55 +261,55 @@ object Checking {
258261
// curried, tupled, toString are harmless
259262

260263
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(_))
265267
}
266268
}
267269
}
268270

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])) {
270272
pot match {
271273
case MethodReturn(pot1, sym) =>
272274
pot1 match {
273275
case thisRef @ ThisRef(cls) =>
274276
assert(cls == state.thisClass, "unexpected potential " + pot.show)
275277

276278
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
279281

280282
case SuperRef(thisRef @ ThisRef(cls), supercls) =>
281283
assert(cls == state.thisClass, "unexpected potential " + pot.show)
282284

283285
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
286288

287289

288290
case Fun(pots, effs) =>
289291
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)
292294
else if (name == "curried") {
293295
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)
295298
}
296-
else Potentials.empty
299+
else Summary.empty
297300

298301
case warm : Warm =>
299302
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
302305

303306
case _: Cold =>
304-
Potentials.empty // error already reported, ignore
307+
Summary.empty // error already reported, ignore
305308

306309
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)
310313
}
311314

312315
case FieldReturn(pot1, sym) =>
@@ -315,58 +318,62 @@ object Checking {
315318
assert(cls == state.thisClass, "unexpected potential " + pot.show)
316319

317320
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)
320323

321324
case SuperRef(thisRef @ ThisRef(cls), supercls) =>
322325
assert(cls == state.thisClass, "unexpected potential " + pot.show)
323326

324327
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)
327330

328331
case _: Fun =>
329332
throw new Exception("Unexpected code reached")
330333

331334
case warm: Warm =>
332335
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)
335338

336339
case _: Cold =>
337-
Potentials.empty // error already reported, ignore
340+
Summary.empty // error already reported, ignore
338341

339342
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)
343346
}
344347

345348
case Outer(pot1, cls) =>
346349
pot1 match {
347350
case ThisRef(cls) =>
348351
assert(cls == state.thisClass, "unexpected potential " + pot.show)
349352

350-
Potentials.empty
353+
Summary.empty
351354

352355
case _: Fun =>
353356
throw new Exception("Unexpected code reached")
354357

355358
case warm: Warm =>
356-
warm.outerFor(cls)
359+
(warm.outerFor(cls), Effects.empty)
357360

358361
case _: Cold =>
359362
throw new Exception("Unexpected code reached")
360363

361364
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)
363368
}
364369

365370
case _: ThisRef | _: Fun | _: Warm | _: Cold =>
366-
Set(pot)
371+
(Set(pot), Effects.empty)
367372

368373
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)
370377
}
371378
}
372379
}

0 commit comments

Comments
 (0)