Fix for KT-14162: Support @InlineOnly on inline properties

#KT-14162 Fixed
This commit is contained in:
Mikhael Bogdanov
2017-01-03 16:32:52 +01:00
parent e920166879
commit dc4cdbf82d
15 changed files with 219 additions and 12 deletions
@@ -438,7 +438,9 @@ public class PropertyCodegen {
@Nullable KtPropertyAccessor accessor,
@NotNull PropertyAccessorDescriptor accessorDescriptor
) {
if (context instanceof MultifileClassFacadeContext && Visibilities.isPrivate(accessorDescriptor.getVisibility())) {
if (context instanceof MultifileClassFacadeContext &&
(Visibilities.isPrivate(accessorDescriptor.getVisibility()) ||
AsmUtil.getVisibilityAccessFlag(accessorDescriptor) == Opcodes.ACC_PRIVATE)) {
return;
}
@@ -69,7 +69,7 @@ import java.util.*;
import static org.jetbrains.kotlin.codegen.AsmUtil.getMethodAsmFlags;
import static org.jetbrains.kotlin.codegen.AsmUtil.isPrimitive;
import static org.jetbrains.kotlin.codegen.inline.InlineCodegenUtil.*;
import static org.jetbrains.kotlin.descriptors.annotations.AnnotationUtilKt.hasInlineOnlyAnnotation;
import static org.jetbrains.kotlin.descriptors.annotations.AnnotationUtilKt.isInlineOnly;
import static org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils.isFunctionLiteral;
public class InlineCodegen extends CallGenerator {
@@ -436,7 +436,7 @@ public class InlineCodegen extends CallGenerator {
node, parameters, info, new FieldRemapper(null, null, parameters), isSameModule,
"Method inlining " + callElement.getText(),
createNestedSourceMapper(nodeAndSmap, sourceMapper), info.getCallSiteInfo(),
hasInlineOnlyAnnotation(functionDescriptor) ? new InlineOnlySmapSkipper(codegen) : null
isInlineOnly(functionDescriptor) ? new InlineOnlySmapSkipper(codegen) : null
); //with captured
LocalVarRemapper remapper = new LocalVarRemapper(parameters, initialFrameSize);
@@ -0,0 +1,30 @@
// FILE: 1.kt
// WITH_RUNTIME
package test
inline fun stub() {
}
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@kotlin.internal.InlineOnly
inline val prop: String
get() = "OK"
// FILE: 2.kt
import test.*
fun box(): String {
return prop
}
// FILE: 2.smap
SMAP
2.kt
Kotlin
*S Kotlin
*F
+ 1 2.kt
_2Kt
*L
1#1,8:1
*E
@@ -0,0 +1,39 @@
// FILE: 1.kt
// WITH_REFLECT
package test
inline val <reified T : Any> T.className: String; get() = T::class.java.simpleName
// FILE: 2.kt
import test.*
fun box(): String {
val z = "OK".className
if (z != "String") return "fail: $z"
return "OK"
}
// FILE: 2.smap
SMAP
2.kt
Kotlin
*S Kotlin
*F
+ 1 2.kt
_2Kt
+ 2 1.kt
test/_1Kt
*L
1#1,12:1
5#2:13
*E
*S KotlinDebug
*F
+ 1 2.kt
_2Kt
*L
6#1:13
*E
@@ -5,8 +5,13 @@ package test
fun foo() {
inlineOnly<String>()
inlineOnlyAnnotated()
}
// No method should be generated in multifile facade for 'inlineOnly'
// Because 'inlineOnly' is private in file part (because it's inline-only) and can't be delegated from facade
public inline fun <reified T> inlineOnly() {}
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@kotlin.internal.InlineOnly
inline fun inlineOnlyAnnotated() { }
@@ -7,4 +7,5 @@ public final class test/Foo {
synthetic final class test/Foo__InlineOnlyMultifileKt {
public final static method foo(): void
private final static method inlineOnly(): void
}
private final static @kotlin.internal.InlineOnly method inlineOnlyAnnotated(): void
}
@@ -0,0 +1,20 @@
// WITH_RUNTIME
@file:[JvmName("Foo") JvmMultifileClass]
package test
fun foo() {
prop
"".extProp
}
// No method should be generated in multifile facade for 'inlineOnly'
// Because 'inlineOnly' is private in file part (because it's inline-only) and can't be delegated from facade
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@kotlin.internal.InlineOnly
inline var prop: String
get() = "12"
set(value) {}
inline val <reified Z> Z.extProp: String
get() = "123"
@@ -0,0 +1,13 @@
@kotlin.Metadata
public final class test/Foo {
public final static method foo(): void
}
@kotlin.Metadata
synthetic final class test/Foo__InlineOnlyPropertyMultifileKt {
public final static method foo(): void
private final static method getExtProp(p0: java.lang.Object): java.lang.String
private final static method getProp(): java.lang.String
private synthetic deprecated static @kotlin.internal.InlineOnly method prop$annotations(): void
private final static method setProp(p0: java.lang.String): void
}
@@ -0,0 +1,38 @@
// WITH_RUNTIME
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@kotlin.internal.InlineOnly
inline var prop: String
get() = "12"
set(value) {}
inline var prop2: String
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@kotlin.internal.InlineOnly
get() = "12"
set(value) {}
inline val <reified Z> Z.extProp: String
get() = "123"
class Foo {
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@kotlin.internal.InlineOnly
inline var prop: String
get() = "12"
set(value) {}
inline var prop2: String
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@kotlin.internal.InlineOnly
get() = "12"
set(value) {}
inline val <reified Z> Z.extProp: String
get() = "123"
}
@@ -0,0 +1,20 @@
@kotlin.Metadata
public final class Foo {
public method <init>(): void
private final method getExtProp(p0: java.lang.Object): java.lang.String
private final method getProp(): java.lang.String
private final @kotlin.internal.InlineOnly method getProp2(): java.lang.String
private synthetic deprecated static @kotlin.internal.InlineOnly method prop$annotations(): void
private final method setProp(p0: java.lang.String): void
public final method setProp2(@org.jetbrains.annotations.NotNull p0: java.lang.String): void
}
@kotlin.Metadata
public final class InlineOnlyPropertyKt {
private final static method getExtProp(p0: java.lang.Object): java.lang.String
private final static method getProp(): java.lang.String
private final static @kotlin.internal.InlineOnly method getProp2(): java.lang.String
private synthetic deprecated static @kotlin.internal.InlineOnly method prop$annotations(): void
private final static method setProp(p0: java.lang.String): void
public final static method setProp2(@org.jetbrains.annotations.NotNull p0: java.lang.String): void
}
@@ -2236,11 +2236,23 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo
doTest(fileName);
}
@TestMetadata("noSmapWithProperty.kt")
public void testNoSmapWithProperty() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/smap/inlineOnly/noSmapWithProperty.kt");
doTest(fileName);
}
@TestMetadata("reified.kt")
public void testReified() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/smap/inlineOnly/reified.kt");
doTest(fileName);
}
@TestMetadata("reifiedProperty.kt")
public void testReifiedProperty() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/smap/inlineOnly/reifiedProperty.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/codegen/boxInline/smap/newsmap")
@@ -78,6 +78,18 @@ public class BytecodeListingTestGenerated extends AbstractBytecodeListingTest {
doTest(fileName);
}
@TestMetadata("inlineOnlyProperty.kt")
public void testInlineOnlyProperty() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeListing/inlineOnlyProperty.kt");
doTest(fileName);
}
@TestMetadata("InlineOnlyPropertyMultifile.kt")
public void testInlineOnlyPropertyMultifile() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeListing/InlineOnlyPropertyMultifile.kt");
doTest(fileName);
}
@TestMetadata("noCollectionStubMethodsInInterface.kt")
public void testNoCollectionStubMethodsInInterface() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeListing/noCollectionStubMethodsInInterface.kt");
@@ -2236,11 +2236,23 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
doTest(fileName);
}
@TestMetadata("noSmapWithProperty.kt")
public void testNoSmapWithProperty() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/smap/inlineOnly/noSmapWithProperty.kt");
doTest(fileName);
}
@TestMetadata("reified.kt")
public void testReified() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/smap/inlineOnly/reified.kt");
doTest(fileName);
}
@TestMetadata("reifiedProperty.kt")
public void testReifiedProperty() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/smap/inlineOnly/reifiedProperty.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/codegen/boxInline/smap/newsmap")