[KLIB] Mark klib that contains error with special flag
This commit is contained in:
@@ -44,6 +44,7 @@ import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
|||||||
import org.jetbrains.kotlin.js.analyzer.JsAnalysisResult
|
import org.jetbrains.kotlin.js.analyzer.JsAnalysisResult
|
||||||
import org.jetbrains.kotlin.js.config.ErrorTolerancePolicy
|
import org.jetbrains.kotlin.js.config.ErrorTolerancePolicy
|
||||||
import org.jetbrains.kotlin.js.config.JSConfigurationKeys
|
import org.jetbrains.kotlin.js.config.JSConfigurationKeys
|
||||||
|
import org.jetbrains.kotlin.konan.properties.Properties
|
||||||
import org.jetbrains.kotlin.konan.properties.propertyList
|
import org.jetbrains.kotlin.konan.properties.propertyList
|
||||||
import org.jetbrains.kotlin.konan.util.KlibMetadataFactories
|
import org.jetbrains.kotlin.konan.util.KlibMetadataFactories
|
||||||
import org.jetbrains.kotlin.library.*
|
import org.jetbrains.kotlin.library.*
|
||||||
@@ -142,7 +143,7 @@ fun generateKLib(
|
|||||||
val depsDescriptors =
|
val depsDescriptors =
|
||||||
ModulesStructure(project, MainModule.SourceFiles(files), analyzer, configuration, allDependencies, friendDependencies)
|
ModulesStructure(project, MainModule.SourceFiles(files), analyzer, configuration, allDependencies, friendDependencies)
|
||||||
|
|
||||||
val psi2IrContext = runAnalysisAndPreparePsi2Ir(depsDescriptors, irFactory, errorPolicy)
|
val (psi2IrContext, hasErrors) = runAnalysisAndPreparePsi2Ir(depsDescriptors, irFactory, errorPolicy)
|
||||||
val irBuiltIns = psi2IrContext.irBuiltIns
|
val irBuiltIns = psi2IrContext.irBuiltIns
|
||||||
val functionFactory = IrFunctionFactory(irBuiltIns, psi2IrContext.symbolTable)
|
val functionFactory = IrFunctionFactory(irBuiltIns, psi2IrContext.symbolTable)
|
||||||
irBuiltIns.functionFactory = functionFactory
|
irBuiltIns.functionFactory = functionFactory
|
||||||
@@ -192,7 +193,7 @@ fun generateKLib(
|
|||||||
expectDescriptorToSymbol,
|
expectDescriptorToSymbol,
|
||||||
icData,
|
icData,
|
||||||
nopack,
|
nopack,
|
||||||
false
|
hasErrors
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,7 +229,7 @@ fun loadIr(
|
|||||||
|
|
||||||
when (mainModule) {
|
when (mainModule) {
|
||||||
is MainModule.SourceFiles -> {
|
is MainModule.SourceFiles -> {
|
||||||
val psi2IrContext: GeneratorContext = runAnalysisAndPreparePsi2Ir(depsDescriptors, irFactory, errorPolicy)
|
val (psi2IrContext, _) = runAnalysisAndPreparePsi2Ir(depsDescriptors, irFactory, errorPolicy)
|
||||||
val irBuiltIns = psi2IrContext.irBuiltIns
|
val irBuiltIns = psi2IrContext.irBuiltIns
|
||||||
val symbolTable = psi2IrContext.symbolTable
|
val symbolTable = psi2IrContext.symbolTable
|
||||||
val functionFactory = IrFunctionFactory(irBuiltIns, symbolTable)
|
val functionFactory = IrFunctionFactory(irBuiltIns, symbolTable)
|
||||||
@@ -297,11 +298,18 @@ fun loadIr(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun runAnalysisAndPreparePsi2Ir(depsDescriptors: ModulesStructure, irFactory: IrFactory, errorIgnorancePolicy: ErrorTolerancePolicy): GeneratorContext {
|
private fun runAnalysisAndPreparePsi2Ir(
|
||||||
val (bindingContext, moduleDescriptor) = depsDescriptors.runAnalysis(errorIgnorancePolicy)
|
depsDescriptors: ModulesStructure,
|
||||||
val psi2Ir = Psi2IrTranslator(depsDescriptors.compilerConfiguration.languageVersionSettings, Psi2IrConfiguration(errorIgnorancePolicy.allowErrors))
|
irFactory: IrFactory,
|
||||||
|
errorIgnorancePolicy: ErrorTolerancePolicy
|
||||||
|
): Pair<GeneratorContext, Boolean> {
|
||||||
|
val analysisResult = depsDescriptors.runAnalysis(errorIgnorancePolicy)
|
||||||
|
val psi2Ir = Psi2IrTranslator(
|
||||||
|
depsDescriptors.compilerConfiguration.languageVersionSettings,
|
||||||
|
Psi2IrConfiguration(errorIgnorancePolicy.allowErrors)
|
||||||
|
)
|
||||||
val symbolTable = SymbolTable(IdSignatureDescriptor(JsManglerDesc), irFactory)
|
val symbolTable = SymbolTable(IdSignatureDescriptor(JsManglerDesc), irFactory)
|
||||||
return psi2Ir.createGeneratorContext(moduleDescriptor, bindingContext, symbolTable)
|
return psi2Ir.createGeneratorContext(analysisResult.moduleDescriptor, analysisResult.bindingContext, symbolTable) to analysisResult.hasErrors
|
||||||
}
|
}
|
||||||
|
|
||||||
fun GeneratorContext.generateModuleFragmentWithPlugins(
|
fun GeneratorContext.generateModuleFragmentWithPlugins(
|
||||||
@@ -385,7 +393,9 @@ private class ModulesStructure(
|
|||||||
|
|
||||||
val builtInsDep = allDependencies.getFullList().find { it.isBuiltIns }
|
val builtInsDep = allDependencies.getFullList().find { it.isBuiltIns }
|
||||||
|
|
||||||
fun runAnalysis(errorPolicy: ErrorTolerancePolicy): JsAnalysisResult {
|
class JsFrontEndResult(val moduleDescriptor: ModuleDescriptor, val bindingContext: BindingContext, val hasErrors: Boolean)
|
||||||
|
|
||||||
|
fun runAnalysis(errorPolicy: ErrorTolerancePolicy): JsFrontEndResult {
|
||||||
require(mainModule is MainModule.SourceFiles)
|
require(mainModule is MainModule.SourceFiles)
|
||||||
val files = mainModule.files
|
val files = mainModule.files
|
||||||
|
|
||||||
@@ -409,12 +419,16 @@ private class ModulesStructure(
|
|||||||
compareMetadataAndGoToNextICRoundIfNeeded(analysisResult, compilerConfiguration, files)
|
compareMetadataAndGoToNextICRoundIfNeeded(analysisResult, compilerConfiguration, files)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!errorPolicy.allowErrors && analyzer.hasErrors() || analysisResult !is JsAnalysisResult)
|
var hasErrors = false
|
||||||
throw JsIrCompilationError
|
if (analyzer.hasErrors() || analysisResult !is JsAnalysisResult) {
|
||||||
|
if (!errorPolicy.allowErrors)
|
||||||
|
throw JsIrCompilationError
|
||||||
|
else hasErrors = true
|
||||||
|
}
|
||||||
|
|
||||||
TopDownAnalyzerFacadeForJSIR.checkForErrors(files, analysisResult.bindingContext, errorPolicy)
|
hasErrors = TopDownAnalyzerFacadeForJSIR.checkForErrors(files, analysisResult.bindingContext, errorPolicy) || hasErrors
|
||||||
|
|
||||||
return analysisResult
|
return JsFrontEndResult(analysisResult.moduleDescriptor, analysisResult.bindingContext, hasErrors)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val languageVersionSettings: LanguageVersionSettings = compilerConfiguration.languageVersionSettings
|
private val languageVersionSettings: LanguageVersionSettings = compilerConfiguration.languageVersionSettings
|
||||||
@@ -467,7 +481,8 @@ fun serializeModuleIntoKlib(
|
|||||||
expectDescriptorToSymbol: MutableMap<DeclarationDescriptor, IrSymbol>,
|
expectDescriptorToSymbol: MutableMap<DeclarationDescriptor, IrSymbol>,
|
||||||
cleanFiles: List<KotlinFileSerializedData>,
|
cleanFiles: List<KotlinFileSerializedData>,
|
||||||
nopack: Boolean,
|
nopack: Boolean,
|
||||||
perFile: Boolean
|
perFile: Boolean,
|
||||||
|
containsErrorCode: Boolean = false
|
||||||
) {
|
) {
|
||||||
assert(files.size == moduleFragment.files.size)
|
assert(files.size == moduleFragment.files.size)
|
||||||
|
|
||||||
@@ -537,12 +552,18 @@ fun serializeModuleIntoKlib(
|
|||||||
irVersion = KlibIrVersion.INSTANCE.toString()
|
irVersion = KlibIrVersion.INSTANCE.toString()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val properties = if (containsErrorCode) {
|
||||||
|
Properties().also {
|
||||||
|
it.setProperty(KLIB_PROPERTY_CONTAINS_ERROR_CODE, "true")
|
||||||
|
}
|
||||||
|
} else null
|
||||||
|
|
||||||
buildKotlinLibrary(
|
buildKotlinLibrary(
|
||||||
linkDependencies = dependencies,
|
linkDependencies = dependencies,
|
||||||
ir = fullSerializedIr,
|
ir = fullSerializedIr,
|
||||||
metadata = serializedMetadata,
|
metadata = serializedMetadata,
|
||||||
dataFlowGraph = null,
|
dataFlowGraph = null,
|
||||||
manifestProperties = null,
|
manifestProperties = properties,
|
||||||
moduleName = moduleName,
|
moduleName = moduleName,
|
||||||
nopack = nopack,
|
nopack = nopack,
|
||||||
perFile = perFile,
|
perFile = perFile,
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ const val KLIB_PROPERTY_SHORT_NAME = "short_name"
|
|||||||
const val KLIB_PROPERTY_DEPENDS = "depends"
|
const val KLIB_PROPERTY_DEPENDS = "depends"
|
||||||
const val KLIB_PROPERTY_PACKAGE = "package"
|
const val KLIB_PROPERTY_PACKAGE = "package"
|
||||||
const val KLIB_PROPERTY_BUILTINS_PLATFORM = "builtins_platform"
|
const val KLIB_PROPERTY_BUILTINS_PLATFORM = "builtins_platform"
|
||||||
|
const val KLIB_PROPERTY_CONTAINS_ERROR_CODE = "contains_error_code"
|
||||||
|
|
||||||
// Native-specific:
|
// Native-specific:
|
||||||
const val KLIB_PROPERTY_INTEROP = "interop"
|
const val KLIB_PROPERTY_INTEROP = "interop"
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.serialization.js.KotlinJavascriptSerializationUtil
|
|||||||
import org.jetbrains.kotlin.serialization.js.ModuleKind
|
import org.jetbrains.kotlin.serialization.js.ModuleKind
|
||||||
import org.jetbrains.kotlin.serialization.js.PackagesWithHeaderMetadata
|
import org.jetbrains.kotlin.serialization.js.PackagesWithHeaderMetadata
|
||||||
import org.jetbrains.kotlin.utils.JsMetadataVersion
|
import org.jetbrains.kotlin.utils.JsMetadataVersion
|
||||||
|
import java.lang.Exception
|
||||||
|
|
||||||
abstract class AbstractTopDownAnalyzerFacadeForJS {
|
abstract class AbstractTopDownAnalyzerFacadeForJS {
|
||||||
|
|
||||||
@@ -115,15 +116,31 @@ abstract class AbstractTopDownAnalyzerFacadeForJS {
|
|||||||
return JsAnalysisResult.success(trace, moduleContext.module)
|
return JsAnalysisResult.success(trace, moduleContext.module)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun checkForErrors(allFiles: Collection<KtFile>, bindingContext: BindingContext, errorPolicy: ErrorTolerancePolicy) {
|
fun checkForErrors(allFiles: Collection<KtFile>, bindingContext: BindingContext, errorPolicy: ErrorTolerancePolicy): Boolean {
|
||||||
if (!errorPolicy.allowSemanticErrors) {
|
var hasErrors = false
|
||||||
|
try {
|
||||||
AnalyzingUtils.throwExceptionOnErrors(bindingContext)
|
AnalyzingUtils.throwExceptionOnErrors(bindingContext)
|
||||||
|
} catch (ex: Exception) {
|
||||||
|
if (!errorPolicy.allowSemanticErrors) {
|
||||||
|
throw ex
|
||||||
|
} else {
|
||||||
|
hasErrors = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!errorPolicy.allowSyntaxErrors) {
|
|
||||||
|
try {
|
||||||
for (file in allFiles) {
|
for (file in allFiles) {
|
||||||
AnalyzingUtils.checkForSyntacticErrors(file)
|
AnalyzingUtils.checkForSyntacticErrors(file)
|
||||||
}
|
}
|
||||||
|
} catch (ex: Exception) {
|
||||||
|
if (!errorPolicy.allowSyntaxErrors) {
|
||||||
|
throw ex
|
||||||
|
} else {
|
||||||
|
hasErrors = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return hasErrors
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user