Skip to content

Commit f6c3c81

Browse files
committed
Ensure native-image contains all needed deoptimization entrypoints.
Small code refactorings to ensure native-image is able to generate all deoptimization entrypoints required from graalpython.
1 parent 4f22561 commit f6c3c81

File tree

2 files changed

+13
-27
lines changed

2 files changed

+13
-27
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SequenceStorageNodes.java

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,6 @@ public interface GenNodeSupplier {
194194
GeneralizationNode getUncached();
195195
}
196196

197-
public interface ContainerFactory {
198-
199-
Object apply(SequenceStorage s, PythonObjectFactory factory);
200-
}
201-
202197
@GenerateUncached
203198
public abstract static class IsAssignCompatibleNode extends Node {
204199

@@ -598,63 +593,60 @@ public static GetItemNode create(NormalizeIndexNode normalizeIndexNode, BiFuncti
598593
@ImportStatic(PGuards.class)
599594
public abstract static class GetItemDynamicNode extends Node {
600595

601-
public abstract Object execute(ContainerFactory factoryMethod, SequenceStorage s, Object key);
596+
public abstract Object executeObject(SequenceStorage s, Object key);
602597

603598
public final Object execute(SequenceStorage s, int key) {
604-
return execute(null, s, key);
599+
return executeObject(s, key);
605600
}
606601

607602
public final Object execute(SequenceStorage s, long key) {
608-
return execute(null, s, key);
603+
return executeObject(s, key);
609604
}
610605

611606
public final Object execute(SequenceStorage s, PInt key) {
612-
return execute(null, s, key);
607+
return executeObject(s, key);
613608
}
614609

615610
@Specialization
616-
protected static Object doScalarInt(@SuppressWarnings("unused") ContainerFactory factoryMethod, SequenceStorage storage, int idx,
611+
protected static Object doScalarInt(SequenceStorage storage, int idx,
617612
@Shared("getItemScalarNode") @Cached GetItemScalarNode getItemScalarNode,
618613
@Shared("normalizeIndexNode") @Cached NormalizeIndexCustomMessageNode normalizeIndexNode,
619614
@Shared("lenNode") @Cached LenNode lenNode) {
620615
return getItemScalarNode.execute(storage, normalizeIndexNode.execute(idx, lenNode.execute(storage), ErrorMessages.INDEX_OUT_OF_RANGE));
621616
}
622617

623618
@Specialization
624-
protected static Object doScalarLong(@SuppressWarnings("unused") ContainerFactory factoryMethod, SequenceStorage storage, long idx,
619+
protected static Object doScalarLong(SequenceStorage storage, long idx,
625620
@Shared("getItemScalarNode") @Cached GetItemScalarNode getItemScalarNode,
626621
@Shared("normalizeIndexNode") @Cached NormalizeIndexCustomMessageNode normalizeIndexNode,
627622
@Shared("lenNode") @Cached LenNode lenNode) {
628623
return getItemScalarNode.execute(storage, normalizeIndexNode.execute(idx, lenNode.execute(storage), ErrorMessages.INDEX_OUT_OF_RANGE));
629624
}
630625

631626
@Specialization
632-
protected static Object doScalarPInt(@SuppressWarnings("unused") ContainerFactory factoryMethod, SequenceStorage storage, PInt idx,
627+
protected static Object doScalarPInt(SequenceStorage storage, PInt idx,
633628
@Shared("getItemScalarNode") @Cached GetItemScalarNode getItemScalarNode,
634629
@Shared("normalizeIndexNode") @Cached NormalizeIndexCustomMessageNode normalizeIndexNode,
635630
@Shared("lenNode") @Cached LenNode lenNode) {
636631
return getItemScalarNode.execute(storage, normalizeIndexNode.execute(idx, lenNode.execute(storage), ErrorMessages.INDEX_OUT_OF_RANGE));
637632
}
638633

639634
@Specialization(guards = "!isPSlice(idx)")
640-
protected static Object doScalarGeneric(@SuppressWarnings("unused") ContainerFactory factoryMethod, SequenceStorage storage, Object idx,
635+
protected static Object doScalarGeneric(SequenceStorage storage, Object idx,
641636
@Shared("getItemScalarNode") @Cached GetItemScalarNode getItemScalarNode,
642637
@Shared("normalizeIndexNode") @Cached NormalizeIndexCustomMessageNode normalizeIndexNode,
643638
@Shared("lenNode") @Cached LenNode lenNode) {
644639
return getItemScalarNode.execute(storage, normalizeIndexNode.execute(idx, lenNode.execute(storage), ErrorMessages.INDEX_OUT_OF_RANGE));
645640
}
646641

647642
@Specialization
648-
protected static Object doSlice(ContainerFactory factoryMethod, SequenceStorage storage, PSlice slice,
643+
@SuppressWarnings("unused")
644+
protected static Object doSlice(SequenceStorage storage, PSlice slice,
649645
@Cached GetItemSliceNode getItemSliceNode,
650646
@Cached PythonObjectFactory factory,
651647
@Cached CoerceToIntSlice sliceCast,
652648
@Cached ComputeIndices compute,
653649
@Cached LenOfRangeNode sliceLen) {
654-
SliceInfo info = compute.execute(sliceCast.execute(slice), storage.length());
655-
if (factoryMethod != null) {
656-
return factoryMethod.apply(getItemSliceNode.execute(storage, info.start, info.stop, info.step, sliceLen.len(info)), factory);
657-
}
658650
CompilerDirectives.transferToInterpreterAndInvalidate();
659651
throw new IllegalStateException();
660652
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeNodes.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,18 +1502,12 @@ static Long getItemsizeManaged(PythonClass cls,
15021502
if (hasValueProfile.profile(itemsize != PNone.NO_VALUE)) {
15031503
return (long) itemsize;
15041504
}
1505-
itemsize = computeItemSize(cls, getBaseNode, baseItemsizeNode);
1506-
writeNode.execute(cls, TYPE_ITEMSIZE, itemsize);
1507-
return (long) itemsize;
1508-
}
15091505

1510-
private static Long computeItemSize(PythonManagedClass cls, GetBaseClassNode getBaseNode, GetItemsizeNode baseItemsizeNode) {
1511-
if (cls instanceof PythonBuiltinClass) {
1512-
return getItemsizeType(((PythonBuiltinClass) cls).getType());
1513-
}
15141506
Object base = getBaseNode.execute(cls);
15151507
assert base != null;
1516-
return baseItemsizeNode.execute(base);
1508+
itemsize = baseItemsizeNode.execute(base);
1509+
writeNode.execute(cls, TYPE_ITEMSIZE, itemsize);
1510+
return (long) itemsize;
15171511
}
15181512

15191513
@Specialization

0 commit comments

Comments
 (0)