Skip to content

Commit 8cdb1ed

Browse files
committed
Add definition
1 parent 75556ad commit 8cdb1ed

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

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

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ class Semantic {
7777
*
7878
* We need to restrict nesting levels of `outer` to finitize the domain.
7979
*/
80-
case class Warm(klass: ClassSymbol, outer: Value) extends Addr
80+
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, thisV: Addr, klass: ClassSymbol) extends Value
83+
case class Fun(expr: Tree, params: List[Symbol], thisV: Addr, klass: ClassSymbol, env: Env) extends Value
8484

8585
/** A value which represents a set of addresses
8686
*
@@ -138,6 +138,32 @@ class Semantic {
138138
import Heap._
139139
val heap: Heap = Heap.empty
140140

141+
/** The environment for method parameters */
142+
object Env {
143+
opaque type Env = Map[Symbol, Value]
144+
145+
val empty: Env = Map.empty
146+
147+
def apply(bindings: Map[Symbol, Value]): Env = bindings
148+
149+
def apply(ddef: DefDef, args: List[Value])(using Context): Env =
150+
val params = ddef.termParamss.flatten.map(_.symbol)
151+
assert(args.size == params.size, "arguments = " + args.size + ", params = " + params.size)
152+
params.zip(args).toMap
153+
154+
extension (env: Env)
155+
def lookup(sym: Symbol)(using Context): Value = env(sym)
156+
157+
def getOrElse(sym: Symbol, default: Value)(using Context): Value = env.getOrElse(sym, default)
158+
159+
def union(other: Env): Env = env ++ other
160+
}
161+
162+
type Env = Env.Env
163+
def env(using env: Env) = env
164+
165+
import Env._
166+
141167
object Promoted {
142168
/** Values that have been safely promoted */
143169
opaque type Promoted = mutable.Set[Value]
@@ -251,11 +277,21 @@ class Semantic {
251277

252278
case (RefSet(refs1), RefSet(refs2)) => RefSet(refs1 ++ refs2)
253279

280+
def widen: Value =
281+
a match
282+
case RefSet(refs) => refs.map(_.widen).join
283+
case _: Addr => Cold
284+
case Fun(e, params, thisV, klass, env) => Fun(e, params, thisV.widen, klass, env)
285+
case _ => a
286+
287+
254288
extension (values: Seq[Value])
255289
def join: Value =
256290
if values.isEmpty then Hot
257291
else values.reduce { (v1, v2) => v1.join(v2) }
258292

293+
def widen: List[Value] = values.map(_.widen).toList
294+
259295
extension (value: Value)
260296
def select(field: Symbol, source: Tree, needResolve: Boolean = true): Contextual[Result] =
261297
value match {

0 commit comments

Comments
 (0)