Skip to content

Commit 47d9e75

Browse files
committed
Address review feedback
1 parent c98e84e commit 47d9e75

13 files changed

+145
-49
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectCallMethodObjArgs.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@
4242

4343
import com.oracle.graal.python.builtins.objects.function.PKeyword;
4444
import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
45+
import com.oracle.graal.python.nodes.call.BoundDescriptor;
4546
import com.oracle.graal.python.nodes.call.CallNode;
4647
import com.oracle.graal.python.nodes.call.special.CallBinaryMethodNode;
4748
import com.oracle.graal.python.nodes.call.special.CallQuaternaryMethodNode;
4849
import com.oracle.graal.python.nodes.call.special.CallTernaryMethodNode;
4950
import com.oracle.graal.python.nodes.call.special.CallUnaryMethodNode;
50-
import com.oracle.graal.python.nodes.call.special.MaybeBindDescriptorNode.BoundDescriptor;
5151
import com.oracle.graal.python.util.PythonUtils;
5252
import com.oracle.truffle.api.dsl.Cached;
5353
import com.oracle.truffle.api.dsl.Cached.Shared;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectGetMethod.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,15 @@
5353
import com.oracle.graal.python.nodes.attributes.LookupAttributeInMRONode;
5454
import com.oracle.graal.python.nodes.attributes.LookupCallableSlotInMRONode;
5555
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromObjectNode;
56+
import com.oracle.graal.python.nodes.call.BoundDescriptor;
57+
import com.oracle.graal.python.nodes.call.CallNode;
58+
import com.oracle.graal.python.nodes.call.ForeignMethod;
5659
import com.oracle.graal.python.nodes.call.special.CallTernaryMethodNode;
60+
import com.oracle.graal.python.nodes.call.special.CallUnaryMethodNode;
5761
import com.oracle.graal.python.nodes.call.special.MaybeBindDescriptorNode;
58-
import com.oracle.graal.python.nodes.call.special.MaybeBindDescriptorNode.BoundDescriptor;
5962
import com.oracle.graal.python.nodes.object.GetClassNode;
6063
import com.oracle.graal.python.nodes.object.IsForeignObjectNode;
6164
import com.oracle.graal.python.runtime.GilNode;
62-
import com.oracle.truffle.api.CompilerDirectives.ValueType;
6365
import com.oracle.truffle.api.dsl.Bind;
6466
import com.oracle.truffle.api.dsl.Cached;
6567
import com.oracle.truffle.api.dsl.Cached.Shared;
@@ -78,26 +80,16 @@
7880
* Equivalent of _PyObject_GetMethod. Like CPython, the node uses {@link PyObjectGetAttr} for any
7981
* object that does not have the generic {@code object.__getattribute__}. For the generic {@code
8082
* object.__getattribute__} the node inlines the default logic but without binding methods, and
81-
* falls back to looking into the object dict. Returns something that can be handled by our
82-
* CallSpecial nodes.
83+
* falls back to looking into the object dict. Returns something that can be handled by
84+
* {@link CallNode} or one of the {@code CallNAryMethodNode} nodes, like
85+
* {@link CallUnaryMethodNode}.
8386
*/
8487
@GenerateUncached
8588
@ImportStatic(SpecialMethodSlot.class)
8689
public abstract class PyObjectGetMethod extends Node {
8790

8891
public abstract Object execute(Frame frame, Object receiver, TruffleString name);
8992

90-
@ValueType
91-
public static final class ForeignMethod {
92-
public final Object receiver;
93-
public final String methodName;
94-
95-
public ForeignMethod(Object receiver, String methodName) {
96-
this.receiver = receiver;
97-
this.methodName = methodName;
98-
}
99-
}
100-
10193
protected static boolean isObjectGetAttribute(Object lazyClass) {
10294
Object getattributeSlot = null;
10395
Object getattrSlot = null;
@@ -241,7 +233,7 @@ Object getForeignMethod(VirtualFrame frame, Object receiver, TruffleString name,
241233
gil.acquire();
242234
}
243235
if (memberInvocable) {
244-
return new ForeignMethod(receiver, jName);
236+
return new BoundDescriptor(new ForeignMethod(receiver, jName));
245237
} else {
246238
return new BoundDescriptor(getAttr.execute(frame, receiver, name));
247239
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
41+
package com.oracle.graal.python.nodes.call;
42+
43+
import com.oracle.truffle.api.CompilerDirectives.ValueType;
44+
45+
/**
46+
* Wrapper for distinguishing bound descriptors from unbound methods in lookup/call nodes that allow
47+
* those.
48+
*/
49+
@ValueType
50+
public class BoundDescriptor {
51+
public final Object descriptor;
52+
53+
public BoundDescriptor(Object descriptor) {
54+
this.descriptor = descriptor;
55+
}
56+
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/CallNode.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import com.oracle.graal.python.builtins.objects.function.PKeyword;
5050
import com.oracle.graal.python.builtins.objects.method.PBuiltinMethod;
5151
import com.oracle.graal.python.builtins.objects.method.PMethod;
52-
import com.oracle.graal.python.lib.PyObjectGetMethod.ForeignMethod;
5352
import com.oracle.graal.python.nodes.ErrorMessages;
5453
import com.oracle.graal.python.nodes.PGuards;
5554
import com.oracle.graal.python.nodes.PNodeWithContext;
@@ -60,7 +59,6 @@
6059
import com.oracle.graal.python.nodes.attributes.LookupCallableSlotInMRONode;
6160
import com.oracle.graal.python.nodes.attributes.LookupInheritedSlotNode;
6261
import com.oracle.graal.python.nodes.call.special.CallVarargsMethodNode;
63-
import com.oracle.graal.python.nodes.call.special.MaybeBindDescriptorNode.BoundDescriptor;
6462
import com.oracle.graal.python.nodes.interop.PForeignToPTypeNode;
6563
import com.oracle.graal.python.nodes.object.GetClassNode;
6664
import com.oracle.graal.python.nodes.truffle.PythonTypes;
@@ -186,7 +184,7 @@ protected Object doForeignMethod(ForeignMethod callable, Object[] arguments, PKe
186184
}
187185
gil.release(true);
188186
try {
189-
return fromForeign.executeConvert(interop.invokeMember(callable.receiver, callable.methodName, PythonUtils.arrayCopyOfRange(arguments, 1, arguments.length)));
187+
return fromForeign.executeConvert(interop.invokeMember(callable.receiver, callable.methodName, arguments));
190188
} catch (ArityException | UnsupportedTypeException e) {
191189
typeError.enter();
192190
throw raise.raise(TypeError, e);
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
41+
package com.oracle.graal.python.nodes.call;
42+
43+
import com.oracle.truffle.api.CompilerDirectives.ValueType;
44+
import com.oracle.truffle.api.interop.InteropLibrary;
45+
46+
/**
47+
* Wrapper for a result of method lookup on an interop object that returned true from
48+
* {@link InteropLibrary#isMemberInvocable} for given method name. It is necessary to support
49+
* languages where method calls have different semantics than executing a result of attribute
50+
* lookup.
51+
*/
52+
@ValueType
53+
public final class ForeignMethod {
54+
public final Object receiver;
55+
public final String methodName;
56+
57+
public ForeignMethod(Object receiver, String methodName) {
58+
this.receiver = receiver;
59+
this.methodName = methodName;
60+
}
61+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2022, 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
@@ -79,7 +79,7 @@
7979
@TypeSystemReference(PythonTypes.class)
8080
@ImportStatic({PythonOptions.class, PGuards.class})
8181
@NodeField(name = "maxSizeExceeded", type = boolean.class)
82-
abstract class CallSpecialMethodNode extends PNodeWithContext {
82+
abstract class AbstractCallMethodNode extends PNodeWithContext {
8383

8484
/**
8585
* for interpreter performance: cache if we exceeded the max caller size. We never allow

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/CallBinaryMethodNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@
5050
import com.oracle.graal.python.builtins.objects.function.PKeyword;
5151
import com.oracle.graal.python.builtins.objects.method.PBuiltinMethod;
5252
import com.oracle.graal.python.nodes.builtins.FunctionNodes.GetCallTargetNode;
53+
import com.oracle.graal.python.nodes.call.BoundDescriptor;
5354
import com.oracle.graal.python.nodes.call.CallNode;
5455
import com.oracle.graal.python.nodes.call.GenericInvokeNode;
55-
import com.oracle.graal.python.nodes.call.special.MaybeBindDescriptorNode.BoundDescriptor;
5656
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
5757
import com.oracle.graal.python.nodes.function.builtins.PythonQuaternaryBuiltinNode;
5858
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/CallQuaternaryMethodNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
import com.oracle.graal.python.builtins.objects.function.PKeyword;
4545
import com.oracle.graal.python.builtins.objects.method.PBuiltinMethod;
4646
import com.oracle.graal.python.nodes.builtins.FunctionNodes.GetCallTargetNode;
47+
import com.oracle.graal.python.nodes.call.BoundDescriptor;
4748
import com.oracle.graal.python.nodes.call.CallNode;
48-
import com.oracle.graal.python.nodes.call.special.MaybeBindDescriptorNode.BoundDescriptor;
4949
import com.oracle.graal.python.nodes.function.builtins.PythonQuaternaryBuiltinNode;
5050
import com.oracle.truffle.api.RootCallTarget;
5151
import com.oracle.truffle.api.dsl.Cached;
@@ -56,7 +56,7 @@
5656
import com.oracle.truffle.api.profiles.ConditionProfile;
5757

5858
@GenerateUncached
59-
public abstract class CallQuaternaryMethodNode extends CallSpecialMethodNode {
59+
public abstract class CallQuaternaryMethodNode extends AbstractCallMethodNode {
6060
public static CallQuaternaryMethodNode create() {
6161
return CallQuaternaryMethodNodeGen.create();
6262
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/CallReversibleMethodNode.java

Lines changed: 2 additions & 2 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, 2022, 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
@@ -44,7 +44,7 @@
4444
import com.oracle.truffle.api.CompilerAsserts;
4545
import com.oracle.truffle.api.RootCallTarget;
4646

47-
abstract class CallReversibleMethodNode extends CallSpecialMethodNode {
47+
abstract class CallReversibleMethodNode extends AbstractCallMethodNode {
4848
protected boolean isForReverseBinaryOperation(RootCallTarget ct) {
4949
CompilerAsserts.neverPartOfCompilation();
5050
return PBuiltinFunction.isReverseOperationSlot(ct);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/CallTernaryMethodNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2022, 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
@@ -47,9 +47,9 @@
4747
import com.oracle.graal.python.builtins.objects.function.PKeyword;
4848
import com.oracle.graal.python.builtins.objects.method.PBuiltinMethod;
4949
import com.oracle.graal.python.nodes.builtins.FunctionNodes.GetCallTargetNode;
50+
import com.oracle.graal.python.nodes.call.BoundDescriptor;
5051
import com.oracle.graal.python.nodes.call.CallNode;
5152
import com.oracle.graal.python.nodes.call.GenericInvokeNode;
52-
import com.oracle.graal.python.nodes.call.special.MaybeBindDescriptorNode.BoundDescriptor;
5353
import com.oracle.graal.python.nodes.function.builtins.PythonQuaternaryBuiltinNode;
5454
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode;
5555
import com.oracle.truffle.api.RootCallTarget;

0 commit comments

Comments
 (0)