From d6feea6a1740b7d98233571556a1bea2676a17a2 Mon Sep 17 00:00:00 2001 From: Mikhael Bogdanov Date: Fri, 31 Jan 2014 12:06:42 +0400 Subject: [PATCH] Identity fix, removed primitive box/unbox --- .../jet/codegen/ExpressionCodegen.java | 8 +++++--- .../jet/codegen/asm/InlineCodegen.java | 17 +++++++++++++---- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java index 9c017c89f5d..27616b44e62 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java @@ -1368,10 +1368,12 @@ public class ExpressionCodegen extends JetVisitor implem ClassDescriptor captureThis = closure.getCaptureThis(); if (captureThis != null) { StackValue thisOrOuter = generateThisOrOuter(captureThis, false); - if (inliner.shouldPutValue(OBJECT_TYPE, thisOrOuter, context, null)) { - thisOrOuter.put(OBJECT_TYPE, v); + + assert !isPrimitive(thisOrOuter.type) : "This or outer should be non primitive: " + thisOrOuter.type; + if (inliner.shouldPutValue(thisOrOuter.type, thisOrOuter, context, null)) { + thisOrOuter.put(thisOrOuter.type, v); } - inliner.putCapturedInLocal(OBJECT_TYPE, thisOrOuter, null, paramIndex++); + inliner.putCapturedInLocal(thisOrOuter.type, thisOrOuter, null, paramIndex++); } JetType captureReceiver = closure.getCaptureReceiverType(); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/asm/InlineCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/asm/InlineCodegen.java index bd43f267ed7..9c4b08b3f62 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/asm/InlineCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/asm/InlineCodegen.java @@ -52,6 +52,7 @@ import java.io.StringWriter; import java.util.*; import static org.jetbrains.jet.codegen.AsmUtil.getMethodAsmFlags; +import static org.jetbrains.jet.codegen.AsmUtil.isPrimitive; import static org.jetbrains.jet.codegen.binding.CodegenBinding.asmTypeForAnonymousClass; public class InlineCodegen implements ParentCodegenAware, Inliner { @@ -236,13 +237,13 @@ public class InlineCodegen implements ParentCodegenAware, Inliner { @Override - public void putInLocal(Type type, StackValue stackValue, ValueParameterDescriptor valueParameterDescriptor) { + public void putInLocal(@NotNull Type type, @Nullable StackValue stackValue, ValueParameterDescriptor valueParameterDescriptor) { putCapturedInLocal(type, stackValue, valueParameterDescriptor, -1); } @Override public void putCapturedInLocal( - Type type, StackValue stackValue, ValueParameterDescriptor valueParameterDescriptor, int index + @NotNull Type type, @Nullable StackValue stackValue, @Nullable ValueParameterDescriptor valueParameterDescriptor, int index ) { if (!disabled && notSeparateInline && Type.VOID_TYPE != type) { //TODO remap only inlinable closure => otherwise we could get a lot of problem @@ -261,7 +262,7 @@ public class InlineCodegen implements ParentCodegenAware, Inliner { } @Override - public boolean shouldPutValue(Type type, StackValue stackValue, MethodContext context, ValueParameterDescriptor descriptor) { + public boolean shouldPutValue(@NotNull Type type, @Nullable StackValue stackValue, MethodContext context, ValueParameterDescriptor descriptor) { //boolean isInline = true/*context.isInlineFunction() || context.getParentContext() instanceof ClosureContext*/; //if (stackValue != null && isInline && stackValue instanceof StackValue.Local) { // if (isInvokeOnInlinable(type.getClassName(), "invoke") && (descriptor == null || !InlineUtil.hasNoinlineAnnotation(descriptor))) { @@ -269,7 +270,15 @@ public class InlineCodegen implements ParentCodegenAware, Inliner { // return false; // } //} - boolean shouldPut = false == (stackValue != null && stackValue instanceof StackValue.Local); + + //remap only inline functions (and maybe non primitives) + //TODO - clean asserion and remapping logic + if (stackValue == null || isPrimitive(type) ^ isPrimitive(stackValue.type)) { + //don't remap boxing/unboxing primitives - lost identity and perfomance + return true; + } + + boolean shouldPut = !(stackValue != null && stackValue instanceof StackValue.Local); if (shouldPut) { //we could recapture field of anonymous objects cause they couldn't change boolean isInlineClosure = codegen.getContext().isInlineClosure();