Optimize runtime representation for callable reference subclasses

Instead of generating overrides for getOwner/getName/getSignature in
each anonymous class representing a callable reference, pass them to the
superclass' constructor and store as fields. This occupies some small
memory but helps to reduce the size of the generated class files, and
will be helpful for adding further runtime information to callable
references, such as information about implicit conversions this
reference has been subject to.

Represent owner as java.lang.Class + boolean instead of
KDeclarationContainer, so that the unnecessary wrapping Class->KClass
wouldn't happen before it's needed, and also to make sure all callable
references remain serializable.

Note that the argument type where the "is declaration container a class"
is passed is int instead of boolean. The plan is to pass the
aforementioned implicit conversion information as bits of this same
integer value.

 #KT-27362 Fixed
This commit is contained in:
Alexander Udalov
2020-02-14 20:28:43 +01:00
parent 8d7c8672ac
commit 98aecbef6b
38 changed files with 502 additions and 262 deletions
@@ -70,6 +70,7 @@ public class ClosureCodegen extends MemberCodegen<KtElement> {
protected final Type asmType;
protected final int visibilityFlag;
private final boolean shouldHaveBoundReferenceReceiver;
private final boolean isOptimizedFunctionReference;
private Method constructor;
protected Type superClassAsmType;
@@ -119,6 +120,9 @@ public class ClosureCodegen extends MemberCodegen<KtElement> {
assert closure != null : "Closure must be calculated for class: " + classDescriptor;
this.shouldHaveBoundReferenceReceiver = CallableReferenceUtilKt.isForBoundCallableReference(closure);
this.isOptimizedFunctionReference =
functionReferenceTarget != null &&
superClassType.getConstructor().getDeclarationDescriptor() == state.getJvmRuntimeTypes().getFunctionReferenceImpl();
this.asmType = typeMapper.mapClass(classDescriptor);
@@ -180,7 +184,7 @@ public class ClosureCodegen extends MemberCodegen<KtElement> {
protected void generateClosureBody() {
functionCodegen.generateMethod(JvmDeclarationOriginKt.OtherOrigin(element, funDescriptor), funDescriptor, strategy);
if (functionReferenceTarget != null) {
if (functionReferenceTarget != null && !isOptimizedFunctionReference) {
generateFunctionReferenceMethods(functionReferenceTarget);
}
@@ -285,7 +289,7 @@ public class ClosureCodegen extends MemberCodegen<KtElement> {
);
}
protected void generateBridge(
private void generateBridge(
@NotNull Method bridge,
@NotNull List<KotlinType> bridgeParameterKotlinTypes,
@Nullable KotlinType bridgeReturnType,
@@ -396,7 +400,8 @@ public class ClosureCodegen extends MemberCodegen<KtElement> {
}
}
public static void generateCallableReferenceDeclarationContainer(
// Returns false if null was generated.
public static boolean generateCallableReferenceDeclarationContainerClass(
@NotNull InstructionAdapter iv,
@NotNull CallableDescriptor descriptor,
@NotNull GenerationState state
@@ -420,15 +425,20 @@ public class ClosureCodegen extends MemberCodegen<KtElement> {
}
else {
iv.aconst(null);
return;
return false;
}
boolean isContainerPackage =
descriptor instanceof LocalVariableDescriptor
? DescriptorUtils.getParentOfType(descriptor, ClassDescriptor.class) == null
: container instanceof PackageFragmentDescriptor;
return true;
}
if (isContainerPackage) {
public static void generateCallableReferenceDeclarationContainer(
@NotNull InstructionAdapter iv,
@NotNull CallableDescriptor descriptor,
@NotNull GenerationState state
) {
if (!generateCallableReferenceDeclarationContainerClass(iv, descriptor, state)) return;
if (isTopLevelCallableReference(descriptor)) {
// Note that this name is not used in reflection. There should be the name of the referenced declaration's module instead,
// but there's no nice API to obtain that name here yet
// TODO: write the referenced declaration's module name and use it in reflection
@@ -441,6 +451,12 @@ public class ClosureCodegen extends MemberCodegen<KtElement> {
}
}
public static boolean isTopLevelCallableReference(@NotNull CallableDescriptor descriptor) {
return descriptor instanceof LocalVariableDescriptor
? DescriptorUtils.getParentOfType(descriptor, ClassDescriptor.class) == null
: descriptor.getContainingDeclaration() instanceof PackageFragmentDescriptor;
}
@NotNull
protected Method generateConstructor() {
List<FieldInfo> args = calculateConstructorParameters(typeMapper, state.getLanguageVersionSettings(), closure, asmType);
@@ -476,24 +492,38 @@ public class ClosureCodegen extends MemberCodegen<KtElement> {
iv.load(0, superClassAsmType);
String superClassConstructorDescriptor;
List<Type> superCtorArgTypes = new ArrayList<>();
if (superClassAsmType.equals(LAMBDA) || superClassAsmType.equals(FUNCTION_REFERENCE) ||
superClassAsmType.equals(FUNCTION_REFERENCE_IMPL) ||
CoroutineCodegenUtilKt.isCoroutineSuperClass(state.getLanguageVersionSettings(), superClassAsmType.getInternalName())) {
int arity = calculateArity();
iv.iconst(arity);
superCtorArgTypes.add(Type.INT_TYPE);
if (shouldHaveBoundReferenceReceiver) {
CallableReferenceUtilKt.loadBoundReferenceReceiverParameter(iv, boundReceiverParameterIndex, boundReceiverType, boundReceiverKotlinType);
superClassConstructorDescriptor = "(ILjava/lang/Object;)V";
CallableReferenceUtilKt.loadBoundReferenceReceiverParameter(
iv, boundReceiverParameterIndex, boundReceiverType, boundReceiverKotlinType
);
superCtorArgTypes.add(OBJECT_TYPE);
}
else {
superClassConstructorDescriptor = "(I)V";
if (isOptimizedFunctionReference) {
assert functionReferenceTarget != null : "No function reference target: " + funDescriptor;
generateCallableReferenceDeclarationContainerClass(iv, functionReferenceTarget, state);
iv.aconst(functionReferenceTarget.getName().asString());
PropertyReferenceCodegen.generateCallableReferenceSignature(iv, functionReferenceTarget, state);
iv.aconst(isTopLevelCallableReference(functionReferenceTarget) ? 1 : 0);
superCtorArgTypes.add(JAVA_CLASS_TYPE);
superCtorArgTypes.add(JAVA_STRING_TYPE);
superCtorArgTypes.add(JAVA_STRING_TYPE);
superCtorArgTypes.add(Type.INT_TYPE);
}
}
else {
assert !shouldHaveBoundReferenceReceiver : "Unexpected bound reference with supertype " + superClassAsmType;
superClassConstructorDescriptor = "()V";
}
iv.invokespecial(superClassAsmType.getInternalName(), "<init>", superClassConstructorDescriptor, false);
iv.invokespecial(
superClassAsmType.getInternalName(), "<init>",
Type.getMethodDescriptor(Type.VOID_TYPE, superCtorArgTypes.toArray(new Type[0])), false
);
iv.visitInsn(RETURN);
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.builtins.createFunctionType
import org.jetbrains.kotlin.codegen.coroutines.coroutinesJvmInternalPackageFqName
import org.jetbrains.kotlin.codegen.coroutines.getOrCreateJvmSuspendFunctionView
import org.jetbrains.kotlin.codegen.coroutines.isSuspendLambdaOrLocalFunction
import org.jetbrains.kotlin.config.ApiVersion
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.config.isReleaseCoroutines
@@ -30,14 +31,22 @@ class JvmRuntimeTypes(module: ModuleDescriptor, private val languageVersionSetti
private val kotlinCoroutinesJvmInternalPackage =
MutablePackageFragmentDescriptor(module, languageVersionSettings.coroutinesJvmInternalPackageFqName())
val generateOptimizedCallableReferenceSuperClasses = languageVersionSettings.apiVersion >= ApiVersion.KOTLIN_1_4
private fun internal(className: String, packageFragment: PackageFragmentDescriptor = kotlinJvmInternalPackage): Lazy<ClassDescriptor> =
lazy { createClass(packageFragment, className) }
private fun coroutinesInternal(name: String): Lazy<ClassDescriptor> =
lazy { createCoroutineSuperClass(name) }
private fun propertyClasses(prefix: String, suffix: String): Lazy<List<ClassDescriptor>> =
lazy { (0..2).map { i -> createClass(kotlinJvmInternalPackage, prefix + i + suffix) } }
private val lambda: ClassDescriptor by internal("Lambda")
private val functionReference: ClassDescriptor by internal("FunctionReference")
val functionReferenceImpl: ClassDescriptor by internal("FunctionReferenceImpl")
private val localVariableReference: ClassDescriptor by internal("LocalVariableReference")
private val mutableLocalVariableReference: ClassDescriptor by internal("MutableLocalVariableReference")
@@ -60,13 +69,10 @@ class JvmRuntimeTypes(module: ModuleDescriptor, private val languageVersionSetti
coroutineImpl
}
private val propertyReferences: List<ClassDescriptor> by lazy {
(0..2).map { i -> createClass(kotlinJvmInternalPackage, "PropertyReference$i") }
}
private val mutablePropertyReferences: List<ClassDescriptor> by lazy {
(0..2).map { i -> createClass(kotlinJvmInternalPackage, "MutablePropertyReference$i") }
}
private val propertyReferences: List<ClassDescriptor> by propertyClasses("PropertyReference", "")
private val mutablePropertyReferences: List<ClassDescriptor> by propertyClasses("MutablePropertyReference", "")
private val propertyReferenceImpls: List<ClassDescriptor> by propertyClasses("PropertyReference", "Impl")
private val mutablePropertyReferenceImpls: List<ClassDescriptor> by propertyClasses("MutablePropertyReference", "Impl")
private fun createClass(
packageFragment: PackageFragmentDescriptor,
@@ -144,7 +150,8 @@ class JvmRuntimeTypes(module: ModuleDescriptor, private val languageVersionSetti
)
val suspendFunctionType = if (referencedFunction.isSuspend) suspendFunctionInterface?.defaultType else null
return listOfNotNull(functionReference.defaultType, functionType, suspendFunctionType)
val superClass = if (generateOptimizedCallableReferenceSuperClasses) functionReferenceImpl else functionReference
return listOfNotNull(superClass.defaultType, functionType, suspendFunctionType)
}
fun getSupertypeForPropertyReference(descriptor: VariableDescriptorWithAccessors, isMutable: Boolean, isBound: Boolean): KotlinType {
@@ -157,6 +164,11 @@ class JvmRuntimeTypes(module: ModuleDescriptor, private val languageVersionSetti
(if (descriptor.dispatchReceiverParameter != null) 1 else 0) -
if (isBound) 1 else 0
return (if (isMutable) mutablePropertyReferences else propertyReferences)[arity].defaultType
val classes = when {
generateOptimizedCallableReferenceSuperClasses -> if (isMutable) mutablePropertyReferenceImpls else propertyReferenceImpls
else -> if (isMutable) mutablePropertyReferences else propertyReferences
}
return classes[arity].defaultType
}
}
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.codegen.inline.SourceMapper;
import org.jetbrains.kotlin.codegen.state.GenerationState;
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper;
import org.jetbrains.kotlin.codegen.state.TypeMapperUtilsKt;
import org.jetbrains.kotlin.config.ApiVersion;
import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.descriptors.annotations.AnnotatedImpl;
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
@@ -642,6 +643,8 @@ public abstract class MemberCodegen<T extends KtPureElement/* TODO: & KtDeclarat
if (!state.getClassBuilderMode().generateBodies) return;
boolean generateClassIntCtorCall = state.getJvmRuntimeTypes().getGenerateOptimizedCallableReferenceSuperClasses();
InstructionAdapter iv = createOrGetClInitCodegen().v;
iv.iconst(delegatedProperties.size());
iv.newarray(K_PROPERTY_TYPE);
@@ -658,14 +661,29 @@ public abstract class MemberCodegen<T extends KtPureElement/* TODO: & KtDeclarat
iv.anew(implType);
iv.dup();
// TODO: generate the container once and save to a local field instead (KT-10495)
ClosureCodegen.generateCallableReferenceDeclarationContainer(iv, property, state);
List<Type> superCtorArgTypes = new ArrayList<>();
if (generateClassIntCtorCall) {
ClosureCodegen.generateCallableReferenceDeclarationContainerClass(iv, property, state);
superCtorArgTypes.add(JAVA_CLASS_TYPE);
} else {
// TODO: generate the container once and save to a local field instead (KT-10495)
ClosureCodegen.generateCallableReferenceDeclarationContainer(iv, property, state);
superCtorArgTypes.add(K_DECLARATION_CONTAINER_TYPE);
}
iv.aconst(property.getName().asString());
PropertyReferenceCodegen.generateCallableReferenceSignature(iv, property, state);
superCtorArgTypes.add(JAVA_STRING_TYPE);
superCtorArgTypes.add(JAVA_STRING_TYPE);
if (generateClassIntCtorCall) {
iv.aconst(ClosureCodegen.isTopLevelCallableReference(property) ? 1 : 0);
superCtorArgTypes.add(Type.INT_TYPE);
}
iv.invokespecial(
implType.getInternalName(), "<init>",
Type.getMethodDescriptor(Type.VOID_TYPE, K_DECLARATION_CONTAINER_TYPE, JAVA_STRING_TYPE, JAVA_STRING_TYPE), false
Type.getMethodDescriptor(Type.VOID_TYPE, superCtorArgTypes.toArray(new Type[0])), false
);
Method wrapper = PropertyReferenceCodegen.getWrapperMethodForPropertyReference(property, receiverCount);
iv.invokestatic(REFLECTION, wrapper.getName(), wrapper.getDescriptor(), false);
@@ -114,16 +114,16 @@ class PropertyReferenceCodegen(
generateConstructor()
generateMethod("property reference getName", ACC_PUBLIC, method("getName", JAVA_STRING_TYPE)) {
aconst(target.name.asString())
}
generateMethod("property reference getSignature", ACC_PUBLIC, method("getSignature", JAVA_STRING_TYPE)) {
generateCallableReferenceSignature(this, target, state)
}
generateMethod("property reference getOwner", ACC_PUBLIC, method("getOwner", K_DECLARATION_CONTAINER_TYPE)) {
ClosureCodegen.generateCallableReferenceDeclarationContainer(this, target, state)
if (!isOptimizedPropertyReferenceSupertype(superAsmType)) {
generateMethod("property reference getName", ACC_PUBLIC, method("getName", JAVA_STRING_TYPE)) {
aconst(target.name.asString())
}
generateMethod("property reference getSignature", ACC_PUBLIC, method("getSignature", JAVA_STRING_TYPE)) {
generateCallableReferenceSignature(this, target, state)
}
generateMethod("property reference getOwner", ACC_PUBLIC, method("getOwner", K_DECLARATION_CONTAINER_TYPE)) {
ClosureCodegen.generateCallableReferenceDeclarationContainer(this, target, state)
}
}
if (!isLocalDelegatedProperty) {
@@ -136,16 +136,31 @@ class PropertyReferenceCodegen(
val shouldHaveBoundReferenceReceiver = closure.isForBoundCallableReference()
val receiverIndexAndFieldInfo = generateClosureFieldsInitializationFromParameters(closure, constructorArgs)
if (receiverIndexAndFieldInfo == null) {
assert(!shouldHaveBoundReferenceReceiver) { "No bound reference receiver in constructor parameters: $constructorArgs" }
load(0, OBJECT_TYPE)
invokespecial(superAsmType.internalName, "<init>", "()V", false)
} else {
load(0, OBJECT_TYPE)
val superCtorArgTypes = mutableListOf<Type>()
if (receiverIndexAndFieldInfo != null) {
val (receiverIndex, receiverFieldInfo) = receiverIndexAndFieldInfo
load(0, OBJECT_TYPE)
loadBoundReferenceReceiverParameter(receiverIndex, receiverFieldInfo.fieldType, receiverFieldInfo.fieldKotlinType)
invokespecial(superAsmType.internalName, "<init>", "(Ljava/lang/Object;)V", false)
superCtorArgTypes.add(OBJECT_TYPE)
} else {
assert(!shouldHaveBoundReferenceReceiver) { "No bound reference receiver in constructor parameters: $constructorArgs" }
}
if (isOptimizedPropertyReferenceSupertype(superAsmType)) {
ClosureCodegen.generateCallableReferenceDeclarationContainerClass(this, target, state)
aconst(target.name.asString())
generateCallableReferenceSignature(this, target, state)
aconst(if (ClosureCodegen.isTopLevelCallableReference(target)) 1 else 0)
superCtorArgTypes.add(JAVA_CLASS_TYPE)
superCtorArgTypes.add(JAVA_STRING_TYPE)
superCtorArgTypes.add(JAVA_STRING_TYPE)
superCtorArgTypes.add(Type.INT_TYPE)
}
invokespecial(
superAsmType.internalName, "<init>",
Type.getMethodDescriptor(Type.VOID_TYPE, *superCtorArgTypes.toTypedArray()), false
)
}
}
@@ -141,7 +141,7 @@ abstract class DefaultLambda(
interfaces: Array<out String>?
) {
isPropertyReference = superName in PROPERTY_REFERENCE_SUPER_CLASSES
isFunctionReference = superName == FUNCTION_REFERENCE.internalName
isFunctionReference = superName == FUNCTION_REFERENCE.internalName || superName == FUNCTION_REFERENCE_IMPL.internalName
super.visit(version, access, name, signature, superName, interfaces)
}
@@ -204,10 +204,12 @@ abstract class DefaultLambda(
protected abstract fun mapAsmSignature(sourceCompiler: SourceCompilerForInline): Method
private companion object {
val PROPERTY_REFERENCE_SUPER_CLASSES = listOf(
PROPERTY_REFERENCE0, PROPERTY_REFERENCE1, PROPERTY_REFERENCE2,
MUTABLE_PROPERTY_REFERENCE0, MUTABLE_PROPERTY_REFERENCE1, MUTABLE_PROPERTY_REFERENCE2
).mapTo(HashSet(), Type::getInternalName)
val PROPERTY_REFERENCE_SUPER_CLASSES =
listOf(
PROPERTY_REFERENCE0, PROPERTY_REFERENCE1, PROPERTY_REFERENCE2,
MUTABLE_PROPERTY_REFERENCE0, MUTABLE_PROPERTY_REFERENCE1, MUTABLE_PROPERTY_REFERENCE2
).plus(OPTIMIZED_PROPERTY_REFERENCE_SUPERTYPES)
.mapTo(HashSet(), Type::getInternalName)
}
}
@@ -1978,6 +1978,16 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/callableReference/nested.kt");
}
@TestMetadata("optimizedSuperclasses_after.kt")
public void testOptimizedSuperclasses_after() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/optimizedSuperclasses_after.kt");
}
@TestMetadata("optimizedSuperclasses_before.kt")
public void testOptimizedSuperclasses_before() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/optimizedSuperclasses_before.kt");
}
@TestMetadata("compiler/testData/codegen/box/callableReference/bound")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -8625,6 +8635,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/delegatedProperty"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@TestMetadata("beforeDeclarationContainerOptimization.kt")
public void testBeforeDeclarationContainerOptimization() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/beforeDeclarationContainerOptimization.kt");
}
@TestMetadata("capturePropertyInClosure.kt")
public void testCapturePropertyInClosure() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/capturePropertyInClosure.kt");
@@ -5,12 +5,12 @@
package org.jetbrains.kotlin.resolve.jvm;
import kotlin.collections.CollectionsKt;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.builtins.PrimitiveType;
import org.jetbrains.org.objectweb.asm.Type;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
public class AsmTypes {
private static final Map<Class<?>, Type> TYPES_MAP = new HashMap<>();
@@ -29,7 +29,10 @@ public class AsmTypes {
public static final Type UNIT_TYPE = Type.getObjectType("kotlin/Unit");
public static final Type LAMBDA = Type.getObjectType("kotlin/jvm/internal/Lambda");
public static final Type FUNCTION_REFERENCE = Type.getObjectType("kotlin/jvm/internal/FunctionReference");
public static final Type FUNCTION_REFERENCE_IMPL = Type.getObjectType("kotlin/jvm/internal/FunctionReferenceImpl");
public static final Type PROPERTY_REFERENCE0 = Type.getObjectType("kotlin/jvm/internal/PropertyReference0");
public static final Type PROPERTY_REFERENCE1 = Type.getObjectType("kotlin/jvm/internal/PropertyReference1");
public static final Type PROPERTY_REFERENCE2 = Type.getObjectType("kotlin/jvm/internal/PropertyReference2");
@@ -37,8 +40,6 @@ public class AsmTypes {
public static final Type MUTABLE_PROPERTY_REFERENCE1 = Type.getObjectType("kotlin/jvm/internal/MutablePropertyReference1");
public static final Type MUTABLE_PROPERTY_REFERENCE2 = Type.getObjectType("kotlin/jvm/internal/MutablePropertyReference2");
public static final Type RESULT_FAILURE = Type.getObjectType("kotlin/Result$Failure");
public static final Type FUNCTION0 = Type.getObjectType("kotlin/jvm/functions/Function0");
public static final Type FUNCTION1 = Type.getObjectType("kotlin/jvm/functions/Function1");
@@ -124,6 +125,16 @@ public class AsmTypes {
return TYPES_MAP.computeIfAbsent(javaClass, k -> Type.getType(javaClass));
}
public static final List<Type> OPTIMIZED_PROPERTY_REFERENCE_SUPERTYPES =
CollectionsKt.flatten(Arrays.asList(
Arrays.asList(PROPERTY_REFERENCE_IMPL),
Arrays.asList(MUTABLE_PROPERTY_REFERENCE_IMPL)
));
public static boolean isOptimizedPropertyReferenceSupertype(@NotNull Type type) {
return OPTIMIZED_PROPERTY_REFERENCE_SUPERTYPES.contains(type);
}
private AsmTypes() {
}
}
@@ -0,0 +1,29 @@
// TARGET_BACKEND: JVM
// IGNORE_BACKEND_FIR: JVM_IR
// IGNORE_BACKEND: JVM_IR
// WITH_RUNTIME
class A {
fun memberFunction() {}
val memberProperty: String = ""
}
val topLevelProperty: Int = 0
fun check(reference: Any, expected: String, message: String) {
val actual = reference.javaClass.declaredMethods.map { it.name }.sorted().toString()
if (expected != actual) {
throw AssertionError("Fail on $message. Expected: $expected. Actual: $actual")
}
}
fun box(): String {
check(A::memberFunction, "[invoke, invoke]", "unbound function reference")
check(A()::memberFunction, "[invoke, invoke]", "bound function reference")
check(::topLevelProperty, "[get]", "unbound property reference 0")
check(A::memberProperty, "[get]", "unbound property reference 1")
check(A()::memberProperty, "[get]", "bound property reference 1")
return "OK"
}
@@ -0,0 +1,29 @@
// !API_VERSION: 1.3
// TARGET_BACKEND: JVM
// IGNORE_BACKEND_FIR: JVM_IR
// WITH_RUNTIME
class A {
fun memberFunction() {}
val memberProperty: String = ""
}
val topLevelProperty: Int = 0
fun check(reference: Any, expected: String, message: String) {
val actual = reference.javaClass.declaredMethods.map { it.name }.sorted().toString()
if (expected != actual) {
throw AssertionError("Fail on $message. Expected: $expected. Actual: $actual")
}
}
fun box(): String {
check(A::memberFunction, "[getName, getOwner, getSignature, invoke, invoke]", "unbound function reference")
check(A()::memberFunction, "[getName, getOwner, getSignature, invoke, invoke]", "bound function reference")
check(::topLevelProperty, "[get, getName, getOwner, getSignature]", "unbound property reference 0")
check(A::memberProperty, "[get, getName, getOwner, getSignature]", "unbound property reference 1")
check(A()::memberProperty, "[get, getName, getOwner, getSignature]", "bound property reference 1")
return "OK"
}
@@ -0,0 +1,19 @@
// !API_VERSION: 1.3
// IGNORE_BACKEND_FIR: JVM_IR
// This test simply checks that we still generate correct calls to PropertyReference1Impl constructors for API version < 1.4,
// where we added and started using new constructors which take j.l.Class+int instead of KDeclarationContainer.
class D(val v: String) {
operator fun getValue(a: Any?, b: Any?): String = v
operator fun setValue(a: Any?, b: Any?, c: String) {}
}
class A {
val o by D("O")
var k by D("K")
val z by D("")
}
fun box(): String =
A().o + A().k + A().z
@@ -12,9 +12,6 @@ synthetic final class NoReceiverInCallableReferenceClassesKt$A_bar$1 {
static method <clinit>(): void
method <init>(): void
public @org.jetbrains.annotations.Nullable method get(@org.jetbrains.annotations.Nullable p0: java.lang.Object): java.lang.Object
public method getName(): java.lang.String
public method getOwner(): kotlin.reflect.KDeclarationContainer
public method getSignature(): java.lang.String
}
@kotlin.Metadata
@@ -23,9 +20,6 @@ synthetic final class NoReceiverInCallableReferenceClassesKt$A_foo$1 {
inner class NoReceiverInCallableReferenceClassesKt$A_foo$1
static method <clinit>(): void
method <init>(): void
public final method getName(): java.lang.String
public final method getOwner(): kotlin.reflect.KDeclarationContainer
public final method getSignature(): java.lang.String
public final method invoke(@org.jetbrains.annotations.NotNull p0: A): void
public synthetic bridge method invoke(p0: java.lang.Object): java.lang.Object
}
@@ -34,18 +28,12 @@ synthetic final class NoReceiverInCallableReferenceClassesKt$A_foo$1 {
synthetic final class NoReceiverInCallableReferenceClassesKt$aBar$1 {
method <init>(p0: A): void
public @org.jetbrains.annotations.Nullable method get(): java.lang.Object
public method getName(): java.lang.String
public method getOwner(): kotlin.reflect.KDeclarationContainer
public method getSignature(): java.lang.String
}
@kotlin.Metadata
synthetic final class NoReceiverInCallableReferenceClassesKt$aFoo$1 {
inner class NoReceiverInCallableReferenceClassesKt$aFoo$1
method <init>(p0: A): void
public final method getName(): java.lang.String
public final method getOwner(): kotlin.reflect.KDeclarationContainer
public final method getSignature(): java.lang.String
public synthetic bridge method invoke(): java.lang.Object
public final method invoke(): void
}
@@ -8,18 +8,6 @@ class A {
// TESTED_OBJECTS: A$bar$1
// FLAGS: ACC_FINAL, ACC_SUPER, ACC_SYNTHETIC
// TESTED_OBJECT_KIND: function
// TESTED_OBJECTS: A$bar$1, getName
// FLAGS: ACC_PUBLIC, ACC_FINAL
// TESTED_OBJECT_KIND: function
// TESTED_OBJECTS: A$bar$1, getOwner
// FLAGS: ACC_PUBLIC, ACC_FINAL
// TESTED_OBJECT_KIND: function
// TESTED_OBJECTS: A$bar$1, getSignature
// FLAGS: ACC_PUBLIC, ACC_FINAL
// TESTED_OBJECT_KIND: function
// TESTED_OBJECTS: A$bar$1, invoke
// FLAGS: ACC_PUBLIC, ACC_FINAL
// FLAGS: ACC_PUBLIC, ACC_FINAL
@@ -8,18 +8,6 @@ class A {
// TESTED_OBJECTS: A$bar$1
// FLAGS: ACC_FINAL, ACC_SUPER, ACC_SYNTHETIC
// TESTED_OBJECT_KIND: function
// TESTED_OBJECTS: A$bar$1, getName
// FLAGS: ACC_PUBLIC
// TESTED_OBJECT_KIND: function
// TESTED_OBJECTS: A$bar$1, getOwner
// FLAGS: ACC_PUBLIC
// TESTED_OBJECT_KIND: function
// TESTED_OBJECTS: A$bar$1, getSignature
// FLAGS: ACC_PUBLIC
// TESTED_OBJECT_KIND: function
// TESTED_OBJECTS: A$bar$1, get
// FLAGS: ACC_PUBLIC
// FLAGS: ACC_PUBLIC
@@ -1998,6 +1998,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/callableReference/nested.kt");
}
@TestMetadata("optimizedSuperclasses_after.kt")
public void testOptimizedSuperclasses_after() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/optimizedSuperclasses_after.kt");
}
@TestMetadata("optimizedSuperclasses_before.kt")
public void testOptimizedSuperclasses_before() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/optimizedSuperclasses_before.kt");
}
@TestMetadata("compiler/testData/codegen/box/callableReference/bound")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -9770,6 +9780,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/delegatedProperty"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
}
@TestMetadata("beforeDeclarationContainerOptimization.kt")
public void testBeforeDeclarationContainerOptimization() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/beforeDeclarationContainerOptimization.kt");
}
@TestMetadata("capturePropertyInClosure.kt")
public void testCapturePropertyInClosure() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/capturePropertyInClosure.kt");
@@ -1998,6 +1998,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/callableReference/nested.kt");
}
@TestMetadata("optimizedSuperclasses_after.kt")
public void testOptimizedSuperclasses_after() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/optimizedSuperclasses_after.kt");
}
@TestMetadata("optimizedSuperclasses_before.kt")
public void testOptimizedSuperclasses_before() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/optimizedSuperclasses_before.kt");
}
@TestMetadata("compiler/testData/codegen/box/callableReference/bound")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -9775,6 +9785,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/delegatedProperty"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
}
@TestMetadata("beforeDeclarationContainerOptimization.kt")
public void testBeforeDeclarationContainerOptimization() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/beforeDeclarationContainerOptimization.kt");
}
@TestMetadata("capturePropertyInClosure.kt")
public void testCapturePropertyInClosure() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/capturePropertyInClosure.kt");
@@ -1978,6 +1978,16 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/callableReference/nested.kt");
}
@TestMetadata("optimizedSuperclasses_after.kt")
public void testOptimizedSuperclasses_after() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/optimizedSuperclasses_after.kt");
}
@TestMetadata("optimizedSuperclasses_before.kt")
public void testOptimizedSuperclasses_before() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/optimizedSuperclasses_before.kt");
}
@TestMetadata("compiler/testData/codegen/box/callableReference/bound")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -8625,6 +8635,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/delegatedProperty"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@TestMetadata("beforeDeclarationContainerOptimization.kt")
public void testBeforeDeclarationContainerOptimization() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/beforeDeclarationContainerOptimization.kt");
}
@TestMetadata("capturePropertyInClosure.kt")
public void testCapturePropertyInClosure() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/capturePropertyInClosure.kt");
@@ -52,7 +52,7 @@ abstract class KotlinSyntheticTypeComponentProviderBase : SyntheticTypeComponent
return true
}
// The direct supertype may be PropertyReference0 or something
// The direct supertype may be FunctionReferenceImpl, PropertyReference0Impl, MutablePropertyReference0, etc.
return if (superClassName.startsWith("kotlin.jvm.internal."))
superClass.isCallableReferenceSyntheticClass()
else
@@ -7345,6 +7345,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/delegatedProperty"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true);
}
@TestMetadata("beforeDeclarationContainerOptimization.kt")
public void testBeforeDeclarationContainerOptimization() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/beforeDeclarationContainerOptimization.kt");
}
@TestMetadata("capturePropertyInClosure.kt")
public void testCapturePropertyInClosure() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/capturePropertyInClosure.kt");
@@ -7345,6 +7345,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/delegatedProperty"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true);
}
@TestMetadata("beforeDeclarationContainerOptimization.kt")
public void testBeforeDeclarationContainerOptimization() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/beforeDeclarationContainerOptimization.kt");
}
@TestMetadata("capturePropertyInClosure.kt")
public void testCapturePropertyInClosure() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/capturePropertyInClosure.kt");
@@ -32,6 +32,18 @@ public abstract class CallableReference implements KCallable, Serializable {
@SinceKotlin(version = "1.1")
protected final Object receiver;
@SinceKotlin(version = "1.4")
private final Class owner;
@SinceKotlin(version = "1.4")
private final String name;
@SinceKotlin(version = "1.4")
private final String signature;
@SinceKotlin(version = "1.4")
private final boolean isTopLevel;
@SinceKotlin(version = "1.1")
public static final Object NO_RECEIVER = NoReceiver.INSTANCE;
@@ -50,7 +62,20 @@ public abstract class CallableReference implements KCallable, Serializable {
@SinceKotlin(version = "1.1")
protected CallableReference(Object receiver) {
this(receiver, null, null, null, 0);
}
/**
* @param flags Bitmask where bits represent the following flags:<br/>
* <li><ul>0 - the owner of this reference is a package, not a class.</ul></li>
*/
@SinceKotlin(version = "1.4")
protected CallableReference(Object receiver, Class owner, String name, String signature, int flags) {
this.receiver = receiver;
this.owner = owner;
this.name = name;
this.signature = signature;
this.isTopLevel = (flags & 1) == 1;
}
protected abstract KCallable computeReflected();
@@ -79,14 +104,16 @@ public abstract class CallableReference implements KCallable, Serializable {
return result;
}
// The following methods provide the information identifying this callable, which is used by the reflection implementation.
// They are supposed to be overridden in each subclass (each anonymous class generated for a callable reference).
// The following methods provide the information identifying this callable, which is used by the reflection implementation and
// by equals/hashCode/toString. For callable references compiled prior to 1.4, these methods were overridden in each subclass
// (each anonymous class generated for a callable reference).
/**
* @return the class or package where the callable should be located, usually specified on the LHS of the '::' operator
*/
public KDeclarationContainer getOwner() {
throw new AbstractMethodError();
return owner == null ? null :
isTopLevel ? Reflection.getOrCreateKotlinPackage(owner) : Reflection.getOrCreateKotlinClass(owner);
}
/**
@@ -94,7 +121,7 @@ public abstract class CallableReference implements KCallable, Serializable {
*/
@Override
public String getName() {
throw new AbstractMethodError();
return name;
}
/**
@@ -106,7 +133,7 @@ public abstract class CallableReference implements KCallable, Serializable {
* but only as a unique and unambiguous way to map a function/property descriptor to a string.
*/
public String getSignature() {
throw new AbstractMethodError();
return signature;
}
// The following methods are the delegating implementations of reflection functions. They are called when you're using reflection
@@ -9,7 +9,7 @@ import kotlin.SinceKotlin;
import kotlin.reflect.KCallable;
import kotlin.reflect.KFunction;
@SuppressWarnings("rawtypes")
@SuppressWarnings({"rawtypes", "unused"})
public class FunctionReference extends CallableReference implements FunctionBase, KFunction {
private final int arity;
@@ -19,7 +19,12 @@ public class FunctionReference extends CallableReference implements FunctionBase
@SinceKotlin(version = "1.1")
public FunctionReference(int arity, Object receiver) {
super(receiver);
this(arity, receiver, null, null, null, 0);
}
@SinceKotlin(version = "1.4")
public FunctionReference(int arity, Object receiver, Class owner, String name, String signature, int flags) {
super(receiver, owner, name, signature, flags);
this.arity = arity;
}
@@ -5,33 +5,27 @@
package kotlin.jvm.internal;
import kotlin.SinceKotlin;
import kotlin.reflect.KClass;
import kotlin.reflect.KDeclarationContainer;
@SuppressWarnings({"unused", "NullableProblems"})
@SuppressWarnings({"unused", "rawtypes"})
public class FunctionReferenceImpl extends FunctionReference {
private final KDeclarationContainer owner;
private final String name;
private final String signature;
public FunctionReferenceImpl(int arity, KDeclarationContainer owner, String name, String signature) {
super(arity);
this.owner = owner;
this.name = name;
this.signature = signature;
super(
arity, NO_RECEIVER,
((ClassBasedDeclarationContainer) owner).getJClass(), name, signature,
owner instanceof KClass ? 0 : 1
);
}
@Override
public KDeclarationContainer getOwner() {
return owner;
@SinceKotlin(version = "1.4")
public FunctionReferenceImpl(int arity, Class owner, String name, String signature, int flags) {
super(arity, NO_RECEIVER, owner, name, signature, flags);
}
@Override
public String getName() {
return name;
}
@Override
public String getSignature() {
return signature;
@SinceKotlin(version = "1.4")
public FunctionReferenceImpl(int arity, Object receiver, Class owner, String name, String signature, int flags) {
super(arity, receiver, owner, name, signature, flags);
}
}
@@ -8,7 +8,7 @@ package kotlin.jvm.internal;
import kotlin.SinceKotlin;
import kotlin.reflect.KMutableProperty;
@SuppressWarnings("rawtypes")
@SuppressWarnings({"rawtypes", "unused"})
public abstract class MutablePropertyReference extends PropertyReference implements KMutableProperty {
public MutablePropertyReference() {
}
@@ -17,4 +17,9 @@ public abstract class MutablePropertyReference extends PropertyReference impleme
public MutablePropertyReference(Object receiver) {
super(receiver);
}
@SinceKotlin(version = "1.4")
public MutablePropertyReference(Object receiver, Class owner, String name, String signature, int flags) {
super(receiver, owner, name, signature, flags);
}
}
@@ -20,6 +20,11 @@ public abstract class MutablePropertyReference0 extends MutablePropertyReference
super(receiver);
}
@SinceKotlin(version = "1.4")
public MutablePropertyReference0(Object receiver, Class owner, String name, String signature, int flags) {
super(receiver, owner, name, signature, flags);
}
@Override
protected KCallable computeReflected() {
return Reflection.mutableProperty0(this);
@@ -5,33 +5,28 @@
package kotlin.jvm.internal;
import kotlin.SinceKotlin;
import kotlin.reflect.KClass;
import kotlin.reflect.KDeclarationContainer;
@SuppressWarnings({"unused", "NullableProblems"})
@SuppressWarnings({"unused", "rawtypes"})
public class MutablePropertyReference0Impl extends MutablePropertyReference0 {
private final KDeclarationContainer owner;
private final String name;
private final String signature;
public MutablePropertyReference0Impl(KDeclarationContainer owner, String name, String signature) {
this.owner = owner;
this.name = name;
this.signature = signature;
super(
NO_RECEIVER,
((ClassBasedDeclarationContainer) owner).getJClass(), name, signature,
owner instanceof KClass ? 0 : 1
);
}
@Override
public KDeclarationContainer getOwner() {
return owner;
@SinceKotlin(version = "1.4")
public MutablePropertyReference0Impl(Class owner, String name, String signature, int flags) {
super(NO_RECEIVER, owner, name, signature, flags);
}
@Override
public String getName() {
return name;
}
@Override
public String getSignature() {
return signature;
@SinceKotlin(version = "1.4")
public MutablePropertyReference0Impl(Object receiver, Class owner, String name, String signature, int flags) {
super(receiver, owner, name, signature, flags);
}
@Override
@@ -13,6 +13,7 @@ import kotlin.reflect.KProperty1;
@SuppressWarnings({"unchecked", "rawtypes", "unused", "NullableProblems"})
public abstract class MutablePropertyReference1 extends MutablePropertyReference implements KMutableProperty1 {
public MutablePropertyReference1() {
super();
}
@SinceKotlin(version = "1.1")
@@ -20,6 +21,11 @@ public abstract class MutablePropertyReference1 extends MutablePropertyReference
super(receiver);
}
@SinceKotlin(version = "1.4")
public MutablePropertyReference1(Object receiver, Class owner, String name, String signature, int flags) {
super(receiver, owner, name, signature, flags);
}
@Override
protected KCallable computeReflected() {
return Reflection.mutableProperty1(this);
@@ -5,33 +5,28 @@
package kotlin.jvm.internal;
import kotlin.SinceKotlin;
import kotlin.reflect.KClass;
import kotlin.reflect.KDeclarationContainer;
@SuppressWarnings({"unused", "NullableProblems"})
@SuppressWarnings({"unused", "rawtypes"})
public class MutablePropertyReference1Impl extends MutablePropertyReference1 {
private final KDeclarationContainer owner;
private final String name;
private final String signature;
public MutablePropertyReference1Impl(KDeclarationContainer owner, String name, String signature) {
this.owner = owner;
this.name = name;
this.signature = signature;
super(
NO_RECEIVER,
((ClassBasedDeclarationContainer) owner).getJClass(), name, signature,
owner instanceof KClass ? 0 : 1
);
}
@Override
public KDeclarationContainer getOwner() {
return owner;
@SinceKotlin(version = "1.4")
public MutablePropertyReference1Impl(Class owner, String name, String signature, int flags) {
super(NO_RECEIVER, owner, name, signature, flags);
}
@Override
public String getName() {
return name;
}
@Override
public String getSignature() {
return signature;
@SinceKotlin(version = "1.4")
public MutablePropertyReference1Impl(Object receiver, Class owner, String name, String signature, int flags) {
super(receiver, owner, name, signature, flags);
}
@Override
@@ -10,8 +10,17 @@ import kotlin.reflect.KCallable;
import kotlin.reflect.KMutableProperty2;
import kotlin.reflect.KProperty2;
@SuppressWarnings({"unchecked", "rawtypes", "NullableProblems"})
@SuppressWarnings({"unchecked", "rawtypes", "NullableProblems", "unused"})
public abstract class MutablePropertyReference2 extends MutablePropertyReference implements KMutableProperty2 {
public MutablePropertyReference2() {
super();
}
@SinceKotlin(version = "1.4")
public MutablePropertyReference2(Class owner, String name, String signature, int flags) {
super(NO_RECEIVER, owner, name, signature, flags);
}
@Override
protected KCallable computeReflected() {
return Reflection.mutableProperty2(this);
@@ -5,33 +5,22 @@
package kotlin.jvm.internal;
import kotlin.SinceKotlin;
import kotlin.reflect.KClass;
import kotlin.reflect.KDeclarationContainer;
@SuppressWarnings({"unused", "NullableProblems"})
@SuppressWarnings({"unused", "rawtypes"})
public class MutablePropertyReference2Impl extends MutablePropertyReference2 {
private final KDeclarationContainer owner;
private final String name;
private final String signature;
public MutablePropertyReference2Impl(KDeclarationContainer owner, String name, String signature) {
this.owner = owner;
this.name = name;
this.signature = signature;
super(
((ClassBasedDeclarationContainer) owner).getJClass(), name, signature,
owner instanceof KClass ? 0 : 1
);
}
@Override
public KDeclarationContainer getOwner() {
return owner;
}
@Override
public String getName() {
return name;
}
@Override
public String getSignature() {
return signature;
@SinceKotlin(version = "1.4")
public MutablePropertyReference2Impl(Class owner, String name, String signature, int flags) {
super(owner, name, signature, flags);
}
@Override
@@ -20,6 +20,11 @@ public abstract class PropertyReference extends CallableReference implements KPr
super(receiver);
}
@SinceKotlin(version = "1.4")
public PropertyReference(Object receiver, Class owner, String name, String signature, int flags) {
super(receiver, owner, name, signature, flags);
}
@Override
@SinceKotlin(version = "1.1")
protected KProperty getReflected() {
@@ -20,6 +20,11 @@ public abstract class PropertyReference0 extends PropertyReference implements KP
super(receiver);
}
@SinceKotlin(version = "1.4")
public PropertyReference0(Object receiver, Class owner, String name, String signature, int flags) {
super(receiver, owner, name, signature, flags);
}
@Override
protected KCallable computeReflected() {
return Reflection.property0(this);
@@ -5,33 +5,28 @@
package kotlin.jvm.internal;
import kotlin.SinceKotlin;
import kotlin.reflect.KClass;
import kotlin.reflect.KDeclarationContainer;
@SuppressWarnings({"unused", "NullableProblems"})
@SuppressWarnings({"unused", "rawtypes"})
public class PropertyReference0Impl extends PropertyReference0 {
private final KDeclarationContainer owner;
private final String name;
private final String signature;
public PropertyReference0Impl(KDeclarationContainer owner, String name, String signature) {
this.owner = owner;
this.name = name;
this.signature = signature;
super(
NO_RECEIVER,
((ClassBasedDeclarationContainer) owner).getJClass(), name, signature,
owner instanceof KClass ? 0 : 1
);
}
@Override
public KDeclarationContainer getOwner() {
return owner;
@SinceKotlin(version = "1.4")
public PropertyReference0Impl(Class owner, String name, String signature, int flags) {
super(NO_RECEIVER, owner, name, signature, flags);
}
@Override
public String getName() {
return name;
}
@Override
public String getSignature() {
return signature;
@SinceKotlin(version = "1.4")
public PropertyReference0Impl(Object receiver, Class owner, String name, String signature, int flags) {
super(receiver, owner, name, signature, flags);
}
@Override
@@ -12,6 +12,7 @@ import kotlin.reflect.KProperty1;
@SuppressWarnings({"unchecked", "rawtypes", "unused", "NullableProblems"})
public abstract class PropertyReference1 extends PropertyReference implements KProperty1 {
public PropertyReference1() {
super();
}
@SinceKotlin(version = "1.1")
@@ -19,6 +20,11 @@ public abstract class PropertyReference1 extends PropertyReference implements KP
super(receiver);
}
@SinceKotlin(version = "1.4")
public PropertyReference1(Object receiver, Class owner, String name, String signature, int flags) {
super(receiver, owner, name, signature, flags);
}
@Override
protected KCallable computeReflected() {
return Reflection.property1(this);
@@ -5,33 +5,28 @@
package kotlin.jvm.internal;
import kotlin.SinceKotlin;
import kotlin.reflect.KClass;
import kotlin.reflect.KDeclarationContainer;
@SuppressWarnings("NullableProblems")
@SuppressWarnings({"unused", "rawtypes"})
public class PropertyReference1Impl extends PropertyReference1 {
private final KDeclarationContainer owner;
private final String name;
private final String signature;
public PropertyReference1Impl(KDeclarationContainer owner, String name, String signature) {
this.owner = owner;
this.name = name;
this.signature = signature;
super(
NO_RECEIVER,
((ClassBasedDeclarationContainer) owner).getJClass(), name, signature,
owner instanceof KClass ? 0 : 1
);
}
@Override
public KDeclarationContainer getOwner() {
return owner;
@SinceKotlin(version = "1.4")
public PropertyReference1Impl(Class owner, String name, String signature, int flags) {
super(NO_RECEIVER, owner, name, signature, flags);
}
@Override
public String getName() {
return name;
}
@Override
public String getSignature() {
return signature;
@SinceKotlin(version = "1.4")
public PropertyReference1Impl(Object receiver, Class owner, String name, String signature, int flags) {
super(receiver, owner, name, signature, flags);
}
@Override
@@ -9,8 +9,17 @@ import kotlin.SinceKotlin;
import kotlin.reflect.KCallable;
import kotlin.reflect.KProperty2;
@SuppressWarnings({"unchecked", "rawtypes", "NullableProblems"})
@SuppressWarnings({"unchecked", "rawtypes", "NullableProblems", "unused"})
public abstract class PropertyReference2 extends PropertyReference implements KProperty2 {
public PropertyReference2() {
super();
}
@SinceKotlin(version = "1.4")
public PropertyReference2(Class owner, String name, String signature, int flags) {
super(NO_RECEIVER, owner, name, signature, flags);
}
@Override
protected KCallable computeReflected() {
return Reflection.property2(this);
@@ -5,33 +5,22 @@
package kotlin.jvm.internal;
import kotlin.SinceKotlin;
import kotlin.reflect.KClass;
import kotlin.reflect.KDeclarationContainer;
@SuppressWarnings({"unused", "NullableProblems"})
@SuppressWarnings({"unused", "rawtypes"})
public class PropertyReference2Impl extends PropertyReference2 {
private final KDeclarationContainer owner;
private final String name;
private final String signature;
public PropertyReference2Impl(KDeclarationContainer owner, String name, String signature) {
this.owner = owner;
this.name = name;
this.signature = signature;
super(
((ClassBasedDeclarationContainer) owner).getJClass(), name, signature,
owner instanceof KClass ? 0 : 1
);
}
@Override
public KDeclarationContainer getOwner() {
return owner;
}
@Override
public String getName() {
return name;
}
@Override
public String getSignature() {
return signature;
@SinceKotlin(version = "1.4")
public PropertyReference2Impl(Class owner, String name, String signature, int flags) {
super(owner, name, signature, flags);
}
@Override
@@ -46,6 +46,11 @@ public class Reflection {
return factory.createKotlinClass(javaClass, internalName);
}
@SinceKotlin(version = "1.4")
public static KDeclarationContainer getOrCreateKotlinPackage(Class javaClass) {
return factory.getOrCreateKotlinPackage(javaClass, "");
}
public static KDeclarationContainer getOrCreateKotlinPackage(Class javaClass, String moduleName) {
return factory.getOrCreateKotlinPackage(javaClass, moduleName);
}
@@ -3192,6 +3192,7 @@ public abstract class kotlin/jvm/internal/CallableReference : java/io/Serializab
protected final field receiver Ljava/lang/Object;
public fun <init> ()V
protected fun <init> (Ljava/lang/Object;)V
protected fun <init> (Ljava/lang/Object;Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
public fun call ([Ljava/lang/Object;)Ljava/lang/Object;
public fun callBy (Ljava/util/Map;)Ljava/lang/Object;
public fun compute ()Lkotlin/reflect/KCallable;
@@ -3348,6 +3349,7 @@ public abstract class kotlin/jvm/internal/FunctionImpl : java/io/Serializable, k
public class kotlin/jvm/internal/FunctionReference : kotlin/jvm/internal/CallableReference, kotlin/jvm/internal/FunctionBase, kotlin/reflect/KFunction {
public fun <init> (I)V
public fun <init> (ILjava/lang/Object;)V
public fun <init> (ILjava/lang/Object;Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
protected fun computeReflected ()Lkotlin/reflect/KCallable;
public fun equals (Ljava/lang/Object;)Z
public fun getArity ()I
@@ -3363,10 +3365,9 @@ public class kotlin/jvm/internal/FunctionReference : kotlin/jvm/internal/Callabl
}
public class kotlin/jvm/internal/FunctionReferenceImpl : kotlin/jvm/internal/FunctionReference {
public fun <init> (ILjava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
public fun <init> (ILjava/lang/Object;Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
public fun <init> (ILkotlin/reflect/KDeclarationContainer;Ljava/lang/String;Ljava/lang/String;)V
public fun getName ()Ljava/lang/String;
public fun getOwner ()Lkotlin/reflect/KDeclarationContainer;
public fun getSignature ()Ljava/lang/String;
}
public class kotlin/jvm/internal/InlineMarker {
@@ -3495,11 +3496,13 @@ public class kotlin/jvm/internal/MutableLocalVariableReference : kotlin/jvm/inte
public abstract class kotlin/jvm/internal/MutablePropertyReference : kotlin/jvm/internal/PropertyReference, kotlin/reflect/KMutableProperty {
public fun <init> ()V
public fun <init> (Ljava/lang/Object;)V
public fun <init> (Ljava/lang/Object;Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
}
public abstract class kotlin/jvm/internal/MutablePropertyReference0 : kotlin/jvm/internal/MutablePropertyReference, kotlin/reflect/KMutableProperty0 {
public fun <init> ()V
public fun <init> (Ljava/lang/Object;)V
public fun <init> (Ljava/lang/Object;Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
protected fun computeReflected ()Lkotlin/reflect/KCallable;
public fun getDelegate ()Ljava/lang/Object;
public synthetic fun getGetter ()Lkotlin/reflect/KProperty$Getter;
@@ -3510,17 +3513,17 @@ public abstract class kotlin/jvm/internal/MutablePropertyReference0 : kotlin/jvm
}
public class kotlin/jvm/internal/MutablePropertyReference0Impl : kotlin/jvm/internal/MutablePropertyReference0 {
public fun <init> (Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
public fun <init> (Ljava/lang/Object;Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
public fun <init> (Lkotlin/reflect/KDeclarationContainer;Ljava/lang/String;Ljava/lang/String;)V
public fun get ()Ljava/lang/Object;
public fun getName ()Ljava/lang/String;
public fun getOwner ()Lkotlin/reflect/KDeclarationContainer;
public fun getSignature ()Ljava/lang/String;
public fun set (Ljava/lang/Object;)V
}
public abstract class kotlin/jvm/internal/MutablePropertyReference1 : kotlin/jvm/internal/MutablePropertyReference, kotlin/reflect/KMutableProperty1 {
public fun <init> ()V
public fun <init> (Ljava/lang/Object;)V
public fun <init> (Ljava/lang/Object;Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
protected fun computeReflected ()Lkotlin/reflect/KCallable;
public fun getDelegate (Ljava/lang/Object;)Ljava/lang/Object;
public synthetic fun getGetter ()Lkotlin/reflect/KProperty$Getter;
@@ -3531,16 +3534,16 @@ public abstract class kotlin/jvm/internal/MutablePropertyReference1 : kotlin/jvm
}
public class kotlin/jvm/internal/MutablePropertyReference1Impl : kotlin/jvm/internal/MutablePropertyReference1 {
public fun <init> (Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
public fun <init> (Ljava/lang/Object;Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
public fun <init> (Lkotlin/reflect/KDeclarationContainer;Ljava/lang/String;Ljava/lang/String;)V
public fun get (Ljava/lang/Object;)Ljava/lang/Object;
public fun getName ()Ljava/lang/String;
public fun getOwner ()Lkotlin/reflect/KDeclarationContainer;
public fun getSignature ()Ljava/lang/String;
public fun set (Ljava/lang/Object;Ljava/lang/Object;)V
}
public abstract class kotlin/jvm/internal/MutablePropertyReference2 : kotlin/jvm/internal/MutablePropertyReference, kotlin/reflect/KMutableProperty2 {
public fun <init> ()V
public fun <init> (Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
protected fun computeReflected ()Lkotlin/reflect/KCallable;
public fun getDelegate (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
public synthetic fun getGetter ()Lkotlin/reflect/KProperty$Getter;
@@ -3551,11 +3554,9 @@ public abstract class kotlin/jvm/internal/MutablePropertyReference2 : kotlin/jvm
}
public class kotlin/jvm/internal/MutablePropertyReference2Impl : kotlin/jvm/internal/MutablePropertyReference2 {
public fun <init> (Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
public fun <init> (Lkotlin/reflect/KDeclarationContainer;Ljava/lang/String;Ljava/lang/String;)V
public fun get (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
public fun getName ()Ljava/lang/String;
public fun getOwner ()Lkotlin/reflect/KDeclarationContainer;
public fun getSignature ()Ljava/lang/String;
public fun set (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V
}
@@ -3581,6 +3582,7 @@ public abstract class kotlin/jvm/internal/PrimitiveSpreadBuilder {
public abstract class kotlin/jvm/internal/PropertyReference : kotlin/jvm/internal/CallableReference, kotlin/reflect/KProperty {
public fun <init> ()V
public fun <init> (Ljava/lang/Object;)V
public fun <init> (Ljava/lang/Object;Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
public fun equals (Ljava/lang/Object;)Z
protected synthetic fun getReflected ()Lkotlin/reflect/KCallable;
protected fun getReflected ()Lkotlin/reflect/KProperty;
@@ -3593,6 +3595,7 @@ public abstract class kotlin/jvm/internal/PropertyReference : kotlin/jvm/interna
public abstract class kotlin/jvm/internal/PropertyReference0 : kotlin/jvm/internal/PropertyReference, kotlin/reflect/KProperty0 {
public fun <init> ()V
public fun <init> (Ljava/lang/Object;)V
public fun <init> (Ljava/lang/Object;Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
protected fun computeReflected ()Lkotlin/reflect/KCallable;
public fun getDelegate ()Ljava/lang/Object;
public synthetic fun getGetter ()Lkotlin/reflect/KProperty$Getter;
@@ -3601,16 +3604,16 @@ public abstract class kotlin/jvm/internal/PropertyReference0 : kotlin/jvm/intern
}
public class kotlin/jvm/internal/PropertyReference0Impl : kotlin/jvm/internal/PropertyReference0 {
public fun <init> (Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
public fun <init> (Ljava/lang/Object;Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
public fun <init> (Lkotlin/reflect/KDeclarationContainer;Ljava/lang/String;Ljava/lang/String;)V
public fun get ()Ljava/lang/Object;
public fun getName ()Ljava/lang/String;
public fun getOwner ()Lkotlin/reflect/KDeclarationContainer;
public fun getSignature ()Ljava/lang/String;
}
public abstract class kotlin/jvm/internal/PropertyReference1 : kotlin/jvm/internal/PropertyReference, kotlin/reflect/KProperty1 {
public fun <init> ()V
public fun <init> (Ljava/lang/Object;)V
public fun <init> (Ljava/lang/Object;Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
protected fun computeReflected ()Lkotlin/reflect/KCallable;
public fun getDelegate (Ljava/lang/Object;)Ljava/lang/Object;
public synthetic fun getGetter ()Lkotlin/reflect/KProperty$Getter;
@@ -3619,15 +3622,15 @@ public abstract class kotlin/jvm/internal/PropertyReference1 : kotlin/jvm/intern
}
public class kotlin/jvm/internal/PropertyReference1Impl : kotlin/jvm/internal/PropertyReference1 {
public fun <init> (Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
public fun <init> (Ljava/lang/Object;Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
public fun <init> (Lkotlin/reflect/KDeclarationContainer;Ljava/lang/String;Ljava/lang/String;)V
public fun get (Ljava/lang/Object;)Ljava/lang/Object;
public fun getName ()Ljava/lang/String;
public fun getOwner ()Lkotlin/reflect/KDeclarationContainer;
public fun getSignature ()Ljava/lang/String;
}
public abstract class kotlin/jvm/internal/PropertyReference2 : kotlin/jvm/internal/PropertyReference, kotlin/reflect/KProperty2 {
public fun <init> ()V
public fun <init> (Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
protected fun computeReflected ()Lkotlin/reflect/KCallable;
public fun getDelegate (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
public synthetic fun getGetter ()Lkotlin/reflect/KProperty$Getter;
@@ -3636,11 +3639,9 @@ public abstract class kotlin/jvm/internal/PropertyReference2 : kotlin/jvm/intern
}
public class kotlin/jvm/internal/PropertyReference2Impl : kotlin/jvm/internal/PropertyReference2 {
public fun <init> (Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
public fun <init> (Lkotlin/reflect/KDeclarationContainer;Ljava/lang/String;Ljava/lang/String;)V
public fun get (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
public fun getName ()Ljava/lang/String;
public fun getOwner ()Lkotlin/reflect/KDeclarationContainer;
public fun getSignature ()Ljava/lang/String;
}
public class kotlin/jvm/internal/Ref {
@@ -3708,6 +3709,7 @@ public class kotlin/jvm/internal/Reflection {
public static fun getOrCreateKotlinClass (Ljava/lang/Class;)Lkotlin/reflect/KClass;
public static fun getOrCreateKotlinClass (Ljava/lang/Class;Ljava/lang/String;)Lkotlin/reflect/KClass;
public static fun getOrCreateKotlinClasses ([Ljava/lang/Class;)[Lkotlin/reflect/KClass;
public static fun getOrCreateKotlinPackage (Ljava/lang/Class;)Lkotlin/reflect/KDeclarationContainer;
public static fun getOrCreateKotlinPackage (Ljava/lang/Class;Ljava/lang/String;)Lkotlin/reflect/KDeclarationContainer;
public static fun mutableProperty0 (Lkotlin/jvm/internal/MutablePropertyReference0;)Lkotlin/reflect/KMutableProperty0;
public static fun mutableProperty1 (Lkotlin/jvm/internal/MutablePropertyReference1;)Lkotlin/reflect/KMutableProperty1;