[KLIB] Support error code in metadata
This commit is contained in:
+3
-2
@@ -23,8 +23,9 @@ import org.jetbrains.kotlin.serialization.DescriptorSerializer
|
|||||||
class KlibMetadataIncrementalSerializer(
|
class KlibMetadataIncrementalSerializer(
|
||||||
languageVersionSettings: LanguageVersionSettings,
|
languageVersionSettings: LanguageVersionSettings,
|
||||||
metadataVersion: BinaryVersion,
|
metadataVersion: BinaryVersion,
|
||||||
skipExpects: Boolean
|
skipExpects: Boolean,
|
||||||
) : KlibMetadataSerializer(languageVersionSettings, metadataVersion, skipExpects) {
|
allowErrorTypes: Boolean = false
|
||||||
|
) : KlibMetadataSerializer(languageVersionSettings, metadataVersion, skipExpects, allowErrorTypes = allowErrorTypes) {
|
||||||
|
|
||||||
fun serializePackageFragment(
|
fun serializePackageFragment(
|
||||||
module: ModuleDescriptor,
|
module: ModuleDescriptor,
|
||||||
|
|||||||
+3
-2
@@ -23,8 +23,9 @@ class KlibMetadataMonolithicSerializer(
|
|||||||
languageVersionSettings: LanguageVersionSettings,
|
languageVersionSettings: LanguageVersionSettings,
|
||||||
metadataVersion: BinaryVersion,
|
metadataVersion: BinaryVersion,
|
||||||
skipExpects: Boolean,
|
skipExpects: Boolean,
|
||||||
includeOnlyModuleContent: Boolean = false
|
includeOnlyModuleContent: Boolean = false,
|
||||||
) : KlibMetadataSerializer(languageVersionSettings, metadataVersion, skipExpects, includeOnlyModuleContent) {
|
allowErrorTypes: Boolean = false
|
||||||
|
) : KlibMetadataSerializer(languageVersionSettings, metadataVersion, skipExpects, includeOnlyModuleContent, allowErrorTypes) {
|
||||||
|
|
||||||
private fun serializePackageFragment(fqName: FqName, module: ModuleDescriptor): List<ProtoBuf.PackageFragment> {
|
private fun serializePackageFragment(fqName: FqName, module: ModuleDescriptor): List<ProtoBuf.PackageFragment> {
|
||||||
|
|
||||||
|
|||||||
+4
-2
@@ -32,7 +32,8 @@ abstract class KlibMetadataSerializer(
|
|||||||
val languageVersionSettings: LanguageVersionSettings,
|
val languageVersionSettings: LanguageVersionSettings,
|
||||||
val metadataVersion: BinaryVersion,
|
val metadataVersion: BinaryVersion,
|
||||||
val skipExpects: Boolean = false,
|
val skipExpects: Boolean = false,
|
||||||
val includeOnlyModuleContent: Boolean = false
|
val includeOnlyModuleContent: Boolean = false,
|
||||||
|
private val allowErrorTypes: Boolean
|
||||||
) {
|
) {
|
||||||
|
|
||||||
lateinit var serializerContext: SerializerContext
|
lateinit var serializerContext: SerializerContext
|
||||||
@@ -48,7 +49,8 @@ abstract class KlibMetadataSerializer(
|
|||||||
val extension = KlibMetadataSerializerExtension(
|
val extension = KlibMetadataSerializerExtension(
|
||||||
languageVersionSettings,
|
languageVersionSettings,
|
||||||
metadataVersion,
|
metadataVersion,
|
||||||
KlibMetadataStringTable()
|
KlibMetadataStringTable(),
|
||||||
|
allowErrorTypes
|
||||||
)
|
)
|
||||||
return SerializerContext(
|
return SerializerContext(
|
||||||
extension,
|
extension,
|
||||||
|
|||||||
+7
-1
@@ -17,11 +17,13 @@ import org.jetbrains.kotlin.serialization.DescriptorSerializer
|
|||||||
import org.jetbrains.kotlin.serialization.KotlinSerializerExtensionBase
|
import org.jetbrains.kotlin.serialization.KotlinSerializerExtensionBase
|
||||||
import org.jetbrains.kotlin.serialization.StringTableImpl
|
import org.jetbrains.kotlin.serialization.StringTableImpl
|
||||||
import org.jetbrains.kotlin.types.FlexibleType
|
import org.jetbrains.kotlin.types.FlexibleType
|
||||||
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
|
|
||||||
class KlibMetadataSerializerExtension(
|
class KlibMetadataSerializerExtension(
|
||||||
private val languageVersionSettings: LanguageVersionSettings,
|
private val languageVersionSettings: LanguageVersionSettings,
|
||||||
override val metadataVersion: BinaryVersion,
|
override val metadataVersion: BinaryVersion,
|
||||||
override val stringTable: StringTableImpl
|
override val stringTable: StringTableImpl,
|
||||||
|
private val allowErrorTypes: Boolean
|
||||||
) : KotlinSerializerExtensionBase(KlibMetadataSerializerProtocol) {
|
) : KotlinSerializerExtensionBase(KlibMetadataSerializerProtocol) {
|
||||||
override fun shouldUseTypeTable(): Boolean = true
|
override fun shouldUseTypeTable(): Boolean = true
|
||||||
|
|
||||||
@@ -34,6 +36,10 @@ class KlibMetadataSerializerExtension(
|
|||||||
lowerProto.flexibleTypeCapabilitiesId = stringTable.getStringIndex(DynamicTypeDeserializer.id)
|
lowerProto.flexibleTypeCapabilitiesId = stringTable.getStringIndex(DynamicTypeDeserializer.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun serializeErrorType(type: KotlinType, builder: ProtoBuf.Type.Builder) {
|
||||||
|
if (!allowErrorTypes) super.serializeErrorType(type, builder)
|
||||||
|
}
|
||||||
|
|
||||||
override fun serializeClass(
|
override fun serializeClass(
|
||||||
descriptor: ClassDescriptor,
|
descriptor: ClassDescriptor,
|
||||||
proto: ProtoBuf.Class.Builder,
|
proto: ProtoBuf.Class.Builder,
|
||||||
|
|||||||
@@ -418,7 +418,7 @@ private class ModulesStructure(
|
|||||||
val analysisResult = analyzer.analysisResult
|
val analysisResult = analyzer.analysisResult
|
||||||
if (IncrementalCompilation.isEnabledForJs()) {
|
if (IncrementalCompilation.isEnabledForJs()) {
|
||||||
/** can throw [IncrementalNextRoundException] */
|
/** can throw [IncrementalNextRoundException] */
|
||||||
compareMetadataAndGoToNextICRoundIfNeeded(analysisResult, compilerConfiguration, files)
|
compareMetadataAndGoToNextICRoundIfNeeded(analysisResult, compilerConfiguration, files, errorPolicy.allowErrors)
|
||||||
}
|
}
|
||||||
|
|
||||||
var hasErrors = false
|
var hasErrors = false
|
||||||
@@ -497,7 +497,7 @@ fun serializeModuleIntoKlib(
|
|||||||
).serializedIrModule(moduleFragment)
|
).serializedIrModule(moduleFragment)
|
||||||
|
|
||||||
val moduleDescriptor = moduleFragment.descriptor
|
val moduleDescriptor = moduleFragment.descriptor
|
||||||
val metadataSerializer = KlibMetadataIncrementalSerializer(configuration)
|
val metadataSerializer = KlibMetadataIncrementalSerializer(configuration, containsErrorCode)
|
||||||
|
|
||||||
val incrementalResultsConsumer = configuration.get(JSConfigurationKeys.INCREMENTAL_RESULTS_CONSUMER)
|
val incrementalResultsConsumer = configuration.get(JSConfigurationKeys.INCREMENTAL_RESULTS_CONSUMER)
|
||||||
val empty = ByteArray(0)
|
val empty = ByteArray(0)
|
||||||
@@ -587,11 +587,12 @@ private fun KlibMetadataIncrementalSerializer.serializeScope(
|
|||||||
private fun compareMetadataAndGoToNextICRoundIfNeeded(
|
private fun compareMetadataAndGoToNextICRoundIfNeeded(
|
||||||
analysisResult: AnalysisResult,
|
analysisResult: AnalysisResult,
|
||||||
config: CompilerConfiguration,
|
config: CompilerConfiguration,
|
||||||
files: List<KtFile>
|
files: List<KtFile>,
|
||||||
|
allowErrors: Boolean
|
||||||
) {
|
) {
|
||||||
val nextRoundChecker = config.get(JSConfigurationKeys.INCREMENTAL_NEXT_ROUND_CHECKER) ?: return
|
val nextRoundChecker = config.get(JSConfigurationKeys.INCREMENTAL_NEXT_ROUND_CHECKER) ?: return
|
||||||
val bindingContext = analysisResult.bindingContext
|
val bindingContext = analysisResult.bindingContext
|
||||||
val serializer = KlibMetadataIncrementalSerializer(config)
|
val serializer = KlibMetadataIncrementalSerializer(config, allowErrors)
|
||||||
for (ktFile in files) {
|
for (ktFile in files) {
|
||||||
val packageFragment = serializer.serializeScope(ktFile, bindingContext, analysisResult.moduleDescriptor)
|
val packageFragment = serializer.serializeScope(ktFile, bindingContext, analysisResult.moduleDescriptor)
|
||||||
// to minimize a number of IC rounds, we should inspect all proto for changes first,
|
// to minimize a number of IC rounds, we should inspect all proto for changes first,
|
||||||
@@ -602,8 +603,9 @@ private fun compareMetadataAndGoToNextICRoundIfNeeded(
|
|||||||
if (nextRoundChecker.shouldGoToNextRound()) throw IncrementalNextRoundException()
|
if (nextRoundChecker.shouldGoToNextRound()) throw IncrementalNextRoundException()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun KlibMetadataIncrementalSerializer(configuration: CompilerConfiguration) = KlibMetadataIncrementalSerializer(
|
private fun KlibMetadataIncrementalSerializer(configuration: CompilerConfiguration, allowErrors: Boolean) = KlibMetadataIncrementalSerializer(
|
||||||
languageVersionSettings = configuration.languageVersionSettings,
|
languageVersionSettings = configuration.languageVersionSettings,
|
||||||
metadataVersion = configuration.metadataVersion,
|
metadataVersion = configuration.metadataVersion,
|
||||||
skipExpects = !configuration.expectActualLinker
|
skipExpects = !configuration.expectActualLinker,
|
||||||
|
allowErrorTypes = allowErrors
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user