Skip to content

Commit 89153af

Browse files
committed
Remove Painless Type From Painless Method/Field (#28466)
1 parent 485ac47 commit 89153af

File tree

15 files changed

+116
-121
lines changed

15 files changed

+116
-121
lines changed

modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ static MethodHandle lookupMethod(Definition definition, Lookup lookup, MethodTyp
279279
captures[capture] = callSiteType.parameterType(i + 1 + capture);
280280
}
281281
MethodHandle filter;
282-
Definition.Type interfaceType = method.arguments.get(i - 1 - replaced);
282+
Definition.Type interfaceType = definition.ClassToType(method.arguments.get(i - 1 - replaced));
283283
if (signature.charAt(0) == 'S') {
284284
// the implementation is strongly typed, now that we know the interface type,
285285
// we have everything.

modules/lang-painless/src/main/java/org/elasticsearch/painless/Definition.java

Lines changed: 44 additions & 45 deletions
Large diffs are not rendered by default.

modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECallLocal.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ void analyze(Locals locals) {
6969
for (int argument = 0; argument < arguments.size(); ++argument) {
7070
AExpression expression = arguments.get(argument);
7171

72-
expression.expected = Definition.TypeToClass(method.arguments.get(argument));
72+
expression.expected = method.arguments.get(argument);
7373
expression.internal = true;
7474
expression.analyze(locals);
7575
arguments.set(argument, expression.cast(locals));
7676
}
7777

7878
statement = true;
79-
actual = Definition.TypeToClass(method.rtn);
79+
actual = method.rtn;
8080
}
8181

8282
@Override

modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECapturingFunctionRef.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,13 @@ void analyze(Locals locals) {
8080

8181
// check casts between the interface method and the delegate method are legal
8282
for (int i = 0; i < ref.interfaceMethod.arguments.size(); ++i) {
83-
Class<?> from = Definition.TypeToClass(ref.interfaceMethod.arguments.get(i));
84-
Class<?> to = Definition.TypeToClass(ref.delegateMethod.arguments.get(i));
83+
Class<?> from = ref.interfaceMethod.arguments.get(i);
84+
Class<?> to = ref.delegateMethod.arguments.get(i);
8585
AnalyzerCaster.getLegalCast(location, from, to, false, true);
8686
}
8787

88-
if (ref.interfaceMethod.rtn.clazz != void.class) {
89-
AnalyzerCaster.getLegalCast(location,
90-
Definition.TypeToClass(ref.delegateMethod.rtn), Definition.TypeToClass(ref.interfaceMethod.rtn), false, true);
88+
if (ref.interfaceMethod.rtn != void.class) {
89+
AnalyzerCaster.getLegalCast(location, ref.delegateMethod.rtn, ref.interfaceMethod.rtn, false, true);
9190
}
9291
} catch (IllegalArgumentException e) {
9392
throw createError(e);

modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EFunctionRef.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,13 @@ void analyze(Locals locals) {
8080

8181
// check casts between the interface method and the delegate method are legal
8282
for (int i = 0; i < interfaceMethod.arguments.size(); ++i) {
83-
Class<?> from = Definition.TypeToClass(interfaceMethod.arguments.get(i));
84-
Class<?> to = Definition.TypeToClass(delegateMethod.arguments.get(i));
83+
Class<?> from = interfaceMethod.arguments.get(i);
84+
Class<?> to = delegateMethod.arguments.get(i);
8585
AnalyzerCaster.getLegalCast(location, from, to, false, true);
8686
}
8787

88-
if (interfaceMethod.rtn.clazz != void.class) {
89-
AnalyzerCaster.getLegalCast(
90-
location, Definition.TypeToClass(delegateMethod.rtn), Definition.TypeToClass(interfaceMethod.rtn), false, true);
88+
if (interfaceMethod.rtn != void.class) {
89+
AnalyzerCaster.getLegalCast(location, delegateMethod.rtn, interfaceMethod.rtn, false, true);
9190
}
9291
} else {
9392
// whitelist lookup

modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ELambda.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,17 @@ void analyze(Locals locals) {
130130
throw new IllegalArgumentException("Incorrect number of parameters for [" + interfaceMethod.name +
131131
"] in [" + Definition.ClassToName(expected) + "]");
132132
// for method invocation, its allowed to ignore the return value
133-
if (interfaceMethod.rtn.equals(locals.getDefinition().voidType)) {
133+
if (interfaceMethod.rtn == void.class) {
134134
returnType = def.class;
135135
} else {
136-
returnType = Definition.TypeToClass(interfaceMethod.rtn);
136+
returnType = interfaceMethod.rtn;
137137
}
138138
// replace any null types with the actual type
139139
actualParamTypeStrs = new ArrayList<>(paramTypeStrs.size());
140140
for (int i = 0; i < paramTypeStrs.size(); i++) {
141141
String paramType = paramTypeStrs.get(i);
142142
if (paramType == null) {
143-
actualParamTypeStrs.add(interfaceMethod.arguments.get(i).name);
143+
actualParamTypeStrs.add(Definition.ClassToName(interfaceMethod.arguments.get(i)));
144144
} else {
145145
actualParamTypeStrs.add(paramType);
146146
}
@@ -190,14 +190,13 @@ void analyze(Locals locals) {
190190

191191
// check casts between the interface method and the delegate method are legal
192192
for (int i = 0; i < interfaceMethod.arguments.size(); ++i) {
193-
Class<?> from = Definition.TypeToClass(interfaceMethod.arguments.get(i));
193+
Class<?> from = interfaceMethod.arguments.get(i);
194194
Class<?> to = Definition.TypeToClass(desugared.parameters.get(i + captures.size()).type);
195195
AnalyzerCaster.getLegalCast(location, from, to, false, true);
196196
}
197197

198-
if (interfaceMethod.rtn.clazz != void.class) {
199-
AnalyzerCaster.getLegalCast(
200-
location, Definition.TypeToClass(desugared.rtnType), Definition.TypeToClass(interfaceMethod.rtn), false, true);
198+
if (interfaceMethod.rtn != void.class) {
199+
AnalyzerCaster.getLegalCast(location, desugared.rtnType, interfaceMethod.rtn, false, true);
201200
}
202201

203202
actual = expected;

modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENewObj.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void analyze(Locals locals) {
6868
constructor = struct.constructors.get(new Definition.MethodKey("<init>", arguments.size()));
6969

7070
if (constructor != null) {
71-
Type[] types = new Type[constructor.arguments.size()];
71+
Class<?>[] types = new Class<?>[constructor.arguments.size()];
7272
constructor.arguments.toArray(types);
7373

7474
if (constructor.arguments.size() != arguments.size()) {
@@ -79,7 +79,7 @@ void analyze(Locals locals) {
7979
for (int argument = 0; argument < arguments.size(); ++argument) {
8080
AExpression expression = arguments.get(argument);
8181

82-
expression.expected = Definition.TypeToClass(types[argument]);
82+
expression.expected = types[argument];
8383
expression.internal = true;
8484
expression.analyze(locals);
8585
arguments.set(argument, expression.cast(locals));

modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubCallInvoke.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ void analyze(Locals locals) {
5757
for (int argument = 0; argument < arguments.size(); ++argument) {
5858
AExpression expression = arguments.get(argument);
5959

60-
expression.expected = Definition.TypeToClass(method.arguments.get(argument));
60+
expression.expected = method.arguments.get(argument);
6161
expression.internal = true;
6262
expression.analyze(locals);
6363
arguments.set(argument, expression.cast(locals));
6464
}
6565

6666
statement = true;
67-
actual = Definition.TypeToClass(method.rtn);
67+
actual = method.rtn;
6868
}
6969

7070
@Override

modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubField.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,20 @@ void extractVariables(Set<String> variables) {
5252
void analyze(Locals locals) {
5353
if (write && Modifier.isFinal(field.modifiers)) {
5454
throw createError(new IllegalArgumentException(
55-
"Cannot write to read-only field [" + field.name + "] for type [" + field.type.name + "]."));
55+
"Cannot write to read-only field [" + field.name + "] for type [" + Definition.ClassToName(field.clazz) + "]."));
5656
}
5757

58-
actual = Definition.TypeToClass(field.type);
58+
actual = field.clazz;
5959
}
6060

6161
@Override
6262
void write(MethodWriter writer, Globals globals) {
6363
writer.writeDebugInfo(location);
6464

6565
if (java.lang.reflect.Modifier.isStatic(field.modifiers)) {
66-
writer.getStatic(field.owner.type, field.javaName, field.type.type);
66+
writer.getStatic(field.owner.type, field.javaName, MethodWriter.getType(field.clazz));
6767
} else {
68-
writer.getField(field.owner.type, field.javaName, field.type.type);
68+
writer.getField(field.owner.type, field.javaName, MethodWriter.getType(field.clazz));
6969
}
7070
}
7171

@@ -94,9 +94,9 @@ void load(MethodWriter writer, Globals globals) {
9494
writer.writeDebugInfo(location);
9595

9696
if (java.lang.reflect.Modifier.isStatic(field.modifiers)) {
97-
writer.getStatic(field.owner.type, field.javaName, field.type.type);
97+
writer.getStatic(field.owner.type, field.javaName, MethodWriter.getType(field.clazz));
9898
} else {
99-
writer.getField(field.owner.type, field.javaName, field.type.type);
99+
writer.getField(field.owner.type, field.javaName, MethodWriter.getType(field.clazz));
100100
}
101101
}
102102

@@ -105,9 +105,9 @@ void store(MethodWriter writer, Globals globals) {
105105
writer.writeDebugInfo(location);
106106

107107
if (java.lang.reflect.Modifier.isStatic(field.modifiers)) {
108-
writer.putStatic(field.owner.type, field.javaName, field.type.type);
108+
writer.putStatic(field.owner.type, field.javaName, MethodWriter.getType(field.clazz));
109109
} else {
110-
writer.putField(field.owner.type, field.javaName, field.type.type);
110+
writer.putField(field.owner.type, field.javaName, MethodWriter.getType(field.clazz));
111111
}
112112
}
113113

modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubListShortcut.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ void analyze(Locals locals) {
5959
getter = struct.methods.get(new Definition.MethodKey("get", 1));
6060
setter = struct.methods.get(new Definition.MethodKey("set", 2));
6161

62-
if (getter != null && (getter.rtn.clazz == void.class || getter.arguments.size() != 1 ||
63-
getter.arguments.get(0).clazz != int.class)) {
62+
if (getter != null && (getter.rtn == void.class || getter.arguments.size() != 1 ||
63+
getter.arguments.get(0) != int.class)) {
6464
throw createError(new IllegalArgumentException("Illegal list get shortcut for type [" + struct.name + "]."));
6565
}
6666

67-
if (setter != null && (setter.arguments.size() != 2 || setter.arguments.get(0).clazz != int.class)) {
67+
if (setter != null && (setter.arguments.size() != 2 || setter.arguments.get(0) != int.class)) {
6868
throw createError(new IllegalArgumentException("Illegal list set shortcut for type [" + struct.name + "]."));
6969
}
7070

@@ -78,7 +78,7 @@ void analyze(Locals locals) {
7878
index.analyze(locals);
7979
index = index.cast(locals);
8080

81-
actual = setter != null ? Definition.TypeToClass(setter.arguments.get(1)) : Definition.TypeToClass(getter.rtn);
81+
actual = setter != null ? setter.arguments.get(1) : getter.rtn;
8282
} else {
8383
throw createError(new IllegalArgumentException("Illegal list shortcut for type [" + struct.name + "]."));
8484
}
@@ -119,8 +119,8 @@ void load(MethodWriter writer, Globals globals) {
119119

120120
getter.write(writer);
121121

122-
if (!getter.rtn.clazz.equals(getter.handle.type().returnType())) {
123-
writer.checkCast(getter.rtn.type);
122+
if (getter.rtn == getter.handle.type().returnType()) {
123+
writer.checkCast(MethodWriter.getType(getter.rtn));
124124
}
125125
}
126126

@@ -130,7 +130,7 @@ void store(MethodWriter writer, Globals globals) {
130130

131131
setter.write(writer);
132132

133-
writer.writePop(setter.rtn.type.getSize());
133+
writer.writePop(MethodWriter.getType(setter.rtn).getSize());
134134
}
135135

136136
@Override

0 commit comments

Comments
 (0)