Skip to content

Commit 19db61f

Browse files
committed
Remove uneccessary user arguments bounds checks
1 parent 0bf21ff commit 19db61f

File tree

3 files changed

+6
-44
lines changed

3 files changed

+6
-44
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/PArguments.java

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,9 @@
3030
import com.oracle.graal.python.builtins.objects.object.PythonObject;
3131
import com.oracle.graal.python.runtime.PythonOptions;
3232
import com.oracle.graal.python.runtime.exception.PException;
33-
import com.oracle.graal.python.util.PythonUtils;
3433
import com.oracle.truffle.api.exception.AbstractTruffleException;
3534
import com.oracle.truffle.api.frame.Frame;
3635
import com.oracle.truffle.api.frame.MaterializedFrame;
37-
import com.oracle.truffle.api.frame.VirtualFrame;
3836

3937
//@formatter:off
4038
/**
@@ -218,26 +216,13 @@ public static void setArgument(Object[] arguments, int index, Object value) {
218216
}
219217

220218
public static Object getArgument(Object[] arguments, int index) {
221-
int argIdx = USER_ARGUMENTS_OFFSET + index;
222-
if (argIdx < arguments.length) {
223-
return arguments[argIdx];
224-
} else {
225-
return null;
226-
}
219+
return arguments[USER_ARGUMENTS_OFFSET + index];
227220
}
228221

229222
public static Object getArgument(Frame frame, int index) {
230223
return getArgument(frame.getArguments(), index);
231224
}
232225

233-
public static int getUserArgumentLength(VirtualFrame frame) {
234-
return frame.getArguments().length - USER_ARGUMENTS_OFFSET;
235-
}
236-
237-
public static int getUserArgumentLength(Object[] arguments) {
238-
return arguments.length - USER_ARGUMENTS_OFFSET;
239-
}
240-
241226
public static MaterializedFrame getGeneratorFrame(Object[] arguments) {
242227
assert !PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER;
243228
return (MaterializedFrame) arguments[INDEX_GENERATOR_FRAME];
@@ -288,9 +273,6 @@ public static void synchronizeArgs(Frame frameToMaterialize, PFrame escapedFrame
288273
setGlobals(copiedArgs, getGlobals(arguments));
289274
setClosure(copiedArgs, getClosure(arguments));
290275

291-
// copy all user arguments
292-
PythonUtils.arraycopy(arguments, USER_ARGUMENTS_OFFSET, copiedArgs, USER_ARGUMENTS_OFFSET, getUserArgumentLength(arguments));
293-
294276
escapedFrame.setArguments(copiedArgs);
295277
}
296278
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/argument/ReadIndexedArgumentNode.java

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2021, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2025, Oracle and/or its affiliates.
33
* Copyright (c) 2013, Regents of the University of California
44
*
55
* All rights reserved.
@@ -25,11 +25,9 @@
2525
*/
2626
package com.oracle.graal.python.nodes.argument;
2727

28-
import com.oracle.graal.python.builtins.objects.PNone;
2928
import com.oracle.graal.python.builtins.objects.function.PArguments;
3029
import com.oracle.truffle.api.dsl.Specialization;
3130
import com.oracle.truffle.api.frame.VirtualFrame;
32-
import com.oracle.truffle.api.nodes.InvalidAssumptionException;
3331
import com.oracle.truffle.api.profiles.ValueProfile;
3432

3533
public abstract class ReadIndexedArgumentNode extends ReadArgumentNode {
@@ -44,22 +42,9 @@ public static ReadIndexedArgumentNode create(int idx) {
4442
return ReadIndexedArgumentNodeGen.create(idx);
4543
}
4644

47-
@Specialization(rewriteOn = InvalidAssumptionException.class)
48-
Object readArg(VirtualFrame frame) throws InvalidAssumptionException {
49-
Object argumentAt = PArguments.getArgument(frame, index);
50-
if (argumentAt == null) {
51-
throw new InvalidAssumptionException();
52-
}
53-
return profile.profile(argumentAt);
54-
}
55-
56-
@Specialization(replaces = "readArg")
57-
Object readArgOffBounds(VirtualFrame frame) {
58-
Object argumentAt = PArguments.getArgument(frame, index);
59-
if (argumentAt == null) {
60-
return PNone.NO_VALUE;
61-
}
62-
return profile.profile(argumentAt);
45+
@Specialization
46+
Object readArg(VirtualFrame frame) {
47+
return profile.profile(PArguments.getArgument(frame, index));
6348
}
6449

6550
public int getIndex() {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/builtins/WrapperDescrCall.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,7 @@ public WrapperDescrCall(BuiltinCallNode func, String name, PythonBuiltinClassTyp
7171

7272
@Override
7373
public Object execute(VirtualFrame frame) {
74-
Object[] args = frame.getArguments();
75-
if (PArguments.getUserArgumentLength(args) <= 0) {
76-
CompilerDirectives.transferToInterpreterAndInvalidate();
77-
throw PRaiseNode.raiseStatic(this, PythonBuiltinClassType.TypeError, ErrorMessages.DESCRIPTOR_NEED_OBJ, name, "_");
78-
}
79-
Object self = PArguments.getArgument(args, 0);
74+
Object self = PArguments.getArgument(frame, 0);
8075
Object selfClass = getClassNode.executeCached(self);
8176
if (selfClass != type && !isSubtypeNode.execute(selfClass, type)) {
8277
CompilerDirectives.transferToInterpreterAndInvalidate();

0 commit comments

Comments
 (0)