Skip to content

Commit

Permalink
Remove kotlin.jvm.internal.KotlinPackage and corresponding code
Browse files Browse the repository at this point in the history
  • Loading branch information
udalov committed Nov 27, 2015
1 parent ad6888d commit 8594cfc
Show file tree
Hide file tree
Showing 31 changed files with 63 additions and 182 deletions.
Expand Up @@ -17,19 +17,19 @@
package org.jetbrains.kotlin.codegen.serialization;

import com.intellij.openapi.util.Pair;
import kotlin.jvm.functions.Function3;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor;
import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
import org.jetbrains.kotlin.descriptors.PropertyDescriptor;
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor;
import org.jetbrains.kotlin.util.slicedMap.*;
import org.jetbrains.kotlin.util.slicedMap.BasicWritableSlice;
import org.jetbrains.kotlin.util.slicedMap.MutableSlicedMap;
import org.jetbrains.kotlin.util.slicedMap.SlicedMapImpl;
import org.jetbrains.kotlin.util.slicedMap.Slices;
import org.jetbrains.org.objectweb.asm.Type;
import org.jetbrains.org.objectweb.asm.commons.Method;

import java.util.Collection;

public final class JvmSerializationBindings {
public static final SerializationMappingSlice<FunctionDescriptor, Method> METHOD_FOR_FUNCTION =
SerializationMappingSlice.create();
Expand Down Expand Up @@ -70,32 +70,7 @@ public static <K> SerializationMappingSetSlice<K> create() {
BasicWritableSlice.initSliceDebugNames(JvmSerializationBindings.class);
}

private final MutableSlicedMap map;

private JvmSerializationBindings(@NotNull MutableSlicedMap map) {
this.map = map;
}

public JvmSerializationBindings() {
this(SlicedMapImpl.create());
}

@NotNull
public static JvmSerializationBindings union(@NotNull Collection<JvmSerializationBindings> bindings) {
final MutableSlicedMap result = SlicedMapImpl.create();

for (JvmSerializationBindings binding : bindings) {
binding.map.forEach(new Function3<WritableSlice, Object, Object, Void>() {
@Override
public Void invoke(WritableSlice slice, Object key, Object value) {
result.put(slice, key, value);
return null;
}
});
}

return new JvmSerializationBindings(result);
}
private final MutableSlicedMap map = SlicedMapImpl.create();

public <K, V> void put(@NotNull SerializationMappingSlice<K, V> slice, @NotNull K key, @NotNull V value) {
map.put(slice, key, value);
Expand Down
Expand Up @@ -17,24 +17,19 @@
package org.jetbrains.kotlin.resolve.jvm.diagnostics

import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKind.*
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKind.*

public enum class MemberKind { FIELD, METHOD }

public data class RawSignature(public val name: String, public val desc: String, public val kind: MemberKind)

public enum class JvmDeclarationOriginKind {
OTHER,
PACKAGE_FACADE,
PACKAGE_PART,
INTERFACE_DEFAULT_IMPL,
DELEGATION_TO_DEFAULT_IMPLS,
Expand Down Expand Up @@ -68,7 +63,6 @@ public fun OtherOrigin(descriptor: DeclarationDescriptor): JvmDeclarationOrigin
public fun Bridge(descriptor: DeclarationDescriptor, element: PsiElement? = DescriptorToSourceUtils.descriptorToDeclaration(descriptor)): JvmDeclarationOrigin =
JvmDeclarationOrigin(BRIDGE, element, descriptor)

public fun PackageFacade(descriptor: PackageFragmentDescriptor): JvmDeclarationOrigin = JvmDeclarationOrigin(PACKAGE_FACADE, null, descriptor)
public fun PackagePart(file: KtFile, descriptor: PackageFragmentDescriptor): JvmDeclarationOrigin = JvmDeclarationOrigin(PACKAGE_PART, file, descriptor)

/**
Expand Down
Expand Up @@ -17,18 +17,18 @@
package org.jetbrains.kotlin.asJava

import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics
import com.intellij.psi.search.GlobalSearchScope
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm.*
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ConflictingJvmDeclarationsData
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKind.*
import org.jetbrains.kotlin.diagnostics.Errors.*
import org.jetbrains.kotlin.diagnostics.DiagnosticFactory.*
import org.jetbrains.kotlin.diagnostics.DiagnosticFactory
import org.jetbrains.kotlin.diagnostics.DiagnosticFactory.cast
import org.jetbrains.kotlin.diagnostics.Errors.*
import org.jetbrains.kotlin.fileClasses.NoResolveFileClassesProvider
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ConflictingJvmDeclarationsData
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm.*
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKind.*

public fun getJvmSignatureDiagnostics(element: PsiElement, otherDiagnostics: Diagnostics, moduleScope: GlobalSearchScope): Diagnostics? {
fun getDiagnosticsForFileFacade(file: KtFile): Diagnostics? {
Expand Down Expand Up @@ -118,8 +118,8 @@ class FilteredJvmDiagnostics(val jvmDiagnostics: Diagnostics, val otherDiagnosti
// in case of implementation copied from a super trait there will be both diagnostics on the same signature
other.factory == ErrorsJvm.CONFLICTING_JVM_DECLARATIONS && (me.factory == ACCIDENTAL_OVERRIDE ||
me.factory == CONFLICTING_INHERITED_JVM_DECLARATIONS)
// there are paris of corresponding signatures that frequently clash simultaneously: package facade & part, trait and trait-impl
|| other.data() higherThan me.data()
// there are paris of corresponding signatures that frequently clash simultaneously: multifile class & part, trait and trait-impl
|| other.data().higherThan(me.data())
)
}
}
Expand All @@ -140,7 +140,6 @@ class FilteredJvmDiagnostics(val jvmDiagnostics: Diagnostics, val otherDiagnosti

private infix fun ConflictingJvmDeclarationsData.higherThan(other: ConflictingJvmDeclarationsData): Boolean {
return when (other.classOrigin.originKind) {
PACKAGE_PART -> this.classOrigin.originKind == PACKAGE_FACADE
INTERFACE_DEFAULT_IMPL -> this.classOrigin.originKind != INTERFACE_DEFAULT_IMPL
MULTIFILE_CLASS_PART -> this.classOrigin.originKind == MULTIFILE_CLASS
else -> false
Expand Down
3 changes: 1 addition & 2 deletions compiler/testData/cli/jvm/wrongAbiVersion.out
Expand Up @@ -8,6 +8,5 @@ public fun kotlin.Throwable.printStackTrace(writer: java.io.PrintWriter): kotlin
(note: this may be caused by the fact that some classes compiled with an incompatible version of Kotlin were found in the classpath. Such classes cannot be loaded properly by this version of Kotlin compiler. See below for more information)
1.printStackTrace(2, 3)
^
compiler/testData/cli/jvm/wrongAbiVersionLib/bin/ClassWithWrongAbiVersion.class: error: class 'ClassWithWrongAbiVersion' was compiled with an incompatible version of Kotlin. Its ABI version is unknown, expected ABI version is $ABI_VERSION$
compiler/testData/cli/jvm/wrongAbiVersionLib/bin/wrong/WrongPackage.class: error: class 'wrong/WrongPackage' was compiled with an incompatible version of Kotlin. Its ABI version is unknown, expected ABI version is $ABI_VERSION$
compiler/testData/cli/jvm/wrongAbiVersionLib/bin/ClassWithWrongAbiVersion.class: error: class 'ClassWithWrongAbiVersion' was compiled with an incompatible version of Kotlin. Its ABI version is 0.30.0, expected ABI version is $ABI_VERSION$
COMPILATION_ERROR
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion compiler/testData/cli/jvm/wrongAbiVersionLib/readme.txt
@@ -1,6 +1,6 @@
/*
To regenerate this test:
1. Change JvmAbi.VERSION to -1
1. Change JvmAbi.VERSION to an incompatible one, e.g. 0.30.0
2. Run 'ant dist'
3. Compile files with the newly built compiler from dist/

Expand Down
11 changes: 5 additions & 6 deletions compiler/tests/org/jetbrains/kotlin/codegen/InlineTestUtil.kt
Expand Up @@ -30,12 +30,11 @@ import org.jetbrains.org.objectweb.asm.tree.MethodNode
import java.util.*
import kotlin.properties.Delegates

public object InlineTestUtil {
object InlineTestUtil {
private val KOTLIN_MULTIFILE_CLASS_DESC =
"L" + AsmUtil.internalNameByFqNameWithoutInnerClasses(JvmAnnotationNames.KOTLIN_MULTIFILE_CLASS) + ";"

private val KOTLIN_PACKAGE_DESC = "L" + AsmUtil.internalNameByFqNameWithoutInnerClasses(JvmAnnotationNames.KOTLIN_PACKAGE) + ";"
private val KOTLIN_MULTIFILE_CLASS_DESC = "L" + AsmUtil.internalNameByFqNameWithoutInnerClasses(JvmAnnotationNames.KOTLIN_MULTIFILE_CLASS) + ";"

public fun checkNoCallsToInline(files: Iterable<OutputFile>, sourceFiles: List<KtFile>) {
fun checkNoCallsToInline(files: Iterable<OutputFile>, sourceFiles: List<KtFile>) {
val inlineInfo = obtainInlineInfo(files)
val inlineMethods = inlineInfo.inlineMethods
assert(!inlineMethods.isEmpty()) { "There are no inline methods" }
Expand Down Expand Up @@ -94,7 +93,7 @@ public object InlineTestUtil {
private var skipMethodsOfThisClass = false

override fun visitAnnotation(desc: String, visible: Boolean): AnnotationVisitor? {
if (desc == KOTLIN_PACKAGE_DESC || desc == KOTLIN_MULTIFILE_CLASS_DESC) {
if (desc == KOTLIN_MULTIFILE_CLASS_DESC) {
skipMethodsOfThisClass = true
}
return null
Expand Down
Expand Up @@ -157,10 +157,7 @@ public abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdi
val klass = classLoader.loadClass(className).sure { "Couldn't load class $className" }
val header = ReflectKotlinClass.create(klass)?.getClassHeader()

if (header?.kind == KotlinClassHeader.Kind.PACKAGE_FACADE ||
header?.kind == KotlinClassHeader.Kind.FILE_FACADE ||
header?.kind == KotlinClassHeader.Kind.MULTIFILE_CLASS
) {
if (header?.kind == KotlinClassHeader.Kind.FILE_FACADE || header?.kind == KotlinClassHeader.Kind.MULTIFILE_CLASS) {
val packageView = module.getPackage(LoadDescriptorUtil.TEST_PACKAGE_FQNAME)
if (!packageScopes.contains(packageView.memberScope)) {
packageScopes.add(packageView.memberScope)
Expand Down
Expand Up @@ -29,7 +29,6 @@

public final class JvmAnnotationNames {
public static final FqName KOTLIN_CLASS = new FqName("kotlin.jvm.internal.KotlinClass");
public static final FqName KOTLIN_PACKAGE = new FqName("kotlin.jvm.internal.KotlinPackage");
public static final FqName KOTLIN_FILE_FACADE = new FqName("kotlin.jvm.internal.KotlinFileFacade");
public static final FqName KOTLIN_MULTIFILE_CLASS = new FqName("kotlin.jvm.internal.KotlinMultifileClass");
public static final FqName KOTLIN_MULTIFILE_CLASS_PART = new FqName("kotlin.jvm.internal.KotlinMultifileClassPart");
Expand Down Expand Up @@ -81,9 +80,7 @@ public final class JvmAnnotationNames {
private static final Set<JvmClassName> NULLABILITY_ANNOTATIONS = new HashSet<JvmClassName>();
private static final Set<JvmClassName> SPECIAL_META_ANNOTATIONS = new HashSet<JvmClassName>();
static {
for (FqName fqName : Arrays.asList(
KOTLIN_CLASS, KOTLIN_PACKAGE, KOTLIN_SYNTHETIC_CLASS, KOTLIN_INTERFACE_DEFAULT_IMPLS, KOTLIN_LOCAL_CLASS
)) {
for (FqName fqName : Arrays.asList(KOTLIN_CLASS, KOTLIN_SYNTHETIC_CLASS, KOTLIN_INTERFACE_DEFAULT_IMPLS, KOTLIN_LOCAL_CLASS)) {
SPECIAL_ANNOTATIONS.add(JvmClassName.byFqNameWithoutInnerClasses(fqName));
}

Expand Down
Expand Up @@ -22,8 +22,6 @@ import org.jetbrains.kotlin.load.java.lazy.LazyJavaResolverContext
import org.jetbrains.kotlin.load.java.structure.JavaClass
import org.jetbrains.kotlin.load.java.structure.JavaPackage
import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinaryPackageSourceElement
import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinarySourceElement
import org.jetbrains.kotlin.load.kotlin.PackageClassUtils
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.storage.getValue
Expand All @@ -39,10 +37,6 @@ class LazyJavaPackageFragment(
LazyJavaClassDescriptor(c, this, javaClass.fqName!!, javaClass)
}

internal val oldPackageFacade by c.storageManager.createNullableLazyValue {
c.components.kotlinClassFinder.findKotlinClass(PackageClassUtils.getPackageClassId(fqName))
}

internal val kotlinBinaryClasses by c.storageManager.createLazyValue {
val simpleNames = c.components.packageMapper.findPackageParts(fqName.asString())
simpleNames.map {
Expand Down
Expand Up @@ -25,13 +25,12 @@ import org.jetbrains.kotlin.load.java.lazy.LazyJavaResolverContext
import org.jetbrains.kotlin.load.java.lazy.resolveKotlinBinaryClass
import org.jetbrains.kotlin.load.java.structure.JavaClass
import org.jetbrains.kotlin.load.java.structure.JavaPackage
import org.jetbrains.kotlin.load.kotlin.DeserializedDescriptorResolver
import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.name.SpecialNames
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.storage.getValue

public class LazyJavaPackageScope(
c: LazyJavaResolverContext,
Expand Down Expand Up @@ -62,20 +61,8 @@ public class LazyJavaPackageScope(
public fun getFacadeSimpleNameForPartSimpleName(partName: String): String? =
partToFacade()[partName]

private val deserializedPackageScope = c.storageManager.createLazyValue {
if (ownerDescriptor.kotlinBinaryClasses.isEmpty()) {
// If the scope is queried but no package parts are found, there's a possibility that we're trying to load symbols
// from an old package with the binary-incompatible facade.
// We try to read the old package facade if there is one, to report the "incompatible ABI version" message.
ownerDescriptor.oldPackageFacade?.let { binaryClass ->
c.components.deserializedDescriptorResolver.readData(binaryClass, DeserializedDescriptorResolver.KOTLIN_PACKAGE_FACADE)
}

MemberScope.Empty
}
else {
c.components.deserializedDescriptorResolver.createKotlinPackageScope(ownerDescriptor, ownerDescriptor.kotlinBinaryClasses)
}
private val deserializedPackageScope by c.storageManager.createLazyValue {
c.components.deserializedDescriptorResolver.createKotlinPackageScope(ownerDescriptor, ownerDescriptor.kotlinBinaryClasses)
}

private val classes = c.storageManager.createMemoizedFunctionWithNullableValues<Name, ClassDescriptor> { name ->
Expand Down Expand Up @@ -107,19 +94,19 @@ public class LazyJavaPackageScope(
override fun getContributedVariables(name: Name, location: LookupLocation): Collection<PropertyDescriptor> {
// We should track lookups here because this scope can be used for kotlin packages too (if it doesn't contain toplevel properties nor functions).
recordLookup(name, location)
return deserializedPackageScope().getContributedVariables(name, NoLookupLocation.FOR_ALREADY_TRACKED)
return deserializedPackageScope.getContributedVariables(name, NoLookupLocation.FOR_ALREADY_TRACKED)
}

override fun getContributedFunctions(name: Name, location: LookupLocation): List<FunctionDescriptor> {
// We should track lookups here because this scope can be used for kotlin packages too (if it doesn't contain toplevel properties nor functions).
recordLookup(name, location)
return deserializedPackageScope().getContributedFunctions(name, NoLookupLocation.FOR_ALREADY_TRACKED) + super.getContributedFunctions(name, NoLookupLocation.FOR_ALREADY_TRACKED)
return deserializedPackageScope.getContributedFunctions(name, NoLookupLocation.FOR_ALREADY_TRACKED) + super.getContributedFunctions(name, NoLookupLocation.FOR_ALREADY_TRACKED)
}

override fun addExtraDescriptors(result: MutableSet<DeclarationDescriptor>,
kindFilter: DescriptorKindFilter,
nameFilter: (Name) -> Boolean) {
result.addAll(deserializedPackageScope().getContributedDescriptors(kindFilter, nameFilter))
result.addAll(deserializedPackageScope.getContributedDescriptors(kindFilter, nameFilter))
}

override fun computeMemberIndex(): MemberIndex = object : MemberIndex by EMPTY_MEMBER_INDEX {
Expand Down
Expand Up @@ -45,7 +45,6 @@ public final class DeserializedDescriptorResolver {

public static final Set<KotlinClassHeader.Kind> KOTLIN_CLASS = setOf(CLASS);
public static final Set<KotlinClassHeader.Kind> KOTLIN_FILE_FACADE_OR_MULTIFILE_CLASS_PART = setOf(FILE_FACADE, MULTIFILE_CLASS_PART);
public static final Set<KotlinClassHeader.Kind> KOTLIN_PACKAGE_FACADE = setOf(PACKAGE_FACADE);

public DeserializedDescriptorResolver(@NotNull ErrorReporter errorReporter) {
this.errorReporter = errorReporter;
Expand Down Expand Up @@ -95,8 +94,11 @@ public Collection<Name> invoke() {
}

@NotNull
public MemberScope createKotlinPackageScope(@NotNull PackageFragmentDescriptor descriptor, @NotNull List<KotlinJvmBinaryClass> packageParts) {
List<MemberScope> list = new ArrayList<MemberScope>();
public MemberScope createKotlinPackageScope(
@NotNull PackageFragmentDescriptor descriptor,
@NotNull List<KotlinJvmBinaryClass> packageParts
) {
List<MemberScope> list = new ArrayList<MemberScope>(packageParts.size());
for (KotlinJvmBinaryClass callable : packageParts) {
MemberScope scope = createKotlinPackagePartScope(descriptor, callable);
if (scope != null) {
Expand Down
Expand Up @@ -34,7 +34,6 @@ class KotlinClassHeader(

enum class Kind {
CLASS,
PACKAGE_FACADE,
FILE_FACADE,
MULTIFILE_CLASS,
MULTIFILE_CLASS_PART,
Expand All @@ -49,7 +48,6 @@ class KotlinClassHeader(
}

fun KotlinClassHeader.isCompatibleClassKind(): Boolean = isCompatibleAbiVersion && kind == KotlinClassHeader.Kind.CLASS
fun KotlinClassHeader.isCompatiblePackageFacadeKind(): Boolean = isCompatibleAbiVersion && kind == KotlinClassHeader.Kind.PACKAGE_FACADE
fun KotlinClassHeader.isCompatibleFileFacadeKind(): Boolean = isCompatibleAbiVersion && kind == KotlinClassHeader.Kind.FILE_FACADE
fun KotlinClassHeader.isCompatibleMultifileClassKind(): Boolean = isCompatibleAbiVersion && kind == KotlinClassHeader.Kind.MULTIFILE_CLASS
fun KotlinClassHeader.isCompatibleMultifileClassPartKind(): Boolean = isCompatibleAbiVersion && kind == KotlinClassHeader.Kind.MULTIFILE_CLASS_PART

0 comments on commit 8594cfc

Please sign in to comment.