diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java index a44c5212b2c..e8bd90537af 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java @@ -1350,7 +1350,7 @@ public class ExpressionCodegen extends JetVisitor implem Type[] argumentTypes = superCallable.getAsmMethod().getArgumentTypes(); ResolvedCall resolvedCall = bindingContext.get(BindingContext.RESOLVED_CALL, superCall.getCalleeExpression()); assert resolvedCall != null; - pushMethodArguments(resolvedCall, Arrays.asList(argumentTypes), null); + pushMethodArguments(resolvedCall, Arrays.asList(argumentTypes), defaulCallGenerator); } v.invokespecial(type.getInternalName(), "", constructor.getAsmMethod().getDescriptor()); @@ -1984,7 +1984,7 @@ public class ExpressionCodegen extends JetVisitor implem @NotNull public StackValue invokeFunction( - @NotNull Call call, + Call call, StackValue receiver, ResolvedCall resolvedCall ) { @@ -2307,11 +2307,11 @@ public class ExpressionCodegen extends JetVisitor implem return false; } - public int pushMethodArguments(@NotNull ResolvedCall resolvedCall, List valueParameterTypes, CallGenerator callGenerator) { + public int pushMethodArguments(@NotNull ResolvedCall resolvedCall, List valueParameterTypes, @NotNull CallGenerator callGenerator) { return pushMethodArguments(resolvedCall, valueParameterTypes, false, callGenerator); } - private int pushMethodArguments(@NotNull ResolvedCall resolvedCall, List valueParameterTypes, boolean skipLast, CallGenerator callGenerator) { + private int pushMethodArguments(@NotNull ResolvedCall resolvedCall, List valueParameterTypes, boolean skipLast, @NotNull CallGenerator callGenerator) { @SuppressWarnings("unchecked") List valueArguments = resolvedCall.getValueArgumentsByIndex(); CallableDescriptor fd = resolvedCall.getResultingDescriptor(); @@ -2321,7 +2321,6 @@ public class ExpressionCodegen extends JetVisitor implem throw new IllegalStateException(); } - callGenerator = callGenerator != null ? callGenerator : defaulCallGenerator; int mask = 0; for (Iterator iterator = valueParameters.iterator(); iterator.hasNext(); ) { @@ -3409,7 +3408,7 @@ public class ExpressionCodegen extends JetVisitor implem if (callable instanceof CallableMethod) { genThisAndReceiverFromResolvedCall(receiver, resolvedCall, (CallableMethod) callable); boolean skipLast = !isGetter; - pushMethodArguments(resolvedCall, ((CallableMethod) callable).getValueParameterTypes(), skipLast, null); + pushMethodArguments(resolvedCall, ((CallableMethod) callable).getValueParameterTypes(), skipLast, defaulCallGenerator); } else { gen(array, arrayType); // intrinsic method diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/context/CodegenContext.java b/compiler/backend/src/org/jetbrains/jet/codegen/context/CodegenContext.java index 571a77709cf..e0377a07b1e 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/context/CodegenContext.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/context/CodegenContext.java @@ -180,7 +180,11 @@ public abstract class CodegenContext { @NotNull public MethodContext intoFunction(FunctionDescriptor descriptor) { - return new MethodContext(descriptor, getContextKind(), this, null); + return new MethodContext(descriptor, getContextKind(), this, null, false); + } + + public MethodContext intoInlinedLambda(FunctionDescriptor descriptor) { + return new MethodContext(descriptor, getContextKind(), this, null, true); } @NotNull @@ -459,4 +463,4 @@ public abstract class CodegenContext { public CodegenContext findChildContext(@NotNull DeclarationDescriptor child) { return childContexts == null ? null : childContexts.get(child); } -} \ No newline at end of file +} diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/context/ConstructorContext.java b/compiler/backend/src/org/jetbrains/jet/codegen/context/ConstructorContext.java index 7f228ac6dfd..6e6349342b5 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/context/ConstructorContext.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/context/ConstructorContext.java @@ -34,7 +34,7 @@ public class ConstructorContext extends MethodContext { @NotNull CodegenContext parent, @Nullable MutableClosure closure ) { - super(contextDescriptor, kind, parent, closure); + super(contextDescriptor, kind, parent, closure, false); } @Override diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/context/MethodContext.java b/compiler/backend/src/org/jetbrains/jet/codegen/context/MethodContext.java index 7af24f65666..06740deb4cb 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/context/MethodContext.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/context/MethodContext.java @@ -30,26 +30,20 @@ public class MethodContext extends CodegenContext { private Label methodStartLabel; - private boolean isInlineClosure; - - public MethodContext( - @NotNull FunctionDescriptor contextType, - @NotNull OwnerKind contextKind, - @NotNull CodegenContext parentContext - ) { - this(contextType, contextKind, parentContext, null); - } + private final boolean isInliningLambda; protected MethodContext( @NotNull FunctionDescriptor contextDescriptor, @NotNull OwnerKind contextKind, @NotNull CodegenContext parentContext, - @Nullable MutableClosure closure + @Nullable MutableClosure closure, + boolean isInliningLambda ) { super(contextDescriptor instanceof PropertyAccessorDescriptor ? ((PropertyAccessorDescriptor) contextDescriptor).getCorrespondingProperty() : contextDescriptor, contextKind, parentContext, closure, parentContext.hasThisDescriptor() ? parentContext.getThisDescriptor() : null, null); + this.isInliningLambda = isInliningLambda; } @Override @@ -96,16 +90,12 @@ public class MethodContext extends CodegenContext { return false; } - public void setInlineClosure(boolean isInlineClosure) { - this.isInlineClosure = isInlineClosure; - } - - public boolean isInlineClosure() { - return isInlineClosure; + public boolean isInliningLambda() { + return isInliningLambda; } public boolean isSpecialStackValue(StackValue stackValue) { - if (isInlineClosure && stackValue instanceof StackValue.Composed) { + if (isInliningLambda && stackValue instanceof StackValue.Composed) { StackValue prefix = ((StackValue.Composed) stackValue).prefix; StackValue suffix = ((StackValue.Composed) stackValue).suffix; if (prefix instanceof StackValue.Local && ((StackValue.Local) prefix).index == 0) { diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/inline/InlineCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/inline/InlineCodegen.java index f27c79503d2..62d8cb96096 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/inline/InlineCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/inline/InlineCodegen.java @@ -213,18 +213,17 @@ public class InlineCodegen implements ParentCodegenAware, CallGenerator { private void generateClosuresBodies() { for (LambdaInfo info : expressionMap.values()) { - info.setNode(generateClosureBody(info)); + info.setNode(generateLambdaBody(info)); } } - private MethodNode generateClosureBody(LambdaInfo info) { + private MethodNode generateLambdaBody(LambdaInfo info) { JetFunctionLiteral declaration = info.getFunctionLiteral(); FunctionDescriptor descriptor = info.getFunctionDescriptor(); MethodContext parentContext = codegen.getContext(); - MethodContext context = parentContext.intoClosure(descriptor, codegen, typeMapper).intoFunction(descriptor); - context.setInlineClosure(true); + MethodContext context = parentContext.intoClosure(descriptor, codegen, typeMapper).intoInlinedLambda(descriptor); JvmMethodSignature jvmMethodSignature = typeMapper.mapSignature(descriptor); Method asmMethod = jvmMethodSignature.getAsmMethod(); @@ -294,7 +293,7 @@ public class InlineCodegen implements ParentCodegenAware, CallGenerator { if (stackValue instanceof StackValue.Composed) { //see: Method.isSpecialStackValue: go through aload 0 - if (codegen.getContext().isInlineClosure() && codegen.getContext().getContextDescriptor() instanceof AnonymousFunctionDescriptor) { + if (codegen.getContext().isInliningLambda() && codegen.getContext().getContextDescriptor() instanceof AnonymousFunctionDescriptor) { if (descriptor != null && !InlineUtil.hasNoinlineAnnotation(descriptor)) { //TODO: check type of context return false; @@ -425,11 +424,11 @@ public class InlineCodegen implements ParentCodegenAware, CallGenerator { return parent.intoFunction((FunctionDescriptor) descriptor); } - throw new IllegalStateException("Coudn't build context for " + descriptorName(descriptor)); + throw new IllegalStateException("Couldn't build context for " + descriptorName(descriptor)); } private static boolean isStaticMethod(FunctionDescriptor functionDescriptor, MethodContext context) { - return (getMethodAsmFlags(functionDescriptor, context.getContextKind()) & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC; + return (getMethodAsmFlags(functionDescriptor, context.getContextKind()) & Opcodes.ACC_STATIC) != 0; } @NotNull diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/StupidSync.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/StupidSync.java index 289be1ef3ae..415c87dd73f 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/StupidSync.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/StupidSync.java @@ -52,7 +52,7 @@ public class StupidSync extends IntrinsicMethod { assert resolvedCall != null : "Resolved call for " + element.getText() + " should be not null"; - codegen.pushMethodArguments(resolvedCall, Arrays.asList(OBJECT_TYPE, FUNCTION0_TYPE), null); + codegen.pushMethodArguments(resolvedCall, Arrays.asList(OBJECT_TYPE, FUNCTION0_TYPE), codegen.defaulCallGenerator); v.invokestatic("kotlin/jvm/internal/Intrinsics", "stupidSync", Type.getMethodDescriptor(OBJECT_TYPE, OBJECT_TYPE, FUNCTION0_TYPE)); return OBJECT_TYPE; } diff --git a/core/descriptors/src/org/jetbrains/jet/lang/types/lang/InlineUtil.java b/core/descriptors/src/org/jetbrains/jet/lang/types/lang/InlineUtil.java index 523de25ba45..338956ddb1b 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/types/lang/InlineUtil.java +++ b/core/descriptors/src/org/jetbrains/jet/lang/types/lang/InlineUtil.java @@ -37,11 +37,6 @@ public class InlineUtil { public static boolean DEFAULT_INLINE_FLAG_FOR_STUB = false; /*always false*/ - @NotNull - public static InlineStrategy getInlineType(@NotNull Annotated annotated) { - return getInlineType(annotated.getAnnotations()); - } - public static boolean hasNoinlineAnnotation(@NotNull CallableDescriptor valueParameterDescriptor) { KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance(); return KotlinBuiltIns.containsAnnotation(valueParameterDescriptor, builtIns.getNoinlineClassAnnotation()); @@ -62,6 +57,7 @@ public class InlineUtil { else { assert argument instanceof EnumValue : "Inline annotation parameter should be inline entry but was: " + argument + "!"; ClassDescriptor value = ((EnumValue) argument).getValue(); + assert value != null : "Value for enum value should be not null " + argument; String name = value.getName().asString(); return name.equals(InlineStrategy.IN_PLACE.name()) ? InlineStrategy.IN_PLACE : InlineStrategy.AS_FUNCTION; }