Support new scheme of compilation of OptionalExpectation annotations

Instead of generating these annotation classes as package-private on
JVM, serialize their metadata to the .kotlin_module file, and load it
when compiling dependent multiplatform modules.

The problem with generating them as package-private was that
kotlin-stdlib for JVM would end up declaring symbols from other
platforms, which would include some annotations from package
kotlin.native. But using that package is discouraged by some tools
because it has a Java keyword in its name. In particular, jlink refused
to work with such artifact altogether (KT-21266).

 #KT-38652 Fixed
This commit is contained in:
Alexander Udalov
2019-12-17 17:43:42 +01:00
committed by Alexander Udalov
parent 63e355d979
commit 012ffa2993
42 changed files with 1469 additions and 145 deletions
+20
View File
@@ -0,0 +1,20 @@
// !LANGUAGE: +MultiPlatformProjects
// !USE_EXPERIMENTAL: kotlin.ExperimentalMultiplatform
// NO_READ_WRITE_COMPARE
package test
@OptionalExpectation
expect annotation class A(val x: Int)
@OptionalExpectation
expect annotation class B(val a: Array<String>)
@OptionalExpectation
expect annotation class C()
@Suppress("OPTIONAL_DECLARATION_USAGE_IN_NON_COMMON_SOURCE")
@A(42)
@B(["OK", ""])
@C
fun ok() {}
+44
View File
@@ -0,0 +1,44 @@
// test/OptionalAnnotationKt.class
// ------------------------------------------
package {
// signature: ok()V
public final fun ok(): kotlin/Unit
}
// META-INF/test-module.kotlin_module
// ------------------------------------------
module {
package test {
test/OptionalAnnotationKt
}
// Optional annotations
public final expect annotation class test/A : kotlin/Annotation {
// signature: <init>(I)V
public /* primary */ constructor(x: kotlin/Int)
public final expect val x: kotlin/Int
public final get
// module name: main
}
public final expect annotation class test/B : kotlin/Annotation {
// signature: <init>(Lkotlin/Array;)V
public /* primary */ constructor(a: kotlin/Array<kotlin/String>)
public final expect val a: kotlin/Array<kotlin/String>
public final get
// module name: main
}
public final expect annotation class test/C : kotlin/Annotation {
// signature: <init>()V
public /* primary */ constructor()
// module name: main
}
}