Skip to content

Commit e095571

Browse files
committed
Added shortCircuitPrimitive to ConversionFactory
1 parent c375e3a commit e095571

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

graalpython/com.oracle.graal.python.annotations/src/com/oracle/graal/python/annotations/ArgumentClinic.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@
7676
* types and will just pass them directly to the specializations. This does not apply to
7777
* primitive values that are already boxed: those are always passed to the convertor.
7878
*
79-
* It is not necessary to set this when using a builtin conversion. Built-in convertors provide
80-
* their own list of short circuit types, which is applied if this field is set to its default
81-
* value.
79+
* It is not necessary to set this when using a builtin conversion or
80+
* {@link #conversionClass()}. Built-in convertors and {@link ConversionFactory} provide their
81+
* own list of short circuit types, which is applied if this field is set to its default value.
8282
*/
8383
PrimitiveType[] shortCircuitPrimitive() default {};
8484

@@ -163,6 +163,14 @@ enum ClinicConversion {
163163
*/
164164
ClinicArgument[] clinicArgs() default {};
165165

166+
/**
167+
* The boxing optimized execute method variants will not attempt to cast the listed
168+
* primitive types and will just pass them directly to the specializations. This does not
169+
* apply to primitive values that are already boxed: those are always passed to the
170+
* convertor.
171+
*/
172+
PrimitiveType[] shortCircuitPrimitive() default {};
173+
166174
enum ClinicArgument {
167175
/**
168176
* The default value {@link #defaultValue()}.

graalpython/com.oracle.graal.python.processor/src/com/oracle/graal/python/processor/ConverterFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ public class ConverterFactory {
6464
public final ClinicArgument[] clinicArgs;
6565
public final PrimitiveType[] acceptedPrimitiveTypes;
6666

67-
private ConverterFactory(ExecutableElement method, ClinicArgument[] clinicArgs) {
67+
private ConverterFactory(ExecutableElement method, ClinicArgument[] clinicArgs, PrimitiveType[] acceptedPrimitiveTypes) {
6868
fullClassName = method.getEnclosingElement().toString();
6969
className = fullClassName.substring(fullClassName.lastIndexOf('.') + 1);
7070
methodName = method.getSimpleName().toString();
7171
paramCount = method.getParameters().size() - clinicArgs.length;
7272
this.clinicArgs = clinicArgs;
73-
acceptedPrimitiveTypes = new PrimitiveType[0];
73+
this.acceptedPrimitiveTypes = acceptedPrimitiveTypes;
7474
}
7575

7676
private ConverterFactory(String className, ClinicArgument[] clinicArgs, PrimitiveType[] acceptedPrimitiveTypes) {
@@ -150,7 +150,7 @@ public static ConverterFactory getForClass(TypeElement conversionClass) throws P
150150
if (factory != null) {
151151
throw new ProcessingError(conversionClass, "Multiple ConversionFactory annotations in a single class.");
152152
}
153-
factory = new ConverterFactory((ExecutableElement) e, annot.clinicArgs());
153+
factory = new ConverterFactory((ExecutableElement) e, annot.clinicArgs(), annot.shortCircuitPrimitive());
154154
}
155155
}
156156
if (factory == null) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tuple/TupleBuiltins.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,16 @@ int doOthers(VirtualFrame frame, Object value,
135135
throw raise(TypeError, ErrorMessages.SLICE_INDICES_TYPE_ERROR);
136136
}
137137

138-
@ArgumentClinic.ConversionFactory(clinicArgs = {ArgumentClinic.ConversionFactory.ClinicArgument.DefaultValue})
138+
@ArgumentClinic.ConversionFactory(shortCircuitPrimitive = PrimitiveType.Int, clinicArgs = {ArgumentClinic.ConversionFactory.ClinicArgument.DefaultValue})
139139
public static SliceIndexNode create(int defaultValue) {
140140
return SliceIndexNodeGen.create(defaultValue);
141141
}
142142
}
143143

144144
// index(element)
145145
@Builtin(name = "index", minNumOfPositionalArgs = 2, parameterNames = {"$self", "value", "start", "stop"})
146-
@ArgumentClinic(name = "start", conversionClass = SliceIndexNode.class, defaultValue = "0", shortCircuitPrimitive = PrimitiveType.Int)
147-
@ArgumentClinic(name = "stop", conversionClass = SliceIndexNode.class, defaultValue = "Integer.MAX_VALUE", shortCircuitPrimitive = PrimitiveType.Int)
146+
@ArgumentClinic(name = "start", conversionClass = SliceIndexNode.class, defaultValue = "0")
147+
@ArgumentClinic(name = "stop", conversionClass = SliceIndexNode.class, defaultValue = "Integer.MAX_VALUE")
148148
@TypeSystemReference(PythonArithmeticTypes.class)
149149
@ImportStatic(MathGuards.class)
150150
@GenerateNodeFactory

0 commit comments

Comments
 (0)