Skip to content

Commit 1b3bda8

Browse files
committed
Restrict function arguments to be hot
This aligns with the design of restricting method arguments to be hot. We only allow non-hot to constructors.
1 parent 020b478 commit 1b3bda8

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class Semantic {
8080
case class Warm(klass: ClassSymbol, outer: Value, ctor: Symbol, args: List[Value]) extends Addr
8181

8282
/** A function value */
83-
case class Fun(expr: Tree, params: List[Symbol], thisV: Addr, klass: ClassSymbol, env: Env) extends Value
83+
case class Fun(expr: Tree, thisV: Addr, klass: ClassSymbol, env: Env) extends Value
8484

8585
/** A value which represents a set of addresses
8686
*
@@ -416,13 +416,12 @@ class Semantic {
416416
else
417417
value.select(target, source, needResolve = false)
418418

419-
case Fun(body, params, thisV, klass, env2) =>
419+
case Fun(body, thisV, klass, env) =>
420420
// meth == NoSymbol for poly functions
421421
if meth.name.toString == "tupled" then Result(value, Nil) // a call like `fun.tupled`
422422
else
423-
val env3 = Env(params.zip(args.map(_.value).widen).toMap).union(env2)
424-
use(env3) {
425-
eval(body, thisV, klass, cacheResult = true)
423+
use(env) {
424+
eval(body, thisV, klass, cacheResult = true) ++ checkArgs
426425
}
427426

428427
case RefSet(refs) =>
@@ -479,7 +478,7 @@ class Semantic {
479478
if !env.isHot then Result(Cold, res.errors)
480479
else Result(value, res.errors)
481480

482-
case Fun(body, params, thisV, klass, env) =>
481+
case Fun(body, thisV, klass, env) =>
483482
report.error("unexpected tree in instantiating a function, fun = " + body.show, source)
484483
Result(Hot, Nil)
485484

@@ -553,7 +552,7 @@ class Semantic {
553552
errors
554553
}
555554

556-
case fun @ Fun(body, params, thisV, klass, env) =>
555+
case fun @ Fun(body, thisV, klass, env) =>
557556
if promoted.contains(fun) then Nil
558557
else
559558
val res = eval(body, thisV, klass)
@@ -687,7 +686,7 @@ class Semantic {
687686
args.foreach { arg =>
688687
val res =
689688
if arg.isByName then
690-
val fun = Fun(arg.tree, Nil, thisV, klass, env)
689+
val fun = Fun(arg.tree, thisV, klass, env)
691690
Result(fun, Nil)
692691
else
693692
eval(arg.tree, thisV, klass)
@@ -774,12 +773,11 @@ class Semantic {
774773
eval(rhs, thisV, klass).ensureHot("May only assign fully initialized value", rhs)
775774

776775
case closureDef(ddef) =>
777-
val params = ddef.termParamss.head.map(_.symbol)
778-
val value = Fun(ddef.rhs, params, thisV, klass, env)
776+
val value = Fun(ddef.rhs, thisV, klass, env)
779777
Result(value, Nil)
780778

781779
case PolyFun(body) =>
782-
val value = Fun(body, Nil, thisV, klass, env)
780+
val value = Fun(body, thisV, klass, env)
783781
Result(value, Nil)
784782

785783
case Block(stats, expr) =>

0 commit comments

Comments
 (0)