Skip to content

Commit

Permalink
Address review: factor out isByNameParam
Browse files Browse the repository at this point in the history
  • Loading branch information
liufengyun committed May 27, 2023
1 parent d6629e8 commit 61a6449
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions compiler/src/dotty/tools/dotc/transform/init/Objects.scala
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ object Objects:
* @param ctor The symbol of the target method.
* @param args Arguments of the constructor call (all parameter blocks flatten to a list).
*/
def callConstructor(thisV: Value, ctor: Symbol, args: List[ArgInfo]): Contextual[Value] = log("call " + ctor.show + ", args = " + args.map(_.value.show), printer, (_: Value).show) {
def callConstructor(thisV: Value, ctor: Symbol, args: List[ArgInfo]): Contextual[Unit] = log("call " + ctor.show + ", args = " + args.map(_.value.show), printer, (_: Value).show) {

thisV match
case ref: Ref =>
Expand All @@ -648,7 +648,6 @@ object Objects:
if ctor.isPrimaryConstructor then
val tpl = cls.defTree.asInstanceOf[TypeDef].rhs.asInstanceOf[Template]
extendTrace(cls.defTree) { eval(tpl, ref, cls, cacheResult = true) }
ref
else
extendTrace(ddef) { eval(ddef.rhs, ref, cls, cacheResult = true) }
else
Expand Down Expand Up @@ -817,6 +816,7 @@ object Objects:
* @param sym The symbol of the variable.
*/
def readLocal(thisV: Value, sym: Symbol): Contextual[Value] = log("reading local " + sym.show, printer, (_: Value).show) {
def isByNameParam(sym: Symbol) = sym.is(Flags.Param) && sym.info.isInstanceOf[ExprType]
Env.resolveEnv(sym.enclosingMethod, thisV, summon[Env.Data]) match
case Some(thisV -> env) =>
if sym.is(Flags.Mutable) then
Expand All @@ -837,7 +837,7 @@ object Objects:
try
// Assume forward reference check is doing a good job
val value = Env.valValue(sym)
if sym.is(Flags.Param) && sym.info.isInstanceOf[ExprType] then
if isByNameParam(sym) then
value match
case fun: Fun =>
given Env.Data = fun.env
Expand All @@ -856,7 +856,7 @@ object Objects:
Bottom

case _ =>
if sym.is(Flags.Param) && sym.info.isInstanceOf[ExprType] then
if isByNameParam(sym) then
report.warning("Calling cold by-name alias. Call trace: \n" + Trace.show, Trace.position)
Bottom
else
Expand Down Expand Up @@ -988,7 +988,7 @@ object Objects:
case Select(qual, _) =>
val receiver = eval(qual, thisV, klass)
if ref.symbol.isConstructor then
withTrace(trace2) { callConstructor(receiver, ref.symbol, args) }
withTrace(trace2) { callConstructor(receiver, ref.symbol, args); Bottom }
else
withTrace(trace2) { call(receiver, ref.symbol, args, receiver = qual.tpe, superType = NoType) }

Expand All @@ -1003,7 +1003,7 @@ object Objects:
case TermRef(prefix, _) =>
val receiver = withTrace(trace2) { evalType(prefix, thisV, klass) }
if id.symbol.isConstructor then
withTrace(trace2) { callConstructor(receiver, id.symbol, args) }
withTrace(trace2) { callConstructor(receiver, id.symbol, args); Bottom }
else
withTrace(trace2) { call(receiver, id.symbol, args, receiver = prefix, superType = NoType) }

Expand Down Expand Up @@ -1089,10 +1089,10 @@ object Objects:
eval(expr, thisV, klass)

case Try(block, cases, finalizer) =>
eval(block, thisV, klass)
val res = evalExprs(block :: cases.map(_.body), thisV, klass).join
if !finalizer.isEmpty then
eval(finalizer, thisV, klass)
evalExprs(cases.map(_.body), thisV, klass).join
res

case SeqLiteral(elems, elemtpt) =>
evalExprs(elems, thisV, klass).join
Expand Down Expand Up @@ -1259,7 +1259,6 @@ object Objects:
tasks.append { () =>
printer.println("init super class " + cls.show)
callConstructor(thisV, ctor, args)
()
}

// parents
Expand Down

0 comments on commit 61a6449

Please sign in to comment.