Skip to content

Commit 4eff8b5

Browse files
committed
strip temp locals from locals() dict
1 parent b2c536a commit 4eff8b5

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/LocalsStorage.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
package com.oracle.graal.python.builtins.objects.common;
4242

4343
import static com.oracle.graal.python.nodes.frame.FrameSlotIDs.RETURN_SLOT_ID;
44+
import static com.oracle.graal.python.nodes.frame.FrameSlotIDs.TEMP_LOCAL_PREFIX;
4445

4546
import java.util.Iterator;
4647
import java.util.NoSuchElementException;
@@ -76,11 +77,6 @@ private Object getValue(FrameSlot slot) {
7677
return null;
7778
}
7879

79-
@TruffleBoundary
80-
private static FrameSlot findReturnSlot(Frame frame) {
81-
return frame.getFrameDescriptor().findFrameSlot(RETURN_SLOT_ID);
82-
}
83-
8480
public Frame getFrame() {
8581
return frame;
8682
}
@@ -96,11 +92,17 @@ public Object getItem(Object key, Equivalence eq) {
9692
assert eq == DEFAULT_EQIVALENCE;
9793
if (RETURN_SLOT_ID.equals(key)) {
9894
return null;
95+
} else if (isTempLocal(key)) {
96+
return null;
9997
}
10098
FrameSlot slot = frame.getFrameDescriptor().findFrameSlot(key);
10199
return getValue(slot);
102100
}
103101

102+
private static boolean isTempLocal(Object key) {
103+
return key instanceof String && ((String) key).startsWith(TEMP_LOCAL_PREFIX);
104+
}
105+
104106
@Override
105107
public void setItem(Object key, Object value, Equivalence eq) {
106108
throw UnmodifiableStorageException.INSTANCE;
@@ -122,6 +124,8 @@ public boolean hasKey(Object key, Equivalence eq) {
122124
assert eq == DEFAULT_EQIVALENCE;
123125
if (RETURN_SLOT_ID.equals(key)) {
124126
return false;
127+
} else if (isTempLocal(key)) {
128+
return false;
125129
}
126130
return frame.getFrameDescriptor().findFrameSlot(key) != null;
127131
}
@@ -132,7 +136,8 @@ public int length() {
132136
if (length == -1) {
133137
length = frame.getFrameDescriptor().getSize();
134138
for (FrameSlot slot : frame.getFrameDescriptor().getSlots()) {
135-
if (slot.getIdentifier().equals(RETURN_SLOT_ID) || frame.getValue(slot) == null) {
139+
Object identifier = slot.getIdentifier();
140+
if (identifier.equals(RETURN_SLOT_ID) || isTempLocal(identifier) || frame.getValue(slot) == null) {
136141
length--;
137142
}
138143
}
@@ -210,7 +215,8 @@ public FrameSlot nextSlot() {
210215
private boolean loadNext() {
211216
while (keysIterator().hasNext()) {
212217
FrameSlot nextCandidate = keysIterator().next();
213-
if (!RETURN_SLOT_ID.equals(nextCandidate.getIdentifier())) {
218+
Object identifier = nextCandidate.getIdentifier();
219+
if (!RETURN_SLOT_ID.equals(identifier) && !isTempLocal(identifier)) {
214220
Object nextValue = frame.getValue(nextCandidate);
215221
if (skipCells && nextValue instanceof PCell) {
216222
continue;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/FrameSlotIDs.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@
2727

2828
public abstract class FrameSlotIDs {
2929
public static final String RETURN_SLOT_ID = "<return_val>";
30+
public static final String TEMP_LOCAL_PREFIX = "<>temp";
3031
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/parser/TranslationEnvironment.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import static com.oracle.graal.python.nodes.SpecialAttributeNames.__CLASS__;
2929
import static com.oracle.graal.python.nodes.frame.FrameSlotIDs.RETURN_SLOT_ID;
30+
import static com.oracle.graal.python.nodes.frame.FrameSlotIDs.TEMP_LOCAL_PREFIX;
3031

3132
import java.util.List;
3233
import java.util.function.Function;
@@ -56,8 +57,6 @@ public final class TranslationEnvironment implements CellFrameSlotSupplier {
5657
private ScopeInfo currentScope;
5758
private ScopeInfo globalScope;
5859

59-
private static final String TEMP_LOCAL_PREFIX = "<>temp_";
60-
6160
public TranslationEnvironment(PythonLanguage language) {
6261
this.factory = language.getNodeFactory();
6362
}

0 commit comments

Comments
 (0)