K1: support pre-release checks for klibs
This commit makes the compiler read the pre-release flag from loaded klibs. Now the K1 frontend checks this flag in MissingDependencyClassChecker checker, reporting errors if the current compiler configuration doesn't allow using pre-release dependencies. ^KT-54905 Fixed
This commit is contained in:
committed by
Space Team
parent
7788304645
commit
5320fbeb6e
+4
-2
@@ -11,11 +11,13 @@ import org.jetbrains.kotlin.metadata.deserialization.NameResolver
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.serialization.deserialization.ClassData
|
||||
import org.jetbrains.kotlin.serialization.deserialization.ClassDataFinder
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource
|
||||
import org.jetbrains.kotlin.serialization.deserialization.getClassId
|
||||
|
||||
class KlibMetadataClassDataFinder(
|
||||
private val fragment: PackageFragment,
|
||||
private val nameResolver: NameResolver
|
||||
private val nameResolver: NameResolver,
|
||||
private val containerSource: DeserializedContainerSource? = null
|
||||
) : ClassDataFinder {
|
||||
val nameList = fragment.getExtension(KlibMetadataProtoBuf.className).orEmpty()
|
||||
|
||||
@@ -29,6 +31,6 @@ class KlibMetadataClassDataFinder(
|
||||
val foundClass = fragment.getClass_(index) ?: error("Could not find data for serialized class $classId")
|
||||
|
||||
/* TODO: binary version supposed to be read from protobuf. */
|
||||
return ClassData(nameResolver, foundClass, KlibMetadataVersion.INSTANCE, SourceElement.NO_SOURCE)
|
||||
return ClassData(nameResolver, foundClass, KlibMetadataVersion.INSTANCE, containerSource ?: SourceElement.NO_SOURCE)
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -3,6 +3,7 @@ package org.jetbrains.kotlin.library.metadata
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.library.KotlinLibrary
|
||||
import org.jetbrains.kotlin.serialization.deserialization.DeserializationConfiguration
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
|
||||
interface KlibMetadataDeserializedPackageFragmentsFactory {
|
||||
@@ -11,7 +12,8 @@ interface KlibMetadataDeserializedPackageFragmentsFactory {
|
||||
packageFragmentNames: List<String>,
|
||||
moduleDescriptor: ModuleDescriptor,
|
||||
packageAccessedHandler: PackageAccessHandler?,
|
||||
storageManager: StorageManager
|
||||
storageManager: StorageManager,
|
||||
configuration: DeserializationConfiguration
|
||||
): List<KlibMetadataPackageFragment>
|
||||
|
||||
fun createCachedPackageFragments(
|
||||
|
||||
+12
-8
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.serialization.deserialization.DeserializationComponents
|
||||
import org.jetbrains.kotlin.serialization.deserialization.DeserializedPackageFragment
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedPackageMemberScope
|
||||
import org.jetbrains.kotlin.serialization.deserialization.getClassId
|
||||
import org.jetbrains.kotlin.serialization.deserialization.getName
|
||||
@@ -26,8 +27,9 @@ open class KlibMetadataDeserializedPackageFragment(
|
||||
private val packageAccessHandler: PackageAccessHandler?,
|
||||
storageManager: StorageManager,
|
||||
module: ModuleDescriptor,
|
||||
private val partName: String
|
||||
) : KlibMetadataPackageFragment(fqName, storageManager, module) {
|
||||
private val partName: String,
|
||||
containerSource: DeserializedContainerSource
|
||||
) : KlibMetadataPackageFragment(fqName, storageManager, module, containerSource) {
|
||||
|
||||
// The proto field is lazy so that we can load only needed
|
||||
// packages from the library.
|
||||
@@ -57,8 +59,9 @@ class BuiltInKlibMetadataDeserializedPackageFragment(
|
||||
packageAccessHandler: PackageAccessHandler?,
|
||||
storageManager: StorageManager,
|
||||
module: ModuleDescriptor,
|
||||
partName: String
|
||||
) : KlibMetadataDeserializedPackageFragment(fqName, library, packageAccessHandler, storageManager, module, partName),
|
||||
partName: String,
|
||||
containerSource: DeserializedContainerSource
|
||||
) : KlibMetadataDeserializedPackageFragment(fqName, library, packageAccessHandler, storageManager, module, partName, containerSource),
|
||||
BuiltInsPackageFragment {
|
||||
|
||||
override val isFallback: Boolean
|
||||
@@ -71,12 +74,13 @@ class KlibMetadataCachedPackageFragment(
|
||||
module: ModuleDescriptor,
|
||||
override val protoForNames: ProtoBuf.PackageFragment = parsePackageFragment(byteArray),
|
||||
fqName: FqName = FqName(protoForNames.getExtension(KlibMetadataProtoBuf.fqName))
|
||||
) : KlibMetadataPackageFragment(fqName, storageManager, module)
|
||||
) : KlibMetadataPackageFragment(fqName, storageManager, module, containerSource = null)
|
||||
|
||||
abstract class KlibMetadataPackageFragment(
|
||||
fqName: FqName,
|
||||
storageManager: StorageManager,
|
||||
module: ModuleDescriptor
|
||||
module: ModuleDescriptor,
|
||||
containerSource: DeserializedContainerSource?
|
||||
) : DeserializedPackageFragment(fqName, storageManager, module) {
|
||||
|
||||
lateinit var components: DeserializationComponents
|
||||
@@ -97,7 +101,7 @@ abstract class KlibMetadataPackageFragment(
|
||||
}
|
||||
|
||||
override val classDataFinder by lazy {
|
||||
KlibMetadataClassDataFinder(protoForNames, nameResolver)
|
||||
KlibMetadataClassDataFinder(protoForNames, nameResolver, containerSource)
|
||||
}
|
||||
|
||||
private val _memberScope by lazy {
|
||||
@@ -107,7 +111,7 @@ abstract class KlibMetadataPackageFragment(
|
||||
proto.getPackage(),
|
||||
nameResolver,
|
||||
KlibMetadataVersion.INSTANCE,
|
||||
/* containerSource = */ null,
|
||||
/* containerSource = */ containerSource,
|
||||
components,
|
||||
"scope for $this"
|
||||
) { loadClassNames() }
|
||||
|
||||
+33
-16
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.getAllSuperClassifiers
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScopeImpl
|
||||
import org.jetbrains.kotlin.serialization.deserialization.DeserializationConfiguration
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
|
||||
@@ -25,22 +26,38 @@ open class KlibMetadataDeserializedPackageFragmentsFactoryImpl : KlibMetadataDes
|
||||
packageFragmentNames: List<String>,
|
||||
moduleDescriptor: ModuleDescriptor,
|
||||
packageAccessedHandler: PackageAccessHandler?,
|
||||
storageManager: StorageManager
|
||||
) = packageFragmentNames.flatMap {
|
||||
val fqName = FqName(it)
|
||||
val parts = library.packageMetadataParts(fqName.asString())
|
||||
val isBuiltInModule = moduleDescriptor.builtIns.builtInsModule === moduleDescriptor
|
||||
parts.map { partName ->
|
||||
if (isBuiltInModule)
|
||||
BuiltInKlibMetadataDeserializedPackageFragment(
|
||||
fqName,
|
||||
library,
|
||||
packageAccessedHandler,
|
||||
storageManager,
|
||||
moduleDescriptor,
|
||||
partName
|
||||
) else
|
||||
KlibMetadataDeserializedPackageFragment(fqName, library, packageAccessedHandler, storageManager, moduleDescriptor, partName)
|
||||
storageManager: StorageManager,
|
||||
configuration: DeserializationConfiguration
|
||||
): List<KlibMetadataDeserializedPackageFragment> {
|
||||
val libraryHeader = (packageAccessedHandler ?: SimplePackageAccessHandler).loadModuleHeader(library)
|
||||
|
||||
return packageFragmentNames.flatMap {
|
||||
val fqName = FqName(it)
|
||||
val containerSource = KlibDeserializedContainerSource(libraryHeader, configuration, fqName)
|
||||
val parts = library.packageMetadataParts(fqName.asString())
|
||||
val isBuiltInModule = moduleDescriptor.builtIns.builtInsModule === moduleDescriptor
|
||||
parts.map { partName ->
|
||||
if (isBuiltInModule)
|
||||
BuiltInKlibMetadataDeserializedPackageFragment(
|
||||
fqName,
|
||||
library,
|
||||
packageAccessedHandler,
|
||||
storageManager,
|
||||
moduleDescriptor,
|
||||
partName,
|
||||
containerSource
|
||||
)
|
||||
else
|
||||
KlibMetadataDeserializedPackageFragment(
|
||||
fqName,
|
||||
library,
|
||||
packageAccessedHandler,
|
||||
storageManager,
|
||||
moduleDescriptor,
|
||||
partName,
|
||||
containerSource
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -106,7 +106,7 @@ class KlibMetadataModuleDescriptorFactoryImpl(
|
||||
): PackageFragmentProvider {
|
||||
|
||||
val deserializedPackageFragments = packageFragmentsFactory.createDeserializedPackageFragments(
|
||||
library, packageFragmentNames, moduleDescriptor, packageAccessHandler, storageManager
|
||||
library, packageFragmentNames, moduleDescriptor, packageAccessHandler, storageManager, configuration
|
||||
)
|
||||
|
||||
// TODO: this is native specific. Move to a child class.
|
||||
|
||||
Reference in New Issue
Block a user