@@ -118,7 +118,7 @@ object Semantic:
118118 end Warm
119119
120120 /** A function value */
121- case class Fun (expr : Tree , thisV : Ref , klass : ClassSymbol , env : Env ) extends Value
121+ case class Fun (expr : Tree , thisV : Ref , klass : ClassSymbol ) extends Value
122122
123123 /** A value which represents a set of addresses
124124 *
@@ -144,7 +144,7 @@ object Semantic:
144144
145145 def hasField (f : Symbol ) = fields.contains(f)
146146
147- /** The environment for method parameters
147+ /** The environment stores values for constructor parameters
148148 *
149149 * For performance and usability, we restrict parameters to be either `Cold`
150150 * or `Hot`.
@@ -162,6 +162,9 @@ object Semantic:
162162 * key. The reason is that given the same receiver, a method or function may
163163 * be called with different arguments -- they are not decided by the receiver
164164 * anymore.
165+ *
166+ * TODO: remove Env as it is only used to pass value from `callConstructor` -> `eval` -> `init`.
167+ * It goes through `eval` for caching (termination) purposes.
165168 */
166169 object Env :
167170 opaque type Env = Map [Symbol , Value ]
@@ -704,14 +707,12 @@ object Semantic:
704707 else
705708 value.select(target, needResolve = false )
706709
707- case Fun (body, thisV, klass, env ) =>
710+ case Fun (body, thisV, klass) =>
708711 // meth == NoSymbol for poly functions
709712 if meth.name.toString == " tupled" then value // a call like `fun.tupled`
710713 else
711714 promoteArgs()
712- withEnv(env) {
713- eval(body, thisV, klass, cacheResult = true )
714- }
715+ eval(body, thisV, klass, cacheResult = true )
715716
716717 case RefSet (refs) =>
717718 refs.map(_.call(meth, args, receiver, superType)).join
@@ -823,7 +824,7 @@ object Semantic:
823824 warm.callConstructor(ctor, argInfos2)
824825 warm
825826
826- case Fun (body, thisV, klass, env ) =>
827+ case Fun (body, thisV, klass) =>
827828 report.error(" unexpected tree in instantiating a function, fun = " + body.show, trace.toVector.last)
828829 Hot
829830
@@ -933,10 +934,10 @@ object Semantic:
933934 if errors.nonEmpty then promoted.remove(warm)
934935 reporter.reportAll(errors)
935936
936- case fun @ Fun (body, thisV, klass, env ) =>
937+ case fun @ Fun (body, thisV, klass) =>
937938 if ! promoted.contains(fun) then
938939 val errors = Reporter .stopEarly {
939- val res = withEnv(env) {
940+ val res = {
940941 given Trace = Trace .empty
941942 eval(body, thisV, klass)
942943 }
@@ -1121,7 +1122,7 @@ object Semantic:
11211122 args.foreach { arg =>
11221123 val res =
11231124 if arg.isByName then
1124- Fun (arg.tree, thisV, klass, env )
1125+ Fun (arg.tree, thisV, klass)
11251126 else
11261127 eval(arg.tree, thisV, klass)
11271128
@@ -1227,10 +1228,10 @@ object Semantic:
12271228 }
12281229
12291230 case closureDef(ddef) =>
1230- Fun (ddef.rhs, thisV, klass, env )
1231+ Fun (ddef.rhs, thisV, klass)
12311232
12321233 case PolyFun (body) =>
1233- Fun (body, thisV, klass, env )
1234+ Fun (body, thisV, klass)
12341235
12351236 case Block (stats, expr) =>
12361237 eval(stats, thisV, klass)
0 commit comments