From 1208fa94388725a7c67de4d617d893e3a5141cbf Mon Sep 17 00:00:00 2001 From: Daniel Chao Date: Fri, 28 Aug 2026 09:18:56 -0700 Subject: [PATCH] Improve reading of const members (#1835) The previous implementation can cause the JIT compiler to permanently bail out when reading const memebrs. --- .../src/main/java/org/pkl/core/runtime/VmUtils.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pkl-core/src/main/java/org/pkl/core/runtime/VmUtils.java b/pkl-core/src/main/java/org/pkl/core/runtime/VmUtils.java index 0466087fb..471524360 100644 --- a/pkl-core/src/main/java/org/pkl/core/runtime/VmUtils.java +++ b/pkl-core/src/main/java/org/pkl/core/runtime/VmUtils.java @@ -353,9 +353,16 @@ public final class VmUtils { // can be re-used for all children in the amends chain. if (member.isConst() && owner != receiver) { assert member.isProp(); + // `const` properties can possibly be declared on non-prototypes, but they must be also + // declared `local`; and that code path goes through `Read*LocalPropertyNode`. + // thus, this assertion is correct here. assert owner.isPrototype(); - var result = readMemberOrNull(owner, memberKey, checkType, callNode); - assert result != null; + var cachedValue = owner.getCachedValue(memberKey); + if (cachedValue != null) { + receiver.setCachedValue(memberKey, cachedValue); + return cachedValue; + } + var result = doReadMember(owner, owner, memberKey, member, checkType, callNode); receiver.setCachedValue(memberKey, result); return result; }