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