Inline properties support in incremental compilation

This commit is contained in:
Mikhael Bogdanov
2016-06-23 16:40:00 +03:00
parent 93a770fcc8
commit a090133581
40 changed files with 455 additions and 4 deletions
@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.codegen.intrinsics.IntrinsicArrayConstructorsKt;
import org.jetbrains.kotlin.codegen.state.GenerationState;
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper;
import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.incremental.KotlinLookupLocation;
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache;
import org.jetbrains.kotlin.name.ClassId;
import org.jetbrains.kotlin.name.Name;
@@ -46,6 +47,7 @@ import org.jetbrains.kotlin.resolve.jvm.AsmTypes;
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterKind;
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterSignature;
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature;
import org.jetbrains.kotlin.resolve.scopes.MemberScope;
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor;
import org.jetbrains.kotlin.types.expressions.DoubleColonLHS;
import org.jetbrains.kotlin.types.expressions.LabelResolver;
@@ -129,9 +131,31 @@ public class InlineCodegen extends CallGenerator {
if (!(functionDescriptor instanceof FictitiousArrayConstructor)) {
reportIncrementalInfo(functionDescriptor, codegen.getContext().getFunctionDescriptor().getOriginal(), jvmSignature, state);
String functionOrAccessorName = typeMapper.mapAsmMethod(function).getName();
//track changes for property accessor and @JvmName inline functions/property accessors
if(!functionOrAccessorName.equals(functionDescriptor.getName().asString())) {
MemberScope scope = getMemberScope(functionDescriptor);
if (scope != null) {
//Fake lookup to track track changes for property accessors and @JvmName functions/property accessors
scope.getContributedFunctions(Name.identifier(functionOrAccessorName), new KotlinLookupLocation(callElement));
}
}
}
}
@Nullable
private static MemberScope getMemberScope(@NotNull FunctionDescriptor functionOrAccessor) {
CallableMemberDescriptor callableMemberDescriptor = JvmCodegenUtil.getDirectMember(functionOrAccessor);
DeclarationDescriptor classOrPackageFragment = callableMemberDescriptor.getContainingDeclaration();
if (classOrPackageFragment instanceof ClassDescriptor) {
return ((ClassDescriptor) classOrPackageFragment).getUnsubstitutedMemberScope();
}
else if (classOrPackageFragment instanceof PackageFragmentDescriptor) {
return ((PackageFragmentDescriptor) classOrPackageFragment).getMemberScope();
}
return null;
}
@Override
public void genCallInner(
@NotNull Callable callableMethod,
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.codegen.inline
import org.jetbrains.kotlin.codegen.ExpressionCodegen
import org.jetbrains.kotlin.codegen.JvmCodegenUtil
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper
import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithSource
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
@@ -26,7 +27,6 @@ import org.jetbrains.kotlin.load.kotlin.VirtualFileKotlinClass
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache
import org.jetbrains.kotlin.resolve.source.PsiSourceElement
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedSimpleFunctionDescriptor
import org.jetbrains.org.objectweb.asm.Label
import org.jetbrains.org.objectweb.asm.MethodVisitor
@@ -43,10 +43,11 @@ fun FunctionDescriptor.getClassFilePath(typeMapper: KotlinTypeMapper, cache: Inc
return when (source) {
is KotlinJvmBinaryPackageSourceElement -> {
if (this !is DeserializedCallableMemberDescriptor) {
val directMember = JvmCodegenUtil.getDirectMember(this)
if (directMember !is DeserializedCallableMemberDescriptor) {
throw AssertionError("Expected DeserializedCallableMemberDescriptor, got: $this")
}
val kotlinClass = source.getContainingBinaryClass(this) ?:
val kotlinClass = source.getContainingBinaryClass(directMember) ?:
throw AssertionError("Descriptor $this is not found, in: $source")
if (kotlinClass !is VirtualFileKotlinClass) {
throw AssertionError("Expected VirtualFileKotlinClass, got $kotlinClass")
@@ -54,7 +55,8 @@ fun FunctionDescriptor.getClassFilePath(typeMapper: KotlinTypeMapper, cache: Inc
kotlinClass.file.canonicalPath!!
}
is KotlinJvmBinarySourceElement -> {
assert(this is DeserializedSimpleFunctionDescriptor) { "Expected DeserializedSimpleFunctionDescriptor, got: $this" }
val directMember = JvmCodegenUtil.getDirectMember(this)
assert(directMember is DeserializedCallableMemberDescriptor) { "Expected DeserializedSimpleFunctionDescriptor, got: $this" }
val kotlinClass = source.binaryClass as VirtualFileKotlinClass
kotlinClass.file.canonicalPath!!
}
@@ -443,6 +443,18 @@ public class ExperimentalIncrementalJpsTestGenerated extends AbstractExperimenta
doTest(fileName);
}
@TestMetadata("inlineClassValProperty")
public void testInlineClassValProperty() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/inlineClassValProperty/");
doTest(fileName);
}
@TestMetadata("inlineClassVarProperty")
public void testInlineClassVarProperty() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/inlineClassVarProperty/");
doTest(fileName);
}
@TestMetadata("inlineFunctionRemoved")
public void testInlineFunctionRemoved() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/inlineFunctionRemoved/");
@@ -479,6 +491,30 @@ public class ExperimentalIncrementalJpsTestGenerated extends AbstractExperimenta
doTest(fileName);
}
@TestMetadata("inlineTopLevelFunctionWithJvmName")
public void testInlineTopLevelFunctionWithJvmName() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/inlineTopLevelFunctionWithJvmName/");
doTest(fileName);
}
@TestMetadata("inlineTopLevelValProperty")
public void testInlineTopLevelValProperty() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/inlineTopLevelValProperty/");
doTest(fileName);
}
@TestMetadata("inlineTopLevelValPropertyWithJvmName")
public void testInlineTopLevelValPropertyWithJvmName() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/inlineTopLevelValPropertyWithJvmName/");
doTest(fileName);
}
@TestMetadata("inlineTopLevelVarProperty")
public void testInlineTopLevelVarProperty() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/inlineTopLevelVarProperty/");
doTest(fileName);
}
@TestMetadata("inlineTwoFunctionsOneChanged")
public void testInlineTwoFunctionsOneChanged() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/inlineTwoFunctionsOneChanged/");
@@ -845,6 +881,12 @@ public class ExperimentalIncrementalJpsTestGenerated extends AbstractExperimenta
doTest(fileName);
}
@TestMetadata("topLevelFunctionWithJvmName")
public void testTopLevelFunctionWithJvmName() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/topLevelFunctionWithJvmName/");
doTest(fileName);
}
@TestMetadata("topLevelMembersInTwoFiles")
public void testTopLevelMembersInTwoFiles() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/topLevelMembersInTwoFiles/");
@@ -857,6 +899,12 @@ public class ExperimentalIncrementalJpsTestGenerated extends AbstractExperimenta
doTest(fileName);
}
@TestMetadata("topLevelPropertyWithJvmName")
public void testTopLevelPropertyWithJvmName() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/topLevelPropertyWithJvmName/");
doTest(fileName);
}
@TestMetadata("traitClassObjectConstantChanged")
public void testTraitClassObjectConstantChanged() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/traitClassObjectConstantChanged/");
@@ -443,6 +443,18 @@ public class IncrementalJpsTestGenerated extends AbstractIncrementalJpsTest {
doTest(fileName);
}
@TestMetadata("inlineClassValProperty")
public void testInlineClassValProperty() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/inlineClassValProperty/");
doTest(fileName);
}
@TestMetadata("inlineClassVarProperty")
public void testInlineClassVarProperty() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/inlineClassVarProperty/");
doTest(fileName);
}
@TestMetadata("inlineFunctionRemoved")
public void testInlineFunctionRemoved() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/inlineFunctionRemoved/");
@@ -479,6 +491,30 @@ public class IncrementalJpsTestGenerated extends AbstractIncrementalJpsTest {
doTest(fileName);
}
@TestMetadata("inlineTopLevelFunctionWithJvmName")
public void testInlineTopLevelFunctionWithJvmName() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/inlineTopLevelFunctionWithJvmName/");
doTest(fileName);
}
@TestMetadata("inlineTopLevelValProperty")
public void testInlineTopLevelValProperty() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/inlineTopLevelValProperty/");
doTest(fileName);
}
@TestMetadata("inlineTopLevelValPropertyWithJvmName")
public void testInlineTopLevelValPropertyWithJvmName() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/inlineTopLevelValPropertyWithJvmName/");
doTest(fileName);
}
@TestMetadata("inlineTopLevelVarProperty")
public void testInlineTopLevelVarProperty() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/inlineTopLevelVarProperty/");
doTest(fileName);
}
@TestMetadata("inlineTwoFunctionsOneChanged")
public void testInlineTwoFunctionsOneChanged() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/inlineTwoFunctionsOneChanged/");
@@ -845,6 +881,12 @@ public class IncrementalJpsTestGenerated extends AbstractIncrementalJpsTest {
doTest(fileName);
}
@TestMetadata("topLevelFunctionWithJvmName")
public void testTopLevelFunctionWithJvmName() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/topLevelFunctionWithJvmName/");
doTest(fileName);
}
@TestMetadata("topLevelMembersInTwoFiles")
public void testTopLevelMembersInTwoFiles() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/topLevelMembersInTwoFiles/");
@@ -857,6 +899,12 @@ public class IncrementalJpsTestGenerated extends AbstractIncrementalJpsTest {
doTest(fileName);
}
@TestMetadata("topLevelPropertyWithJvmName")
public void testTopLevelPropertyWithJvmName() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/topLevelPropertyWithJvmName/");
doTest(fileName);
}
@TestMetadata("traitClassObjectConstantChanged")
public void testTraitClassObjectConstantChanged() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/traitClassObjectConstantChanged/");
@@ -0,0 +1,5 @@
package usage
class Usage {
val x = inline.A().f
}
@@ -0,0 +1,20 @@
================ Step #1 =================
Cleaning output files:
out/production/module/inline/A.class
End of files
Compiling files:
src/inline.kt
End of files
Marked as dirty by Kotlin:
src/Usage.kt
Exit code: ADDITIONAL_PASS_REQUIRED
------------------------------------------
Cleaning output files:
out/production/module/usage/Usage.class
End of files
Compiling files:
src/Usage.kt
End of files
Exit code: OK
------------------------------------------
@@ -0,0 +1,6 @@
package inline
class A {
inline val f: Int
get() = 0
}
@@ -0,0 +1,6 @@
package inline
class A {
inline val f: Int
get() = 1
}
@@ -0,0 +1,21 @@
================ Step #1 =================
Cleaning output files:
out/production/module/inline/A.class
End of files
Compiling files:
src/inline.kt
End of files
Marked as dirty by Kotlin:
src/usage.kt
Exit code: ADDITIONAL_PASS_REQUIRED
------------------------------------------
Cleaning output files:
out/production/module/META-INF/module.kotlin_module
out/production/module/usage/UsageKt.class
End of files
Compiling files:
src/usage.kt
End of files
Exit code: OK
------------------------------------------
@@ -0,0 +1,9 @@
package inline
class A {
inline var f: Int
get() = 0
set(p: Int) {
0
}
}
@@ -0,0 +1,9 @@
package inline
class A {
inline var f: Int
get() = 0
set(p: Int) {
1
}
}
@@ -0,0 +1,5 @@
package usage
fun a() {
inline.A().f = 1
}
@@ -0,0 +1,5 @@
package usage2
fun b() {
inline.A().f
}
@@ -0,0 +1,22 @@
================ Step #1 =================
Cleaning output files:
out/production/module/META-INF/module.kotlin_module
out/production/module/inline/InlineKt.class
End of files
Compiling files:
src/inline.kt
End of files
Marked as dirty by Kotlin:
src/usage.kt
Exit code: ADDITIONAL_PASS_REQUIRED
------------------------------------------
Cleaning output files:
out/production/module/META-INF/module.kotlin_module
out/production/module/usage/UsageKt.class
End of files
Compiling files:
src/usage.kt
End of files
Exit code: OK
------------------------------------------
@@ -0,0 +1,3 @@
package inline
@JvmName("test") inline fun g() = 0
@@ -0,0 +1,3 @@
package inline
@JvmName("test") inline fun g() = 1
@@ -0,0 +1,3 @@
package usage
val x = inline.g()
@@ -0,0 +1,22 @@
================ Step #1 =================
Cleaning output files:
out/production/module/META-INF/module.kotlin_module
out/production/module/inline/InlineKt.class
End of files
Compiling files:
src/inline.kt
End of files
Marked as dirty by Kotlin:
src/usage.kt
Exit code: ADDITIONAL_PASS_REQUIRED
------------------------------------------
Cleaning output files:
out/production/module/META-INF/module.kotlin_module
out/production/module/usage/UsageKt.class
End of files
Compiling files:
src/usage.kt
End of files
Exit code: OK
------------------------------------------
@@ -0,0 +1,4 @@
package inline
inline val f: Int
get() = 0
@@ -0,0 +1,4 @@
package inline
inline val f: Int
get() = 1
@@ -0,0 +1,3 @@
package usage
val x = inline.f
@@ -0,0 +1,22 @@
================ Step #1 =================
Cleaning output files:
out/production/module/META-INF/module.kotlin_module
out/production/module/inline/InlineKt.class
End of files
Compiling files:
src/inline.kt
End of files
Marked as dirty by Kotlin:
src/usage.kt
Exit code: ADDITIONAL_PASS_REQUIRED
------------------------------------------
Cleaning output files:
out/production/module/META-INF/module.kotlin_module
out/production/module/usage/UsageKt.class
End of files
Compiling files:
src/usage.kt
End of files
Exit code: OK
------------------------------------------
@@ -0,0 +1,4 @@
package inline
inline val f: Int
@JvmName("getG") get() = 0
@@ -0,0 +1,4 @@
package inline
inline val f: Int
@JvmName("getG") get() = 1
@@ -0,0 +1,3 @@
package usage
val x = inline.f
@@ -0,0 +1,22 @@
================ Step #1 =================
Cleaning output files:
out/production/module/META-INF/module.kotlin_module
out/production/module/inline/InlineKt.class
End of files
Compiling files:
src/inline.kt
End of files
Marked as dirty by Kotlin:
src/usage.kt
Exit code: ADDITIONAL_PASS_REQUIRED
------------------------------------------
Cleaning output files:
out/production/module/META-INF/module.kotlin_module
out/production/module/usage/UsageKt.class
End of files
Compiling files:
src/usage.kt
End of files
Exit code: OK
------------------------------------------
@@ -0,0 +1,5 @@
package inline
inline var f: Int
get() = 0
set(p: Int) {0}
@@ -0,0 +1,5 @@
package inline
inline var f: Int
get() = 0
set(p: Int) { 1 }
@@ -0,0 +1,5 @@
package usage
fun a() {
inline.f = 1
}
@@ -0,0 +1,5 @@
package usage2
fun b() {
inline.f
}
@@ -0,0 +1,20 @@
================ Step #1 =================
Cleaning output files:
out/production/module/META-INF/module.kotlin_module
out/production/module/inline/FunctionKt.class
End of files
Compiling files:
src/function.kt
End of files
Exit code: ADDITIONAL_PASS_REQUIRED
------------------------------------------
Cleaning output files:
out/production/module/META-INF/module.kotlin_module
out/production/module/usage/UsageKt.class
End of files
Compiling files:
src/usage.kt
End of files
Exit code: OK
------------------------------------------
@@ -0,0 +1,22 @@
================ Step #1 =================
Cleaning output files:
out/production/module/META-INF/module.kotlin_module
out/production/module/inline/FunctionKt.class
End of files
Compiling files:
src/function.kt
End of files
Marked as dirty by Kotlin:
src/usage.kt
Exit code: ADDITIONAL_PASS_REQUIRED
------------------------------------------
Cleaning output files:
out/production/module/META-INF/module.kotlin_module
out/production/module/usage/UsageKt.class
End of files
Compiling files:
src/usage.kt
End of files
Exit code: OK
------------------------------------------
@@ -0,0 +1,3 @@
package inline
@JvmName("oldName") fun g() = 0
@@ -0,0 +1,3 @@
package inline
@JvmName("newName") fun g() = 1
@@ -0,0 +1,3 @@
package usage
val x = inline.g()
@@ -0,0 +1,20 @@
================ Step #1 =================
Cleaning output files:
out/production/module/META-INF/module.kotlin_module
out/production/module/test/PropertyKt.class
End of files
Compiling files:
src/property.kt
End of files
Exit code: ADDITIONAL_PASS_REQUIRED
------------------------------------------
Cleaning output files:
out/production/module/META-INF/module.kotlin_module
out/production/module/usage/UsageKt.class
End of files
Compiling files:
src/usage.kt
End of files
Exit code: OK
------------------------------------------
@@ -0,0 +1,22 @@
================ Step #1 =================
Cleaning output files:
out/production/module/META-INF/module.kotlin_module
out/production/module/test/PropertyKt.class
End of files
Compiling files:
src/property.kt
End of files
Marked as dirty by Kotlin:
src/usage.kt
Exit code: ADDITIONAL_PASS_REQUIRED
------------------------------------------
Cleaning output files:
out/production/module/META-INF/module.kotlin_module
out/production/module/usage/UsageKt.class
End of files
Compiling files:
src/usage.kt
End of files
Exit code: OK
------------------------------------------
@@ -0,0 +1,4 @@
package test
val g: Int
@JvmName("oldName") get() = 0
@@ -0,0 +1,4 @@
package test
val g: Int
@JvmName("newName") get() = 0
@@ -0,0 +1,3 @@
package usage
val x = test.g