Skip to content

Commit fc2ae30

Browse files
committed
Address review (thanks @michelou)
1 parent 9e9c4a5 commit fc2ae30

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,18 @@ class Semantic {
494494

495495
// ----- Promotion ----------------------------------------------------
496496
extension (addr: Addr)
497+
/** Whether the object is fully initialized
498+
*
499+
* It means all fields and outers are set. For performance, we don't check
500+
* outers here, because Scala semantics ensure that they are always set
501+
* before any user code in the constructor.
502+
*
503+
* The interesting case is the outers for traits. The compiler synthesizes
504+
* proxy accessors for the outers in the class that extends the trait. As
505+
* those outers must be stable values, they are initialized immediately
506+
* following class parameters and before super constructor calls and user
507+
* code in the class body.
508+
*/
497509
def isFullyInitialized: Contextual[Boolean] = log("isFullyInitialized " + addr, printer) {
498510
val obj = heap(addr)
499511
addr.klass.baseClasses.forall { klass =>
@@ -512,7 +524,6 @@ class Semantic {
512524
extension (thisRef: ThisRef)
513525
def tryPromoteCurrentObject: Contextual[Boolean] = log("tryPromoteCurrentObject ", printer) {
514526
promoted.isCurrentObjectPromoted || {
515-
val obj = heap(thisRef)
516527
// If we have all fields initialized, then we can promote This to hot.
517528
thisRef.isFullyInitialized && {
518529
promoted.promoteCurrent(thisRef)
@@ -999,6 +1010,11 @@ class Semantic {
9991010
val parents = tpl.parents.tail
10001011
val mixins = klass.baseClasses.tail.takeWhile(_ != superCls)
10011012

1013+
// The interesting case is the outers for traits. The compiler
1014+
// synthesizes proxy accessors for the outers in the class that extends
1015+
// the trait. As those outers must be stable values, they are initialized
1016+
// immediately following class parameters and before super constructor
1017+
// calls and user code in the class body.
10021018
mixins.reverse.foreach { mixin =>
10031019
parents.find(_.tpe.classSymbol == mixin) match
10041020
case Some(parent) => initParent(parent, handler)

0 commit comments

Comments
 (0)