Skip to content

Commit f78f7ae

Browse files
committed
Don't check cell assumptions if not constant
1 parent 6f909cb commit f78f7ae

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848

4949
import java.util.List;
5050

51+
import com.oracle.graal.python.PythonLanguage;
5152
import com.oracle.graal.python.builtins.Builtin;
5253
import com.oracle.graal.python.builtins.CoreFunctions;
5354
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -61,6 +62,7 @@
6162
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
6263
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
6364
import com.oracle.graal.python.nodes.object.GetLazyClassNode;
65+
import com.oracle.truffle.api.Assumption;
6466
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
6567
import com.oracle.truffle.api.dsl.Cached;
6668
import com.oracle.truffle.api.dsl.Fallback;
@@ -169,8 +171,13 @@ public Object set(PCell self, Object ref) {
169171
public abstract static class GetRefNode extends Node {
170172
public abstract Object execute(PCell self);
171173

172-
@Specialization(guards = "self == cachedSelf", assumptions = "cachedSelf.isEffectivelyFinalAssumption()", limit = "1")
174+
protected static Assumption singleContextAssumption() {
175+
return PythonLanguage.getCurrent().singleContextAssumption;
176+
}
177+
178+
@Specialization(guards = "self == cachedSelf", assumptions = {"cachedSelf.isEffectivelyFinalAssumption()", "singleContextAssumption"}, limit = "1")
173179
Object cached(@SuppressWarnings("unused") PCell self,
180+
@SuppressWarnings("unused") @Cached("singleContextAssumption()") Assumption singleContextAssumption,
174181
@SuppressWarnings("unused") @Cached("self") PCell cachedSelf,
175182
@Cached("self.getRef()") Object ref) {
176183
return ref;

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import com.oracle.truffle.api.Assumption;
4848
import com.oracle.truffle.api.CompilerAsserts;
4949
import com.oracle.truffle.api.CompilerDirectives;
50+
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
5051
import com.oracle.truffle.api.library.ExportLibrary;
5152
import com.oracle.truffle.api.library.ExportMessage;
5253

@@ -63,15 +64,22 @@ public Object getRef() {
6364
return ref;
6465
}
6566

67+
public void clearRef(Assumption assumption) {
68+
setRef(null, assumption);
69+
}
70+
6671
public void clearRef() {
6772
setRef(null);
6873
}
6974

75+
@TruffleBoundary
76+
private static void invalidateAssumption(Assumption assumption) {
77+
assumption.invalidate();
78+
}
79+
7080
public void setRef(Object ref) {
71-
if (effectivelyFinal.isValid()) {
72-
if (this.ref != null) {
73-
effectivelyFinal.invalidate();
74-
}
81+
if (this.ref != null) {
82+
invalidateAssumption(effectivelyFinal);
7583
}
7684
this.ref = ref;
7785
}

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,18 @@
2727

2828
import static com.oracle.graal.python.builtins.objects.PNone.NO_VALUE;
2929

30+
import com.oracle.graal.python.PythonLanguage;
3031
import com.oracle.graal.python.builtins.objects.cell.PCell;
3132
import com.oracle.graal.python.nodes.expression.ExpressionNode;
3233
import com.oracle.graal.python.nodes.frame.WriteIdentifierNode;
3334
import com.oracle.graal.python.nodes.statement.StatementNode;
35+
import com.oracle.graal.python.runtime.PythonOptions;
3436
import com.oracle.truffle.api.Assumption;
3537
import com.oracle.truffle.api.CompilerDirectives;
3638
import com.oracle.truffle.api.dsl.Cached;
39+
import com.oracle.truffle.api.dsl.ImportStatic;
3740
import com.oracle.truffle.api.dsl.NodeChild;
41+
import com.oracle.truffle.api.dsl.ReportPolymorphism;
3842
import com.oracle.truffle.api.dsl.Specialization;
3943
import com.oracle.truffle.api.frame.FrameSlot;
4044
import com.oracle.truffle.api.frame.VirtualFrame;
@@ -83,21 +87,32 @@ public Object getIdentifier() {
8387
return frameSlot.getIdentifier();
8488
}
8589

90+
@ImportStatic(PythonOptions.class)
91+
@ReportPolymorphism
8692
abstract static class WriteToCellNode extends Node {
8793

8894
public abstract void execute(PCell cell, Object value);
8995

90-
@Specialization(guards = "cell == cachedCell", limit = "1")
96+
protected static Assumption singleContextAssumption() {
97+
return PythonLanguage.getCurrent().singleContextAssumption;
98+
}
99+
100+
@Specialization(guards = "cell == cachedCell", limit = "getAttributeAccessInlineCacheMaxDepth()", assumptions = "singleContextAssumption")
91101
void doWriteCached(@SuppressWarnings("unused") PCell cell, Object value,
102+
@SuppressWarnings("unused") @Cached("singleContextAssumption()") Assumption singleContextAssumption,
92103
@Cached("cell") PCell cachedCell) {
93-
doWriteGeneric(cachedCell, value);
104+
if (value == NO_VALUE) {
105+
cachedCell.clearRef(cachedCell.isEffectivelyFinalAssumption());
106+
} else {
107+
cachedCell.setRef(value, cachedCell.isEffectivelyFinalAssumption());
108+
}
94109
}
95110

96-
@Specialization(guards = "cell.isEffectivelyFinalAssumption() == effectivelyFinalAssumption", limit = "1", assumptions = "effectivelyFinalAssumption")
111+
@Specialization(guards = "cell.isEffectivelyFinalAssumption() == effectivelyFinalAssumption", limit = "getAttributeAccessInlineCacheMaxDepth()", assumptions = "effectivelyFinalAssumption")
97112
void doWriteCachedAssumption(PCell cell, Object value,
98113
@SuppressWarnings("unused") @Cached("cell.isEffectivelyFinalAssumption()") Assumption effectivelyFinalAssumption) {
99114
if (value == NO_VALUE) {
100-
cell.clearRef();
115+
cell.clearRef(effectivelyFinalAssumption);
101116
} else {
102117
cell.setRef(value, effectivelyFinalAssumption);
103118
}

0 commit comments

Comments
 (0)