[PL] Support handling IR error types
This commit is contained in:
committed by
Space Team
parent
161c3fccb6
commit
16da1af525
@@ -84,7 +84,12 @@ fun generateIrForKlibSerialization(
|
||||
messageLogger,
|
||||
psi2IrContext.irBuiltIns,
|
||||
psi2IrContext.symbolTable,
|
||||
partialLinkageSupport = createPartialLinkageSupportForLinker(configuration.partialLinkageConfig, psi2IrContext.irBuiltIns, messageLogger),
|
||||
partialLinkageSupport = createPartialLinkageSupportForLinker(
|
||||
partialLinkageConfig = configuration.partialLinkageConfig,
|
||||
allowErrorTypes = errorPolicy.allowErrors,
|
||||
builtIns = psi2IrContext.irBuiltIns,
|
||||
messageLogger = messageLogger
|
||||
),
|
||||
feContext,
|
||||
ICData(icData.map { it.irData }, errorPolicy.allowErrors),
|
||||
stubGenerator = stubGenerator
|
||||
|
||||
+9
-1
@@ -28,6 +28,8 @@ import org.jetbrains.kotlin.ir.linkage.partial.partialLinkageConfig
|
||||
import org.jetbrains.kotlin.ir.util.ExternalDependenciesGenerator
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
import org.jetbrains.kotlin.ir.util.irMessageLogger
|
||||
import org.jetbrains.kotlin.js.config.ErrorTolerancePolicy
|
||||
import org.jetbrains.kotlin.js.config.JSConfigurationKeys
|
||||
import org.jetbrains.kotlin.library.KotlinLibrary
|
||||
import org.jetbrains.kotlin.library.uniqueName
|
||||
import org.jetbrains.kotlin.library.unresolvedDependencies
|
||||
@@ -108,6 +110,7 @@ internal class JsIrLinkerLoader(
|
||||
val symbolTable = SymbolTable(signaturer, irFactory)
|
||||
val moduleDescriptor = loadedModules.keys.last()
|
||||
val typeTranslator = TypeTranslatorImpl(symbolTable, compilerConfiguration.languageVersionSettings, moduleDescriptor)
|
||||
val errorPolicy = compilerConfiguration[JSConfigurationKeys.ERROR_TOLERANCE_POLICY] ?: ErrorTolerancePolicy.DEFAULT
|
||||
val irBuiltIns = IrBuiltInsOverDescriptors(moduleDescriptor.builtIns, typeTranslator, symbolTable)
|
||||
val messageLogger = compilerConfiguration.irMessageLogger
|
||||
val linker = JsIrLinker(
|
||||
@@ -115,7 +118,12 @@ internal class JsIrLinkerLoader(
|
||||
messageLogger = messageLogger,
|
||||
builtIns = irBuiltIns,
|
||||
symbolTable = symbolTable,
|
||||
partialLinkageSupport = createPartialLinkageSupportForLinker(compilerConfiguration.partialLinkageConfig, irBuiltIns, messageLogger),
|
||||
partialLinkageSupport = createPartialLinkageSupportForLinker(
|
||||
partialLinkageConfig = compilerConfiguration.partialLinkageConfig,
|
||||
allowErrorTypes = errorPolicy.allowErrors,
|
||||
builtIns = irBuiltIns,
|
||||
messageLogger = messageLogger
|
||||
),
|
||||
translationPluginContext = null,
|
||||
friendModules = mapOf(mainLibrary.uniqueName to mainModuleFriends.map { it.uniqueName })
|
||||
)
|
||||
|
||||
+11
-2
@@ -30,7 +30,11 @@ import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import org.jetbrains.kotlin.ir.linkage.partial.PartialLinkageUtils.Module as PLModule
|
||||
|
||||
internal class ClassifierExplorer(private val builtIns: IrBuiltIns, private val stubGenerator: MissingDeclarationStubGenerator) {
|
||||
internal class ClassifierExplorer(
|
||||
private val builtIns: IrBuiltIns,
|
||||
private val stubGenerator: MissingDeclarationStubGenerator,
|
||||
private val allowErrorTypes: Boolean
|
||||
) {
|
||||
private val exploredSymbols = ExploredClassifiers()
|
||||
|
||||
private val permittedAnnotationArrayParameterSymbols: Set<IrClassSymbol> by lazy {
|
||||
@@ -72,7 +76,12 @@ internal class ClassifierExplorer(private val builtIns: IrBuiltIns, private val
|
||||
?: arguments.firstUnusable { it.typeOrNull?.exploreType(visitedSymbols) }
|
||||
?: Usable
|
||||
is IrDynamicType -> Usable
|
||||
else -> throw IllegalArgumentException("Unsupported IR type: ${this::class.java}, $this")
|
||||
else -> {
|
||||
if (this is IrErrorType && allowErrorTypes)
|
||||
Usable
|
||||
else
|
||||
throw IllegalArgumentException("Unsupported IR type: ${this::class.java}, $this")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-2
@@ -18,20 +18,22 @@ import org.jetbrains.kotlin.ir.util.allUnbound
|
||||
|
||||
fun createPartialLinkageSupportForLinker(
|
||||
partialLinkageConfig: PartialLinkageConfig,
|
||||
allowErrorTypes: Boolean,
|
||||
builtIns: IrBuiltIns,
|
||||
messageLogger: IrMessageLogger
|
||||
): PartialLinkageSupportForLinker = if (partialLinkageConfig.isEnabled)
|
||||
PartialLinkageSupportForLinkerImpl(builtIns, partialLinkageConfig.logLevel, messageLogger)
|
||||
PartialLinkageSupportForLinkerImpl(builtIns, allowErrorTypes, partialLinkageConfig.logLevel, messageLogger)
|
||||
else
|
||||
PartialLinkageSupportForLinker.DISABLED
|
||||
|
||||
internal class PartialLinkageSupportForLinkerImpl(
|
||||
builtIns: IrBuiltIns,
|
||||
allowErrorTypes: Boolean,
|
||||
logLevel: PartialLinkageLogLevel,
|
||||
messageLogger: IrMessageLogger
|
||||
) : PartialLinkageSupportForLinker {
|
||||
private val stubGenerator = MissingDeclarationStubGenerator(builtIns)
|
||||
private val classifierExplorer = ClassifierExplorer(builtIns, stubGenerator)
|
||||
private val classifierExplorer = ClassifierExplorer(builtIns, stubGenerator, allowErrorTypes)
|
||||
private val patcher = PartiallyLinkedIrTreePatcher(builtIns, classifierExplorer, stubGenerator, logLevel, messageLogger)
|
||||
|
||||
override val isEnabled get() = true
|
||||
|
||||
@@ -264,13 +264,19 @@ fun getIrModuleInfoForKlib(
|
||||
val mainModuleLib = sortedDependencies.last()
|
||||
val typeTranslator = TypeTranslatorImpl(symbolTable, configuration.languageVersionSettings, moduleDescriptor)
|
||||
val irBuiltIns = IrBuiltInsOverDescriptors(moduleDescriptor.builtIns, typeTranslator, symbolTable)
|
||||
val errorPolicy = configuration[JSConfigurationKeys.ERROR_TOLERANCE_POLICY] ?: ErrorTolerancePolicy.DEFAULT
|
||||
|
||||
val irLinker = JsIrLinker(
|
||||
currentModule = null,
|
||||
messageLogger = messageLogger,
|
||||
builtIns = irBuiltIns,
|
||||
symbolTable = symbolTable,
|
||||
partialLinkageSupport = createPartialLinkageSupportForLinker(configuration.partialLinkageConfig, irBuiltIns, messageLogger),
|
||||
partialLinkageSupport = createPartialLinkageSupportForLinker(
|
||||
partialLinkageConfig = configuration.partialLinkageConfig,
|
||||
allowErrorTypes = errorPolicy.allowErrors,
|
||||
builtIns = irBuiltIns,
|
||||
messageLogger = messageLogger
|
||||
),
|
||||
translationPluginContext = null,
|
||||
icData = null,
|
||||
friendModules = friendModules
|
||||
@@ -322,13 +328,19 @@ fun getIrModuleInfoForSourceFiles(
|
||||
val feContext = psi2IrContext.run {
|
||||
JsIrLinker.JsFePluginContext(moduleDescriptor, symbolTable, typeTranslator, irBuiltIns)
|
||||
}
|
||||
val errorPolicy = configuration[JSConfigurationKeys.ERROR_TOLERANCE_POLICY] ?: ErrorTolerancePolicy.DEFAULT
|
||||
|
||||
val irLinker = JsIrLinker(
|
||||
currentModule = psi2IrContext.moduleDescriptor,
|
||||
messageLogger = messageLogger,
|
||||
builtIns = irBuiltIns,
|
||||
symbolTable = symbolTable,
|
||||
partialLinkageSupport = createPartialLinkageSupportForLinker(configuration.partialLinkageConfig, irBuiltIns, messageLogger),
|
||||
partialLinkageSupport = createPartialLinkageSupportForLinker(
|
||||
partialLinkageConfig = configuration.partialLinkageConfig,
|
||||
allowErrorTypes = errorPolicy.allowErrors,
|
||||
builtIns = irBuiltIns,
|
||||
messageLogger = messageLogger
|
||||
),
|
||||
translationPluginContext = feContext,
|
||||
icData = null,
|
||||
friendModules = friendModules,
|
||||
|
||||
+6
-1
@@ -143,7 +143,12 @@ internal fun PsiToIrContext.psiToIr(
|
||||
stubGenerator = stubGenerator,
|
||||
cenumsProvider = irProviderForCEnumsAndCStructs,
|
||||
exportedDependencies = exportedDependencies,
|
||||
partialLinkageSupport = createPartialLinkageSupportForLinker(partialLinkageConfig, generatorContext.irBuiltIns, messageLogger),
|
||||
partialLinkageSupport = createPartialLinkageSupportForLinker(
|
||||
partialLinkageConfig = partialLinkageConfig,
|
||||
allowErrorTypes = false, // Kotlin/Native does not support error types.
|
||||
builtIns = generatorContext.irBuiltIns,
|
||||
messageLogger = messageLogger
|
||||
),
|
||||
cachedLibraries = config.cachedLibraries,
|
||||
lazyIrForCaches = config.lazyIrForCaches,
|
||||
libraryBeingCached = config.libraryToCache,
|
||||
|
||||
Reference in New Issue
Block a user