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