|
36 | 36 | import com.oracle.graal.python.builtins.objects.common.SequenceNodes;
|
37 | 37 | import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes;
|
38 | 38 | import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.ListGeneralizationNode;
|
| 39 | +import com.oracle.graal.python.builtins.objects.dict.DictBuiltins; |
39 | 40 | import com.oracle.graal.python.builtins.objects.dict.DictNodes;
|
40 | 41 | import com.oracle.graal.python.builtins.objects.dict.PDict;
|
41 | 42 | import com.oracle.graal.python.builtins.objects.exception.ChainExceptionsNode;
|
|
100 | 101 | import com.oracle.graal.python.nodes.argument.keywords.SameDictKeyException;
|
101 | 102 | import com.oracle.graal.python.nodes.attributes.GetAttributeNode.GetFixedAttributeNode;
|
102 | 103 | 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; |
103 | 106 | import com.oracle.graal.python.nodes.bytecode.GetSendValueNode;
|
104 | 107 | import com.oracle.graal.python.nodes.bytecode.GetTPFlagsNode;
|
105 | 108 | import com.oracle.graal.python.nodes.bytecode.GetYieldFromIterNode;
|
@@ -1119,16 +1122,6 @@ public static Object perform(VirtualFrame frame, Object receiver,
|
1119 | 1122 | }
|
1120 | 1123 | }
|
1121 | 1124 |
|
1122 |
| - @Operation |
1123 |
| - public static final class GetItem { |
1124 |
| - @Specialization |
1125 |
| - public static Object perform(VirtualFrame frame, Object key, Object value, |
1126 |
| - @Bind Node inliningTarget, |
1127 |
| - @Cached PyObjectGetItem getItemNode) { |
1128 |
| - return getItemNode.execute(frame, inliningTarget, key, value); |
1129 |
| - } |
1130 |
| - } |
1131 |
| - |
1132 | 1125 | @Operation
|
1133 | 1126 | public static final class FormatStr {
|
1134 | 1127 | @Specialization
|
@@ -2232,45 +2225,30 @@ public static PKeyword[] perform(Object sourceCollection,
|
2232 | 2225 | @ConstantOperand(type = int.class)
|
2233 | 2226 | public static final class MakeDict {
|
2234 | 2227 | @Specialization
|
| 2228 | + @ExplodeLoop |
2235 | 2229 | public static PDict perform(VirtualFrame frame,
|
2236 | 2230 | int entries,
|
2237 | 2231 | @Variadic Object[] keysAndValues,
|
2238 | 2232 | @Bind PBytecodeDSLRootNode rootNode,
|
| 2233 | + @Cached DictBuiltins.SetItemNode setItemNode, |
2239 | 2234 | @Cached DictNodes.UpdateNode updateNode) {
|
2240 |
| - PDict dict = rootNode.factory.createDict(); |
2241 |
| - if (entries <= EXPLODE_LOOP_THRESHOLD) { |
2242 |
| - doExploded(frame, keysAndValues, entries, updateNode, dict); |
2243 |
| - } else { |
2244 |
| - doRegular(frame, keysAndValues, entries, updateNode, dict); |
| 2235 | + if (keysAndValues.length != entries * 2) { |
| 2236 | + throw CompilerDirectives.shouldNotReachHere(); |
2245 | 2237 | }
|
2246 |
| - return dict; |
2247 |
| - } |
2248 |
| - |
2249 |
| - @ExplodeLoop |
2250 |
| - private static void doExploded(VirtualFrame frame, Object[] keysAndValues, int entries, DictNodes.UpdateNode updateNode, PDict dict) { |
2251 |
| - CompilerAsserts.partialEvaluationConstant(entries); |
| 2238 | + PDict dict = rootNode.factory.createDict(); |
2252 | 2239 | for (int i = 0; i < entries; i++) {
|
2253 | 2240 | Object key = keysAndValues[i * 2];
|
2254 | 2241 | Object value = keysAndValues[i * 2 + 1];
|
| 2242 | + // Each entry represents either a k: v pair or a **splats. splats have no key. |
2255 | 2243 | if (key == PNone.NO_VALUE) {
|
2256 | 2244 | updateNode.execute(frame, dict, value);
|
2257 | 2245 | } else {
|
2258 |
| - dict.setItem(key, value); |
| 2246 | + setItemNode.execute(frame, dict, key, value); |
2259 | 2247 | }
|
2260 | 2248 | }
|
| 2249 | + return dict; |
2261 | 2250 | }
|
2262 | 2251 |
|
2263 |
| - private static void doRegular(VirtualFrame frame, Object[] keysAndValues, int entries, DictNodes.UpdateNode updateNode, PDict dict) { |
2264 |
| - for (int i = 0; i < entries; i++) { |
2265 |
| - Object key = keysAndValues[i * 2]; |
2266 |
| - Object value = keysAndValues[i * 2 + 1]; |
2267 |
| - if (key == PNone.NO_VALUE) { |
2268 |
| - updateNode.execute(frame, dict, value); |
2269 |
| - } else { |
2270 |
| - dict.setItem(key, value); |
2271 |
| - } |
2272 |
| - } |
2273 |
| - } |
2274 | 2252 | }
|
2275 | 2253 |
|
2276 | 2254 | @Operation
|
@@ -3212,22 +3190,25 @@ private static Object[] doRegular(Object[] values, int length) {
|
3212 | 3190 | }
|
3213 | 3191 |
|
3214 | 3192 | @Operation
|
| 3193 | + @ConstantOperand(type = LocalAccessor.class) |
3215 | 3194 | public static final class KwargsMerge {
|
3216 | 3195 | @Specialization
|
3217 | 3196 | public static PDict doMerge(VirtualFrame frame,
|
| 3197 | + LocalAccessor callee, |
3218 | 3198 | PDict dict,
|
3219 | 3199 | Object toMerge,
|
3220 |
| - Object function, |
3221 | 3200 | @Bind PBytecodeDSLRootNode rootNode,
|
| 3201 | + @Bind BytecodeNode bytecodeNode, |
3222 | 3202 | @Cached ConcatDictToStorageNode concatNode,
|
3223 | 3203 | @Cached PRaiseNode raise) {
|
3224 | 3204 | try {
|
3225 | 3205 | HashingStorage resultStorage = concatNode.execute(frame, dict.getDictStorage(), toMerge);
|
3226 | 3206 | dict.setDictStorage(resultStorage);
|
3227 | 3207 | } catch (SameDictKeyException e) {
|
3228 |
| - throw raise.raise(PythonBuiltinClassType.TypeError, ErrorMessages.S_GOT_MULTIPLE_VALUES_FOR_KEYWORD_ARG, PyObjectFunctionStr.execute(function), e.getKey()); |
| 3208 | + throw raise.raise(PythonBuiltinClassType.TypeError, ErrorMessages.S_GOT_MULTIPLE_VALUES_FOR_KEYWORD_ARG, PyObjectFunctionStr.execute(callee.getObject(bytecodeNode, frame)), |
| 3209 | + e.getKey()); |
3229 | 3210 | } catch (NonMappingException e) {
|
3230 |
| - throw raise.raise(PythonBuiltinClassType.TypeError, ErrorMessages.ARG_AFTER_MUST_BE_MAPPING, PyObjectFunctionStr.execute(function), toMerge); |
| 3211 | + throw raise.raise(PythonBuiltinClassType.TypeError, ErrorMessages.ARG_AFTER_MUST_BE_MAPPING, PyObjectFunctionStr.execute(callee.getObject(bytecodeNode, frame)), toMerge); |
3231 | 3212 | }
|
3232 | 3213 | return dict;
|
3233 | 3214 | }
|
@@ -3814,50 +3795,47 @@ public static boolean doObject(Object value,
|
3814 | 3795 | @Operation
|
3815 | 3796 | @ImportStatic(PGuards.class)
|
3816 | 3797 | public static final class BinarySubscript {
|
3817 |
| - // TODO: support boxing elimination |
3818 |
| -// @Specialization(guards = "cannotBeOverriddenForImmutableType(sequence)") |
3819 |
| -// public static int doIntSequence(PList sequence, int index, |
3820 |
| -// @Shared("list") @Cached("createForList()") SequenceStorageNodes.GetItemNode getItemNode) throws |
3821 |
| -// UnexpectedResultException { |
3822 |
| -// return getItemNode.executeInt(sequence.getSequenceStorage(), index); |
3823 |
| -// } |
3824 |
| -// |
3825 |
| -// @Specialization(guards = "cannotBeOverriddenForImmutableType(sequence)") |
3826 |
| -// public static int doIntTuple(PTuple sequence, int index, |
3827 |
| -// @Shared("tuple") @Cached("createForTuple()") SequenceStorageNodes.GetItemNode getItemNode) throws |
3828 |
| -// UnexpectedResultException { |
3829 |
| -// return getItemNode.executeInt(sequence.getSequenceStorage(), index); |
3830 |
| -// } |
3831 |
| -// |
3832 |
| -// @Specialization(guards = "cannotBeOverriddenForImmutableType(sequence)") |
3833 |
| -// public static double doDoubleSequence(PList sequence, int index, |
3834 |
| -// @Shared("list") @Cached("createForList()") SequenceStorageNodes.GetItemNode getItemNode) throws |
3835 |
| -// UnexpectedResultException { |
3836 |
| -// return getItemNode.executeDouble(sequence.getSequenceStorage(), index); |
3837 |
| -// } |
3838 |
| -// |
3839 |
| -// @Specialization(guards = "cannotBeOverriddenForImmutableType(sequence)") |
3840 |
| -// public static double doDoubleTuple(PTuple sequence, int index, |
3841 |
| -// @Shared("tuple") @Cached("createForTuple()") SequenceStorageNodes.GetItemNode getItemNode) throws |
3842 |
| -// UnexpectedResultException { |
3843 |
| -// return getItemNode.executeDouble(sequence.getSequenceStorage(), index); |
3844 |
| -// } |
3845 |
| -// TODO: add @Shared to GetItemNodes |
3846 |
| - |
3847 |
| - @Specialization(guards = "isBuiltinList(sequence)") |
3848 |
| - public static Object doObjectSequence(PList sequence, int index, |
3849 |
| - @Cached("createForList()") SequenceStorageNodes.GetItemNode getItemNode) { |
3850 |
| - return getItemNode.execute(sequence.getSequenceStorage(), index); |
3851 |
| - } |
3852 |
| - |
3853 |
| - @Specialization(guards = "isBuiltinTuple(sequence)") |
3854 |
| - public static Object doObjectTuple(PTuple sequence, int index, |
3855 |
| - @Cached("createForTuple()") SequenceStorageNodes.GetItemNode getItemNode) { |
3856 |
| - return getItemNode.execute(sequence.getSequenceStorage(), index); |
3857 |
| - } |
3858 |
| - |
3859 |
| - @Specialization |
3860 |
| - public static Object doObjectKey(VirtualFrame frame, Object receiver, Object key, |
| 3798 | + // TODO: the result is not BE'd because of the UnexpectedResultException. maybe we should |
| 3799 | + // explicitly check for an int storage type? |
| 3800 | + @Specialization(rewriteOn = UnexpectedResultException.class) |
| 3801 | + public static int doIntList(PList list, int index, |
| 3802 | + @Shared @Cached("createForList()") SequenceStorageNodes.GetItemNode getListItemNode) throws UnexpectedResultException { |
| 3803 | + return getListItemNode.executeInt(list.getSequenceStorage(), index); |
| 3804 | + } |
| 3805 | + |
| 3806 | + @Specialization(rewriteOn = UnexpectedResultException.class) |
| 3807 | + public static double doDoubleList(PList list, int index, |
| 3808 | + @Shared @Cached("createForList()") SequenceStorageNodes.GetItemNode getListItemNode) throws UnexpectedResultException { |
| 3809 | + return getListItemNode.executeDouble(list.getSequenceStorage(), index); |
| 3810 | + } |
| 3811 | + |
| 3812 | + @Specialization(replaces = {"doIntList", "doDoubleList"}) |
| 3813 | + public static Object doObjectList(PList sequence, int index, |
| 3814 | + @Shared @Cached("createForList()") SequenceStorageNodes.GetItemNode getListItemNode) { |
| 3815 | + return getListItemNode.execute(sequence.getSequenceStorage(), index); |
| 3816 | + } |
| 3817 | + |
| 3818 | + @Specialization(rewriteOn = UnexpectedResultException.class) |
| 3819 | + public static int doIntTuple(PTuple tuple, int index, |
| 3820 | + @Shared @Cached("createForTuple()") SequenceStorageNodes.GetItemNode getTupleItemNode) throws UnexpectedResultException { |
| 3821 | + return getTupleItemNode.executeInt(tuple.getSequenceStorage(), index); |
| 3822 | + |
| 3823 | + } |
| 3824 | + |
| 3825 | + @Specialization(rewriteOn = UnexpectedResultException.class) |
| 3826 | + public static double doDoubleTuple(PTuple tuple, int index, |
| 3827 | + @Shared @Cached("createForTuple()") SequenceStorageNodes.GetItemNode getTupleItemNode) throws UnexpectedResultException { |
| 3828 | + return getTupleItemNode.executeDouble(tuple.getSequenceStorage(), index); |
| 3829 | + } |
| 3830 | + |
| 3831 | + @Specialization(replaces = {"doIntTuple", "doDoubleTuple"}) |
| 3832 | + public static Object doObjectTuple(PTuple tuple, int index, |
| 3833 | + @Shared @Cached("createForTuple()") SequenceStorageNodes.GetItemNode getTupleItemNode) { |
| 3834 | + return getTupleItemNode.execute(tuple.getSequenceStorage(), index); |
| 3835 | + } |
| 3836 | + |
| 3837 | + @Fallback |
| 3838 | + public static Object doOther(VirtualFrame frame, Object receiver, Object key, |
3861 | 3839 | @Cached(inline = false) PyObjectGetItem getItemNode) {
|
3862 | 3840 | return getItemNode.executeCached(frame, receiver, key);
|
3863 | 3841 | }
|
|
0 commit comments