From de00d4c9603e121046dda37a3b51483286930cc1 Mon Sep 17 00:00:00 2001 From: Jack Conradson Date: Tue, 7 Nov 2017 13:17:26 -0800 Subject: [PATCH] Further removal of Painless Type from lambdas and references. --- .../elasticsearch/painless/FunctionRef.java | 9 +++--- .../painless/node/ECapturingFunctionRef.java | 11 +++---- .../painless/node/EFunctionRef.java | 8 ++--- .../elasticsearch/painless/node/ELambda.java | 32 +++++++++---------- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/FunctionRef.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/FunctionRef.java index 0e3d675f97585..9e381b33bacc0 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/FunctionRef.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/FunctionRef.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless; import org.elasticsearch.painless.Definition.Method; +import org.objectweb.asm.Type; import java.lang.invoke.MethodType; import java.lang.reflect.Modifier; @@ -61,9 +62,9 @@ public class FunctionRef { /** factory method type descriptor */ public final String factoryDescriptor; /** functional interface method as type */ - public final org.objectweb.asm.Type interfaceType; + public final Type interfaceType; /** delegate method type method as type */ - public final org.objectweb.asm.Type delegateType; + public final Type delegateType; /** * Creates a new FunctionRef, which will resolve {@code type::call} from the whitelist. @@ -119,8 +120,8 @@ public FunctionRef(Class expected, Method interfaceMethod, Method delegateMet this.delegateMethod = delegateMethod; factoryDescriptor = factoryMethodType.toMethodDescriptorString(); - interfaceType = org.objectweb.asm.Type.getMethodType(interfaceMethodType.toMethodDescriptorString()); - delegateType = org.objectweb.asm.Type.getMethodType(this.delegateMethodType.toMethodDescriptorString()); + interfaceType = Type.getMethodType(interfaceMethodType.toMethodDescriptorString()); + delegateType = Type.getMethodType(this.delegateMethodType.toMethodDescriptorString()); } /** diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECapturingFunctionRef.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECapturingFunctionRef.java index 2e8e8e6e49664..121778576a18f 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECapturingFunctionRef.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECapturingFunctionRef.java @@ -76,17 +76,16 @@ void analyze(Locals locals) { // static case if (captured.type.dynamic == false) { try { - ref = new FunctionRef( - locals.getDefinition(), expected, captured.type.name, call, 1); + ref = new FunctionRef(locals.getDefinition(), expected, captured.type.name, call, 1); // check casts between the interface method and the delegate method are legal for (int i = 0; i < ref.interfaceMethod.arguments.size(); ++i) { - Definition.Type from = ref.interfaceMethod.arguments.get(i); - Definition.Type to = ref.delegateMethod.arguments.get(i); - AnalyzerCaster.getLegalCast(location, Definition.TypeToClass(from), Definition.TypeToClass(to), false, true); + Class from = Definition.TypeToClass(ref.interfaceMethod.arguments.get(i)); + Class to = Definition.TypeToClass(ref.delegateMethod.arguments.get(i)); + AnalyzerCaster.getLegalCast(location, from, to, false, true); } - if (ref.interfaceMethod.rtn.equals(locals.getDefinition().voidType) == false) { + if (ref.interfaceMethod.rtn.clazz != void.class) { AnalyzerCaster.getLegalCast(location, Definition.TypeToClass(ref.delegateMethod.rtn), Definition.TypeToClass(ref.interfaceMethod.rtn), false, true); } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EFunctionRef.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EFunctionRef.java index deeadede63076..d35354daa24b5 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EFunctionRef.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EFunctionRef.java @@ -80,12 +80,12 @@ void analyze(Locals locals) { // check casts between the interface method and the delegate method are legal for (int i = 0; i < interfaceMethod.arguments.size(); ++i) { - Definition.Type from = interfaceMethod.arguments.get(i); - Definition.Type to = delegateMethod.arguments.get(i); - AnalyzerCaster.getLegalCast(location, Definition.TypeToClass(from), Definition.TypeToClass(to), false, true); + Class from = Definition.TypeToClass(interfaceMethod.arguments.get(i)); + Class to = Definition.TypeToClass(delegateMethod.arguments.get(i)); + AnalyzerCaster.getLegalCast(location, from, to, false, true); } - if (interfaceMethod.rtn.equals(locals.getDefinition().voidType) == false) { + if (interfaceMethod.rtn.clazz != void.class) { AnalyzerCaster.getLegalCast( location, Definition.TypeToClass(delegateMethod.rtn), Definition.TypeToClass(interfaceMethod.rtn), false, true); } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ELambda.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ELambda.java index fb35f9ef08523..c61db94c28c03 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ELambda.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ELambda.java @@ -22,7 +22,7 @@ import org.elasticsearch.painless.AnalyzerCaster; import org.elasticsearch.painless.Definition; import org.elasticsearch.painless.Definition.Method; -import org.elasticsearch.painless.Definition.Type; +import org.elasticsearch.painless.Definition.def; import org.elasticsearch.painless.FunctionRef; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -101,14 +101,14 @@ void extractVariables(Set variables) { @Override void analyze(Locals locals) { - final Type returnType; - final List actualParamTypeStrs; + Class returnType; + List actualParamTypeStrs; Method interfaceMethod; // inspect the target first, set interface method if we know it. if (expected == null) { interfaceMethod = null; // we don't know anything: treat as def - returnType = locals.getDefinition().DefType; + returnType = def.class; // don't infer any types, replace any null types with def actualParamTypeStrs = new ArrayList<>(paramTypeStrs.size()); for (String type : paramTypeStrs) { @@ -131,9 +131,9 @@ void analyze(Locals locals) { "] in [" + Definition.ClassToName(expected) + "]"); // for method invocation, its allowed to ignore the return value if (interfaceMethod.rtn.equals(locals.getDefinition().voidType)) { - returnType = locals.getDefinition().DefType; + returnType = def.class; } else { - returnType = interfaceMethod.rtn; + returnType = Definition.TypeToClass(interfaceMethod.rtn); } // replace any null types with the actual type actualParamTypeStrs = new ArrayList<>(paramTypeStrs.size()); @@ -169,11 +169,11 @@ void analyze(Locals locals) { paramNames.addAll(paramNameStrs); // desugar lambda body into a synthetic method - desugared = new SFunction(reserved, location, returnType.name, name, + desugared = new SFunction(reserved, location, Definition.ClassToName(returnType), name, paramTypes, paramNames, statements, true); desugared.generateSignature(locals.getDefinition()); - desugared.analyze(Locals.newLambdaScope(locals.getProgramScope(), returnType, desugared.parameters, - captures.size(), reserved.getMaxLoopCounter())); + desugared.analyze(Locals.newLambdaScope(locals.getProgramScope(), locals.getDefinition().ClassToType(returnType), + desugared.parameters, captures.size(), reserved.getMaxLoopCounter())); // setup method reference to synthetic method if (expected == null) { @@ -190,12 +190,12 @@ void analyze(Locals locals) { // check casts between the interface method and the delegate method are legal for (int i = 0; i < interfaceMethod.arguments.size(); ++i) { - Type from = interfaceMethod.arguments.get(i); - Type to = desugared.parameters.get(i + captures.size()).type; - AnalyzerCaster.getLegalCast(location, Definition.TypeToClass(from), Definition.TypeToClass(to), false, true); + Class from = Definition.TypeToClass(interfaceMethod.arguments.get(i)); + Class to = Definition.TypeToClass(desugared.parameters.get(i + captures.size()).type); + AnalyzerCaster.getLegalCast(location, from, to, false, true); } - if (interfaceMethod.rtn.equals(locals.getDefinition().voidType) == false) { + if (interfaceMethod.rtn.clazz != void.class) { AnalyzerCaster.getLegalCast( location, Definition.TypeToClass(desugared.rtnType), Definition.TypeToClass(interfaceMethod.rtn), false, true); } @@ -212,7 +212,7 @@ void write(MethodWriter writer, Globals globals) { writer.writeDebugInfo(location); // load captures for (Variable capture : captures) { - writer.visitVarInsn(capture.type.type.getOpcode(Opcodes.ILOAD), capture.getSlot()); + writer.visitVarInsn(MethodWriter.getType(capture.type.clazz).getOpcode(Opcodes.ILOAD), capture.getSlot()); } writer.invokeDynamic( @@ -230,7 +230,7 @@ void write(MethodWriter writer, Globals globals) { writer.push((String)null); // load captures for (Variable capture : captures) { - writer.visitVarInsn(capture.type.type.getOpcode(Opcodes.ILOAD), capture.getSlot()); + writer.visitVarInsn(MethodWriter.getType(capture.type.clazz).getOpcode(Opcodes.ILOAD), capture.getSlot()); } } @@ -247,7 +247,7 @@ public String getPointer() { public org.objectweb.asm.Type[] getCaptures() { org.objectweb.asm.Type[] types = new org.objectweb.asm.Type[captures.size()]; for (int i = 0; i < types.length; i++) { - types[i] = captures.get(i).type.type; + types[i] = MethodWriter.getType(captures.get(i).type.clazz); } return types; }