Skip to content

Commit a876714

Browse files
committed
Migrate more usages of PException#expect* to use inline profile
1 parent 441d677 commit a876714

30 files changed

+315
-241
lines changed

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/builtins/modules/ClinicTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -67,7 +67,7 @@
6767
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryClinicBuiltinNode;
6868
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentCastNode;
6969
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
70-
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
70+
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
7171
import com.oracle.graal.python.runtime.exception.PException;
7272
import com.oracle.graal.python.test.PythonTests;
7373
import com.oracle.truffle.api.CallTarget;
@@ -203,7 +203,7 @@ public Object execute(VirtualFrame frame) {
203203
} catch (PException ex) {
204204
boolean expectTypeError = frame.getArguments().length >= 3 && (boolean) frame.getArguments()[2];
205205
if (expectTypeError) {
206-
ex.expect(PythonBuiltinClassType.TypeError, IsBuiltinClassProfile.getUncached());
206+
ex.expect(null, PythonBuiltinClassType.TypeError, IsBuiltinObjectProfile.getUncached());
207207
return T_TYPE_ERROR;
208208
} else {
209209
throw ex;

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/nodes/util/CastToJavaUnsignedLongNodeTests.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -40,23 +40,24 @@
4040
*/
4141
package com.oracle.graal.python.nodes.util;
4242

43+
import static com.oracle.graal.python.runtime.exception.PythonErrorType.OverflowError;
44+
import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
45+
46+
import java.math.BigInteger;
47+
48+
import org.junit.After;
49+
import org.junit.Assert;
50+
import org.junit.Before;
51+
import org.junit.Test;
52+
4353
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
4454
import com.oracle.graal.python.builtins.objects.ints.PInt;
45-
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
55+
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
4656
import com.oracle.graal.python.runtime.exception.PException;
4757
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
4858
import com.oracle.graal.python.test.PythonTests;
4959
import com.oracle.truffle.api.frame.VirtualFrame;
5060
import com.oracle.truffle.api.nodes.RootNode;
51-
import org.junit.After;
52-
import org.junit.Assert;
53-
import org.junit.Before;
54-
import org.junit.Test;
55-
56-
import java.math.BigInteger;
57-
58-
import static com.oracle.graal.python.runtime.exception.PythonErrorType.OverflowError;
59-
import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
6061

6162
public class CastToJavaUnsignedLongNodeTests {
6263
private static PythonObjectFactory factory = PythonObjectFactory.getUncached();
@@ -139,7 +140,7 @@ private static void expect(PythonBuiltinClassType errorType, Runnable test) {
139140
test.run();
140141
Assert.fail("Expected " + errorType.getName());
141142
} catch (PException e) {
142-
e.expect(errorType, IsBuiltinClassProfile.getUncached());
143+
e.expect(null, errorType, IsBuiltinObjectProfile.getUncached());
143144
}
144145
}
145146

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinConstructors.java

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@
222222
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsAnyBuiltinClassProfile;
223223
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
224224
import com.oracle.graal.python.nodes.object.GetClassNode;
225-
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
226225
import com.oracle.graal.python.nodes.util.CannotCastException;
227226
import com.oracle.graal.python.nodes.util.CastToJavaIntExactNode;
228227
import com.oracle.graal.python.nodes.util.CastToJavaStringNode;
@@ -1831,69 +1830,76 @@ public abstract static class RangeNode extends PythonQuaternaryBuiltinNode {
18311830
// stop
18321831
@Specialization(guards = "isStop(start, stop, step)")
18331832
Object doIntStop(Object cls, int stop, @SuppressWarnings("unused") PNone start, @SuppressWarnings("unused") PNone step,
1834-
@Shared("stepZeroProfile") @Cached ConditionProfile stepZeroProfile,
1833+
@Bind("this") Node inliningTarget,
1834+
@Shared("stepZeroProfile") @Cached InlinedConditionProfile stepZeroProfile,
18351835
@Shared("exceptionProfile") @Cached InlinedBranchProfile exceptionProfile,
18361836
@Shared("lenOfRangeNodeExact") @Cached LenOfIntRangeNodeExact lenOfRangeNodeExact,
18371837
@Shared("createBigRangeNode") @Cached RangeNodes.CreateBigRangeNode createBigRangeNode) {
1838-
return doInt(cls, 0, stop, 1, stepZeroProfile, exceptionProfile, lenOfRangeNodeExact, createBigRangeNode);
1838+
return doInt(cls, 0, stop, 1, inliningTarget, stepZeroProfile, exceptionProfile, lenOfRangeNodeExact, createBigRangeNode);
18391839
}
18401840

18411841
@Specialization(guards = "isStop(start, stop, step)")
18421842
Object doPintStop(Object cls, PInt stop, @SuppressWarnings("unused") PNone start, @SuppressWarnings("unused") PNone step,
1843-
@Shared("stepZeroProfile") @Cached ConditionProfile stepZeroProfile,
1843+
@Bind("this") Node inliningTarget,
1844+
@Shared("stepZeroProfile") @Cached InlinedConditionProfile stepZeroProfile,
18441845
@Shared("lenOfRangeNode") @Cached RangeNodes.LenOfRangeNode lenOfRangeNode) {
1845-
return doPint(cls, factory().createInt(0), stop, factory().createInt(1), stepZeroProfile, lenOfRangeNode);
1846+
return doPint(cls, factory().createInt(0), stop, factory().createInt(1), inliningTarget, stepZeroProfile, lenOfRangeNode);
18461847
}
18471848

18481849
@Specialization(guards = "isStop(start, stop, step)")
18491850
Object doGenericStop(VirtualFrame frame, Object cls, Object stop, @SuppressWarnings("unused") PNone start, @SuppressWarnings("unused") PNone step,
1850-
@Shared("stepZeroProfile") @Cached ConditionProfile stepZeroProfile,
1851+
@Bind("this") Node inliningTarget,
1852+
@Shared("stepZeroProfile") @Cached InlinedConditionProfile stepZeroProfile,
18511853
@Shared("exceptionProfile") @Cached InlinedBranchProfile exceptionProfile,
18521854
@Shared("lenOfRangeNodeExact") @Cached LenOfIntRangeNodeExact lenOfRangeNodeExact,
18531855
@Shared("createBigRangeNode") @Cached RangeNodes.CreateBigRangeNode createBigRangeNode,
18541856
@Shared("cast") @Cached CastToJavaIntExactNode cast,
1855-
@Shared("overflowProfile") @Cached IsBuiltinClassProfile overflowProfile,
1857+
@Shared("overflowProfile") @Cached IsBuiltinObjectProfile overflowProfile,
18561858
@Shared("indexNode") @Cached PyNumberIndexNode indexNode) {
1857-
return doGeneric(frame, cls, 0, stop, 1, stepZeroProfile, exceptionProfile, lenOfRangeNodeExact, createBigRangeNode, cast, overflowProfile, indexNode);
1859+
return doGeneric(frame, cls, 0, stop, 1, inliningTarget, stepZeroProfile, exceptionProfile, lenOfRangeNodeExact, createBigRangeNode, cast, overflowProfile, indexNode);
18581860
}
18591861

18601862
// start stop
18611863
@Specialization(guards = "isStartStop(start, stop, step)")
18621864
Object doIntStartStop(Object cls, int start, int stop, @SuppressWarnings("unused") PNone step,
1863-
@Shared("stepZeroProfile") @Cached ConditionProfile stepZeroProfile,
1865+
@Bind("this") Node inliningTarget,
1866+
@Shared("stepZeroProfile") @Cached InlinedConditionProfile stepZeroProfile,
18641867
@Shared("exceptionProfile") @Cached InlinedBranchProfile exceptionProfile,
18651868
@Shared("lenOfRangeNodeExact") @Cached LenOfIntRangeNodeExact lenOfRangeNodeExact,
18661869
@Shared("createBigRangeNode") @Cached RangeNodes.CreateBigRangeNode createBigRangeNode) {
1867-
return doInt(cls, start, stop, 1, stepZeroProfile, exceptionProfile, lenOfRangeNodeExact, createBigRangeNode);
1870+
return doInt(cls, start, stop, 1, inliningTarget, stepZeroProfile, exceptionProfile, lenOfRangeNodeExact, createBigRangeNode);
18681871
}
18691872

18701873
@Specialization(guards = "isStartStop(start, stop, step)")
18711874
Object doPintStartStop(Object cls, PInt start, PInt stop, @SuppressWarnings("unused") PNone step,
1872-
@Shared("stepZeroProfile") @Cached ConditionProfile stepZeroProfile,
1875+
@Bind("this") Node inliningTarget,
1876+
@Shared("stepZeroProfile") @Cached InlinedConditionProfile stepZeroProfile,
18731877
@Shared("lenOfRangeNode") @Cached RangeNodes.LenOfRangeNode lenOfRangeNode) {
1874-
return doPint(cls, start, stop, factory().createInt(1), stepZeroProfile, lenOfRangeNode);
1878+
return doPint(cls, start, stop, factory().createInt(1), inliningTarget, stepZeroProfile, lenOfRangeNode);
18751879
}
18761880

18771881
@Specialization(guards = "isStartStop(start, stop, step)")
18781882
Object doGenericStartStop(VirtualFrame frame, Object cls, Object start, Object stop, @SuppressWarnings("unused") PNone step,
1879-
@Shared("stepZeroProfile") @Cached ConditionProfile stepZeroProfile,
1883+
@Bind("this") Node inliningTarget,
1884+
@Shared("stepZeroProfile") @Cached InlinedConditionProfile stepZeroProfile,
18801885
@Shared("exceptionProfile") @Cached InlinedBranchProfile exceptionProfile,
18811886
@Shared("lenOfRangeNodeExact") @Cached LenOfIntRangeNodeExact lenOfRangeNodeExact,
18821887
@Shared("createBigRangeNode") @Cached RangeNodes.CreateBigRangeNode createBigRangeNode,
18831888
@Shared("cast") @Cached CastToJavaIntExactNode cast,
1884-
@Shared("overflowProfile") @Cached IsBuiltinClassProfile overflowProfile,
1889+
@Shared("overflowProfile") @Cached IsBuiltinObjectProfile overflowProfile,
18851890
@Shared("indexNode") @Cached PyNumberIndexNode indexNode) {
1886-
return doGeneric(frame, cls, start, stop, 1, stepZeroProfile, exceptionProfile, lenOfRangeNodeExact, createBigRangeNode, cast, overflowProfile, indexNode);
1891+
return doGeneric(frame, cls, start, stop, 1, inliningTarget, stepZeroProfile, exceptionProfile, lenOfRangeNodeExact, createBigRangeNode, cast, overflowProfile, indexNode);
18871892
}
18881893

18891894
// start stop step
18901895
@Specialization
18911896
Object doInt(@SuppressWarnings("unused") Object cls, int start, int stop, int step,
1892-
@Shared("stepZeroProfile") @Cached ConditionProfile stepZeroProfile,
1897+
@Bind("this") Node inliningTarget,
1898+
@Shared("stepZeroProfile") @Cached InlinedConditionProfile stepZeroProfile,
18931899
@Shared("exceptionProfile") @Cached InlinedBranchProfile exceptionProfile,
18941900
@Shared("lenOfRangeNodeExact") @Cached LenOfIntRangeNodeExact lenOfRangeNode,
18951901
@Shared("createBigRangeNode") @Cached RangeNodes.CreateBigRangeNode createBigRangeNode) {
1896-
if (stepZeroProfile.profile(step == 0)) {
1902+
if (stepZeroProfile.profile(inliningTarget, step == 0)) {
18971903
throw raise(ValueError, ARG_MUST_NOT_BE_ZERO, "range()", 3);
18981904
}
18991905
try {
@@ -1907,9 +1913,10 @@ Object doInt(@SuppressWarnings("unused") Object cls, int start, int stop, int st
19071913

19081914
@Specialization
19091915
Object doPint(@SuppressWarnings("unused") Object cls, PInt start, PInt stop, PInt step,
1910-
@Shared("stepZeroProfile") @Cached ConditionProfile stepZeroProfile,
1916+
@Bind("this") Node inliningTarget,
1917+
@Shared("stepZeroProfile") @Cached InlinedConditionProfile stepZeroProfile,
19111918
@Shared("lenOfRangeNode") @Cached RangeNodes.LenOfRangeNode lenOfRangeNode) {
1912-
if (stepZeroProfile.profile(step.isZero())) {
1919+
if (stepZeroProfile.profile(inliningTarget, step.isZero())) {
19131920
throw raise(ValueError, ARG_MUST_NOT_BE_ZERO, "range()", 3);
19141921
}
19151922
BigInteger len = lenOfRangeNode.execute(start.getValue(), stop.getValue(), step.getValue());
@@ -1918,12 +1925,13 @@ Object doPint(@SuppressWarnings("unused") Object cls, PInt start, PInt stop, PIn
19181925

19191926
@Specialization(guards = "isStartStopStep(start, stop, step)")
19201927
Object doGeneric(VirtualFrame frame, @SuppressWarnings("unused") Object cls, Object start, Object stop, Object step,
1921-
@Shared("stepZeroProfile") @Cached ConditionProfile stepZeroProfile,
1928+
@Bind("this") Node inliningTarget,
1929+
@Shared("stepZeroProfile") @Cached InlinedConditionProfile stepZeroProfile,
19221930
@Shared("exceptionProfile") @Cached InlinedBranchProfile exceptionProfile,
19231931
@Shared("lenOfRangeNodeExact") @Cached LenOfIntRangeNodeExact lenOfRangeNodeExact,
19241932
@Shared("createBigRangeNode") @Cached RangeNodes.CreateBigRangeNode createBigRangeNode,
19251933
@Shared("cast") @Cached CastToJavaIntExactNode cast,
1926-
@Shared("overflowProfile") @Cached IsBuiltinClassProfile overflowProfile,
1934+
@Shared("overflowProfile") @Cached IsBuiltinObjectProfile overflowProfile,
19271935
@Shared("indexNode") @Cached PyNumberIndexNode indexNode) {
19281936
Object lstart = indexNode.execute(frame, start);
19291937
Object lstop = indexNode.execute(frame, stop);
@@ -1933,9 +1941,9 @@ Object doGeneric(VirtualFrame frame, @SuppressWarnings("unused") Object cls, Obj
19331941
int istart = cast.execute(lstart);
19341942
int istop = cast.execute(lstop);
19351943
int istep = cast.execute(lstep);
1936-
return doInt(cls, istart, istop, istep, stepZeroProfile, exceptionProfile, lenOfRangeNodeExact, createBigRangeNode);
1944+
return doInt(cls, istart, istop, istep, inliningTarget, stepZeroProfile, exceptionProfile, lenOfRangeNodeExact, createBigRangeNode);
19371945
} catch (PException e) {
1938-
e.expect(OverflowError, overflowProfile);
1946+
e.expect(inliningTarget, OverflowError, overflowProfile);
19391947
return createBigRangeNode.execute(lstart, lstop, lstep, factory());
19401948
}
19411949
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixSubprocessModuleBuiltins.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -72,7 +72,7 @@
7272
import com.oracle.graal.python.nodes.function.builtins.PythonClinicBuiltinNode;
7373
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentCastNode.ArgumentCastNodeWithRaise;
7474
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
75-
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
75+
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
7676
import com.oracle.graal.python.nodes.util.CannotCastException;
7777
import com.oracle.graal.python.nodes.util.CastToJavaIntExactNode;
7878
import com.oracle.graal.python.runtime.GilNode;
@@ -84,13 +84,15 @@
8484
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
8585
import com.oracle.graal.python.util.PythonUtils;
8686
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
87+
import com.oracle.truffle.api.dsl.Bind;
8788
import com.oracle.truffle.api.dsl.Cached;
8889
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
8990
import com.oracle.truffle.api.dsl.NeverDefault;
9091
import com.oracle.truffle.api.dsl.NodeFactory;
9192
import com.oracle.truffle.api.dsl.Specialization;
9293
import com.oracle.truffle.api.frame.VirtualFrame;
9394
import com.oracle.truffle.api.library.CachedLibrary;
95+
import com.oracle.truffle.api.nodes.Node;
9496
import com.oracle.truffle.api.strings.TruffleString;
9597

9698
@CoreFunctions(defineModule = "_posixsubprocess")
@@ -114,16 +116,17 @@ static Object[] doNone(@SuppressWarnings("unused") PNone processArgs) {
114116

115117
@Specialization
116118
Object[] doSequence(VirtualFrame frame, Object processArgs,
119+
@Bind("this") Node inliningTarget,
117120
@Cached FastConstructListNode fastConstructListNode,
118121
@Cached GetSequenceStorageNode getSequenceStorageNode,
119-
@Cached IsBuiltinClassProfile isBuiltinClassProfile,
122+
@Cached IsBuiltinObjectProfile isBuiltinClassProfile,
120123
@Cached ObjectToOpaquePathNode objectToOpaquePathNode,
121124
@Cached("createNotNormalized()") GetItemNode getItemNode) {
122125
PSequence argsSequence;
123126
try {
124127
argsSequence = fastConstructListNode.execute(frame, processArgs);
125128
} catch (PException e) {
126-
e.expect(TypeError, isBuiltinClassProfile);
129+
e.expect(inliningTarget, TypeError, isBuiltinClassProfile);
127130
throw raise(TypeError, ErrorMessages.S_MUST_BE_S, "argv", "a tuple");
128131
}
129132

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SysModuleBuiltins.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,6 @@
214214
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
215215
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
216216
import com.oracle.graal.python.nodes.object.GetClassNode;
217-
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
218217
import com.oracle.graal.python.nodes.util.CannotCastException;
219218
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
220219
import com.oracle.graal.python.nodes.util.ExceptionStateNodes.GetCaughtExceptionNode;
@@ -1570,8 +1569,9 @@ abstract static class DisplayHookNode extends PythonBuiltinNode {
15701569

15711570
@Specialization
15721571
Object doHook(VirtualFrame frame, PythonModule sys, Object obj,
1572+
@Bind("this") Node inliningTarget,
15731573
@Cached PyObjectSetAttr setAttr,
1574-
@Cached IsBuiltinClassProfile unicodeEncodeErrorProfile,
1574+
@Cached IsBuiltinObjectProfile unicodeEncodeErrorProfile,
15751575
@Cached PyObjectLookupAttr lookupAttr,
15761576
@Cached PyObjectCallMethodObjArgs callMethodObjArgs,
15771577
@Cached PyObjectGetAttr getAttr,
@@ -1609,7 +1609,7 @@ Object doHook(VirtualFrame frame, PythonModule sys, Object obj,
16091609
fileWriteString(frame, stdOut, castToString(reprVal, castToStringNode), getAttr, callNode);
16101610
}
16111611
} catch (PException pe) {
1612-
pe.expect(UnicodeEncodeError, unicodeEncodeErrorProfile);
1612+
pe.expect(inliningTarget, UnicodeEncodeError, unicodeEncodeErrorProfile);
16131613
// repr(o) is not encodable to sys.stdout.encoding with sys.stdout.errors error
16141614
// handler (which is probably 'strict')
16151615
unicodeEncodeError = true;

0 commit comments

Comments
 (0)