mirror of
https://github.com/apple/pkl.git
synced 2026-05-28 01:29:15 +02:00
Add optimization for generator bodies that don't introduce new members (#1013)
If a generator object literal doesn't add any object members, we can simply use the parent in its place. Co-authored-by: Kushal Pisavadia <kushi.p@gmail.com>
This commit is contained in:
+46
@@ -0,0 +1,46 @@
|
||||
// should only result in one trace in the output; generator object literals that don't add any
|
||||
// members should be optimized away.
|
||||
res1 {
|
||||
prop = trace("hello")
|
||||
}
|
||||
|
||||
res2 = (res1) {
|
||||
when (false) {
|
||||
prop2 = 2
|
||||
}
|
||||
}
|
||||
|
||||
res3 = (res1) {
|
||||
for (_ in List()) {
|
||||
"hello"
|
||||
}
|
||||
}
|
||||
|
||||
res4 = (res1) {
|
||||
...List()
|
||||
}
|
||||
|
||||
res5 = (res1) {
|
||||
when (true) {
|
||||
} else {
|
||||
prop3 = 3
|
||||
}
|
||||
}
|
||||
|
||||
res6 = (Dynamic) {
|
||||
when (true) {}
|
||||
}
|
||||
|
||||
res7 = (Mapping) {
|
||||
when (true) {}
|
||||
}
|
||||
|
||||
class Person {}
|
||||
|
||||
res8 = (Person) {
|
||||
when (true) {}
|
||||
}
|
||||
|
||||
res9 = (Listing) {
|
||||
when (true) {}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
res1 {
|
||||
prop = "hello"
|
||||
}
|
||||
res2 {
|
||||
prop = "hello"
|
||||
}
|
||||
res3 {
|
||||
prop = "hello"
|
||||
}
|
||||
res4 {
|
||||
prop = "hello"
|
||||
}
|
||||
res5 {
|
||||
prop = "hello"
|
||||
}
|
||||
res6 {}
|
||||
res7 {}
|
||||
res8 {}
|
||||
res9 {}
|
||||
pkl: TRACE: "hello" = "hello" (file:///$snippetsDir/input/generators/generatorNoMembers.pkl)
|
||||
Reference in New Issue
Block a user