mirror of
https://github.com/apple/pkl.git
synced 2026-05-03 05:34:26 +02:00
Optimization: execute const object bodies and typechecks only once (#915)
If the object member is const, it only needs to be executed once, and all children in the prototype chain can use its cached value. There is a possible other optimization here, not included in this PR: we can avoid adding these values to the child object's cachedMembers.
This commit is contained in:
13
pkl-core/src/test/files/LanguageSnippetTests/input/basic/constModifier5.pkl
vendored
Normal file
13
pkl-core/src/test/files/LanguageSnippetTests/input/basic/constModifier5.pkl
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
// should result in only one trace per property
|
||||
class MyClass {
|
||||
// property body only gets executed once
|
||||
const prop = trace("hello")
|
||||
|
||||
// typecheck only happens once
|
||||
const prop2: Int(let (_ = trace("hello again")) true) = 1
|
||||
|
||||
res: Int
|
||||
}
|
||||
|
||||
a = new MyClass { res = 1 }
|
||||
b = (a) { res = 2 }
|
||||
12
pkl-core/src/test/files/LanguageSnippetTests/output/basic/constModifier5.err
vendored
Normal file
12
pkl-core/src/test/files/LanguageSnippetTests/output/basic/constModifier5.err
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
a {
|
||||
prop = "hello"
|
||||
prop2 = 1
|
||||
res = 1
|
||||
}
|
||||
b {
|
||||
prop = "hello"
|
||||
prop2 = 1
|
||||
res = 2
|
||||
}
|
||||
pkl: TRACE: "hello" = "hello" (file:///$snippetsDir/input/basic/constModifier5.pkl)
|
||||
pkl: TRACE: "hello again" = "hello again" (file:///$snippetsDir/input/basic/constModifier5.pkl)
|
||||
Reference in New Issue
Block a user