Added crossinline field to MethodContext

This commit is contained in:
Michael Bogdanov
2015-12-14 17:30:07 +03:00
parent b0a7706812
commit 033698c51d
5 changed files with 18 additions and 11 deletions
@@ -297,12 +297,12 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
@NotNull
public MethodContext intoFunction(FunctionDescriptor descriptor) {
return new MethodContext(descriptor, getContextKind(), this, null, false);
return new MethodContext(descriptor, getContextKind(), this, null, false, false);
}
@NotNull
public MethodContext intoInlinedLambda(FunctionDescriptor descriptor) {
return new MethodContext(descriptor, getContextKind(), this, null, true);
public MethodContext intoInlinedLambda(FunctionDescriptor descriptor, boolean isCrossInline) {
return new MethodContext(descriptor, getContextKind(), this, null, true, isCrossInline);
}
@NotNull
@@ -34,7 +34,7 @@ public class ConstructorContext extends MethodContext {
@NotNull CodegenContext parent,
@Nullable MutableClosure closure
) {
super(contextDescriptor, kind, parent, closure, false);
super(contextDescriptor, kind, parent, closure, false, false);
}
@Override
@@ -39,18 +39,21 @@ public class MethodContext extends CodegenContext<CallableMemberDescriptor> {
// Note: in case of code inside property accessors, functionDescriptor will be that accessor,
// but CodegenContext#contextDescriptor will be the corresponding property
private final FunctionDescriptor functionDescriptor;
private boolean isCrossInline;
protected MethodContext(
@NotNull FunctionDescriptor functionDescriptor,
@NotNull OwnerKind contextKind,
@NotNull CodegenContext parentContext,
@Nullable MutableClosure closure,
boolean isInliningLambda
boolean isInliningLambda,
boolean isCrossInline
) {
super(JvmCodegenUtil.getDirectMember(functionDescriptor), contextKind, parentContext, closure,
parentContext.hasThisDescriptor() ? parentContext.getThisDescriptor() : null, null);
this.isInliningLambda = isInliningLambda;
this.functionDescriptor = functionDescriptor;
this.isCrossInline = isCrossInline;
}
@NotNull
@@ -310,7 +310,7 @@ public class InlineCodegen extends CallGenerator {
MethodContext parentContext = codegen.getContext();
MethodContext context = parentContext.intoClosure(descriptor, codegen, typeMapper).intoInlinedLambda(descriptor);
MethodContext context = parentContext.intoClosure(descriptor, codegen, typeMapper).intoInlinedLambda(descriptor, info.isCrossInline);
JvmMethodSignature jvmMethodSignature = typeMapper.mapSignature(descriptor);
Method asmMethod = jvmMethodSignature.getAsmMethod();
@@ -559,13 +559,14 @@ public class InlineCodegen extends CallGenerator {
deparenthesized instanceof KtCallableReferenceExpression;
}
public void rememberClosure(KtExpression expression, Type type, int parameterIndex) {
public void rememberClosure(KtExpression expression, Type type, ValueParameterDescriptor parameter) {
KtExpression lambda = KtPsiUtil.deparenthesize(expression);
assert isInlinableParameterExpression(lambda) : "Couldn't find inline expression in " + expression.getText();
LambdaInfo info = new LambdaInfo(lambda, typeMapper);
ParameterInfo closureInfo = invocationParamBuilder.addNextValueParameter(type, true, null, parameterIndex);
LambdaInfo info = new LambdaInfo(lambda, typeMapper, parameter.isCrossinline());
ParameterInfo closureInfo = invocationParamBuilder.addNextValueParameter(type, true, null, parameter.getIndex());
closureInfo.setLambda(info);
expressionMap.put(closureInfo.getIndex(), info);
}
@@ -638,7 +639,7 @@ public class InlineCodegen extends CallGenerator {
int parameterIndex
) {
if (isInliningParameter(argumentExpression, valueParameterDescriptor)) {
rememberClosure(argumentExpression, parameterType, valueParameterDescriptor.getIndex());
rememberClosure(argumentExpression, parameterType, valueParameterDescriptor);
}
else {
StackValue value = codegen.gen(argumentExpression);
@@ -50,6 +50,8 @@ public class LambdaInfo implements CapturedParamOwner, LabelOwner {
private final CalculatedClosure closure;
public final boolean isCrossInline;
private SMAPAndMethodNode node;
private List<CapturedParamDesc> capturedVars;
@@ -60,7 +62,8 @@ public class LambdaInfo implements CapturedParamOwner, LabelOwner {
private final Type closureClassType;
LambdaInfo(@NotNull KtExpression expr, @NotNull JetTypeMapper typeMapper) {
LambdaInfo(@NotNull KtExpression expr, @NotNull JetTypeMapper typeMapper, boolean isCrossInline) {
this.isCrossInline = isCrossInline;
this.expression = expr instanceof KtLambdaExpression ?
((KtLambdaExpression) expr).getFunctionLiteral() : expr;