Delete kotlin.jvm.internal.KObject

It was supposed to be used in reflection but the benefits do not outweigh the
cost of KT-6951

 #KT-3223 Fixed
 #KT-6951 Fixed
This commit is contained in:
Alexander Udalov
2015-03-12 14:05:42 +03:00
parent e5d5b49ce2
commit 8af6ca5279
29 changed files with 34 additions and 122 deletions
@@ -23,13 +23,13 @@ import com.intellij.util.ArrayUtil;
import kotlin.*; import kotlin.*;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.codegen.extensions.ExpressionCodegenExtension;
import org.jetbrains.kotlin.backend.common.CodegenUtil; import org.jetbrains.kotlin.backend.common.CodegenUtil;
import org.jetbrains.kotlin.backend.common.CodegenUtilKt; import org.jetbrains.kotlin.backend.common.CodegenUtilKt;
import org.jetbrains.kotlin.backend.common.DataClassMethodGenerator; import org.jetbrains.kotlin.backend.common.DataClassMethodGenerator;
import org.jetbrains.kotlin.builtins.KotlinBuiltIns; import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
import org.jetbrains.kotlin.codegen.binding.MutableClosure; import org.jetbrains.kotlin.codegen.binding.MutableClosure;
import org.jetbrains.kotlin.codegen.context.*; import org.jetbrains.kotlin.codegen.context.*;
import org.jetbrains.kotlin.codegen.extensions.ExpressionCodegenExtension;
import org.jetbrains.kotlin.codegen.signature.BothSignatureWriter; import org.jetbrains.kotlin.codegen.signature.BothSignatureWriter;
import org.jetbrains.kotlin.codegen.state.GenerationState; import org.jetbrains.kotlin.codegen.state.GenerationState;
import org.jetbrains.kotlin.codegen.state.JetTypeMapper; import org.jetbrains.kotlin.codegen.state.JetTypeMapper;
@@ -282,34 +282,16 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
sw.writeSuperclassEnd(); sw.writeSuperclassEnd();
List<JetType> interfaceSupertypes = Lists.newArrayList(); List<JetType> interfaceSupertypes = Lists.newArrayList();
boolean explicitKObject = false;
for (JetDelegationSpecifier specifier : myClass.getDelegationSpecifiers()) { for (JetDelegationSpecifier specifier : myClass.getDelegationSpecifiers()) {
JetType superType = bindingContext.get(BindingContext.TYPE, specifier.getTypeReference()); JetType superType = bindingContext.get(BindingContext.TYPE, specifier.getTypeReference());
assert superType != null : "No supertype for class: " + myClass.getText(); assert superType != null : "No supertype for class: " + myClass.getText();
ClassifierDescriptor classifierDescriptor = superType.getConstructor().getDeclarationDescriptor(); if (isInterface(superType.getConstructor().getDeclarationDescriptor())) {
if (classifierDescriptor instanceof ClassDescriptor) { interfaceSupertypes.add(superType);
ClassDescriptor superClassDescriptor = (ClassDescriptor) classifierDescriptor;
if (isInterface(superClassDescriptor)) {
interfaceSupertypes.add(superType);
if (JvmAbi.K_OBJECT.equalsTo(DescriptorUtils.getFqName(superClassDescriptor))) {
explicitKObject = true;
}
}
} }
} }
LinkedHashSet<String> superInterfaces = new LinkedHashSet<String>(); LinkedHashSet<String> superInterfaces = new LinkedHashSet<String>();
if (!explicitKObject && !isInterface(descriptor)) {
Type kObject = asmTypeByFqNameWithoutInnerClasses(JvmAbi.K_OBJECT);
sw.writeInterface();
sw.writeClassBegin(kObject);
sw.writeClassEnd();
sw.writeInterfaceEnd();
superInterfaces.add(kObject.getInternalName());
}
for (JetType supertype : interfaceSupertypes) { for (JetType supertype : interfaceSupertypes) {
sw.writeInterface(); sw.writeInterface();
Type jvmName = typeMapper.mapSupertype(supertype, sw); Type jvmName = typeMapper.mapSupertype(supertype, sw);
@@ -318,8 +300,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
} }
return new JvmClassSignature(classAsmType.getInternalName(), superClassAsmType.getInternalName(), return new JvmClassSignature(classAsmType.getInternalName(), superClassAsmType.getInternalName(),
new ArrayList<String>(superInterfaces), new ArrayList<String>(superInterfaces), sw.makeJavaGenericSignature());
sw.makeJavaGenericSignature());
} }
protected void getSuperClass() { protected void getSuperClass() {
@@ -1,4 +1,4 @@
public final class WithPlatformTypes implements kotlin.jvm.internal.KObject, java.lang.Iterable<java.lang.String> { public final class WithPlatformTypes implements java.lang.Iterable<java.lang.String> {
public WithPlatformTypes(@org.jetbrains.annotations.NotNull java.lang.Iterable<java.lang.String> i) { /* compiled code */ } public WithPlatformTypes(@org.jetbrains.annotations.NotNull java.lang.Iterable<java.lang.String> i) { /* compiled code */ }
@org.jetbrains.annotations.NotNull @org.jetbrains.annotations.NotNull
@@ -1,4 +1,4 @@
public final class Derived implements kotlin.jvm.internal.KObject, Base { public final class Derived implements Base {
public Derived(@org.jetbrains.annotations.NotNull Base x) { /* compiled code */ } public Derived(@org.jetbrains.annotations.NotNull Base x) { /* compiled code */ }
@org.jetbrains.annotations.NotNull @org.jetbrains.annotations.NotNull
@@ -1,4 +1,4 @@
public final class Derived implements kotlin.jvm.internal.KObject, Base { public final class Derived implements Base {
public Derived(@org.jetbrains.annotations.NotNull Base x) { /* compiled code */ } public Derived(@org.jetbrains.annotations.NotNull Base x) { /* compiled code */ }
@org.jetbrains.annotations.NotNull @org.jetbrains.annotations.NotNull
@@ -1,4 +1,4 @@
public final class WithPlatformTypes implements kotlin.jvm.internal.KObject, p.J { public final class WithPlatformTypes implements p.J {
public WithPlatformTypes(@org.jetbrains.annotations.NotNull p.J j) { /* compiled code */ } public WithPlatformTypes(@org.jetbrains.annotations.NotNull p.J j) { /* compiled code */ }
@org.jetbrains.annotations.NotNull @org.jetbrains.annotations.NotNull
@@ -1,4 +1,4 @@
public final class Class implements kotlin.jvm.internal.KObject { public final class Class {
@org.jetbrains.annotations.Nullable @org.jetbrains.annotations.Nullable
private final java.lang.String nullableVal = ""; private final java.lang.String nullableVal = "";
@org.jetbrains.annotations.Nullable @org.jetbrains.annotations.Nullable
@@ -1,4 +1,4 @@
public final class ClassObjectField implements kotlin.jvm.internal.KObject { public final class ClassObjectField {
@org.jetbrains.annotations.Nullable @org.jetbrains.annotations.Nullable
public static final java.lang.String x = ""; public static final java.lang.String x = "";
private static final java.lang.String y = ""; private static final java.lang.String y = "";
@@ -11,7 +11,7 @@ public final class ClassObjectField implements kotlin.jvm.internal.KObject {
public ClassObjectField() { /* compiled code */ } public ClassObjectField() { /* compiled code */ }
public static final class Default implements kotlin.jvm.internal.KObject { public static final class Default {
@org.jetbrains.annotations.Nullable @org.jetbrains.annotations.Nullable
public final java.lang.String getX() { /* compiled code */ } public final java.lang.String getX() { /* compiled code */ }
@@ -1,3 +1,3 @@
public final class ClassWithConstructor implements kotlin.jvm.internal.KObject { public final class ClassWithConstructor {
public ClassWithConstructor(@org.jetbrains.annotations.Nullable java.lang.String nullable, @org.jetbrains.annotations.NotNull java.lang.String notNull) { /* compiled code */ } public ClassWithConstructor(@org.jetbrains.annotations.Nullable java.lang.String nullable, @org.jetbrains.annotations.NotNull java.lang.String notNull) { /* compiled code */ }
} }
@@ -1,4 +1,4 @@
public final class ClassWithConstructorAndProperties implements kotlin.jvm.internal.KObject { public final class ClassWithConstructorAndProperties {
@org.jetbrains.annotations.Nullable @org.jetbrains.annotations.Nullable
private final java.lang.String nullable; private final java.lang.String nullable;
@org.jetbrains.annotations.NotNull @org.jetbrains.annotations.NotNull
@@ -1,4 +1,4 @@
public final class C implements kotlin.jvm.internal.KObject, Tr { public final class C implements Tr {
private final int v = 1; private final int v = 1;
@org.jetbrains.annotations.NotNull @org.jetbrains.annotations.NotNull
@@ -1,4 +1,4 @@
public final class C implements kotlin.jvm.internal.KObject, Base { public final class C implements Base {
public void foo() { /* compiled code */ } public void foo() { /* compiled code */ }
public C() { /* compiled code */ } public C() { /* compiled code */ }
@@ -1,4 +1,4 @@
public final class PlatformTypes implements kotlin.jvm.internal.KObject { public final class PlatformTypes {
public final java.lang.String simplyPlatform() { /* compiled code */ } public final java.lang.String simplyPlatform() { /* compiled code */ }
@org.jetbrains.annotations.Nullable @org.jetbrains.annotations.Nullable
@@ -1,4 +1,4 @@
public final class PrivateInClass implements kotlin.jvm.internal.KObject { public final class PrivateInClass {
private final java.lang.String getNn() { /* compiled code */ } private final java.lang.String getNn() { /* compiled code */ }
private final void setNn(java.lang.String value) { /* compiled code */ } private final void setNn(java.lang.String value) { /* compiled code */ }
@@ -1,9 +1,9 @@
public final class Synthetic implements kotlin.jvm.internal.KObject { public final class Synthetic {
private final void foo() { /* compiled code */ } private final void foo() { /* compiled code */ }
public Synthetic() { /* compiled code */ } public Synthetic() { /* compiled code */ }
public final class Inner implements kotlin.jvm.internal.KObject { public final class Inner {
public final void test() { /* compiled code */ } public final void test() { /* compiled code */ }
public Inner() { /* compiled code */ } public Inner() { /* compiled code */ }
@@ -8,7 +8,7 @@ public interface TraitClassObjectField {
@org.jetbrains.annotations.Nullable @org.jetbrains.annotations.Nullable
java.lang.String x = ""; java.lang.String x = "";
static final class Default implements kotlin.jvm.internal.KObject { static final class Default {
@org.jetbrains.annotations.Nullable @org.jetbrains.annotations.Nullable
private final java.lang.String x = ""; private final java.lang.String x = "";
private final java.lang.String y = ""; private final java.lang.String y = "";
@@ -1,4 +1,4 @@
public final class C implements kotlin.jvm.internal.KObject, Base<kotlin.Unit> { public final class C implements Base<kotlin.Unit> {
public void foo(@org.jetbrains.annotations.NotNull kotlin.Unit t) { /* compiled code */ } public void foo(@org.jetbrains.annotations.NotNull kotlin.Unit t) { /* compiled code */ }
public C() { /* compiled code */ } public C() { /* compiled code */ }
@@ -1,12 +1,12 @@
package test package test
import kotlin.jvm.internal.KObject
import kotlin.jvm.internal.Intrinsics import kotlin.jvm.internal.Intrinsics
import kotlin.jvm.internal.Ref
fun foo(): String { fun foo(): String {
// This method call should be resolved to kotlin-runtime.jar // This method call should be resolved to kotlin-runtime.jar
val r: String = Intrinsics.stringPlus(":", ")") val r: String = Intrinsics.stringPlus(":", ")")
// This method call should be resolved to sources // This method call should be resolved to sources
return KObject.methodWhichDoesNotExistInKotlinRuntime() return Ref.methodWhichDoesNotExistInKotlinRuntime()
} }
@@ -1,6 +1,6 @@
package kotlin.jvm.internal; package kotlin.jvm.internal;
public class KObject { public class Ref {
public static String methodWhichDoesNotExistInKotlinRuntime() { public static String methodWhichDoesNotExistInKotlinRuntime() {
return ":)"; return ":)";
} }
@@ -1,7 +1,5 @@
// KT-4485 getGenericInterfaces vs getInterfaces for kotlin classes // KT-4485 getGenericInterfaces vs getInterfaces for kotlin classes
import kotlin.jvm.internal.KObject
class SimpleClass class SimpleClass
class ClassWithNonGenericSuperInterface: Cloneable class ClassWithNonGenericSuperInterface: Cloneable
@@ -10,10 +8,6 @@ class ClassWithGenericSuperInterface: java.util.Comparator<String> {
override fun compare(a: String, b: String): Int = 0 override fun compare(a: String, b: String): Int = 0
} }
class ExplicitKObject: java.util.Comparator<String>, KObject {
override fun compare(a: String, b: String): Int = 0
}
fun check(klass: Class<*>) { fun check(klass: Class<*>) {
val interfaces = klass.getInterfaces().toList() val interfaces = klass.getInterfaces().toList()
val genericInterfaces = klass.getGenericInterfaces().toList() val genericInterfaces = klass.getGenericInterfaces().toList()
@@ -26,6 +20,5 @@ fun box(): String {
check(javaClass<SimpleClass>()) check(javaClass<SimpleClass>())
check(javaClass<ClassWithNonGenericSuperInterface>()) check(javaClass<ClassWithNonGenericSuperInterface>())
check(javaClass<ClassWithGenericSuperInterface>()) check(javaClass<ClassWithGenericSuperInterface>())
check(javaClass<ExplicitKObject>())
return "OK" return "OK"
} }
@@ -1,30 +0,0 @@
// KT-5609: interfaces should not inherit from KObject, unless explicitly said so
trait A
trait B : kotlin.jvm.internal.KObject
annotation class C
class D
class E : kotlin.jvm.internal.KObject
fun box(): String {
val a = javaClass<A>().getGenericInterfaces().toList()
if (a.toString() != "[]") return "Fail A: $a"
val b = javaClass<B>().getGenericInterfaces().toList()
if (b.toString() != "[interface kotlin.jvm.internal.KObject]") return "Fail B: $b"
val c = javaClass<C>().getGenericInterfaces().toList()
if (c.toString() != "[interface java.lang.annotation.Annotation]") return "Fail C: $c"
val d = javaClass<D>().getGenericInterfaces().toList()
if (d.toString() != "[interface kotlin.jvm.internal.KObject]") return "Fail D: $d"
val e = javaClass<E>().getGenericInterfaces().toList()
if (e.toString() != "[interface kotlin.jvm.internal.KObject]") return "Fail E: $e"
return "OK"
}
@@ -8,4 +8,4 @@ class Sub: Super<C<*>>()
// class: Sub // class: Sub
// jvm signature: Sub // jvm signature: Sub
// generic signature: LSuper<LC<*>;>;Lkotlin/jvm/internal/KObject; // generic signature: LSuper<LC<*>;>;
@@ -4,4 +4,4 @@ class Derived<A, B, C>: Base<A, B, C>()
// class: Derived // class: Derived
// jvm signature: Derived // jvm signature: Derived
// generic signature: <A:Ljava/lang/Object;B:Ljava/lang/Object;C:Ljava/lang/Object;>LBase<TA;TB;TC;>;Lkotlin/jvm/internal/KObject; // generic signature: <A:Ljava/lang/Object;B:Ljava/lang/Object;C:Ljava/lang/Object;>LBase<TA;TB;TC;>;
@@ -4,4 +4,4 @@ class Derived<A, B, C>: Base<A, B, C>
// class: Derived // class: Derived
// jvm signature: Derived // jvm signature: Derived
// generic signature: <A:Ljava/lang/Object;B:Ljava/lang/Object;C:Ljava/lang/Object;>Ljava/lang/Object;Lkotlin/jvm/internal/KObject;LBase<TA;TB;TC;>; // generic signature: <A:Ljava/lang/Object;B:Ljava/lang/Object;C:Ljava/lang/Object;>Ljava/lang/Object;LBase<TA;TB;TC;>;
@@ -5,4 +5,4 @@ class Derived<A, B, C>: Intermediate<Base<A, B, C>>
// class: Derived // class: Derived
// jvm signature: Derived // jvm signature: Derived
// generic signature: <A:Ljava/lang/Object;B:Ljava/lang/Object;C:Ljava/lang/Object;>Ljava/lang/Object;Lkotlin/jvm/internal/KObject;LIntermediate<LBase<TA;-TB;+TC;>;>; // generic signature: <A:Ljava/lang/Object;B:Ljava/lang/Object;C:Ljava/lang/Object;>Ljava/lang/Object;LIntermediate<LBase<TA;-TB;+TC;>;>;
@@ -3068,12 +3068,6 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
doTestWithStdlib(fileName); doTestWithStdlib(fileName);
} }
@TestMetadata("kt5609.kt")
public void testKt5609() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/regressions/kt5609.kt");
doTestWithStdlib(fileName);
}
@TestMetadata("kt715.kt") @TestMetadata("kt715.kt")
public void testKt715() throws Exception { public void testKt715() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/regressions/kt715.kt"); String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/regressions/kt715.kt");
@@ -17,7 +17,6 @@
package org.jetbrains.kotlin.load.java; package org.jetbrains.kotlin.load.java;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.name.Name; import org.jetbrains.kotlin.name.Name;
public final class JvmAbi { public final class JvmAbi {
@@ -40,7 +39,6 @@ public final class JvmAbi {
public static final String INSTANCE_FIELD = "INSTANCE$"; public static final String INSTANCE_FIELD = "INSTANCE$";
public static final FqName K_OBJECT = new FqName("kotlin.jvm.internal.KObject");
public static final String KOTLIN_CLASS_FIELD_NAME = "$kotlinClass"; public static final String KOTLIN_CLASS_FIELD_NAME = "$kotlinClass";
public static final String KOTLIN_PACKAGE_FIELD_NAME = "$kotlinPackage"; public static final String KOTLIN_PACKAGE_FIELD_NAME = "$kotlinPackage";
@@ -1,20 +0,0 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package kotlin.jvm.internal;
public interface KObject {
}
@@ -33,12 +33,11 @@ import com.intellij.openapi.project.Project
import com.intellij.psi.CommonClassNames import com.intellij.psi.CommonClassNames
import com.sun.jdi.ClassType import com.sun.jdi.ClassType
import com.sun.jdi.Value import com.sun.jdi.Value
import org.jetbrains.eval4j.jdi.* import org.jetbrains.eval4j.jdi.asValue
import org.jetbrains.kotlin.psi.JetExpression
import org.jetbrains.kotlin.psi.JetPsiFactory import org.jetbrains.kotlin.psi.JetPsiFactory
import org.jetbrains.kotlin.types.JetType import org.jetbrains.kotlin.types.JetType
import org.jetbrains.org.objectweb.asm.Type as AsmType import org.jetbrains.org.objectweb.asm.Type as AsmType
import org.jetbrains.kotlin.psi.JetExpression
import org.jetbrains.kotlin.load.java.JvmAbi
public abstract class KotlinRuntimeTypeEvaluator( public abstract class KotlinRuntimeTypeEvaluator(
editor: Editor?, editor: Editor?,
@@ -99,8 +98,6 @@ public abstract class KotlinRuntimeTypeEvaluator(
} }
for (interfaceType in type.interfaces()) { for (interfaceType in type.interfaces()) {
if (JvmAbi.K_OBJECT.asString() == interfaceType.name()) continue
psiClass = AsmType.getType(interfaceType.signature()).getClassDescriptor(project) psiClass = AsmType.getType(interfaceType.signature()).getClassDescriptor(project)
if (psiClass != null) { if (psiClass != null) {
return psiClass!!.getDefaultType() return psiClass!!.getDefaultType()
@@ -16,18 +16,17 @@
package org.jetbrains.kotlin.idea.refactoring package org.jetbrains.kotlin.idea.refactoring
import com.intellij.psi.PsiReferenceList
import com.intellij.psi.PsiReferenceList.Role
import com.intellij.psi.PsiElementFactory import com.intellij.psi.PsiElementFactory
import com.intellij.psi.PsiJavaCodeReferenceElement import com.intellij.psi.PsiJavaCodeReferenceElement
import org.jetbrains.kotlin.load.java.* import com.intellij.psi.PsiReferenceList
import com.intellij.psi.PsiReferenceList.Role
public fun PsiElementFactory.createReferenceListWithRole( public fun PsiElementFactory.createReferenceListWithRole(
references: Array<PsiJavaCodeReferenceElement>, references: Array<PsiJavaCodeReferenceElement>,
role: Role role: Role
): PsiReferenceList? { ): PsiReferenceList? {
val filteredRefs = references.map { it.getCanonicalText() }.filter { it != JvmAbi.K_OBJECT.asString() } val refsText = references.map { it.getCanonicalText() }
val refListText = if (filteredRefs.isNotEmpty()) filteredRefs.joinToString() else return null val refListText = if (refsText.isNotEmpty()) refsText.joinToString() else return null
return when (role) { return when (role) {
Role.THROWS_LIST -> createMethodFromText("void foo() throws $refListText {}", null).getThrowsList() Role.THROWS_LIST -> createMethodFromText("void foo() throws $refListText {}", null).getThrowsList()
Role.EXTENDS_LIST -> createClassFromText("class Foo extends $refListText {}", null).getInnerClasses()[0].getExtendsList() Role.EXTENDS_LIST -> createClassFromText("class Foo extends $refListText {}", null).getInnerClasses()[0].getExtendsList()