K2: report PRE_RELEASE_CLASS on JVM

Note that 3 tests are still muted, but for another reason: for FIR
versions of the tests, we need to compile the "pre-release library" with
the next language version which is 2.1. But since currently
LanguageVersion.LATEST_STABLE is 1.9, the compiler refuses to read
metadata of version 2.1, regardless of its own language version. Which
is correct, but it leads to irrelevant errors in the test output -- the
ones about the incompatible metadata version, NOT about the
prereleaseness.

These 3 tests can be unmuted once the default language version is
switched to 2.0.

 #KT-60780 Fixed
This commit is contained in:
Alexander Udalov
2023-08-12 00:06:48 +02:00
committed by Space Team
parent 8738ffb84f
commit fec2d063c1
14 changed files with 96 additions and 10 deletions
@@ -37,6 +37,7 @@ import org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
import org.jetbrains.kotlin.serialization.deserialization.IncompatibleVersionErrorData
import org.jetbrains.kotlin.serialization.deserialization.builtins.BuiltInSerializerProtocol
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerAbiStability
import org.jetbrains.kotlin.utils.toMetadataVersion
import java.nio.file.Path
import java.nio.file.Paths
@@ -59,6 +60,9 @@ class JvmClassFileBasedSymbolProvider(
private val annotationsLoader = AnnotationsLoader(session, kotlinClassFinder)
private val ownMetadataVersion: JvmMetadataVersion = session.languageVersionSettings.languageVersion.toMetadataVersion()
private val reportErrorsOnPreReleaseDependencies =
!session.languageVersionSettings.getFlag(AnalysisFlags.skipPrereleaseCheck) && !session.languageVersionSettings.isPreRelease()
override fun computePackagePartsInfos(packageFqName: FqName): List<PackagePartsCacheData> =
packagePartProvider.findPackageParts(packageFqName.asString()).mapNotNull { partName ->
computePackagePartInfo(packageFqName, partName)
@@ -89,6 +93,7 @@ class JvmClassFileBasedSymbolProvider(
val source = JvmPackagePartSource(
kotlinClass, packageProto, nameResolver, kotlinClass.incompatibility, kotlinClass.isPreReleaseInvisible,
kotlinClass.abiStability,
)
return PackagePartsCacheData(
@@ -121,8 +126,20 @@ class JvmClassFileBasedSymbolProvider(
)
}
/**
* @return true if the class is invisible because it's compiled by a pre-release compiler, and this compiler is either released
* or is run with a released language version.
*/
private val KotlinJvmBinaryClass.isPreReleaseInvisible: Boolean
get() = classHeader.isPreRelease
get() = reportErrorsOnPreReleaseDependencies && classHeader.isPreRelease
private val KotlinJvmBinaryClass.abiStability: DeserializedContainerAbiStability
get() = when {
session.languageVersionSettings.getFlag(AnalysisFlags.allowUnstableDependencies) -> DeserializedContainerAbiStability.STABLE
classHeader.isUnstableFirBinary -> DeserializedContainerAbiStability.FIR_UNSTABLE
classHeader.isUnstableJvmIrBinary -> DeserializedContainerAbiStability.IR_UNSTABLE
else -> DeserializedContainerAbiStability.STABLE
}
override fun extractClassMetadata(classId: ClassId, parentContext: FirDeserializationContext?): ClassMetadataFindResult? {
// Kotlin classes are annotated Java classes, so this check also looks for them.
@@ -154,7 +171,9 @@ class JvmClassFileBasedSymbolProvider(
classProto,
JvmBinaryAnnotationDeserializer(session, kotlinClass, kotlinClassFinder, result.byteContent),
moduleDataProvider.getModuleData(kotlinClass.containingLibrary?.toPath()),
KotlinJvmBinarySourceElement(kotlinClass, kotlinClass.incompatibility),
KotlinJvmBinarySourceElement(
kotlinClass, kotlinClass.incompatibility, kotlinClass.isPreReleaseInvisible, kotlinClass.abiStability,
),
classPostProcessor = { loadAnnotationsFromClassFile(result, it) }
)
}