Skip to content

Commit 14f0bf5

Browse files
committed
make sure we're checking constant assumptions on PCells of the same function root
1 parent b9e7ac6 commit 14f0bf5

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cell/PCell.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,19 @@ public void setRef(Object ref) {
7070
this.ref = ref;
7171
}
7272

73+
/**
74+
* Use this to pass in the effectivelyFinal assumption from a node that made it constant.
75+
*/
76+
public void setRef(Object ref, Assumption constantAssumption) {
77+
assert constantAssumption == effectivelyFinal;
78+
if (constantAssumption.isValid()) {
79+
if (this.ref != null) {
80+
constantAssumption.invalidate();
81+
}
82+
}
83+
this.ref = ref;
84+
}
85+
7386
public Assumption isEffectivelyFinalAssumption() {
7487
return effectivelyFinal;
7588
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/cell/WriteLocalCellNode.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.oracle.graal.python.nodes.frame.ReadLocalVariableNode;
3333
import com.oracle.graal.python.nodes.frame.WriteIdentifierNode;
3434
import com.oracle.graal.python.nodes.statement.StatementNode;
35+
import com.oracle.truffle.api.Assumption;
3536
import com.oracle.truffle.api.CompilerDirectives;
3637
import com.oracle.truffle.api.dsl.Cached;
3738
import com.oracle.truffle.api.dsl.NodeChild;
@@ -93,7 +94,17 @@ void doWriteCached(@SuppressWarnings("unused") PCell cell, Object value,
9394
doWriteGeneric(cachedCell, value);
9495
}
9596

96-
@Specialization(replaces = "doWriteCached")
97+
@Specialization(guards = "cell.isEffectivelyFinalAssumption() == effectivelyFinalAssumption", limit = "1", assumptions = "effectivelyFinalAssumption")
98+
void doWriteCachedAssumption(PCell cell, Object value,
99+
@SuppressWarnings("unused") @Cached("cell.isEffectivelyFinalAssumption()") Assumption effectivelyFinalAssumption) {
100+
if (value == NO_VALUE) {
101+
cell.clearRef();
102+
} else {
103+
cell.setRef(value, effectivelyFinalAssumption);
104+
}
105+
}
106+
107+
@Specialization(replaces = {"doWriteCached", "doWriteCachedAssumption"})
97108
void doWriteGeneric(PCell cell, Object value) {
98109
if (value == NO_VALUE) {
99110
cell.clearRef();

0 commit comments

Comments
 (0)