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