Skip to content

Commit 31c4643

Browse files
committed
Bytecode DSL: fix bug in BinarySubscript, initialize empty lists to empty storage
1 parent a9fdac0 commit 31c4643

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/PBytecodeDSLRootNode.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@
220220
import com.oracle.graal.python.runtime.sequence.PSequenceWithStorage;
221221
import com.oracle.graal.python.runtime.sequence.storage.BoolSequenceStorage;
222222
import com.oracle.graal.python.runtime.sequence.storage.DoubleSequenceStorage;
223+
import com.oracle.graal.python.runtime.sequence.storage.EmptySequenceStorage;
223224
import com.oracle.graal.python.runtime.sequence.storage.IntSequenceStorage;
224225
import com.oracle.graal.python.runtime.sequence.storage.LongSequenceStorage;
225226
import com.oracle.graal.python.runtime.sequence.storage.ObjectSequenceStorage;
@@ -1636,7 +1637,16 @@ public static Object perform(VirtualFrame frame,
16361637

16371638
@Operation(storeBytecodeIndex = false)
16381639
public static final class MakeList {
1639-
@Specialization
1640+
@Specialization(guards = "elements.length == 0")
1641+
public static PList doEmpty(@Variadic Object[] elements,
1642+
@Bind PBytecodeDSLRootNode rootNode) {
1643+
// Common pattern is to create an empty list and then add items.
1644+
// We need to start from empty storage, so that we can specialize to, say, int storage
1645+
// if only ints are appended to this list
1646+
return PFactory.createList(rootNode.getLanguage(), EmptySequenceStorage.INSTANCE);
1647+
}
1648+
1649+
@Specialization(guards = "elements.length > 0")
16401650
public static PList perform(@Variadic Object[] elements,
16411651
@Bind PBytecodeDSLRootNode rootNode) {
16421652
return PFactory.createList(rootNode.getLanguage(), elements);
@@ -3210,7 +3220,7 @@ public static boolean doObject(long typeFlags, Object value,
32103220
@ImportStatic(PGuards.class)
32113221
public static final class BinarySubscript {
32123222
static boolean isBuiltinListOrTuple(PSequenceWithStorage s) {
3213-
return PGuards.isBuiltinTuple(s) && PGuards.isBuiltinList(s);
3223+
return PGuards.isBuiltinTuple(s) || PGuards.isBuiltinList(s);
32143224
}
32153225

32163226
public static boolean isIntBuiltinListOrTuple(PSequenceWithStorage s) {

0 commit comments

Comments
 (0)