[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,
|
messageLogger,
|
||||||
psi2IrContext.irBuiltIns,
|
psi2IrContext.irBuiltIns,
|
||||||
psi2IrContext.symbolTable,
|
psi2IrContext.symbolTable,
|
||||||
partialLinkageSupport = createPartialLinkageSupportForLinker(configuration.partialLinkageConfig, psi2IrContext.irBuiltIns, messageLogger),
|
partialLinkageSupport = createPartialLinkageSupportForLinker(
|
||||||
|
partialLinkageConfig = configuration.partialLinkageConfig,
|
||||||
|
allowErrorTypes = errorPolicy.allowErrors,
|
||||||
|
builtIns = psi2IrContext.irBuiltIns,
|
||||||
|
messageLogger = messageLogger
|
||||||
|
),
|
||||||
feContext,
|
feContext,
|
||||||
ICData(icData.map { it.irData }, errorPolicy.allowErrors),
|
ICData(icData.map { it.irData }, errorPolicy.allowErrors),
|
||||||
stubGenerator = stubGenerator
|
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.ExternalDependenciesGenerator
|
||||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||||
import org.jetbrains.kotlin.ir.util.irMessageLogger
|
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.KotlinLibrary
|
||||||
import org.jetbrains.kotlin.library.uniqueName
|
import org.jetbrains.kotlin.library.uniqueName
|
||||||
import org.jetbrains.kotlin.library.unresolvedDependencies
|
import org.jetbrains.kotlin.library.unresolvedDependencies
|
||||||
@@ -108,6 +110,7 @@ internal class JsIrLinkerLoader(
|
|||||||
val symbolTable = SymbolTable(signaturer, irFactory)
|
val symbolTable = SymbolTable(signaturer, irFactory)
|
||||||
val moduleDescriptor = loadedModules.keys.last()
|
val moduleDescriptor = loadedModules.keys.last()
|
||||||
val typeTranslator = TypeTranslatorImpl(symbolTable, compilerConfiguration.languageVersionSettings, moduleDescriptor)
|
val typeTranslator = TypeTranslatorImpl(symbolTable, compilerConfiguration.languageVersionSettings, moduleDescriptor)
|
||||||
|
val errorPolicy = compilerConfiguration[JSConfigurationKeys.ERROR_TOLERANCE_POLICY] ?: ErrorTolerancePolicy.DEFAULT
|
||||||
val irBuiltIns = IrBuiltInsOverDescriptors(moduleDescriptor.builtIns, typeTranslator, symbolTable)
|
val irBuiltIns = IrBuiltInsOverDescriptors(moduleDescriptor.builtIns, typeTranslator, symbolTable)
|
||||||
val messageLogger = compilerConfiguration.irMessageLogger
|
val messageLogger = compilerConfiguration.irMessageLogger
|
||||||
val linker = JsIrLinker(
|
val linker = JsIrLinker(
|
||||||
@@ -115,7 +118,12 @@ internal class JsIrLinkerLoader(
|
|||||||
messageLogger = messageLogger,
|
messageLogger = messageLogger,
|
||||||
builtIns = irBuiltIns,
|
builtIns = irBuiltIns,
|
||||||
symbolTable = symbolTable,
|
symbolTable = symbolTable,
|
||||||
partialLinkageSupport = createPartialLinkageSupportForLinker(compilerConfiguration.partialLinkageConfig, irBuiltIns, messageLogger),
|
partialLinkageSupport = createPartialLinkageSupportForLinker(
|
||||||
|
partialLinkageConfig = compilerConfiguration.partialLinkageConfig,
|
||||||
|
allowErrorTypes = errorPolicy.allowErrors,
|
||||||
|
builtIns = irBuiltIns,
|
||||||
|
messageLogger = messageLogger
|
||||||
|
),
|
||||||
translationPluginContext = null,
|
translationPluginContext = null,
|
||||||
friendModules = mapOf(mainLibrary.uniqueName to mainModuleFriends.map { it.uniqueName })
|
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.utils.addIfNotNull
|
||||||
import org.jetbrains.kotlin.ir.linkage.partial.PartialLinkageUtils.Module as PLModule
|
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 exploredSymbols = ExploredClassifiers()
|
||||||
|
|
||||||
private val permittedAnnotationArrayParameterSymbols: Set<IrClassSymbol> by lazy {
|
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) }
|
?: arguments.firstUnusable { it.typeOrNull?.exploreType(visitedSymbols) }
|
||||||
?: Usable
|
?: Usable
|
||||||
is IrDynamicType -> 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(
|
fun createPartialLinkageSupportForLinker(
|
||||||
partialLinkageConfig: PartialLinkageConfig,
|
partialLinkageConfig: PartialLinkageConfig,
|
||||||
|
allowErrorTypes: Boolean,
|
||||||
builtIns: IrBuiltIns,
|
builtIns: IrBuiltIns,
|
||||||
messageLogger: IrMessageLogger
|
messageLogger: IrMessageLogger
|
||||||
): PartialLinkageSupportForLinker = if (partialLinkageConfig.isEnabled)
|
): PartialLinkageSupportForLinker = if (partialLinkageConfig.isEnabled)
|
||||||
PartialLinkageSupportForLinkerImpl(builtIns, partialLinkageConfig.logLevel, messageLogger)
|
PartialLinkageSupportForLinkerImpl(builtIns, allowErrorTypes, partialLinkageConfig.logLevel, messageLogger)
|
||||||
else
|
else
|
||||||
PartialLinkageSupportForLinker.DISABLED
|
PartialLinkageSupportForLinker.DISABLED
|
||||||
|
|
||||||
internal class PartialLinkageSupportForLinkerImpl(
|
internal class PartialLinkageSupportForLinkerImpl(
|
||||||
builtIns: IrBuiltIns,
|
builtIns: IrBuiltIns,
|
||||||
|
allowErrorTypes: Boolean,
|
||||||
logLevel: PartialLinkageLogLevel,
|
logLevel: PartialLinkageLogLevel,
|
||||||
messageLogger: IrMessageLogger
|
messageLogger: IrMessageLogger
|
||||||
) : PartialLinkageSupportForLinker {
|
) : PartialLinkageSupportForLinker {
|
||||||
private val stubGenerator = MissingDeclarationStubGenerator(builtIns)
|
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)
|
private val patcher = PartiallyLinkedIrTreePatcher(builtIns, classifierExplorer, stubGenerator, logLevel, messageLogger)
|
||||||
|
|
||||||
override val isEnabled get() = true
|
override val isEnabled get() = true
|
||||||
|
|||||||
@@ -264,13 +264,19 @@ fun getIrModuleInfoForKlib(
|
|||||||
val mainModuleLib = sortedDependencies.last()
|
val mainModuleLib = sortedDependencies.last()
|
||||||
val typeTranslator = TypeTranslatorImpl(symbolTable, configuration.languageVersionSettings, moduleDescriptor)
|
val typeTranslator = TypeTranslatorImpl(symbolTable, configuration.languageVersionSettings, moduleDescriptor)
|
||||||
val irBuiltIns = IrBuiltInsOverDescriptors(moduleDescriptor.builtIns, typeTranslator, symbolTable)
|
val irBuiltIns = IrBuiltInsOverDescriptors(moduleDescriptor.builtIns, typeTranslator, symbolTable)
|
||||||
|
val errorPolicy = configuration[JSConfigurationKeys.ERROR_TOLERANCE_POLICY] ?: ErrorTolerancePolicy.DEFAULT
|
||||||
|
|
||||||
val irLinker = JsIrLinker(
|
val irLinker = JsIrLinker(
|
||||||
currentModule = null,
|
currentModule = null,
|
||||||
messageLogger = messageLogger,
|
messageLogger = messageLogger,
|
||||||
builtIns = irBuiltIns,
|
builtIns = irBuiltIns,
|
||||||
symbolTable = symbolTable,
|
symbolTable = symbolTable,
|
||||||
partialLinkageSupport = createPartialLinkageSupportForLinker(configuration.partialLinkageConfig, irBuiltIns, messageLogger),
|
partialLinkageSupport = createPartialLinkageSupportForLinker(
|
||||||
|
partialLinkageConfig = configuration.partialLinkageConfig,
|
||||||
|
allowErrorTypes = errorPolicy.allowErrors,
|
||||||
|
builtIns = irBuiltIns,
|
||||||
|
messageLogger = messageLogger
|
||||||
|
),
|
||||||
translationPluginContext = null,
|
translationPluginContext = null,
|
||||||
icData = null,
|
icData = null,
|
||||||
friendModules = friendModules
|
friendModules = friendModules
|
||||||
@@ -322,13 +328,19 @@ fun getIrModuleInfoForSourceFiles(
|
|||||||
val feContext = psi2IrContext.run {
|
val feContext = psi2IrContext.run {
|
||||||
JsIrLinker.JsFePluginContext(moduleDescriptor, symbolTable, typeTranslator, irBuiltIns)
|
JsIrLinker.JsFePluginContext(moduleDescriptor, symbolTable, typeTranslator, irBuiltIns)
|
||||||
}
|
}
|
||||||
|
val errorPolicy = configuration[JSConfigurationKeys.ERROR_TOLERANCE_POLICY] ?: ErrorTolerancePolicy.DEFAULT
|
||||||
|
|
||||||
val irLinker = JsIrLinker(
|
val irLinker = JsIrLinker(
|
||||||
currentModule = psi2IrContext.moduleDescriptor,
|
currentModule = psi2IrContext.moduleDescriptor,
|
||||||
messageLogger = messageLogger,
|
messageLogger = messageLogger,
|
||||||
builtIns = irBuiltIns,
|
builtIns = irBuiltIns,
|
||||||
symbolTable = symbolTable,
|
symbolTable = symbolTable,
|
||||||
partialLinkageSupport = createPartialLinkageSupportForLinker(configuration.partialLinkageConfig, irBuiltIns, messageLogger),
|
partialLinkageSupport = createPartialLinkageSupportForLinker(
|
||||||
|
partialLinkageConfig = configuration.partialLinkageConfig,
|
||||||
|
allowErrorTypes = errorPolicy.allowErrors,
|
||||||
|
builtIns = irBuiltIns,
|
||||||
|
messageLogger = messageLogger
|
||||||
|
),
|
||||||
translationPluginContext = feContext,
|
translationPluginContext = feContext,
|
||||||
icData = null,
|
icData = null,
|
||||||
friendModules = friendModules,
|
friendModules = friendModules,
|
||||||
|
|||||||
+6
-1
@@ -143,7 +143,12 @@ internal fun PsiToIrContext.psiToIr(
|
|||||||
stubGenerator = stubGenerator,
|
stubGenerator = stubGenerator,
|
||||||
cenumsProvider = irProviderForCEnumsAndCStructs,
|
cenumsProvider = irProviderForCEnumsAndCStructs,
|
||||||
exportedDependencies = exportedDependencies,
|
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,
|
cachedLibraries = config.cachedLibraries,
|
||||||
lazyIrForCaches = config.lazyIrForCaches,
|
lazyIrForCaches = config.lazyIrForCaches,
|
||||||
libraryBeingCached = config.libraryToCache,
|
libraryBeingCached = config.libraryToCache,
|
||||||
|
|||||||
Reference in New Issue
Block a user