mirror of
https://github.com/apple/pkl.git
synced 2026-06-25 06:46:18 +02:00
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:
@@ -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)
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
res1 =
|
||||
let (x = 1)
|
||||
let (y = 2)
|
||||
throw("ouch")
|
||||
let (y = 2)
|
||||
throw("ouch")
|
||||
|
||||
+2
-6
@@ -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)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
+2
-2
@@ -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
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user