Search in sources :

Example 1 with DeserializedCallableMemberDescriptor

use of org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor in project kotlin by JetBrains.

the class InlineCodegen method doCreateMethodNodeFromCompiled.

@Nullable
private static SMAPAndMethodNode doCreateMethodNodeFromCompiled(@NotNull CallableMemberDescriptor callableDescriptor, @NotNull final GenerationState state, @NotNull Method asmMethod) {
    if (isBuiltInArrayIntrinsic(callableDescriptor)) {
        ClassId classId = IntrinsicArrayConstructorsKt.getClassId();
        byte[] bytes = InlineCacheKt.getOrPut(state.getInlineCache().getClassBytes(), classId, new Function0<byte[]>() {

            @Override
            public byte[] invoke() {
                return IntrinsicArrayConstructorsKt.getBytecode();
            }
        });
        return InlineCodegenUtil.getMethodNode(bytes, asmMethod.getName(), asmMethod.getDescriptor(), classId);
    }
    assert callableDescriptor instanceof DeserializedCallableMemberDescriptor : "Not a deserialized function or proper: " + callableDescriptor;
    KotlinTypeMapper.ContainingClassesInfo containingClasses = state.getTypeMapper().getContainingClassesForDeserializedCallable((DeserializedCallableMemberDescriptor) callableDescriptor);
    final ClassId containerId = containingClasses.getImplClassId();
    byte[] bytes = InlineCacheKt.getOrPut(state.getInlineCache().getClassBytes(), containerId, new Function0<byte[]>() {

        @Override
        public byte[] invoke() {
            VirtualFile file = InlineCodegenUtil.findVirtualFile(state, containerId);
            if (file == null) {
                throw new IllegalStateException("Couldn't find declaration file for " + containerId);
            }
            try {
                return file.contentsToByteArray();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    });
    return InlineCodegenUtil.getMethodNode(bytes, asmMethod.getName(), asmMethod.getDescriptor(), containerId);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DeserializedCallableMemberDescriptor(org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor) ClassId(org.jetbrains.kotlin.name.ClassId) IOException(java.io.IOException) KotlinTypeMapper(org.jetbrains.kotlin.codegen.state.KotlinTypeMapper) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with DeserializedCallableMemberDescriptor

use of org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor in project kotlin by JetBrains.

the class InlineCodegen method createMethodNode.

@NotNull
static SMAPAndMethodNode createMethodNode(@NotNull final FunctionDescriptor functionDescriptor, @NotNull JvmMethodSignature jvmSignature, @NotNull ExpressionCodegen codegen, @NotNull CodegenContext context, boolean callDefault, @Nullable ResolvedCall<?> resolvedCall) {
    if (InlineCodegenUtil.isSpecialEnumMethod(functionDescriptor)) {
        assert resolvedCall != null : "Resolved call for " + functionDescriptor + " should be not null";
        Map<TypeParameterDescriptor, KotlinType> arguments = resolvedCall.getTypeArguments();
        assert arguments.size() == 1 : "Resolved call for " + functionDescriptor + " should have 1 type argument";
        MethodNode node = InlineCodegenUtil.createSpecialEnumMethodBody(codegen, functionDescriptor.getName().asString(), arguments.keySet().iterator().next().getDefaultType(), codegen.getState().getTypeMapper());
        return new SMAPAndMethodNode(node, SMAPParser.parseOrCreateDefault(null, null, "fake", -1, -1));
    } else if (CoroutineCodegenUtilKt.isBuiltInSuspendCoroutineOrReturnInJvm(functionDescriptor)) {
        return new SMAPAndMethodNode(CoroutineCodegenUtilKt.createMethodNodeForSuspendCoroutineOrReturn(functionDescriptor, codegen.getState().getTypeMapper()), SMAPParser.parseOrCreateDefault(null, null, "fake", -1, -1));
    }
    final GenerationState state = codegen.getState();
    final Method asmMethod = callDefault ? state.getTypeMapper().mapDefaultMethod(functionDescriptor, context.getContextKind()) : jvmSignature.getAsmMethod();
    MethodId methodId = new MethodId(DescriptorUtils.getFqNameSafe(functionDescriptor.getContainingDeclaration()), asmMethod);
    final CallableMemberDescriptor directMember = getDirectMemberAndCallableFromObject(functionDescriptor);
    if (!isBuiltInArrayIntrinsic(functionDescriptor) && !(directMember instanceof DeserializedCallableMemberDescriptor)) {
        return doCreateMethodNodeFromSource(functionDescriptor, jvmSignature, codegen, context, callDefault, state, asmMethod);
    }
    SMAPAndMethodNode resultInCache = InlineCacheKt.getOrPut(state.getInlineCache().getMethodNodeById(), methodId, new Function0<SMAPAndMethodNode>() {

        @Override
        public SMAPAndMethodNode invoke() {
            SMAPAndMethodNode result = doCreateMethodNodeFromCompiled(directMember, state, asmMethod);
            if (result == null) {
                throw new IllegalStateException("Couldn't obtain compiled function body for " + functionDescriptor);
            }
            return result;
        }
    });
    return resultInCache.copyWithNewNode(cloneMethodNode(resultInCache.getNode()));
}
Also used : KotlinType(org.jetbrains.kotlin.types.KotlinType) Method(org.jetbrains.org.objectweb.asm.commons.Method) DeserializedCallableMemberDescriptor(org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor) GenerationState(org.jetbrains.kotlin.codegen.state.GenerationState) MethodNode(org.jetbrains.org.objectweb.asm.tree.MethodNode) DeserializedCallableMemberDescriptor(org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with DeserializedCallableMemberDescriptor

use of org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor in project kotlin by JetBrains.

the class JvmCodegenUtil method isCallInsideSameModuleAsDeclared.

public static boolean isCallInsideSameModuleAsDeclared(@NotNull CallableMemberDescriptor declarationDescriptor, @NotNull CodegenContext context, @Nullable File outDirectory) {
    if (context instanceof RootContext) {
        return true;
    }
    DeclarationDescriptor contextDescriptor = context.getContextDescriptor();
    CallableMemberDescriptor directMember = getDirectMember(declarationDescriptor);
    if (directMember instanceof DeserializedCallableMemberDescriptor) {
        return ModuleVisibilityUtilsKt.isContainedByCompiledPartOfOurModule(directMember, outDirectory);
    } else {
        return DescriptorUtils.areInSameModule(directMember, contextDescriptor);
    }
}
Also used : RootContext(org.jetbrains.kotlin.codegen.context.RootContext) DeserializedCallableMemberDescriptor(org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor) JavaCallableMemberDescriptor(org.jetbrains.kotlin.load.java.descriptors.JavaCallableMemberDescriptor) DeserializedCallableMemberDescriptor(org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor)

Example 4 with DeserializedCallableMemberDescriptor

use of org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor in project kotlin by JetBrains.

the class KotlinTypeMapper method checkOwnerCompatibility.

private void checkOwnerCompatibility(@NotNull FunctionDescriptor descriptor) {
    if (!(descriptor instanceof DeserializedCallableMemberDescriptor))
        return;
    KotlinJvmBinaryClass ownerClass = null;
    DeclarationDescriptor container = descriptor.getContainingDeclaration();
    if (container instanceof DeserializedClassDescriptor) {
        SourceElement source = ((DeserializedClassDescriptor) container).getSource();
        if (source instanceof KotlinJvmBinarySourceElement) {
            ownerClass = ((KotlinJvmBinarySourceElement) source).getBinaryClass();
        }
    } else if (container instanceof LazyJavaPackageFragment) {
        SourceElement source = ((LazyJavaPackageFragment) container).getSource();
        if (source instanceof KotlinJvmBinaryPackageSourceElement) {
            ownerClass = ((KotlinJvmBinaryPackageSourceElement) source).getRepresentativeBinaryClass();
        }
    }
    if (ownerClass != null) {
        JvmBytecodeBinaryVersion version = ownerClass.getClassHeader().getBytecodeVersion();
        if (!version.isCompatible()) {
            incompatibleClassTracker.record(ownerClass);
        }
    }
}
Also used : DeserializedCallableMemberDescriptor(org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor) LazyJavaPackageFragment(org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaPackageFragment) JvmBytecodeBinaryVersion(org.jetbrains.kotlin.load.java.JvmBytecodeBinaryVersion) DeserializedClassDescriptor(org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor)

Example 5 with DeserializedCallableMemberDescriptor

use of org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor in project kotlin by JetBrains.

the class KotlinTypeMapper method internalNameForPackageMemberOwner.

@NotNull
private String internalNameForPackageMemberOwner(@NotNull CallableMemberDescriptor descriptor, boolean publicFacade) {
    boolean isAccessor = descriptor instanceof AccessorForCallableDescriptor;
    if (isAccessor) {
        descriptor = ((AccessorForCallableDescriptor) descriptor).getCalleeDescriptor();
    }
    KtFile file = DescriptorToSourceUtils.getContainingFile(descriptor);
    if (file != null) {
        Visibility visibility = descriptor.getVisibility();
        if (!publicFacade || isNonConstProperty(descriptor) || Visibilities.isPrivate(visibility) || isAccessor) /*Cause of KT-9603*/
        {
            return FileClasses.getFileClassInternalName(fileClassesProvider, file);
        } else {
            return FileClasses.getFacadeClassInternalName(fileClassesProvider, file);
        }
    }
    CallableMemberDescriptor directMember = DescriptorUtils.getDirectMember(descriptor);
    if (directMember instanceof DeserializedCallableMemberDescriptor) {
        String facadeFqName = getPackageMemberOwnerInternalName((DeserializedCallableMemberDescriptor) directMember, publicFacade);
        if (facadeFqName != null)
            return facadeFqName;
    }
    if (descriptor.getContainingDeclaration() instanceof IrBuiltinsPackageFragmentDescriptor) {
        return descriptor.getContainingDeclaration().getName().asString();
    }
    throw new RuntimeException("Could not find package member for " + descriptor + " in package fragment " + descriptor.getContainingDeclaration());
}
Also used : DeserializedCallableMemberDescriptor(org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor) KtFile(org.jetbrains.kotlin.psi.KtFile) IrBuiltinsPackageFragmentDescriptor(org.jetbrains.kotlin.ir.descriptors.IrBuiltinsPackageFragmentDescriptor) JavaCallableMemberDescriptor(org.jetbrains.kotlin.load.java.descriptors.JavaCallableMemberDescriptor) DeserializedCallableMemberDescriptor(org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

DeserializedCallableMemberDescriptor (org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor)6 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 JavaCallableMemberDescriptor (org.jetbrains.kotlin.load.java.descriptors.JavaCallableMemberDescriptor)2 KtFile (org.jetbrains.kotlin.psi.KtFile)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 IOException (java.io.IOException)1 RootContext (org.jetbrains.kotlin.codegen.context.RootContext)1 GenerationState (org.jetbrains.kotlin.codegen.state.GenerationState)1 KotlinTypeMapper (org.jetbrains.kotlin.codegen.state.KotlinTypeMapper)1 JvmFileClassInfo (org.jetbrains.kotlin.fileClasses.JvmFileClassInfo)1 IrBuiltinsPackageFragmentDescriptor (org.jetbrains.kotlin.ir.descriptors.IrBuiltinsPackageFragmentDescriptor)1 JvmBytecodeBinaryVersion (org.jetbrains.kotlin.load.java.JvmBytecodeBinaryVersion)1 LazyJavaPackageFragment (org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaPackageFragment)1 ClassId (org.jetbrains.kotlin.name.ClassId)1 DeserializedClassDescriptor (org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor)1 KotlinType (org.jetbrains.kotlin.types.KotlinType)1 Method (org.jetbrains.org.objectweb.asm.commons.Method)1 MethodNode (org.jetbrains.org.objectweb.asm.tree.MethodNode)1