Keep built-in metadata for reflection interfaces

Reflection interfaces (interfaces in kotlin.reflect.* in core/builtins/) are
now fully considered as built-ins and can be accessed via KotlinBuiltIns. This
increases runtime size by ~20kb, but only because KotlinBuiltIns is static and
is therefore constructed only via resource loading from the compiler classpath
at the moment. As soon as it's possible to inject KotlinBuiltIns to the
particular resolution process, the metadata on JVM will be loaded via standard
annotation mechanism (kotlin.jvm.internal.KotlinClass/KotlinPackage) and wasted
runtime space will be reclaimed
This commit is contained in:
Alexander Udalov
2015-04-20 10:37:40 +03:00
parent 0879860074
commit 45c28abfee
11 changed files with 13 additions and 47 deletions
+2 -3
View File
@@ -438,7 +438,6 @@
<fileset dir="${output}/builtins">
<include name="kotlin/**"/>
<exclude name="kotlin/internal/**"/>
<exclude name="kotlin/reflect/**"/>
</fileset>
<fileset dir="${basedir}/compiler/frontend.java/src" includes="META-INF/services/**"/>
<fileset dir="${basedir}/compiler/backend/src" includes="META-INF/services/**"/>
@@ -741,7 +740,8 @@
<zipfileset dir="${output}/builtins">
<include name="kotlin/**"/>
<exclude name="kotlin/internal/**"/>
<exclude name="kotlin/reflect/**"/>
<!-- TODO: load metadata from @KotlinClass annotation in KotlinBuiltIns on JVM and restore this exclusion -->
<!-- exclude name="kotlin/reflect/**"/ -->
</zipfileset>
</jar-content>
</pack-runtime-jar>
@@ -863,7 +863,6 @@
<fileset dir="${output}/builtins">
<include name="kotlin/**"/>
<exclude name="kotlin/internal/**"/>
<exclude name="kotlin/reflect/**"/>
</fileset>
<fileset dir="${basedir}/compiler/frontend.java/src" includes="META-INF/services/**"/>
<fileset dir="${basedir}/compiler/backend/src" includes="META-INF/services/**"/>
@@ -1,3 +1,3 @@
WARNING: compiler/testData/cli/js/diagnosticForClassLiteral.kt: (6, 5) The expression is unused
ERROR: compiler/testData/cli/js/diagnosticForClassLiteral.kt: (6, 6) Reflection types can't be loaded. Please ensure that you have Kotlin Runtime in your classpath
ERROR: compiler/testData/cli/js/diagnosticForClassLiteral.kt: (6, 5) Cannot translate (not supported yet): 'A::class'
COMPILATION_ERROR
@@ -1,5 +1,5 @@
WARNING: compiler/testData/cli/js/diagnosticWhenReferenceToBuiltinsMember.kt: (4, 5) The expression is unused
ERROR: compiler/testData/cli/js/diagnosticWhenReferenceToBuiltinsMember.kt: (4, 8) Reflection types can't be loaded. Please ensure that you have Kotlin Runtime in your classpath
WARNING: compiler/testData/cli/js/diagnosticWhenReferenceToBuiltinsMember.kt: (5, 5) The expression is unused
ERROR: compiler/testData/cli/js/diagnosticWhenReferenceToBuiltinsMember.kt: (5, 11) Reflection types can't be loaded. Please ensure that you have Kotlin Runtime in your classpath
ERROR: compiler/testData/cli/js/diagnosticWhenReferenceToBuiltinsMember.kt: (4, 5) Callable references for builtin members are not supported yet: 'Int::toByte'
ERROR: compiler/testData/cli/js/diagnosticWhenReferenceToBuiltinsMember.kt: (5, 5) Callable references for builtin members are not supported yet: 'String::length'
COMPILATION_ERROR
@@ -1,11 +0,0 @@
fun foo() {}
class A(val prop: Any) {
fun baz() {}
}
val topLevelFun = <!REFLECTION_TYPES_NOT_LOADED!>::<!>foo
val memberFun = A<!REFLECTION_TYPES_NOT_LOADED!>::<!>baz
val classLiteral = A<!REFLECTION_TYPES_NOT_LOADED!>::<!>class
val property = A<!REFLECTION_TYPES_NOT_LOADED!>::<!>prop
@@ -1,16 +0,0 @@
package
internal val classLiteral: [ERROR : Unresolved class]
internal val memberFun: [ERROR : Type for A::baz]
internal val property: [ERROR : Type for A::prop]
internal val topLevelFun: [ERROR : Type for ::foo]
internal fun foo(): kotlin.Unit
internal final class A {
public constructor A(/*0*/ prop: kotlin.Any)
internal final val prop: kotlin.Any
internal final fun baz(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -4,8 +4,8 @@ kotlin.deprecated(value = "message": kotlin.String) internal fun Obsolete(/*0*/
internal fun block(): kotlin.Unit
internal fun expression(): UsefulClass
internal fun invoker(): kotlin.Unit
internal fun reflection(): [ERROR : Error function type]
internal fun reflection2(): [ERROR : Error function type]
internal fun reflection(): kotlin.reflect.KFunction1<kotlin.Int, UsefulClass>
internal fun reflection2(): kotlin.reflect.KMemberFunction0<UsefulClass, kotlin.Unit>
kotlin.deprecated(value = "does nothing good": kotlin.String) internal fun kotlin.Any.doNothing(): kotlin.String
internal final class Delegation {
@@ -1,4 +1,4 @@
// !DIAGNOSTICS: -REFLECTION_TYPES_NOT_LOADED -UNUSED_EXPRESSION
// !DIAGNOSTICS: -UNUSED_EXPRESSION
fun test() {
dynamic::foo
@@ -6,4 +6,4 @@ fun test() {
class dynamic {
fun foo() {}
}
}
@@ -415,12 +415,6 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("ReflectionTypesNotLoaded.kt")
public void testReflectionTypesNotLoaded() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/ReflectionTypesNotLoaded.kt");
doTest(fileName);
}
@TestMetadata("ResolveOfJavaGenerics.kt")
public void testResolveOfJavaGenerics() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/ResolveOfJavaGenerics.kt");
@@ -38,6 +38,7 @@ import org.jetbrains.kotlin.types.checker.JetTypeChecker;
import java.io.InputStream;
import java.util.*;
import static kotlin.KotlinPackage.setOf;
import static kotlin.KotlinPackage.single;
import static org.jetbrains.kotlin.builtins.PrimitiveType.*;
import static org.jetbrains.kotlin.resolve.DescriptorUtils.getFqName;
@@ -113,7 +114,8 @@ public class KotlinBuiltIns {
);
PackageFragmentProvider packageFragmentProvider = BuiltinsPackage.createBuiltInPackageFragmentProvider(
storageManager, builtInsModule, Collections.singleton(BUILT_INS_PACKAGE_FQ_NAME),
storageManager, builtInsModule,
setOf(BUILT_INS_PACKAGE_FQ_NAME, BuiltinsPackage.getKOTLIN_REFLECT_FQ_NAME()),
FlexibleTypeCapabilitiesDeserializer.ThrowException.INSTANCE$, new Function1<String, InputStream>() {
@Override
public InputStream invoke(String path) {
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.builtins
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.descriptors.annotations.Annotations
@@ -29,7 +28,7 @@ import org.jetbrains.kotlin.types.*
import java.util.ArrayList
import kotlin.properties.Delegates
private val KOTLIN_REFLECT_FQ_NAME = FqName("kotlin.reflect")
val KOTLIN_REFLECT_FQ_NAME = FqName("kotlin.reflect")
public class ReflectionTypes(private val module: ModuleDescriptor) {
private val kotlinReflectScope: JetScope? by Delegates.lazy {
-1
View File
@@ -25,7 +25,6 @@
<include>**/*.kotlin_*</include>
</includes>
<excludes>
<exclude>kotlin/reflect/**/*</exclude>
<exclude>kotlin/internal/**/*</exclude>
</excludes>
</resource>