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 @NotNull
public MethodContext intoFunction(FunctionDescriptor descriptor) { public MethodContext intoFunction(FunctionDescriptor descriptor) {
return new MethodContext(descriptor, getContextKind(), this, null, false); return new MethodContext(descriptor, getContextKind(), this, null, false, false);
} }
@NotNull @NotNull
public MethodContext intoInlinedLambda(FunctionDescriptor descriptor) { public MethodContext intoInlinedLambda(FunctionDescriptor descriptor, boolean isCrossInline) {
return new MethodContext(descriptor, getContextKind(), this, null, true); return new MethodContext(descriptor, getContextKind(), this, null, true, isCrossInline);
} }
@NotNull @NotNull
@@ -34,7 +34,7 @@ public class ConstructorContext extends MethodContext {
@NotNull CodegenContext parent, @NotNull CodegenContext parent,
@Nullable MutableClosure closure @Nullable MutableClosure closure
) { ) {
super(contextDescriptor, kind, parent, closure, false); super(contextDescriptor, kind, parent, closure, false, false);
} }
@Override @Override
@@ -39,18 +39,21 @@ public class MethodContext extends CodegenContext<CallableMemberDescriptor> {
// Note: in case of code inside property accessors, functionDescriptor will be that accessor, // Note: in case of code inside property accessors, functionDescriptor will be that accessor,
// but CodegenContext#contextDescriptor will be the corresponding property // but CodegenContext#contextDescriptor will be the corresponding property
private final FunctionDescriptor functionDescriptor; private final FunctionDescriptor functionDescriptor;
private boolean isCrossInline;
protected MethodContext( protected MethodContext(
@NotNull FunctionDescriptor functionDescriptor, @NotNull FunctionDescriptor functionDescriptor,
@NotNull OwnerKind contextKind, @NotNull OwnerKind contextKind,
@NotNull CodegenContext parentContext, @NotNull CodegenContext parentContext,
@Nullable MutableClosure closure, @Nullable MutableClosure closure,
boolean isInliningLambda boolean isInliningLambda,
boolean isCrossInline
) { ) {
super(JvmCodegenUtil.getDirectMember(functionDescriptor), contextKind, parentContext, closure, super(JvmCodegenUtil.getDirectMember(functionDescriptor), contextKind, parentContext, closure,
parentContext.hasThisDescriptor() ? parentContext.getThisDescriptor() : null, null); parentContext.hasThisDescriptor() ? parentContext.getThisDescriptor() : null, null);
this.isInliningLambda = isInliningLambda; this.isInliningLambda = isInliningLambda;
this.functionDescriptor = functionDescriptor; this.functionDescriptor = functionDescriptor;
this.isCrossInline = isCrossInline;
} }
@NotNull @NotNull
@@ -310,7 +310,7 @@ public class InlineCodegen extends CallGenerator {
MethodContext parentContext = codegen.getContext(); 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); JvmMethodSignature jvmMethodSignature = typeMapper.mapSignature(descriptor);
Method asmMethod = jvmMethodSignature.getAsmMethod(); Method asmMethod = jvmMethodSignature.getAsmMethod();
@@ -559,13 +559,14 @@ public class InlineCodegen extends CallGenerator {
deparenthesized instanceof KtCallableReferenceExpression; 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); KtExpression lambda = KtPsiUtil.deparenthesize(expression);
assert isInlinableParameterExpression(lambda) : "Couldn't find inline expression in " + expression.getText(); 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); closureInfo.setLambda(info);
expressionMap.put(closureInfo.getIndex(), info); expressionMap.put(closureInfo.getIndex(), info);
} }
@@ -638,7 +639,7 @@ public class InlineCodegen extends CallGenerator {
int parameterIndex int parameterIndex
) { ) {
if (isInliningParameter(argumentExpression, valueParameterDescriptor)) { if (isInliningParameter(argumentExpression, valueParameterDescriptor)) {
rememberClosure(argumentExpression, parameterType, valueParameterDescriptor.getIndex()); rememberClosure(argumentExpression, parameterType, valueParameterDescriptor);
} }
else { else {
StackValue value = codegen.gen(argumentExpression); StackValue value = codegen.gen(argumentExpression);
@@ -50,6 +50,8 @@ public class LambdaInfo implements CapturedParamOwner, LabelOwner {
private final CalculatedClosure closure; private final CalculatedClosure closure;
public final boolean isCrossInline;
private SMAPAndMethodNode node; private SMAPAndMethodNode node;
private List<CapturedParamDesc> capturedVars; private List<CapturedParamDesc> capturedVars;
@@ -60,7 +62,8 @@ public class LambdaInfo implements CapturedParamOwner, LabelOwner {
private final Type closureClassType; 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 ? this.expression = expr instanceof KtLambdaExpression ?
((KtLambdaExpression) expr).getFunctionLiteral() : expr; ((KtLambdaExpression) expr).getFunctionLiteral() : expr;