From 45c28abfeeb47931fabf153877f12ce87e49317f Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Mon, 20 Apr 2015 10:37:40 +0300 Subject: [PATCH] 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 --- build.xml | 5 ++--- .../cli/js/diagnosticForClassLiteral.out | 2 +- .../diagnosticWhenReferenceToBuiltinsMember.out | 4 ++-- .../tests/ReflectionTypesNotLoaded.kt | 11 ----------- .../tests/ReflectionTypesNotLoaded.txt | 16 ---------------- .../tests/deprecated/functionUsage.txt | 4 ++-- .../dynamicTypes/callableReferences.kt | 4 ++-- .../checkers/JetDiagnosticsTestGenerated.java | 6 ------ .../kotlin/builtins/KotlinBuiltIns.java | 4 +++- .../jetbrains/kotlin/builtins/ReflectionTypes.kt | 3 +-- libraries/tools/runtime/pom.xml | 1 - 11 files changed, 13 insertions(+), 47 deletions(-) delete mode 100644 compiler/testData/diagnostics/tests/ReflectionTypesNotLoaded.kt delete mode 100644 compiler/testData/diagnostics/tests/ReflectionTypesNotLoaded.txt diff --git a/build.xml b/build.xml index 2e43c55c18a..cb75d671a5b 100644 --- a/build.xml +++ b/build.xml @@ -438,7 +438,6 @@ - @@ -741,7 +740,8 @@ - + + @@ -863,7 +863,6 @@ - diff --git a/compiler/testData/cli/js/diagnosticForClassLiteral.out b/compiler/testData/cli/js/diagnosticForClassLiteral.out index b9b117af56e..12b8af2a949 100644 --- a/compiler/testData/cli/js/diagnosticForClassLiteral.out +++ b/compiler/testData/cli/js/diagnosticForClassLiteral.out @@ -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 diff --git a/compiler/testData/cli/js/diagnosticWhenReferenceToBuiltinsMember.out b/compiler/testData/cli/js/diagnosticWhenReferenceToBuiltinsMember.out index 245ee8366d3..19928207a43 100644 --- a/compiler/testData/cli/js/diagnosticWhenReferenceToBuiltinsMember.out +++ b/compiler/testData/cli/js/diagnosticWhenReferenceToBuiltinsMember.out @@ -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 diff --git a/compiler/testData/diagnostics/tests/ReflectionTypesNotLoaded.kt b/compiler/testData/diagnostics/tests/ReflectionTypesNotLoaded.kt deleted file mode 100644 index d3d32bb1a27..00000000000 --- a/compiler/testData/diagnostics/tests/ReflectionTypesNotLoaded.kt +++ /dev/null @@ -1,11 +0,0 @@ -fun foo() {} - -class A(val prop: Any) { - fun baz() {} -} - -val topLevelFun = ::foo -val memberFun = A::baz - -val classLiteral = A::class -val property = A::prop diff --git a/compiler/testData/diagnostics/tests/ReflectionTypesNotLoaded.txt b/compiler/testData/diagnostics/tests/ReflectionTypesNotLoaded.txt deleted file mode 100644 index a335638f39a..00000000000 --- a/compiler/testData/diagnostics/tests/ReflectionTypesNotLoaded.txt +++ /dev/null @@ -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 -} diff --git a/compiler/testData/diagnostics/tests/deprecated/functionUsage.txt b/compiler/testData/diagnostics/tests/deprecated/functionUsage.txt index 82555499bd9..5eaf534c558 100644 --- a/compiler/testData/diagnostics/tests/deprecated/functionUsage.txt +++ b/compiler/testData/diagnostics/tests/deprecated/functionUsage.txt @@ -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 +internal fun reflection2(): kotlin.reflect.KMemberFunction0 kotlin.deprecated(value = "does nothing good": kotlin.String) internal fun kotlin.Any.doNothing(): kotlin.String internal final class Delegation { diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/callableReferences.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/callableReferences.kt index 3f76efaea35..094c25bb1fe 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/callableReferences.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/callableReferences.kt @@ -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() {} -} \ No newline at end of file +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java index 3ae8b527d2f..b0789f415e8 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java @@ -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"); diff --git a/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java b/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java index ec88eb0e18a..86c2868d3d8 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java +++ b/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java @@ -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() { @Override public InputStream invoke(String path) { diff --git a/core/descriptors/src/org/jetbrains/kotlin/builtins/ReflectionTypes.kt b/core/descriptors/src/org/jetbrains/kotlin/builtins/ReflectionTypes.kt index 3fb31547a2d..0ed90f84229 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/builtins/ReflectionTypes.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/builtins/ReflectionTypes.kt @@ -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 { diff --git a/libraries/tools/runtime/pom.xml b/libraries/tools/runtime/pom.xml index eebeebaefff..90537f85832 100644 --- a/libraries/tools/runtime/pom.xml +++ b/libraries/tools/runtime/pom.xml @@ -25,7 +25,6 @@ **/*.kotlin_* - kotlin/reflect/**/* kotlin/internal/**/*