Skip to content

Commit

Permalink
stash
Browse files Browse the repository at this point in the history
  • Loading branch information
holzensp committed Sep 24, 2024
1 parent 2ea92db commit a2d5b37
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 24 deletions.
17 changes: 10 additions & 7 deletions pkl-core/src/main/java/org/pkl/core/runtime/VmObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,25 @@ public final UnmodifiableEconomicMap<Object, ObjectMember> getMembers() {
/** Tells whether this object has any elements. */
public abstract boolean hasElements();

public final @Nullable Object toReferenceKey(Object definitionKey) {
if (!(definitionKey instanceof Long index) || !hasElements()) {
var member = getMember(definitionKey);
public @Nullable Object toDefinitionKey(Object referenceKey) {
if (!(referenceKey instanceof Long index) || !hasElements()) {
var member = getMember(referenceKey);
if (member != null && member.isDelete()) {
return null;
}
return definitionKey;
return referenceKey;
}

var deletedIndices = getDeletedIndices();
if (deletedIndices == null) {
return definitionKey;
return referenceKey;
}

index -= deletedIndices.subSet(0L, index + 1L).size();
return index < 0 ? null : index;
index += deletedIndices.subSet(0L, index + 1L).size();
for (var m = getMember(index); m != null && m.isDelete(); m = getMember(index)) {
index++;
}
return index;
}

@Override
Expand Down
16 changes: 8 additions & 8 deletions pkl-core/src/main/java/org/pkl/core/runtime/VmUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,20 +244,20 @@ public static Object readMember(
VmObjectLike receiver, Object memberKey, boolean checkType, IndirectCallNode callNode) {
assert (!(memberKey instanceof Identifier identifier) || !identifier.isLocalProp())
: "Must use ReadLocalPropertyNode for local properties.";

final var cachedValue = receiver.getCachedValue(memberKey);
if (cachedValue != null) return cachedValue;

for (var owner = receiver; owner != null; owner = owner.getParent()) {
var member = owner.getMember(memberKey);
if (member == null || member.isDelete()) continue;
var key = (owner instanceof VmObject obj) ? obj.toReferenceKey(memberKey) : memberKey;
assert key != null : "Non-deletion member caused key removal";
if (key == memberKey) {
var key = (owner instanceof VmObject obj) ? obj.toDefinitionKey(memberKey) : memberKey;
if (key == null) {
return null;
}
var member = owner.getMember(key);
if (member != null) {
// The key was not renamed by deletion of other keys.
return doReadMember(receiver, owner, memberKey, member, checkType, callNode);
return doReadMember(receiver, owner, key, member, checkType, callNode);
}
memberKey = key;
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,28 @@ facts {

["direct element access after multiple deletes"] {
local source = (new Dynamic {
"foo" // 0 0 0
"bar" // 1 - -
"baz" // 2 1 -
"qux" // 3 2 -
"quux" // 4 3 1
"corge" // 5 4 2
"zero" // 0 0 0
"one" // 1 - -
"two" // 2 1 -
"three" // 3 - -
"four" // 4 2 -
"five" // 5 3 1
"six" // 6 - -
"seven" // 7 4 -
"eight" // 8 5 2
}) {
[1] = delete
[3] = delete
[6] = delete
} {
[1] = delete
[2] = delete
[4] = "expected"
[3] = "expected"
[4] = delete
}
source[2] == "expected"
trace(trace(source)[2]) == "expected"
local result = source[1]
source[1] == "expected"
result == "expected"
source[2] == "eight"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ facts {
["direct element access after multiple deletes"] {
true
true
true
}
}

0 comments on commit a2d5b37

Please sign in to comment.