|
| 1 | +/* |
| 2 | + * Copyright (c) 2024, 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 | + */ |
1 | 41 | package com.oracle.graal.python.nodes.bytecode_dsl;
|
2 | 42 |
|
3 | 43 | import static com.oracle.graal.python.builtins.PythonBuiltinClassType.AttributeError;
|
|
10 | 50 | import static com.oracle.graal.python.nodes.SpecialAttributeNames.T___DOC__;
|
11 | 51 | import static com.oracle.graal.python.nodes.SpecialMethodNames.T___AENTER__;
|
12 | 52 | import static com.oracle.graal.python.nodes.SpecialMethodNames.T___AEXIT__;
|
13 |
| -import static com.oracle.graal.python.nodes.SpecialMethodNames.T___ENTER__; |
14 |
| -import static com.oracle.graal.python.nodes.SpecialMethodNames.T___EXIT__; |
15 | 53 | import static com.oracle.graal.python.runtime.exception.PythonErrorType.AssertionError;
|
16 | 54 | import static com.oracle.graal.python.util.PythonUtils.tsLiteral;
|
17 | 55 |
|
18 | 56 | import java.math.BigInteger;
|
19 | 57 | import java.util.ArrayList;
|
20 |
| -import java.util.Arrays; |
21 | 58 | import java.util.Iterator;
|
22 | 59 |
|
23 | 60 | import com.oracle.graal.python.PythonLanguage;
|
|
35 | 72 | import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageSetItem;
|
36 | 73 | import com.oracle.graal.python.builtins.objects.common.SequenceNodes;
|
37 | 74 | import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes;
|
38 |
| -import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.ListGeneralizationNode; |
39 | 75 | import com.oracle.graal.python.builtins.objects.dict.DictBuiltins;
|
40 | 76 | import com.oracle.graal.python.builtins.objects.dict.DictNodes;
|
41 | 77 | import com.oracle.graal.python.builtins.objects.dict.PDict;
|
|
50 | 86 | import com.oracle.graal.python.builtins.objects.function.Signature;
|
51 | 87 | import com.oracle.graal.python.builtins.objects.generator.CommonGeneratorBuiltins;
|
52 | 88 | import com.oracle.graal.python.builtins.objects.generator.PGenerator;
|
53 |
| -import com.oracle.graal.python.builtins.objects.iterator.IteratorNodes; |
54 | 89 | import com.oracle.graal.python.builtins.objects.iterator.PDoubleSequenceIterator;
|
55 | 90 | import com.oracle.graal.python.builtins.objects.iterator.PIntRangeIterator;
|
56 | 91 | import com.oracle.graal.python.builtins.objects.iterator.PIntegerIterator;
|
57 | 92 | import com.oracle.graal.python.builtins.objects.iterator.PIntegerSequenceIterator;
|
58 | 93 | import com.oracle.graal.python.builtins.objects.iterator.PLongSequenceIterator;
|
59 | 94 | import com.oracle.graal.python.builtins.objects.iterator.PObjectSequenceIterator;
|
60 |
| -import com.oracle.graal.python.builtins.objects.list.ListBuiltins.ListExtendNode; |
61 | 95 | import com.oracle.graal.python.builtins.objects.list.PList;
|
62 | 96 | import com.oracle.graal.python.builtins.objects.set.PFrozenSet;
|
63 | 97 | import com.oracle.graal.python.builtins.objects.set.PSet;
|
64 | 98 | import com.oracle.graal.python.builtins.objects.set.SetNodes;
|
65 | 99 | import com.oracle.graal.python.builtins.objects.str.StringUtils;
|
66 | 100 | import com.oracle.graal.python.builtins.objects.tuple.PTuple;
|
67 | 101 | import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
|
68 |
| -import com.oracle.graal.python.builtins.objects.type.TypeFlags; |
| 102 | +import com.oracle.graal.python.builtins.objects.type.TpSlots; |
| 103 | +import com.oracle.graal.python.builtins.objects.type.TpSlots.GetObjectSlotsNode; |
69 | 104 | import com.oracle.graal.python.compiler.CodeUnit;
|
70 |
| -import com.oracle.graal.python.compiler.OpCodes; |
71 | 105 | import com.oracle.graal.python.compiler.RaisePythonExceptionErrorCallback;
|
72 |
| -import com.oracle.graal.python.compiler.OpCodes.CollectionBits; |
73 | 106 | import com.oracle.graal.python.lib.GetNextNode;
|
74 | 107 | import com.oracle.graal.python.lib.PyIterCheckNode;
|
75 | 108 | import com.oracle.graal.python.lib.PyNumberAddNode;
|
|
85 | 118 | import com.oracle.graal.python.lib.PyObjectLookupAttr;
|
86 | 119 | import com.oracle.graal.python.lib.PyObjectReprAsTruffleStringNode;
|
87 | 120 | import com.oracle.graal.python.lib.PyObjectSetAttr;
|
88 |
| -import com.oracle.graal.python.lib.PyObjectSetAttrNodeGen; |
89 | 121 | import com.oracle.graal.python.lib.PyObjectSetItem;
|
90 | 122 | import com.oracle.graal.python.lib.PyObjectSizeNode;
|
91 | 123 | import com.oracle.graal.python.lib.PyObjectStrAsTruffleStringNode;
|
|
101 | 133 | import com.oracle.graal.python.nodes.argument.keywords.SameDictKeyException;
|
102 | 134 | import com.oracle.graal.python.nodes.attributes.GetAttributeNode.GetFixedAttributeNode;
|
103 | 135 | import com.oracle.graal.python.nodes.builtins.ListNodes;
|
104 |
| -import com.oracle.graal.python.nodes.bytecode.BinarySubscrSeq; |
105 |
| -import com.oracle.graal.python.nodes.bytecode.BinarySubscrSeqFactory; |
106 | 136 | import com.oracle.graal.python.nodes.bytecode.GetSendValueNode;
|
107 | 137 | import com.oracle.graal.python.nodes.bytecode.GetTPFlagsNode;
|
108 | 138 | import com.oracle.graal.python.nodes.bytecode.GetYieldFromIterNode;
|
109 | 139 | import com.oracle.graal.python.nodes.bytecode.ImportFromNode;
|
110 | 140 | import com.oracle.graal.python.nodes.bytecode.ImportNode;
|
111 | 141 | import com.oracle.graal.python.nodes.bytecode.ImportStarNode;
|
112 |
| -import com.oracle.graal.python.nodes.bytecode.PBytecodeGeneratorFunctionRootNode; |
113 |
| -import com.oracle.graal.python.nodes.bytecode.PBytecodeGeneratorRootNode; |
114 |
| -import com.oracle.graal.python.nodes.bytecode.PBytecodeRootNode; |
115 | 142 | import com.oracle.graal.python.nodes.bytecode.PrintExprNode;
|
116 | 143 | import com.oracle.graal.python.nodes.bytecode.RaiseNode;
|
117 | 144 | import com.oracle.graal.python.nodes.bytecode.SetupAnnotationsNode;
|
|
121 | 148 | import com.oracle.graal.python.nodes.call.special.CallTernaryMethodNode;
|
122 | 149 | import com.oracle.graal.python.nodes.call.special.CallUnaryMethodNode;
|
123 | 150 | import com.oracle.graal.python.nodes.call.special.LookupAndCallBinaryNode;
|
124 |
| -import com.oracle.graal.python.nodes.call.special.LookupAndCallTernaryNode; |
125 | 151 | import com.oracle.graal.python.nodes.call.special.LookupSpecialMethodSlotNode;
|
126 | 152 | import com.oracle.graal.python.nodes.exception.ExceptMatchNode;
|
127 | 153 | import com.oracle.graal.python.nodes.expression.BinaryArithmetic.BitAndNode;
|
|
152 | 178 | import com.oracle.graal.python.nodes.frame.WriteGlobalNode;
|
153 | 179 | import com.oracle.graal.python.nodes.frame.WriteNameNode;
|
154 | 180 | import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
|
155 |
| -import com.oracle.graal.python.nodes.object.GetClassNode.GetPythonObjectClassNode; |
156 | 181 | import com.oracle.graal.python.nodes.object.GetClassNode;
|
| 182 | +import com.oracle.graal.python.nodes.object.GetClassNode.GetPythonObjectClassNode; |
157 | 183 | import com.oracle.graal.python.nodes.object.IsNode;
|
158 | 184 | import com.oracle.graal.python.nodes.truffle.PythonTypes;
|
159 | 185 | import com.oracle.graal.python.nodes.util.ExceptionStateNodes;
|
160 | 186 | import com.oracle.graal.python.runtime.ExecutionContext.CalleeContext;
|
| 187 | +import com.oracle.graal.python.runtime.PythonContext; |
161 | 188 | import com.oracle.graal.python.runtime.PythonContext.ProfileEvent;
|
162 | 189 | import com.oracle.graal.python.runtime.PythonContext.PythonThreadState;
|
163 | 190 | import com.oracle.graal.python.runtime.PythonContext.TraceEvent;
|
164 |
| -import com.oracle.graal.python.runtime.PythonContext; |
165 |
| -import com.oracle.graal.python.runtime.PythonOptions; |
166 | 191 | import com.oracle.graal.python.runtime.exception.ExceptionUtils;
|
167 | 192 | import com.oracle.graal.python.runtime.exception.PException;
|
168 | 193 | import com.oracle.graal.python.runtime.exception.PythonErrorType;
|
|
179 | 204 | import com.oracle.truffle.api.Assumption;
|
180 | 205 | import com.oracle.truffle.api.CompilerAsserts;
|
181 | 206 | import com.oracle.truffle.api.CompilerDirectives;
|
182 |
| -import com.oracle.truffle.api.RootCallTarget; |
183 | 207 | import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
|
184 | 208 | import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
|
185 | 209 | import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
|
186 |
| -import com.oracle.truffle.api.Truffle; |
187 |
| -import com.oracle.truffle.api.TruffleLanguage; |
188 | 210 | import com.oracle.truffle.api.bytecode.BytecodeConfig;
|
189 | 211 | import com.oracle.truffle.api.bytecode.BytecodeLocation;
|
190 | 212 | import com.oracle.truffle.api.bytecode.BytecodeNode;
|
|
217 | 239 | import com.oracle.truffle.api.exception.AbstractTruffleException;
|
218 | 240 | import com.oracle.truffle.api.frame.Frame;
|
219 | 241 | import com.oracle.truffle.api.frame.FrameDescriptor;
|
220 |
| -import com.oracle.truffle.api.frame.MaterializedFrame; |
221 | 242 | import com.oracle.truffle.api.frame.VirtualFrame;
|
222 | 243 | import com.oracle.truffle.api.library.CachedLibrary;
|
223 | 244 | import com.oracle.truffle.api.nodes.EncapsulatingNodeReference;
|
224 | 245 | import com.oracle.truffle.api.nodes.ExplodeLoop;
|
225 | 246 | import com.oracle.truffle.api.nodes.Node;
|
226 | 247 | import com.oracle.truffle.api.nodes.UnexpectedResultException;
|
227 |
| -import com.oracle.truffle.api.nodes.Node.Child; |
228 | 248 | import com.oracle.truffle.api.object.DynamicObjectLibrary;
|
229 | 249 | import com.oracle.truffle.api.profiles.InlinedBranchProfile;
|
230 | 250 | import com.oracle.truffle.api.source.Source;
|
@@ -3698,47 +3718,50 @@ public static boolean doObject(long typeFlags, Object value,
|
3698 | 3718 | public static final class BinarySubscript {
|
3699 | 3719 | // TODO: the result is not BE'd because of the UnexpectedResultException. maybe we should
|
3700 | 3720 | // explicitly check for an int storage type?
|
3701 |
| - @Specialization(rewriteOn = UnexpectedResultException.class) |
| 3721 | + @Specialization(rewriteOn = UnexpectedResultException.class, guards = "isBuiltinList(list)") |
3702 | 3722 | public static int doIntList(PList list, int index,
|
3703 | 3723 | @Shared @Cached("createForList()") SequenceStorageNodes.GetItemNode getListItemNode) throws UnexpectedResultException {
|
3704 | 3724 | return getListItemNode.executeInt(list.getSequenceStorage(), index);
|
3705 | 3725 | }
|
3706 | 3726 |
|
3707 |
| - @Specialization(rewriteOn = UnexpectedResultException.class) |
| 3727 | + @Specialization(rewriteOn = UnexpectedResultException.class, guards = "isBuiltinList(list)") |
3708 | 3728 | public static double doDoubleList(PList list, int index,
|
3709 | 3729 | @Shared @Cached("createForList()") SequenceStorageNodes.GetItemNode getListItemNode) throws UnexpectedResultException {
|
3710 | 3730 | return getListItemNode.executeDouble(list.getSequenceStorage(), index);
|
3711 | 3731 | }
|
3712 | 3732 |
|
3713 |
| - @Specialization(replaces = {"doIntList", "doDoubleList"}) |
3714 |
| - public static Object doObjectList(PList sequence, int index, |
| 3733 | + @Specialization(replaces = {"doIntList", "doDoubleList"}, guards = "isBuiltinList(list)") |
| 3734 | + public static Object doObjectList(PList list, int index, |
3715 | 3735 | @Shared @Cached("createForList()") SequenceStorageNodes.GetItemNode getListItemNode) {
|
3716 |
| - return getListItemNode.execute(sequence.getSequenceStorage(), index); |
| 3736 | + return getListItemNode.execute(list.getSequenceStorage(), index); |
3717 | 3737 | }
|
3718 | 3738 |
|
3719 |
| - @Specialization(rewriteOn = UnexpectedResultException.class) |
| 3739 | + @Specialization(rewriteOn = UnexpectedResultException.class, guards = "isBuiltinTuple(tuple)") |
3720 | 3740 | public static int doIntTuple(PTuple tuple, int index,
|
3721 | 3741 | @Shared @Cached("createForTuple()") SequenceStorageNodes.GetItemNode getTupleItemNode) throws UnexpectedResultException {
|
3722 | 3742 | return getTupleItemNode.executeInt(tuple.getSequenceStorage(), index);
|
3723 | 3743 |
|
3724 | 3744 | }
|
3725 | 3745 |
|
3726 |
| - @Specialization(rewriteOn = UnexpectedResultException.class) |
| 3746 | + @Specialization(rewriteOn = UnexpectedResultException.class, guards = "isBuiltinTuple(tuple)") |
3727 | 3747 | public static double doDoubleTuple(PTuple tuple, int index,
|
3728 | 3748 | @Shared @Cached("createForTuple()") SequenceStorageNodes.GetItemNode getTupleItemNode) throws UnexpectedResultException {
|
3729 | 3749 | return getTupleItemNode.executeDouble(tuple.getSequenceStorage(), index);
|
3730 | 3750 | }
|
3731 | 3751 |
|
3732 |
| - @Specialization(replaces = {"doIntTuple", "doDoubleTuple"}) |
| 3752 | + @Specialization(replaces = {"doIntTuple", "doDoubleTuple"}, guards = "isBuiltinTuple(tuple)") |
3733 | 3753 | public static Object doObjectTuple(PTuple tuple, int index,
|
3734 | 3754 | @Shared @Cached("createForTuple()") SequenceStorageNodes.GetItemNode getTupleItemNode) {
|
3735 | 3755 | return getTupleItemNode.execute(tuple.getSequenceStorage(), index);
|
3736 | 3756 | }
|
3737 | 3757 |
|
3738 | 3758 | @Fallback
|
3739 | 3759 | public static Object doOther(VirtualFrame frame, Object receiver, Object key,
|
3740 |
| - @Cached(inline = false) PyObjectGetItem getItemNode) { |
3741 |
| - return getItemNode.executeCached(frame, receiver, key); |
| 3760 | + @Bind("this") Node inliningTarget, |
| 3761 | + @Cached GetObjectSlotsNode getSlotsNode, |
| 3762 | + @Cached PyObjectGetItem.PyObjectGetItemGeneric getItemNode) { |
| 3763 | + TpSlots slots = getSlotsNode.execute(inliningTarget, receiver); |
| 3764 | + return getItemNode.execute(frame, inliningTarget, receiver, slots, key); |
3742 | 3765 | }
|
3743 | 3766 | }
|
3744 | 3767 |
|
|
0 commit comments