Substitute Call with JetElement in InliningContext to support default inlining (there is no call)
This commit is contained in:
@@ -2070,14 +2070,9 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
@NotNull StackValue receiver
|
||||
) {
|
||||
CallableDescriptor descriptor = resolvedCall.getResultingDescriptor();
|
||||
boolean isInline = state.isInlineEnabled() &&
|
||||
call != null &&
|
||||
descriptor instanceof SimpleFunctionDescriptor &&
|
||||
((SimpleFunctionDescriptor) descriptor).getInlineStrategy().isInline();
|
||||
JetElement callElement = call != null ? call.getCallElement() : null;
|
||||
|
||||
CallGenerator callGenerator = !isInline ? defaultCallGenerator :
|
||||
new InlineCodegen(this, state, (SimpleFunctionDescriptor) DescriptorUtils.unwrapFakeOverride(
|
||||
(CallableMemberDescriptor) descriptor.getOriginal()), call);
|
||||
CallGenerator callGenerator = getOrCreateCallGenerator(descriptor, callElement);
|
||||
|
||||
if (resolvedCall instanceof VariableAsFunctionResolvedCall) {
|
||||
resolvedCall = ((VariableAsFunctionResolvedCall) resolvedCall).getFunctionCall();
|
||||
@@ -2096,6 +2091,16 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
callGenerator.genCall(callableMethod, resolvedCall, mask, this);
|
||||
}
|
||||
|
||||
protected CallGenerator getOrCreateCallGenerator(CallableDescriptor descriptor, JetElement callElement) {
|
||||
boolean isInline = state.isInlineEnabled() &&
|
||||
descriptor instanceof SimpleFunctionDescriptor &&
|
||||
((SimpleFunctionDescriptor) descriptor).getInlineStrategy().isInline();
|
||||
|
||||
return !isInline || callElement == null ? defaultCallGenerator :
|
||||
new InlineCodegen(this, state, (SimpleFunctionDescriptor) DescriptorUtils.unwrapFakeOverride(
|
||||
(CallableMemberDescriptor) descriptor.getOriginal()), callElement);
|
||||
}
|
||||
|
||||
public void generateFromResolvedCall(@NotNull ReceiverValue descriptor, @NotNull Type type) {
|
||||
if (descriptor instanceof ClassReceiver) {
|
||||
Type exprType = asmType(descriptor.getType());
|
||||
|
||||
+1
-1
@@ -275,7 +275,7 @@ public class AnonymousObjectTransformer {
|
||||
|
||||
@NotNull
|
||||
private ClassBuilder createClassBuilder() {
|
||||
return new RemappingClassBuilder(state.getFactory().forLambdaInlining(newLambdaType, inliningContext.getRoot().call.getCallElement().getContainingFile()),
|
||||
return new RemappingClassBuilder(state.getFactory().forLambdaInlining(newLambdaType, inliningContext.getRoot().callElement.getContainingFile()),
|
||||
new TypeRemapper(inliningContext.typeMapping));
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ public class InlineCodegen implements CallGenerator {
|
||||
|
||||
private final SimpleFunctionDescriptor functionDescriptor;
|
||||
private final JvmMethodSignature jvmSignature;
|
||||
private final Call call;
|
||||
private final JetElement callElement;
|
||||
private final MethodContext context;
|
||||
private final ExpressionCodegen codegen;
|
||||
private final FrameMap originalFunctionFrame;
|
||||
@@ -81,14 +81,14 @@ public class InlineCodegen implements CallGenerator {
|
||||
@NotNull ExpressionCodegen codegen,
|
||||
@NotNull GenerationState state,
|
||||
@NotNull SimpleFunctionDescriptor functionDescriptor,
|
||||
@NotNull Call call
|
||||
@NotNull JetElement callElement
|
||||
) {
|
||||
assert functionDescriptor.getInlineStrategy().isInline() : "InlineCodegen could inline only inline function but " + functionDescriptor;
|
||||
|
||||
this.state = state;
|
||||
this.typeMapper = state.getTypeMapper();
|
||||
this.codegen = codegen;
|
||||
this.call = call;
|
||||
this.callElement = callElement;
|
||||
this.functionDescriptor = functionDescriptor.getOriginal();
|
||||
bindingContext = codegen.getBindingContext();
|
||||
initialFrameSize = codegen.getFrameMap().getCurrentSize();
|
||||
@@ -126,7 +126,7 @@ public class InlineCodegen implements CallGenerator {
|
||||
functionDescriptor.getName() +
|
||||
"' into \n" + (element != null ? element.getText() : "null psi element " + this.codegen.getContext().getContextDescriptor()) +
|
||||
(generateNodeText ? ("\ncause: " + getNodeText(node)) : ""),
|
||||
e, call.getCallElement());
|
||||
e, callElement);
|
||||
}
|
||||
|
||||
|
||||
@@ -201,10 +201,10 @@ public class InlineCodegen implements CallGenerator {
|
||||
codegen.getInlineNameGenerator()
|
||||
.subGenerator(functionDescriptor.getName().asString()),
|
||||
codegen.getContext(),
|
||||
call,
|
||||
callElement,
|
||||
codegen.getParentCodegen().getClassName());
|
||||
|
||||
MethodInliner inliner = new MethodInliner(node, parameters, info, new FieldRemapper(null, null, parameters), isSameModule, "Method inlining " + call.getCallElement().getText()); //with captured
|
||||
MethodInliner inliner = new MethodInliner(node, parameters, info, new FieldRemapper(null, null, parameters), isSameModule, "Method inlining " + callElement.getText()); //with captured
|
||||
|
||||
LocalVarRemapper remapper = new LocalVarRemapper(parameters, initialFrameSize);
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.codegen.context.CodegenContext;
|
||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||
import org.jetbrains.jet.lang.psi.Call;
|
||||
import org.jetbrains.jet.lang.psi.JetElement;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
@@ -28,21 +30,20 @@ public class RootInliningContext extends InliningContext {
|
||||
|
||||
public final CodegenContext startContext;
|
||||
|
||||
@NotNull
|
||||
private final String classNameToInline;
|
||||
|
||||
public final Call call;
|
||||
public final JetElement callElement;
|
||||
|
||||
public RootInliningContext(
|
||||
@NotNull Map<Integer, LambdaInfo> map,
|
||||
@NotNull GenerationState state,
|
||||
@NotNull NameGenerator nameGenerator,
|
||||
@NotNull CodegenContext startContext,
|
||||
@NotNull Call call,
|
||||
@NotNull JetElement callElement,
|
||||
@NotNull String classNameToInline
|
||||
) {
|
||||
super(null, map, state, nameGenerator, Collections.<String, String>emptyMap(), false, false);
|
||||
this.call = call;
|
||||
this.callElement = callElement;
|
||||
this.startContext = startContext;
|
||||
this.classNameToInline = classNameToInline;
|
||||
}
|
||||
@@ -52,6 +53,7 @@ public class RootInliningContext extends InliningContext {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getClassNameToInline() {
|
||||
return classNameToInline;
|
||||
|
||||
Reference in New Issue
Block a user