Simplify function invocation in ExpressionCodegen
Callee is now generated only when it could be non-trivial, which is only the case when generating function call in invokeFunction()
This commit is contained in:
@@ -1971,17 +1971,15 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
ResolvedCall<? extends CallableDescriptor> resolvedCall
|
ResolvedCall<? extends CallableDescriptor> resolvedCall
|
||||||
) {
|
) {
|
||||||
if (resolvedCall instanceof VariableAsFunctionResolvedCall) {
|
if (resolvedCall instanceof VariableAsFunctionResolvedCall) {
|
||||||
VariableAsFunctionResolvedCall variableAsFunctionResolvedCall = (VariableAsFunctionResolvedCall) resolvedCall;
|
return invokeFunction(call, receiver, ((VariableAsFunctionResolvedCall) resolvedCall).getFunctionCall());
|
||||||
ResolvedCallWithTrace<FunctionDescriptor> functionCall = variableAsFunctionResolvedCall.getFunctionCall();
|
|
||||||
return invokeFunction(call, receiver, functionCall);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FunctionDescriptor fd = (FunctionDescriptor) resolvedCall.getResultingDescriptor();
|
FunctionDescriptor fd = (FunctionDescriptor) resolvedCall.getResultingDescriptor();
|
||||||
boolean superCall = isSuperCall(call);
|
JetSuperExpression superCallExpression = getSuperCallExpression(call);
|
||||||
|
boolean superCall = superCallExpression != null;
|
||||||
|
|
||||||
if (superCall && !isInterface(fd.getContainingDeclaration())) {
|
if (superCall && !isInterface(fd.getContainingDeclaration())) {
|
||||||
JetSuperExpression expression = getSuperCallExpression(call);
|
ClassDescriptor owner = getSuperCallLabelTarget(superCallExpression);
|
||||||
ClassDescriptor owner = getSuperCallLabelTarget(expression);
|
|
||||||
CodegenContext c = context.findParentContextWithDescriptor(owner);
|
CodegenContext c = context.findParentContextWithDescriptor(owner);
|
||||||
assert c != null : "Couldn't find a context for a super-call: " + fd;
|
assert c != null : "Couldn't find a context for a super-call: " + fd;
|
||||||
if (c != context.getParentContext()) {
|
if (c != context.getParentContext()) {
|
||||||
@@ -1994,15 +1992,26 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
Callable callable = resolveToCallable(fd, superCall);
|
Callable callable = resolveToCallable(fd, superCall);
|
||||||
if (callable instanceof CallableMethod) {
|
if (callable instanceof CallableMethod) {
|
||||||
CallableMethod callableMethod = (CallableMethod) callable;
|
CallableMethod callableMethod = (CallableMethod) callable;
|
||||||
invokeMethodWithArguments(callableMethod, resolvedCall, call, receiver);
|
Type calleeType = callableMethod.getGenerateCalleeType();
|
||||||
|
if (calleeType != null) {
|
||||||
|
assert !callableMethod.isNeedsThis() : "Method should have a receiver: " + resolvedCall.getResultingDescriptor();
|
||||||
|
gen(call.getCalleeExpression(), calleeType);
|
||||||
|
}
|
||||||
|
|
||||||
|
invokeMethodWithArguments(callableMethod, resolvedCall, receiver);
|
||||||
|
|
||||||
Type callReturnType = callableMethod.getSignature().getAsmMethod().getReturnType();
|
Type callReturnType = callableMethod.getSignature().getAsmMethod().getReturnType();
|
||||||
return returnValueAsStackValue(fd, callReturnType);
|
if (callReturnType == Type.VOID_TYPE) return StackValue.none();
|
||||||
|
|
||||||
|
JetType type = fd.getReturnType();
|
||||||
|
assert type != null;
|
||||||
|
Type retType = typeMapper.mapReturnType(type);
|
||||||
|
StackValue.coerce(callReturnType, retType, v);
|
||||||
|
return StackValue.onStack(retType);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
receiver = StackValue.receiver(resolvedCall, receiver, this, null);
|
receiver = StackValue.receiver(resolvedCall, receiver, this, null);
|
||||||
|
|
||||||
IntrinsicMethod intrinsic = (IntrinsicMethod) callable;
|
|
||||||
List<JetExpression> args = new ArrayList<JetExpression>();
|
List<JetExpression> args = new ArrayList<JetExpression>();
|
||||||
for (ValueArgument argument : call.getValueArguments()) {
|
for (ValueArgument argument : call.getValueArguments()) {
|
||||||
args.add(argument.getArgumentExpression());
|
args.add(argument.getArgumentExpression());
|
||||||
@@ -2010,7 +2019,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
|
|
||||||
Type returnType = typeMapper.mapType(resolvedCall.getResultingDescriptor());
|
Type returnType = typeMapper.mapType(resolvedCall.getResultingDescriptor());
|
||||||
|
|
||||||
intrinsic.generate(this, v, returnType, call.getCallElement(), args, receiver);
|
((IntrinsicMethod) callable).generate(this, v, returnType, call.getCallElement(), args, receiver);
|
||||||
return StackValue.onStack(returnType);
|
return StackValue.onStack(returnType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2027,10 +2036,6 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isSuperCall(@NotNull Call call) {
|
|
||||||
return getSuperCallExpression(call) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find the first parent of the current context which corresponds to a subclass of a given class
|
// Find the first parent of the current context which corresponds to a subclass of a given class
|
||||||
@NotNull
|
@NotNull
|
||||||
private static CodegenContext getParentContextSubclassOf(ClassDescriptor descriptor, CodegenContext context) {
|
private static CodegenContext getParentContextSubclassOf(ClassDescriptor descriptor, CodegenContext context) {
|
||||||
@@ -2044,18 +2049,6 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private StackValue returnValueAsStackValue(FunctionDescriptor fd, Type callReturnType) {
|
|
||||||
if (callReturnType != Type.VOID_TYPE) {
|
|
||||||
JetType type = fd.getReturnType();
|
|
||||||
assert type != null;
|
|
||||||
Type retType = typeMapper.mapReturnType(type);
|
|
||||||
StackValue.coerce(callReturnType, retType, v);
|
|
||||||
return StackValue.onStack(retType);
|
|
||||||
}
|
|
||||||
return StackValue.none();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
Callable resolveToCallable(@NotNull FunctionDescriptor fd, boolean superCall) {
|
Callable resolveToCallable(@NotNull FunctionDescriptor fd, boolean superCall) {
|
||||||
IntrinsicMethod intrinsic = state.getIntrinsics().getIntrinsic(fd);
|
IntrinsicMethod intrinsic = state.getIntrinsics().getIntrinsic(fd);
|
||||||
@@ -2092,16 +2085,8 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
public void invokeMethodWithArguments(
|
public void invokeMethodWithArguments(
|
||||||
@NotNull CallableMethod callableMethod,
|
@NotNull CallableMethod callableMethod,
|
||||||
@NotNull ResolvedCall<? extends CallableDescriptor> resolvedCall,
|
@NotNull ResolvedCall<? extends CallableDescriptor> resolvedCall,
|
||||||
@Nullable Call callToGenerateCallee,
|
|
||||||
@NotNull StackValue receiver
|
@NotNull StackValue receiver
|
||||||
) {
|
) {
|
||||||
Type calleeType = callableMethod.getGenerateCalleeType();
|
|
||||||
if (calleeType != null) {
|
|
||||||
assert !callableMethod.isNeedsThis();
|
|
||||||
assert callToGenerateCallee != null : "Call can't be null when generating callee: " + resolvedCall.getResultingDescriptor();
|
|
||||||
gen(callToGenerateCallee.getCalleeExpression(), calleeType);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (resolvedCall instanceof VariableAsFunctionResolvedCall) {
|
if (resolvedCall instanceof VariableAsFunctionResolvedCall) {
|
||||||
resolvedCall = ((VariableAsFunctionResolvedCall) resolvedCall).getFunctionCall();
|
resolvedCall = ((VariableAsFunctionResolvedCall) resolvedCall).getFunctionCall();
|
||||||
}
|
}
|
||||||
@@ -3254,7 +3239,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
|
|
||||||
ConstructorDescriptor originalOfSamAdapter = (ConstructorDescriptor) SamCodegenUtil.getOriginalIfSamAdapter(constructorDescriptor);
|
ConstructorDescriptor originalOfSamAdapter = (ConstructorDescriptor) SamCodegenUtil.getOriginalIfSamAdapter(constructorDescriptor);
|
||||||
CallableMethod method = typeMapper.mapToCallableMethod(originalOfSamAdapter == null ? constructorDescriptor : originalOfSamAdapter);
|
CallableMethod method = typeMapper.mapToCallableMethod(originalOfSamAdapter == null ? constructorDescriptor : originalOfSamAdapter);
|
||||||
invokeMethodWithArguments(method, resolvedCall, null, StackValue.none());
|
invokeMethodWithArguments(method, resolvedCall, StackValue.none());
|
||||||
|
|
||||||
return StackValue.onStack(type);
|
return StackValue.onStack(type);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1563,7 +1563,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
superCallable.invokeWithNotNullAssertion(codegen.v, state, resolvedCall);
|
superCallable.invokeWithNotNullAssertion(codegen.v, state, resolvedCall);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
codegen.invokeMethodWithArguments(superCallable, resolvedCall, null, StackValue.none());
|
codegen.invokeMethodWithArguments(superCallable, resolvedCall, StackValue.none());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1650,7 +1650,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
|
|
||||||
CallableMethod method = typeMapper.mapToCallableMethod((ConstructorDescriptor) resolvedCall.getResultingDescriptor());
|
CallableMethod method = typeMapper.mapToCallableMethod((ConstructorDescriptor) resolvedCall.getResultingDescriptor());
|
||||||
|
|
||||||
codegen.invokeMethodWithArguments(method, resolvedCall, null, StackValue.none());
|
codegen.invokeMethodWithArguments(method, resolvedCall, StackValue.none());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
iv.invokespecial(implClass.getInternalName(), "<init>", "(Ljava/lang/String;I)V");
|
iv.invokespecial(implClass.getInternalName(), "<init>", "(Ljava/lang/String;I)V");
|
||||||
|
|||||||
Reference in New Issue
Block a user