Skip to content

Commit d38cc11

Browse files
committed
WIP: Rule 2 implementation
1 parent 6335940 commit d38cc11

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
@@ -285,6 +285,40 @@ object Checking {
285285
case _ => false
286286
}
287287

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

302336
case pot @ Warm(cls, outer) =>
303-
// TODO: Implement Rule 2
304-
PromoteWarm(pot, eff.source, state.path).toErrors
337+
checkPromoteWarm(pot, eff)
305338

306339
case Fun(pots, effs) =>
307340
val errs1 = state.test {

0 commit comments

Comments
 (0)