Skip to content

Commit b53c63c

Browse files
committed
Address review
1 parent 5c01e0e commit b53c63c

File tree

3 files changed

+27
-36
lines changed

3 files changed

+27
-36
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ object Errors {
6767

6868
/** Promote `this` under initialization to fully-initialized */
6969
case class PromoteThis(pot: ThisRef, source: Tree, trace: Vector[Tree]) extends Error {
70-
def show(implicit ctx: Context): String = "Promote `this` to be initialized while it is not."
70+
def show(implicit ctx: Context): String = "Promote the value under initialization to be initialized."
7171
}
7272

7373
/** Promote `this` under initialization to fully-initialized */
@@ -84,12 +84,12 @@ object Errors {
8484

8585
case class AccessCold(field: Symbol, source: Tree, trace: Vector[Tree]) extends Error {
8686
def show(implicit ctx: Context): String =
87-
"Access field " + source.show + " on a value under unknown initialization status" + "."
87+
"Access field " + source.show + " on a value with an unknown initialization status" + "."
8888
}
8989

9090
case class CallCold(meth: Symbol, source: Tree, trace: Vector[Tree]) extends Error {
9191
def show(implicit ctx: Context): String =
92-
"Call method " + source.show + " on a value under unknown initialization" + "."
92+
"Call method " + source.show + " on a value with an unknown initialization" + "."
9393
}
9494

9595
case class CallUnknown(meth: Symbol, source: Tree, trace: Vector[Tree]) extends Error {

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

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ object Summarization {
150150
(Potentials.empty, effs ++ pots.promote(expr))
151151

152152
case WhileDo(cond, body) =>
153-
// for lazy fields, the translation may result im `while (<empty>)`
153+
// for lazy fields, the translation may result in `while (<empty>)`
154154
val (_, effs1) = if (cond.isEmpty) Summary.empty else analyze(cond)
155155
val (_, effs2) = analyze(body)
156156
(Potentials.empty, effs1 ++ effs2)
@@ -178,7 +178,7 @@ object Summarization {
178178
analyze(expansion).withEffs(effs)
179179

180180
case vdef : ValDef =>
181-
val (pots, effs) = analyze(vdef.rhs)
181+
lazy val (pots, effs) = analyze(vdef.rhs)
182182

183183
if (vdef.symbol.owner.isClass)
184184
(Potentials.empty, if (vdef.symbol.is(Flags.Lazy)) Effects.empty else effs)
@@ -190,7 +190,7 @@ object Summarization {
190190
Summary.empty
191191

192192
case ddef : DefDef =>
193-
val (pots, effs) = analyze(ddef.rhs)
193+
lazy val (pots, effs) = analyze(ddef.rhs)
194194

195195
if (ddef.symbol.owner.isClass) Summary.empty
196196
else (Potentials.empty, pots.promote(ddef) ++ effs)
@@ -265,8 +265,9 @@ object Summarization {
265265
val tpl = ctor.owner.defTree.asInstanceOf[TypeDef].rhs.asInstanceOf[Template]
266266
val effs = analyze(Block(tpl.body, unitLiteral))._2
267267

268-
def parentArgEffs(stats: List[Tree]): Effects =
269-
stats.foldLeft(Effects.empty) { (acc, stat) =>
268+
def parentArgEffsWithInit(stats: List[Tree], ctor: Symbol, source: Tree): Effects =
269+
val initCall = MethodCall(ThisRef(cls)(source), ctor)(source)
270+
stats.foldLeft(Set(initCall)) { (acc, stat) =>
270271
val (_, effs) = Summarization.analyze(stat)
271272
acc ++ effs
272273
}
@@ -275,18 +276,15 @@ object Summarization {
275276
effs ++ (parent match {
276277
case tree @ Block(stats, parent) =>
277278
val (ctor @ Select(qual, _), _, argss) = decomposeCall(parent)
278-
parentArgEffs(qual :: stats ++ argss.flatten) +
279-
MethodCall(ThisRef(cls)(tree), ctor.symbol)(tree)
279+
parentArgEffsWithInit(qual :: stats ++ argss.flatten, ctor.symbol, tree)
280280

281281
case tree @ Apply(Block(stats, parent), args) =>
282282
val (ctor @ Select(qual, _), _, argss) = decomposeCall(parent)
283-
parentArgEffs(qual :: stats ++ args ++ argss.flatten) +
284-
MethodCall(ThisRef(cls)(tree), ctor.symbol)(tree)
283+
parentArgEffsWithInit(qual :: stats ++ args ++ argss.flatten, ctor.symbol, tree)
285284

286285
case parent : Apply =>
287286
val (ctor @ Select(qual, _), _, argss) = decomposeCall(parent)
288-
parentArgEffs(qual :: argss.flatten) +
289-
MethodCall(ThisRef(cls)(parent), ctor.symbol)(parent)
287+
parentArgEffsWithInit(qual :: argss.flatten, ctor.symbol, parent)
290288

291289
case ref =>
292290
val tref: TypeRef = ref.tpe.typeConstructor.asInstanceOf
@@ -305,38 +303,31 @@ object Summarization {
305303
}
306304

307305
def classSummary(cls: ClassSymbol)(implicit env: Env): ClassSummary =
306+
def extractParentOuters(parent: Type, source: Tree): (ClassSymbol, Potentials) = {
307+
val tref = parent.typeConstructor.asInstanceOf[TypeRef]
308+
val parentCls = tref.classSymbol.asClass
309+
if (tref.prefix != NoPrefix)
310+
parentCls ->analyze(tref.prefix, source)._1
311+
else
312+
parentCls -> analyze(cls.enclosingClass.thisType, source)._1
313+
}
314+
308315
if (cls.defTree.isEmpty)
309316
cls.info match {
310317
case cinfo: ClassInfo =>
311-
val parentOuter: List[(ClassSymbol, Potentials)] = cinfo.classParents.map {
312-
case parentTp: TypeRef =>
313-
val source = {
314-
implicit val ctx2: Context = theCtx.withSource(cls.source(theCtx))
315-
TypeTree(parentTp).withSpan(cls.span)
316-
}
317-
val parentCls = parentTp.classSymbol.asClass
318-
if (parentTp.prefix != NoPrefix)
319-
parentCls -> analyze(parentTp.prefix, source)._1
320-
else
321-
parentCls -> analyze(cls.enclosingClass.thisType, source)._1
318+
val source = {
319+
implicit val ctx2: Context = theCtx.withSource(cls.source(theCtx))
320+
TypeTree(cls.typeRef).withSpan(cls.span)
322321
}
323322

324-
ClassSummary(cls, parentOuter.toMap)
323+
val parentOuter = cinfo.classParents.map { extractParentOuters(_, source) }.toMap
324+
ClassSummary(cls, parentOuter)
325325
}
326326
else {
327327
val tpl = cls.defTree.asInstanceOf[TypeDef]
328328
val parents = tpl.rhs.asInstanceOf[Template].parents
329329

330-
val parentOuter: List[(ClassSymbol, Potentials)] = parents.map { parent =>
331-
val tref = parent.tpe.typeConstructor.asInstanceOf[TypeRef]
332-
val parentCls = tref.classSymbol.asClass
333-
if (tref.prefix != NoPrefix)
334-
parentCls ->analyze(tref.prefix, parent)._1
335-
else
336-
parentCls -> analyze(cls.enclosingClass.thisType, parent)._1
337-
338-
}
339-
330+
val parentOuter = parents.map { parent => extractParentOuters(parent.tpe, parent) }
340331
ClassSummary(cls, parentOuter.toMap)
341332
}
342333

0 commit comments

Comments
 (0)