Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further Removal of Painless Type from Lambdas and References. #28433

Merged
merged 1 commit into from
Jan 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -101,14 +101,14 @@ void extractVariables(Set<String> variables) {

@Override
void analyze(Locals locals) {
final Type returnType;
final List<String> actualParamTypeStrs;
Class<?> returnType;
List<String> 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) {
Expand All @@ -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());
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
Expand All @@ -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(
Expand All @@ -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());
}
}

Expand All @@ -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;
}
Expand Down