Skip to content

Commit 25b4bf7

Browse files
committed
Make PRaiseNode only accept PythonBuiltinClassType
1 parent 3d714cb commit 25b4bf7

File tree

2 files changed

+5
-43
lines changed

2 files changed

+5
-43
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/PythonAbstractObject.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ public Object asPIntWithState(ThreadState state,
10151015
return result;
10161016
}
10171017

1018-
private static int longToInt(long longResult, BranchProfile overflow, ConditionProfile ignoreOverflow, Object type, PRaiseNode raise, Object result) throws PException {
1018+
private static int longToInt(long longResult, BranchProfile overflow, ConditionProfile ignoreOverflow, PythonBuiltinClassType type, PRaiseNode raise, Object result) throws PException {
10191019
try {
10201020
return PInt.intValueExact(longResult);
10211021
} catch (OverflowException e) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/PRaiseNode.java

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@
4444
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
4545
import com.oracle.graal.python.builtins.objects.PNone;
4646
import com.oracle.graal.python.builtins.objects.exception.PBaseException;
47-
import com.oracle.graal.python.builtins.objects.type.PythonBuiltinClass;
48-
import com.oracle.graal.python.builtins.objects.type.PythonManagedClass;
4947
import com.oracle.graal.python.runtime.PythonOptions;
5048
import com.oracle.graal.python.runtime.exception.PException;
5149
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
@@ -65,7 +63,7 @@
6563
@GenerateUncached
6664
public abstract class PRaiseNode extends Node {
6765

68-
public abstract PException execute(Node raisingNode, Object type, Object cause, Object format, Object[] arguments);
66+
public abstract PException execute(Node raisingNode, PythonBuiltinClassType type, Object cause, Object format, Object[] arguments);
6967

7068
public final PException raise(PythonBuiltinClassType type) {
7169
throw execute(this, type, PNone.NO_VALUE, PNone.NO_VALUE, PythonUtils.EMPTY_OBJECT_ARRAY);
@@ -91,11 +89,11 @@ public final PException raise(PythonBuiltinClassType type, PBaseException cause,
9189
throw execute(this, type, cause, format, arguments);
9290
}
9391

94-
public static PException raiseUncached(Node raisingNode, Object exceptionType) {
92+
public static PException raiseUncached(Node raisingNode, PythonBuiltinClassType exceptionType) {
9593
throw PRaiseNodeGen.getUncached().execute(raisingNode, exceptionType, PNone.NO_VALUE, PNone.NO_VALUE, PythonUtils.EMPTY_OBJECT_ARRAY);
9694
}
9795

98-
public static PException raiseUncached(Node raisingNode, Object exceptionType, Object message) {
96+
public static PException raiseUncached(Node raisingNode, PythonBuiltinClassType exceptionType, Object message) {
9997
throw PRaiseNodeGen.getUncached().execute(raisingNode, exceptionType, PNone.NO_VALUE, message, PythonUtils.EMPTY_OBJECT_ARRAY);
10098
}
10199

@@ -119,7 +117,7 @@ public static PException raiseUncached(Node raisingNode, PythonBuiltinClassType
119117
* Raise an error saying that the {@code result} cannot fit into an index-sized integer. Use the
120118
* specified {@code type} as exception class.
121119
*/
122-
public final PException raiseNumberTooLarge(Object type, Object result) {
120+
public final PException raiseNumberTooLarge(PythonBuiltinClassType type, Object result) {
123121
return execute(this, type, PNone.NO_VALUE, ErrorMessages.CANNOT_FIT_P_INTO_INDEXSIZED_INT, new Object[]{result});
124122
}
125123

@@ -170,42 +168,6 @@ protected static Assumption singleContextAssumption() {
170168
return PythonLanguage.getCurrent().singleContextAssumption;
171169
}
172170

173-
@Specialization(guards = {"isNoValue(cause)", "isNoValue(format)", "arguments.length == 0", "exceptionType == cachedType"}, limit = "3", assumptions = "singleContextAssumption()")
174-
static PException doPythonBuiltinClassCached(Node raisingNode, @SuppressWarnings("unused") PythonBuiltinClass exceptionType, @SuppressWarnings("unused") PNone cause,
175-
@SuppressWarnings("unused") PNone format,
176-
@SuppressWarnings("unused") Object[] arguments,
177-
@Cached("exceptionType") PythonBuiltinClass cachedType,
178-
@Cached PythonObjectFactory factory,
179-
@CachedLanguage PythonLanguage language) {
180-
throw raiseExceptionObject(raisingNode, factory.createBaseException(cachedType), language);
181-
}
182-
183-
@Specialization(guards = {"isNoValue(cause)", "isNoValue(format)", "arguments.length == 0", "exceptionType.getType() == cachedType"}, limit = "3")
184-
static PException doPythonBuiltinClassCachedMulti(Node raisingNode, @SuppressWarnings("unused") PythonBuiltinClass exceptionType, @SuppressWarnings("unused") PNone cause,
185-
@SuppressWarnings("unused") PNone format,
186-
@SuppressWarnings("unused") Object[] arguments,
187-
@Cached("exceptionType.getType()") PythonBuiltinClassType cachedType,
188-
@Cached PythonObjectFactory factory,
189-
@CachedLanguage PythonLanguage language) {
190-
throw raiseExceptionObject(raisingNode, factory.createBaseException(cachedType), language);
191-
}
192-
193-
@Specialization(guards = {"isNoValue(cause)", "isNoValue(format)", "arguments.length == 0"}, replaces = {"doPythonBuiltinClassCached", "doPythonBuiltinClassCachedMulti"})
194-
static PException doPythonBuiltinClass(Node raisingNode, PythonBuiltinClass exceptionType, @SuppressWarnings("unused") PNone cause, @SuppressWarnings("unused") PNone format,
195-
@SuppressWarnings("unused") Object[] arguments,
196-
@Shared("factory") @Cached PythonObjectFactory factory,
197-
@Shared("language") @CachedLanguage PythonLanguage language) {
198-
throw raiseExceptionObject(raisingNode, factory.createBaseException(exceptionType), language);
199-
}
200-
201-
@Specialization(guards = {"isNoValue(cause)", "isNoValue(format)", "arguments.length == 0"})
202-
static PException doPythonManagedClass(Node raisingNode, PythonManagedClass exceptionType, @SuppressWarnings("unused") PNone cause, @SuppressWarnings("unused") PNone format,
203-
@SuppressWarnings("unused") Object[] arguments,
204-
@Shared("factory") @Cached PythonObjectFactory factory,
205-
@Shared("language") @CachedLanguage PythonLanguage language) {
206-
throw raiseExceptionObject(raisingNode, factory.createBaseException(exceptionType), language);
207-
}
208-
209171
@Specialization(guards = {"isNoValue(cause)", "isNoValue(format)", "arguments.length > 0"})
210172
static PException doBuiltinType(Node raisingNode, PythonBuiltinClassType type, @SuppressWarnings("unused") PNone cause, @SuppressWarnings("unused") PNone format, Object[] arguments,
211173
@Shared("factory") @Cached PythonObjectFactory factory,

0 commit comments

Comments
 (0)