Optimize let expressions as frame slot vars (#1622)

This introduces an optimization to write let expressions to frame slots
of the current frame, rather than transforming them into lambdas. As a
result, let expressions are _much_ faster to execute.
This commit is contained in:
Daniel Chao
2026-06-01 16:53:30 -07:00
committed by GitHub
parent bfda4cc8c8
commit 7dd2bc67de
11 changed files with 191 additions and 139 deletions
@@ -10,24 +10,25 @@ res2 =
res3 =
let (x = 1)
let (y = 2)
x + y + x
let (y = 2)
x + y + x
res4 =
let (x = 1)
let (x = 2)
x + x
let (x = 2)
x + x
res5 =
let (price = 500) new {
lowestPrice = price - 100
averagePrice = new {
price
let (price = 500)
new {
lowestPrice = price - 100
averagePrice = new {
price
}
highestPrice = new {
["price"] = price + 100
}
}
highestPrice = new {
["price"] = price + 100
}
}
res6 =
let (str = "Pigeon".reverse())
@@ -51,8 +52,9 @@ local g = (a) ->
res9 = g.apply(3)
local h = let (b = 2)
(a) -> a + b
local h =
let (b = 2)
(a) -> a + b
res10 = h.apply(3)
@@ -71,9 +73,9 @@ res12 = new Lets {
res13 =
let (x = 1)
let (y = x)
let (z = y)
x + y + z
let (y = x)
let (z = y)
x + y + z
// x can't access y
res14 = test.catch(() -> let (x = y) let (y = 2) x + y)
@@ -1,4 +1,4 @@
res1 =
let (x = 1)
let (y = 2)
throw("ouch")
let (y = 2)
throw("ouch")
@@ -3,15 +3,11 @@ ouch
x | throw("ouch")
^^^^^^^^^^^^^
at letExpressionError1#res1.<function#2> (file:///$snippetsDir/input/errors/letExpressionError1.pkl)
x | let (y = 2)
^^^^^^^^^^^
at letExpressionError1#res1.<function#1> (file:///$snippetsDir/input/errors/letExpressionError1.pkl)
at letExpressionError1#res1 (file:///$snippetsDir/input/errors/letExpressionError1.pkl)
x | let (x = 1)
^^^^^^^^^^^
at letExpressionError1#res1 (file:///$snippetsDir/input/errors/letExpressionError1.pkl)
at letExpressionError1#res1.<let expr> (file:///$snippetsDir/input/errors/letExpressionError1.pkl)
xxx | renderer.renderDocument(value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -3,11 +3,11 @@ ouch
x | let (y = throw("ouch"))
^^^^^^^^^^^^^
at letExpressionError2#res1.<function#1> (file:///$snippetsDir/input/errors/letExpressionError2.pkl)
at letExpressionError2#res1 (file:///$snippetsDir/input/errors/letExpressionError2.pkl)
x | let (x = 1)
^^^^^^^^^^^
at letExpressionError2#res1 (file:///$snippetsDir/input/errors/letExpressionError2.pkl)
at letExpressionError2#res1.<let expr> (file:///$snippetsDir/input/errors/letExpressionError2.pkl)
xxx | renderer.renderDocument(value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -4,10 +4,6 @@ Value: "abc"
x | let (x: Float = "abc")
^^^^^
at letExpressionErrorTyped#res1.<function#1> (file:///$snippetsDir/input/errors/letExpressionErrorTyped.pkl)
x | let (x: Float = "abc")
^^^^^^^^^^^^^^^^^^^^^^
at letExpressionErrorTyped#res1 (file:///$snippetsDir/input/errors/letExpressionErrorTyped.pkl)
xxx | renderer.renderDocument(value)