Skip to content

Commit afd0408

Browse files
committed
Remove obsolete method 'PList.__mul__'.
1 parent 2279839 commit afd0408

File tree

2 files changed

+34
-96
lines changed

2 files changed

+34
-96
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/list/ListBuiltins.java

Lines changed: 34 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -415,25 +415,38 @@ public PNone extendSequence(PList list, Object source,
415415
public PNone extend(PList list, Object source,
416416
@Cached("create()") GetIteratorNode getIterator,
417417
@Cached("create()") GetNextNode next,
418-
@Cached("createBinaryProfile()") ConditionProfile errorProfile) {
418+
@Cached("createBinaryProfile()") ConditionProfile errorProfile,
419+
@Cached("createAppend()") SequenceStorageNodes.AppendNode appendNode) {
419420
Object workSource = list != source ? source : factory().createList(((PList) source).getSequenceStorage().copy());
421+
SequenceStorage s = list.getSequenceStorage();
420422
Object iterator = getIterator.executeWith(workSource);
421423
while (true) {
422424
Object value;
423425
try {
424426
value = next.execute(iterator);
425427
} catch (PException e) {
426428
e.expectStopIteration(getCore(), errorProfile);
429+
updateSequenceStorage(list, s);
427430
return PNone.NONE;
428431
}
429-
list.append(value);
432+
s = appendNode.execute(s, value);
433+
}
434+
}
435+
436+
private static void updateSequenceStorage(PList list, SequenceStorage s) {
437+
if (list.getSequenceStorage() != s) {
438+
list.setSequenceStorage(s);
430439
}
431440
}
432441

433442
protected boolean isPSequenceWithStorage(Object source) {
434443
return (source instanceof PSequence && !(source instanceof PTuple || source instanceof PRange));
435444
}
436445

446+
protected static SequenceStorageNodes.AppendNode createAppend() {
447+
return SequenceStorageNodes.AppendNode.create(() -> ListGeneralizationNode.create());
448+
}
449+
437450
}
438451

439452
// list.insert(i, x)
@@ -1082,76 +1095,18 @@ protected boolean isNotSameStorage(PList left, PList right) {
10821095
@Builtin(name = __MUL__, fixedNumOfPositionalArgs = 2)
10831096
@GenerateNodeFactory
10841097
abstract static class MulNode extends PythonBinaryBuiltinNode {
1085-
public static String CANNOT_FIT_MESSAGE = "cannot fit 'int' into an index-sized integer";
10861098

10871099
@Specialization
1088-
PList doPListInt(PList left, boolean right,
1089-
@Cached("createClassProfile()") ValueProfile profile) {
1090-
return doPListInt(left, PInt.intValue(right), profile);
1091-
}
1092-
1093-
@Specialization
1094-
PList doPListInt(PList left, int right,
1095-
@Cached("createClassProfile()") ValueProfile profile) {
1100+
PList doPListInt(PList left, Object right,
1101+
@Cached("create()") SequenceStorageNodes.RepeatNode repeatNode) {
10961102
try {
1097-
return right > 0 ? left.__mul__(profile, right) : factory().createList();
1103+
SequenceStorage repeated = repeatNode.execute(left.getSequenceStorage(), right);
1104+
return factory().createList(repeated);
10981105
} catch (ArithmeticException | OutOfMemoryError e) {
10991106
throw raise(MemoryError);
11001107
}
11011108
}
11021109

1103-
@Specialization(guards = "right <= 0")
1104-
PList doPListLongNegative(@SuppressWarnings("unused") PList left, @SuppressWarnings("unused") long right) {
1105-
return factory().createList();
1106-
}
1107-
1108-
@Specialization(guards = "right > 0", rewriteOn = ArithmeticException.class)
1109-
PList doPListLong(PList left, long right,
1110-
@Cached("createClassProfile()") ValueProfile profile) {
1111-
return doPListInt(left, PInt.intValueExact(right), profile);
1112-
}
1113-
1114-
@Specialization(replaces = "doPListLong")
1115-
PList doPListLongOvf(PList left, long right,
1116-
@Cached("create()") BranchProfile notPositiveProfile,
1117-
@Cached("createClassProfile()") ValueProfile profile) {
1118-
if (right <= 0) {
1119-
notPositiveProfile.enter();
1120-
return factory().createList();
1121-
}
1122-
try {
1123-
return doPListInt(left, PInt.intValueExact(right), profile);
1124-
} catch (ArithmeticException e) {
1125-
throw raise(OverflowError, CANNOT_FIT_MESSAGE);
1126-
}
1127-
}
1128-
1129-
@Specialization(guards = "right.isZeroOrNegative()", rewriteOn = ArithmeticException.class)
1130-
PList doPListBigIntNegative(@SuppressWarnings("unused") PList left, @SuppressWarnings("unused") PInt right) {
1131-
return factory().createList();
1132-
}
1133-
1134-
@Specialization(guards = "!right.isZeroOrNegative()", rewriteOn = ArithmeticException.class)
1135-
PList doPListBigInt(PList left, PInt right,
1136-
@Cached("createClassProfile()") ValueProfile profile) {
1137-
return doPListInt(left, right.intValueExact(), profile);
1138-
}
1139-
1140-
@Specialization(replaces = "doPListBigInt")
1141-
PList doPListBigIntOvf(PList left, PInt right,
1142-
@Cached("create()") BranchProfile notPositiveProfile,
1143-
@Cached("createClassProfile()") ValueProfile profile) {
1144-
if (right.isZeroOrNegative()) {
1145-
notPositiveProfile.enter();
1146-
return factory().createList();
1147-
}
1148-
try {
1149-
return doPListInt(left, right.intValueExact(), profile);
1150-
} catch (ArithmeticException | OutOfMemoryError e) {
1151-
throw raise(OverflowError, CANNOT_FIT_MESSAGE);
1152-
}
1153-
}
1154-
11551110
@SuppressWarnings("unused")
11561111
@Fallback
11571112
PNotImplemented doGeneric(Object left, Object right) {
@@ -1163,6 +1118,7 @@ PNotImplemented doGeneric(Object left, Object right) {
11631118
@GenerateNodeFactory
11641119
abstract static class IMulNode extends PythonBuiltinNode {
11651120
protected static final String ERROR_MSG = "can't multiply sequence by non-int of type '%p'";
1121+
public static String CANNOT_FIT_MESSAGE = "cannot fit 'int' into an index-sized integer";
11661122

11671123
public abstract PList execute(PList list, Object value);
11681124

@@ -1182,7 +1138,7 @@ PList doEmptyLong(PList list, long right) {
11821138
PInt.intValueExact(right);
11831139
return list;
11841140
} catch (ArithmeticException e) {
1185-
throw raise(OverflowError, MulNode.CANNOT_FIT_MESSAGE);
1141+
throw raise(OverflowError, CANNOT_FIT_MESSAGE);
11861142
}
11871143
}
11881144

@@ -1192,7 +1148,7 @@ PList doEmptyPInt(PList list, PInt right) {
11921148
right.intValueExact();
11931149
return list;
11941150
} catch (ArithmeticException e) {
1195-
throw raise(OverflowError, MulNode.CANNOT_FIT_MESSAGE);
1151+
throw raise(OverflowError, IMulNode.CANNOT_FIT_MESSAGE);
11961152
}
11971153
}
11981154

@@ -1217,7 +1173,7 @@ PList doIntInt(PList list, int right) {
12171173
} catch (OutOfMemoryError e) {
12181174
throw raise(MemoryError);
12191175
} catch (ArithmeticException e) {
1220-
throw raise(OverflowError, MulNode.CANNOT_FIT_MESSAGE);
1176+
throw raise(OverflowError, IMulNode.CANNOT_FIT_MESSAGE);
12211177
}
12221178
}
12231179

@@ -1226,7 +1182,7 @@ PList doIntLong(PList list, long right) {
12261182
try {
12271183
return doIntInt(list, PInt.intValueExact(right));
12281184
} catch (ArithmeticException e) {
1229-
throw raise(OverflowError, MulNode.CANNOT_FIT_MESSAGE);
1185+
throw raise(OverflowError, IMulNode.CANNOT_FIT_MESSAGE);
12301186
}
12311187
}
12321188

@@ -1235,7 +1191,7 @@ PList doIntPInt(PList list, PInt right) {
12351191
try {
12361192
return doIntInt(list, right.intValueExact());
12371193
} catch (ArithmeticException e) {
1238-
throw raise(OverflowError, MulNode.CANNOT_FIT_MESSAGE);
1194+
throw raise(OverflowError, IMulNode.CANNOT_FIT_MESSAGE);
12391195
}
12401196
}
12411197

@@ -1260,7 +1216,7 @@ PList doLongInt(PList list, int right) {
12601216
} catch (OutOfMemoryError e) {
12611217
throw raise(MemoryError);
12621218
} catch (ArithmeticException e) {
1263-
throw raise(OverflowError, MulNode.CANNOT_FIT_MESSAGE);
1219+
throw raise(OverflowError, IMulNode.CANNOT_FIT_MESSAGE);
12641220
}
12651221
}
12661222

@@ -1269,7 +1225,7 @@ PList doLongLong(PList list, long right) {
12691225
try {
12701226
return doLongInt(list, PInt.intValueExact(right));
12711227
} catch (ArithmeticException e) {
1272-
throw raise(OverflowError, MulNode.CANNOT_FIT_MESSAGE);
1228+
throw raise(OverflowError, IMulNode.CANNOT_FIT_MESSAGE);
12731229
}
12741230
}
12751231

@@ -1278,7 +1234,7 @@ PList doLongPInt(PList list, PInt right) {
12781234
try {
12791235
return doLongInt(list, right.intValueExact());
12801236
} catch (ArithmeticException e) {
1281-
throw raise(OverflowError, MulNode.CANNOT_FIT_MESSAGE);
1237+
throw raise(OverflowError, IMulNode.CANNOT_FIT_MESSAGE);
12821238
}
12831239
}
12841240

@@ -1303,7 +1259,7 @@ PList doDoubleInt(PList list, int right) {
13031259
} catch (OutOfMemoryError e) {
13041260
throw raise(MemoryError);
13051261
} catch (ArithmeticException e) {
1306-
throw raise(OverflowError, MulNode.CANNOT_FIT_MESSAGE);
1262+
throw raise(OverflowError, IMulNode.CANNOT_FIT_MESSAGE);
13071263
}
13081264
}
13091265

@@ -1312,7 +1268,7 @@ PList doDoubleLong(PList list, long right) {
13121268
try {
13131269
return doDoubleInt(list, PInt.intValueExact(right));
13141270
} catch (ArithmeticException e) {
1315-
throw raise(OverflowError, MulNode.CANNOT_FIT_MESSAGE);
1271+
throw raise(OverflowError, IMulNode.CANNOT_FIT_MESSAGE);
13161272
}
13171273
}
13181274

@@ -1321,7 +1277,7 @@ PList doDoublePInt(PList list, PInt right) {
13211277
try {
13221278
return doLongInt(list, right.intValueExact());
13231279
} catch (ArithmeticException e) {
1324-
throw raise(OverflowError, MulNode.CANNOT_FIT_MESSAGE);
1280+
throw raise(OverflowError, IMulNode.CANNOT_FIT_MESSAGE);
13251281
}
13261282
}
13271283

@@ -1346,7 +1302,7 @@ PList doObjectInt(PList list, int right) {
13461302
} catch (OutOfMemoryError e) {
13471303
throw raise(MemoryError);
13481304
} catch (ArithmeticException e) {
1349-
throw raise(OverflowError, MulNode.CANNOT_FIT_MESSAGE);
1305+
throw raise(OverflowError, IMulNode.CANNOT_FIT_MESSAGE);
13501306
}
13511307
}
13521308

@@ -1355,7 +1311,7 @@ PList doObjectLong(PList list, long right) {
13551311
try {
13561312
return doObjectInt(list, PInt.intValueExact(right));
13571313
} catch (ArithmeticException e) {
1358-
throw raise(OverflowError, MulNode.CANNOT_FIT_MESSAGE);
1314+
throw raise(OverflowError, IMulNode.CANNOT_FIT_MESSAGE);
13591315
}
13601316
}
13611317

@@ -1364,7 +1320,7 @@ PList doObjectPInt(PList list, PInt right) {
13641320
try {
13651321
return doObjectInt(list, right.intValueExact());
13661322
} catch (ArithmeticException e) {
1367-
throw raise(OverflowError, MulNode.CANNOT_FIT_MESSAGE);
1323+
throw raise(OverflowError, IMulNode.CANNOT_FIT_MESSAGE);
13681324
}
13691325
}
13701326

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/list/PList.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import com.oracle.graal.python.runtime.sequence.storage.SequenceStoreException;
3434
import com.oracle.truffle.api.CompilerDirectives;
3535
import com.oracle.truffle.api.nodes.UnexpectedResultException;
36-
import com.oracle.truffle.api.profiles.ValueProfile;
3736

3837
public final class PList extends PSequence {
3938
private SequenceStorage store;
@@ -84,23 +83,6 @@ public final int len() {
8483
return store.length();
8584
}
8685

87-
public final PList __mul__(ValueProfile storeProfile, int value) {
88-
assert value > 0;
89-
90-
SequenceStorage profiledStore = storeProfile.profile(store);
91-
SequenceStorage newStore = profiledStore.createEmpty(Math.multiplyExact(value, profiledStore.length()));
92-
93-
try {
94-
for (int i = 0; i < value; i++) {
95-
newStore.extend(profiledStore);
96-
}
97-
} catch (SequenceStoreException e) {
98-
throw new IllegalStateException();
99-
}
100-
101-
return new PList(getPythonClass(), newStore);
102-
}
103-
10486
public final void reverse() {
10587
store.reverse();
10688
}

0 commit comments

Comments
 (0)