do not store descriptors or JetTypes in CallableMethod
This commit is contained in:
@@ -20,7 +20,6 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.codegen.signature.JvmMethodSignature;
|
import org.jetbrains.jet.codegen.signature.JvmMethodSignature;
|
||||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
||||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
@@ -43,26 +42,24 @@ public class CallableMethod implements Callable {
|
|||||||
private final JvmClassName defaultImplParam;
|
private final JvmClassName defaultImplParam;
|
||||||
private final JvmMethodSignature signature;
|
private final JvmMethodSignature signature;
|
||||||
private final int invokeOpcode;
|
private final int invokeOpcode;
|
||||||
private final ClassDescriptor thisClass;
|
@Nullable
|
||||||
|
private final JvmClassName thisClass;
|
||||||
private final CallableDescriptor receiverFunction;
|
@Nullable
|
||||||
|
private final Type receiverParameterType;
|
||||||
|
@Nullable
|
||||||
private final Type generateCalleeType;
|
private final Type generateCalleeType;
|
||||||
|
|
||||||
public CallableMethod(@NotNull JvmClassName owner, @Nullable JvmClassName defaultImplOwner, @Nullable JvmClassName defaultImplParam,
|
public CallableMethod(@NotNull JvmClassName owner, @Nullable JvmClassName defaultImplOwner, @Nullable JvmClassName defaultImplParam,
|
||||||
JvmMethodSignature signature, int invokeOpcode,
|
JvmMethodSignature signature, int invokeOpcode,
|
||||||
@Nullable ClassDescriptor thisClass, @Nullable CallableDescriptor receiverFunction, @Nullable Type generateCalleeType) {
|
@Nullable JvmClassName thisClass, @Nullable Type receiverParameterType, @Nullable Type generateCalleeType) {
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.defaultImplOwner = defaultImplOwner;
|
this.defaultImplOwner = defaultImplOwner;
|
||||||
this.defaultImplParam = defaultImplParam;
|
this.defaultImplParam = defaultImplParam;
|
||||||
this.signature = signature;
|
this.signature = signature;
|
||||||
this.invokeOpcode = invokeOpcode;
|
this.invokeOpcode = invokeOpcode;
|
||||||
this.thisClass = thisClass;
|
this.thisClass = thisClass;
|
||||||
this.receiverFunction = receiverFunction;
|
this.receiverParameterType = receiverParameterType;
|
||||||
this.generateCalleeType = generateCalleeType;
|
this.generateCalleeType = generateCalleeType;
|
||||||
|
|
||||||
if (receiverFunction != null && receiverFunction.getOriginal() != receiverFunction) {
|
|
||||||
throw new IllegalArgumentException("receiver function parameter must be original: " + receiverFunction);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -87,12 +84,12 @@ public class CallableMethod implements Callable {
|
|||||||
return signature.getValueParameterTypes();
|
return signature.getValueParameterTypes();
|
||||||
}
|
}
|
||||||
|
|
||||||
public JetType getThisType() {
|
public JvmClassName getThisType() {
|
||||||
return thisClass.getDefaultType();
|
return thisClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JetType getReceiverClass() {
|
public Type getReceiverClass() {
|
||||||
return receiverFunction.getReceiverParameter().getType();
|
return receiverParameterType;
|
||||||
}
|
}
|
||||||
|
|
||||||
void invoke(InstructionAdapter v) {
|
void invoke(InstructionAdapter v) {
|
||||||
@@ -126,6 +123,6 @@ public class CallableMethod implements Callable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isNeedsReceiver() {
|
public boolean isNeedsReceiver() {
|
||||||
return receiverFunction != null;
|
return receiverParameterType != null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,12 +88,19 @@ public class ClosureCodegen extends ObjectOrClosureCodegen {
|
|||||||
return signatureWriter.makeJvmMethodSignature("invoke");
|
return signatureWriter.makeJvmMethodSignature("invoke");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CallableMethod asCallableMethod(FunctionDescriptor fd) {
|
public static CallableMethod asCallableMethod(FunctionDescriptor fd, @NotNull JetTypeMapper typeMapper) {
|
||||||
JvmMethodSignature descriptor = erasedInvokeSignature(fd);
|
JvmMethodSignature descriptor = erasedInvokeSignature(fd);
|
||||||
JvmClassName owner = getInternalClassName(fd);
|
JvmClassName owner = getInternalClassName(fd);
|
||||||
|
Type receiverParameterType;
|
||||||
|
if (fd.getReceiverParameter().exists()) {
|
||||||
|
receiverParameterType = typeMapper.mapType(fd.getOriginal().getReceiverParameter().getType(), MapTypeMode.VALUE);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
receiverParameterType = null;
|
||||||
|
}
|
||||||
final CallableMethod result = new CallableMethod(
|
final CallableMethod result = new CallableMethod(
|
||||||
owner, null, null, descriptor, INVOKEVIRTUAL,
|
owner, null, null, descriptor, INVOKEVIRTUAL,
|
||||||
getInternalType(fd), fd.getReceiverParameter().exists() ? fd.getOriginal() : null, getInternalClassName(fd).getAsmType());
|
getInternalClassName(fd), receiverParameterType, getInternalClassName(fd).getAsmType());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1357,7 +1357,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
|||||||
//}
|
//}
|
||||||
if (fd instanceof ExpressionAsFunctionDescriptor || (fd instanceof SimpleFunctionDescriptor && (fd.getContainingDeclaration() instanceof FunctionDescriptor || fd.getContainingDeclaration() instanceof ScriptDescriptor))) {
|
if (fd instanceof ExpressionAsFunctionDescriptor || (fd instanceof SimpleFunctionDescriptor && (fd.getContainingDeclaration() instanceof FunctionDescriptor || fd.getContainingDeclaration() instanceof ScriptDescriptor))) {
|
||||||
SimpleFunctionDescriptor invoke = CodegenUtil.createInvoke((FunctionDescriptor) fd);
|
SimpleFunctionDescriptor invoke = CodegenUtil.createInvoke((FunctionDescriptor) fd);
|
||||||
callableMethod = ClosureCodegen.asCallableMethod(invoke);
|
callableMethod = ClosureCodegen.asCallableMethod(invoke, typeMapper);
|
||||||
}
|
}
|
||||||
else if (fd instanceof FunctionDescriptor) {
|
else if (fd instanceof FunctionDescriptor) {
|
||||||
callableMethod = typeMapper.mapToCallableMethod((FunctionDescriptor) fd, superCall, OwnerKind.IMPLEMENTATION);
|
callableMethod = typeMapper.mapToCallableMethod((FunctionDescriptor) fd, superCall, OwnerKind.IMPLEMENTATION);
|
||||||
|
|||||||
@@ -545,7 +545,7 @@ public class JetTypeMapper {
|
|||||||
JvmClassName ownerForDefaultImpl;
|
JvmClassName ownerForDefaultImpl;
|
||||||
JvmClassName ownerForDefaultParam;
|
JvmClassName ownerForDefaultParam;
|
||||||
int invokeOpcode;
|
int invokeOpcode;
|
||||||
ClassDescriptor thisClass;
|
JvmClassName thisClass;
|
||||||
if (functionParent instanceof NamespaceDescriptor) {
|
if (functionParent instanceof NamespaceDescriptor) {
|
||||||
assert !superCall;
|
assert !superCall;
|
||||||
owner = jvmClassNameForNamespace((NamespaceDescriptor) functionParent);
|
owner = jvmClassNameForNamespace((NamespaceDescriptor) functionParent);
|
||||||
@@ -595,16 +595,23 @@ public class JetTypeMapper {
|
|||||||
descriptor = mapSignature(functionDescriptor, false, OwnerKind.TRAIT_IMPL);
|
descriptor = mapSignature(functionDescriptor, false, OwnerKind.TRAIT_IMPL);
|
||||||
owner = JvmClassName.byInternalName(owner.getInternalName() + JvmAbi.TRAIT_IMPL_SUFFIX);
|
owner = JvmClassName.byInternalName(owner.getInternalName() + JvmAbi.TRAIT_IMPL_SUFFIX);
|
||||||
}
|
}
|
||||||
thisClass = receiver;
|
thisClass = JvmClassName.byType(mapType(receiver.getDefaultType(), MapTypeMode.VALUE));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new UnsupportedOperationException("unknown function parent");
|
throw new UnsupportedOperationException("unknown function parent");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Type receiverParameterType;
|
||||||
|
if (functionDescriptor.getReceiverParameter().exists()) {
|
||||||
|
receiverParameterType = mapType(functionDescriptor.getOriginal().getReceiverParameter().getType(), MapTypeMode.VALUE);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
receiverParameterType = null;
|
||||||
|
}
|
||||||
return new CallableMethod(
|
return new CallableMethod(
|
||||||
owner, ownerForDefaultImpl, ownerForDefaultParam, descriptor, invokeOpcode,
|
owner, ownerForDefaultImpl, ownerForDefaultParam, descriptor, invokeOpcode,
|
||||||
thisClass, functionDescriptor.getReceiverParameter().exists() ? functionDescriptor.getOriginal() : null, null);
|
thisClass, receiverParameterType, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -1083,10 +1083,10 @@ public abstract class StackValue {
|
|||||||
if (thisObject.exists()) {
|
if (thisObject.exists()) {
|
||||||
if(callableMethod != null) {
|
if(callableMethod != null) {
|
||||||
if(receiverArgument.exists()) {
|
if(receiverArgument.exists()) {
|
||||||
return codegen.typeMapper.mapType(callableMethod.getReceiverClass(), MapTypeMode.VALUE);
|
return callableMethod.getReceiverClass();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return codegen.typeMapper.mapType(callableMethod.getThisType(), MapTypeMode.VALUE);
|
return callableMethod.getThisType().getAsmType();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -1101,7 +1101,7 @@ public abstract class StackValue {
|
|||||||
else {
|
else {
|
||||||
if (receiverArgument.exists()) {
|
if (receiverArgument.exists()) {
|
||||||
if(callableMethod != null)
|
if(callableMethod != null)
|
||||||
return codegen.typeMapper.mapType(callableMethod.getReceiverClass(), MapTypeMode.VALUE);
|
return callableMethod.getReceiverClass();
|
||||||
else
|
else
|
||||||
return codegen.typeMapper.mapType(descriptor.getReceiverParameter().getType(), MapTypeMode.VALUE);
|
return codegen.typeMapper.mapType(descriptor.getReceiverParameter().getType(), MapTypeMode.VALUE);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user