Skip to content

Commit 0fb4a4b

Browse files
committed
WIP: Rule 2 implementation
1 parent 59a890f commit 0fb4a4b

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

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

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,40 @@ object Checking {
275275
case _ => false
276276
}
277277

278+
/// Check the Promotion of a Warm object, according to "Rule 2":
279+
//
280+
// Rule 2: Promote(pot)
281+
//
282+
// for all concrete methods `m` of D
283+
// pot.m!, Promote(pot.m)
284+
//
285+
// for all concrete fields `f` of D
286+
// Promote(pot.f)
287+
//
288+
// for all inner classes `F` of D
289+
// Warm[F, pot].init!, Promote(Warm[F, pot])
290+
private def checkPromoteWarm(warm: Warm, eff: Effect)(using state: State): Errors =
291+
val Warm(cls, outer) = warm
292+
// Errors.empty
293+
val classRef = cls.info.asInstanceOf[ClassInfo].appliedRef
294+
// All members of class must be promotable.
295+
val memberErrs = classRef.allMembers.flatMap { denot =>
296+
val sym = denot.symbol
297+
val summary = warm.toPots.select(sym, warm.source, true)
298+
(summary.effs ++ summary.pots.map(Promote(_)(warm.source)).toList)
299+
}.flatMap(check(_))
300+
301+
// All inner classes of classRef must be promotable.
302+
// TODO: Implement this
303+
val innerClassesErrs = Errors.empty
304+
305+
val errs = memberErrs ++ innerClassesErrs
306+
if errs.isEmpty then {
307+
Errors.empty
308+
} else {
309+
UnsafePromotion(warm, eff.source, state.path, errs.toList).toErrors
310+
}
311+
278312
private def checkPromote(eff: Promote)(using state: State): Errors =
279313
if (state.safePromoted.contains(eff.potential)) Errors.empty
280314
else {
@@ -290,8 +324,7 @@ object Checking {
290324
PromoteCold(eff.source, state.path).toErrors
291325

292326
case pot @ Warm(cls, outer) =>
293-
// TODO: Implement Rule 2
294-
PromoteWarm(pot, eff.source, state.path).toErrors
327+
checkPromoteWarm(pot, eff)
295328

296329
case Fun(pots, effs) =>
297330
val errs1 = state.test {

0 commit comments

Comments
 (0)