Refactor IR reporting and infrastructure
This commit is contained in:
+18
-9
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.codegen.CodegenFactory
|
||||
import org.jetbrains.kotlin.codegen.state.GenerationState
|
||||
import org.jetbrains.kotlin.config.*
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporterFactory
|
||||
import org.jetbrains.kotlin.diagnostics.impl.BaseDiagnosticReporter
|
||||
import org.jetbrains.kotlin.fir.*
|
||||
import org.jetbrains.kotlin.fir.backend.Fir2IrResult
|
||||
import org.jetbrains.kotlin.fir.backend.jvm.FirJvmBackendClassResolver
|
||||
@@ -127,9 +128,14 @@ object FirKotlinToJvmBytecodeCompiler {
|
||||
|
||||
if (!checkKotlinPackageUsage(moduleConfiguration, allSources)) return null
|
||||
|
||||
val firResult = runFrontend(allSources).also {
|
||||
val diagnosticsReporter = DiagnosticReporterFactory.createReporter()
|
||||
val firResult = runFrontend(allSources, diagnosticsReporter).also {
|
||||
performanceManager?.notifyAnalysisFinished()
|
||||
} ?: return null
|
||||
}
|
||||
if (firResult == null) {
|
||||
FirDiagnosticsCompilerResultsReporter.reportToCollector(diagnosticsReporter, messageCollector)
|
||||
return null
|
||||
}
|
||||
|
||||
performanceManager?.notifyGenerationStarted()
|
||||
performanceManager?.notifyIRTranslationStarted()
|
||||
@@ -143,9 +149,12 @@ object FirKotlinToJvmBytecodeCompiler {
|
||||
allSources,
|
||||
fir2IrResult,
|
||||
extensions,
|
||||
firResult.session
|
||||
firResult.session,
|
||||
diagnosticsReporter
|
||||
)
|
||||
|
||||
FirDiagnosticsCompilerResultsReporter.reportToCollector(diagnosticsReporter, messageCollector)
|
||||
|
||||
performanceManager?.notifyIRGenerationFinished()
|
||||
performanceManager?.notifyGenerationFinished()
|
||||
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled()
|
||||
@@ -159,7 +168,7 @@ object FirKotlinToJvmBytecodeCompiler {
|
||||
val fir: List<FirFile>
|
||||
)
|
||||
|
||||
private fun CompilationContext.runFrontend(ktFiles: List<KtFile>): FirResult? {
|
||||
private fun CompilationContext.runFrontend(ktFiles: List<KtFile>, diagnosticsReporter: BaseDiagnosticReporter): FirResult? {
|
||||
@Suppress("NAME_SHADOWING")
|
||||
var ktFiles = ktFiles
|
||||
val syntaxErrors = ktFiles.fold(false) { errorsFound, ktFile ->
|
||||
@@ -243,7 +252,6 @@ object FirKotlinToJvmBytecodeCompiler {
|
||||
val commonRawFir = commonSession?.buildFirFromKtFiles(commonKtFiles)
|
||||
val rawFir = session.buildFirFromKtFiles(ktFiles)
|
||||
|
||||
val diagnosticsReporter = DiagnosticReporterFactory.createReporter()
|
||||
commonSession?.apply {
|
||||
val (commonScopeSession, commonFir) = runResolution(commonRawFir!!)
|
||||
runCheckers(commonScopeSession, commonFir, diagnosticsReporter)
|
||||
@@ -252,9 +260,7 @@ object FirKotlinToJvmBytecodeCompiler {
|
||||
val (scopeSession, fir) = session.runResolution(rawFir)
|
||||
session.runCheckers(scopeSession, fir, diagnosticsReporter)
|
||||
|
||||
val hasErrors = FirDiagnosticsCompilerResultsReporter.reportToCollector(diagnosticsReporter, messageCollector)
|
||||
|
||||
return if (syntaxErrors || hasErrors) null else FirResult(session, scopeSession, fir)
|
||||
return if (syntaxErrors || diagnosticsReporter.hasErrors) null else FirResult(session, scopeSession, fir)
|
||||
}
|
||||
|
||||
private fun CompilationContext.createComponentsForIncrementalCompilation(
|
||||
@@ -280,7 +286,8 @@ object FirKotlinToJvmBytecodeCompiler {
|
||||
ktFiles: List<KtFile>,
|
||||
fir2IrResult: Fir2IrResult,
|
||||
extensions: JvmGeneratorExtensionsImpl,
|
||||
session: FirSession
|
||||
session: FirSession,
|
||||
diagnosticsReporter: BaseDiagnosticReporter
|
||||
): GenerationState {
|
||||
val (moduleFragment, symbolTable, components) = fir2IrResult
|
||||
val dummyBindingContext = NoScopeRecordCliBindingTrace().bindingContext
|
||||
@@ -304,6 +311,8 @@ object FirKotlinToJvmBytecodeCompiler {
|
||||
true
|
||||
).jvmBackendClassResolver(
|
||||
FirJvmBackendClassResolver(components)
|
||||
).diagnosticReporter(
|
||||
diagnosticsReporter
|
||||
).build()
|
||||
|
||||
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled()
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory
|
||||
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
||||
import org.jetbrains.kotlin.cli.common.checkKotlinPackageUsage
|
||||
import org.jetbrains.kotlin.cli.common.config.addKotlinSourceRoot
|
||||
import org.jetbrains.kotlin.cli.common.fir.FirDiagnosticsCompilerResultsReporter
|
||||
import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport
|
||||
import org.jetbrains.kotlin.cli.common.toLogger
|
||||
import org.jetbrains.kotlin.cli.jvm.config.*
|
||||
@@ -40,6 +41,7 @@ import org.jetbrains.kotlin.config.CommonConfigurationKeys
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.config.JVMConfigurationKeys
|
||||
import org.jetbrains.kotlin.config.languageVersionSettings
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporterFactory
|
||||
import org.jetbrains.kotlin.ir.backend.jvm.jvmResolveLibraries
|
||||
import org.jetbrains.kotlin.load.kotlin.ModuleVisibilityManager
|
||||
import org.jetbrains.kotlin.modules.Module
|
||||
@@ -332,6 +334,8 @@ object KotlinToJVMBytecodeCompiler {
|
||||
codegenFactory: CodegenFactory,
|
||||
backendInput: CodegenFactory.BackendInput,
|
||||
): GenerationState {
|
||||
val diagnosticsReporter = DiagnosticReporterFactory.createReporter()
|
||||
|
||||
val state = GenerationState.Builder(
|
||||
environment.project,
|
||||
ClassBuilderFactories.BINARIES,
|
||||
@@ -343,6 +347,7 @@ object KotlinToJVMBytecodeCompiler {
|
||||
.codegenFactory(codegenFactory)
|
||||
.withModule(module)
|
||||
.onIndependentPartCompilationEnd(createOutputFilesFlushingCallbackIfPossible(configuration))
|
||||
.diagnosticReporter(diagnosticsReporter)
|
||||
.build()
|
||||
|
||||
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled()
|
||||
@@ -370,6 +375,7 @@ object KotlinToJVMBytecodeCompiler {
|
||||
),
|
||||
environment.messageCollector
|
||||
)
|
||||
FirDiagnosticsCompilerResultsReporter.reportToCollector(diagnosticsReporter, environment.messageCollector)
|
||||
|
||||
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled()
|
||||
return state
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.diagnostics
|
||||
|
||||
import org.jetbrains.kotlin.AbstractKtSourceElement
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
|
||||
interface DiagnosticContext {
|
||||
@@ -27,3 +28,44 @@ abstract class MutableDiagnosticContext : DiagnosticContext {
|
||||
abstract class DiagnosticReporter {
|
||||
abstract fun report(diagnostic: KtDiagnostic?, context: DiagnosticContext)
|
||||
}
|
||||
|
||||
open class KtDiagnosticReporterWithContext(
|
||||
val diagnosticReporter: DiagnosticReporter,
|
||||
val languageVersionSettings: LanguageVersionSettings
|
||||
) : DiagnosticReporter() {
|
||||
override fun report(diagnostic: KtDiagnostic?, context: DiagnosticContext) = diagnosticReporter.report(diagnostic, context)
|
||||
|
||||
fun at(sourceElement: AbstractKtSourceElement?, containingFilePath: String): DiagnosticContextImpl =
|
||||
DiagnosticContextImpl(sourceElement, containingFilePath)
|
||||
|
||||
open inner class DiagnosticContextImpl(
|
||||
val sourceElement: AbstractKtSourceElement?,
|
||||
override val containingFilePath: String
|
||||
) : DiagnosticContext {
|
||||
|
||||
override fun isDiagnosticSuppressed(diagnostic: KtDiagnostic): Boolean {
|
||||
return false
|
||||
// TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override val languageVersionSettings: LanguageVersionSettings
|
||||
get() = this@KtDiagnosticReporterWithContext.languageVersionSettings
|
||||
|
||||
@OptIn(InternalDiagnosticFactoryMethod::class)
|
||||
fun report(
|
||||
factory: KtDiagnosticFactory0,
|
||||
positioningStrategy: AbstractSourceElementPositioningStrategy? = null
|
||||
) {
|
||||
sourceElement?.let { report(factory.on(it, positioningStrategy), this) }
|
||||
}
|
||||
|
||||
@OptIn(InternalDiagnosticFactoryMethod::class)
|
||||
fun <A : Any> report(
|
||||
factory: KtDiagnosticFactory1<A>,
|
||||
a: A,
|
||||
positioningStrategy: AbstractSourceElementPositioningStrategy? = null
|
||||
) {
|
||||
sourceElement?.let { report(factory.on(it, a, positioningStrategy), this) }
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
@@ -11,4 +11,5 @@ import org.jetbrains.kotlin.diagnostics.KtDiagnostic
|
||||
abstract class BaseDiagnosticReporter : DiagnosticReporter() {
|
||||
abstract val diagnostics: List<KtDiagnostic>
|
||||
abstract val diagnosticsByFilePath: Map<String?, List<KtDiagnostic>>
|
||||
abstract val hasErrors: Boolean
|
||||
}
|
||||
|
||||
+11
-3
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.diagnostics.impl
|
||||
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticContext
|
||||
import org.jetbrains.kotlin.diagnostics.KtDiagnostic
|
||||
import org.jetbrains.kotlin.diagnostics.Severity
|
||||
|
||||
class DiagnosticReporterWithSuppress : BaseDiagnosticReporter() {
|
||||
private val _diagnosticsByFilePath: MutableMap<String?, MutableList<KtDiagnostic>> = mutableMapOf()
|
||||
@@ -15,10 +16,17 @@ class DiagnosticReporterWithSuppress : BaseDiagnosticReporter() {
|
||||
override val diagnosticsByFilePath: Map<String?, List<KtDiagnostic>>
|
||||
get() = _diagnosticsByFilePath
|
||||
|
||||
override var hasErrors = false
|
||||
private set
|
||||
|
||||
override fun report(diagnostic: KtDiagnostic?, context: DiagnosticContext) {
|
||||
if (diagnostic == null) return
|
||||
if (!context.isDiagnosticSuppressed(diagnostic)) {
|
||||
_diagnosticsByFilePath.getOrPut(context.containingFilePath) { mutableListOf() }.add(diagnostic)
|
||||
if (diagnostic != null && !context.isDiagnosticSuppressed(diagnostic)) {
|
||||
_diagnosticsByFilePath.getOrPut(context.containingFilePath) { mutableListOf() }.run {
|
||||
add(diagnostic)
|
||||
if (!hasErrors && diagnostic.severity == Severity.ERROR) {
|
||||
hasErrors = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
-2
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.diagnostics.impl
|
||||
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticContext
|
||||
import org.jetbrains.kotlin.diagnostics.KtDiagnostic
|
||||
import org.jetbrains.kotlin.diagnostics.Severity
|
||||
|
||||
class SimpleDiagnosticReporter : BaseDiagnosticReporter() {
|
||||
private val _diagnosticsByFilePath: MutableMap<String?, MutableList<KtDiagnostic>> = mutableMapOf()
|
||||
@@ -15,8 +16,17 @@ class SimpleDiagnosticReporter : BaseDiagnosticReporter() {
|
||||
override val diagnosticsByFilePath: Map<String?, List<KtDiagnostic>>
|
||||
get() = _diagnosticsByFilePath
|
||||
|
||||
override var hasErrors = false
|
||||
private set
|
||||
|
||||
override fun report(diagnostic: KtDiagnostic?, context: DiagnosticContext) {
|
||||
if (diagnostic == null) return
|
||||
_diagnosticsByFilePath.getOrPut(context.containingFilePath) { mutableListOf() }.add(diagnostic)
|
||||
if (diagnostic != null) {
|
||||
_diagnosticsByFilePath.getOrPut(context.containingFilePath) { mutableListOf() }.run {
|
||||
add(diagnostic)
|
||||
if (!hasErrors && diagnostic.severity == Severity.ERROR) {
|
||||
hasErrors = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve.jvm.diagnostics
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactoryToRendererMap
|
||||
import org.jetbrains.kotlin.diagnostics.SourceElementPositioningStrategies.DECLARATION_SIGNATURE_OR_DEFAULT
|
||||
import org.jetbrains.kotlin.diagnostics.error0
|
||||
import org.jetbrains.kotlin.diagnostics.error1
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.*
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.CommonRenderers.STRING
|
||||
import org.jetbrains.kotlin.resolve.MemberComparator
|
||||
import org.jetbrains.kotlin.utils.join
|
||||
|
||||
object JvmBackendErrors {
|
||||
// TODO: slightly different errors of this type exist also in fir checkers, consider unifying
|
||||
val CONFLICTING_JVM_DECLARATIONS by error1<PsiElement, ConflictingJvmDeclarationsData>(DECLARATION_SIGNATURE_OR_DEFAULT)
|
||||
val CONFLICTING_INHERITED_JVM_DECLARATIONS by error1<PsiElement, ConflictingJvmDeclarationsData>(DECLARATION_SIGNATURE_OR_DEFAULT)
|
||||
val ACCIDENTAL_OVERRIDE by error1<PsiElement, ConflictingJvmDeclarationsData>(DECLARATION_SIGNATURE_OR_DEFAULT)
|
||||
|
||||
val TYPEOF_SUSPEND_TYPE by error0<PsiElement>()
|
||||
val TYPEOF_EXTENSION_FUNCTION_TYPE by error0<PsiElement>()
|
||||
val TYPEOF_ANNOTATED_TYPE by error0<PsiElement>()
|
||||
val TYPEOF_NON_REIFIED_TYPE_PARAMETER_WITH_RECURSIVE_BOUND by error1<PsiElement, String>()
|
||||
|
||||
val SUSPENSION_POINT_INSIDE_MONITOR by error1<PsiElement, String>()
|
||||
|
||||
init {
|
||||
RootDiagnosticRendererFactory.registerFactory(KtDefaultJvmErrorMessages)
|
||||
}
|
||||
}
|
||||
|
||||
object KtDefaultJvmErrorMessages : BaseDiagnosticRendererFactory() {
|
||||
|
||||
@JvmField
|
||||
val CONFLICTING_JVM_DECLARATIONS_DATA = Renderer<ConflictingJvmDeclarationsData> {
|
||||
val renderedDescriptors: List<DeclarationDescriptor?> =
|
||||
it.signatureOrigins.mapNotNull(
|
||||
JvmDeclarationOrigin::descriptor
|
||||
).sortedWith(MemberComparator.INSTANCE)
|
||||
val renderingContext: RenderingContext =
|
||||
RenderingContext.Impl(renderedDescriptors)
|
||||
"""
|
||||
The following declarations have the same JVM signature (${it.signature.name}${it.signature.desc}):
|
||||
|
||||
""".trimIndent() +
|
||||
join(renderedDescriptors.map { descriptor: DeclarationDescriptor? ->
|
||||
" " + Renderers.WITHOUT_MODIFIERS.render(
|
||||
descriptor!!, renderingContext
|
||||
)
|
||||
}, "\n")
|
||||
}
|
||||
|
||||
override val MAP = KtDiagnosticFactoryToRendererMap("KT").also { map ->
|
||||
map.put(JvmBackendErrors.CONFLICTING_JVM_DECLARATIONS, "Platform declaration clash: {0}", CONFLICTING_JVM_DECLARATIONS_DATA)
|
||||
map.put(JvmBackendErrors.ACCIDENTAL_OVERRIDE, "Accidental override: {0}", CONFLICTING_JVM_DECLARATIONS_DATA)
|
||||
map.put(JvmBackendErrors.CONFLICTING_INHERITED_JVM_DECLARATIONS, "Inherited platform declarations clash: {0}", CONFLICTING_JVM_DECLARATIONS_DATA)
|
||||
map.put(JvmBackendErrors.TYPEOF_SUSPEND_TYPE, "Suspend functional types are not supported in typeOf")
|
||||
map.put(JvmBackendErrors.TYPEOF_EXTENSION_FUNCTION_TYPE, "Extension function types are not supported in typeOf")
|
||||
map.put(JvmBackendErrors.TYPEOF_ANNOTATED_TYPE, "Annotated types are not supported in typeOf")
|
||||
map.put(JvmBackendErrors.TYPEOF_NON_REIFIED_TYPE_PARAMETER_WITH_RECURSIVE_BOUND, "Non-reified type parameters with recursive bounds are not supported yet: {0}", STRING)
|
||||
map.put(JvmBackendErrors.SUSPENSION_POINT_INSIDE_MONITOR, "A suspension point at {0} is inside a critical section", STRING)
|
||||
}
|
||||
}
|
||||
-53
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve.jvm.diagnostics
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactoryToRendererMap
|
||||
import org.jetbrains.kotlin.diagnostics.error1
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.Renderer
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.Renderers
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.RenderingContext
|
||||
import org.jetbrains.kotlin.resolve.MemberComparator
|
||||
import org.jetbrains.kotlin.utils.join
|
||||
|
||||
object KtErrorsJvm {
|
||||
// TODO: slightly different errors of this type exist also in fir checkers, consider unifying
|
||||
val CONFLICTING_JVM_DECLARATIONS by error1<PsiElement, ConflictingJvmDeclarationsData>()
|
||||
val CONFLICTING_INHERITED_JVM_DECLARATIONS by error1<PsiElement, ConflictingJvmDeclarationsData>()
|
||||
val ACCIDENTAL_OVERRIDE by error1<PsiElement, ConflictingJvmDeclarationsData>()
|
||||
}
|
||||
|
||||
class KtDefaultJvmErrorMessages {
|
||||
companion object {
|
||||
|
||||
@JvmField
|
||||
val CONFLICTING_JVM_DECLARATIONS_DATA = Renderer<ConflictingJvmDeclarationsData> {
|
||||
val renderedDescriptors: List<DeclarationDescriptor?> =
|
||||
it.signatureOrigins.mapNotNull(
|
||||
JvmDeclarationOrigin::descriptor
|
||||
).sortedWith(MemberComparator.INSTANCE)
|
||||
val renderingContext: RenderingContext =
|
||||
RenderingContext.Impl(renderedDescriptors)
|
||||
"""
|
||||
The following declarations have the same JVM signature (${it.signature.name}${it.signature.desc}):
|
||||
|
||||
""".trimIndent() +
|
||||
join(renderedDescriptors.map { descriptor: DeclarationDescriptor? ->
|
||||
" " + Renderers.WITHOUT_MODIFIERS.render(
|
||||
descriptor!!, renderingContext
|
||||
)
|
||||
}, "\n")
|
||||
}
|
||||
|
||||
val MAP = KtDiagnosticFactoryToRendererMap("KT").also { map ->
|
||||
map.put(KtErrorsJvm.CONFLICTING_JVM_DECLARATIONS, "Platform declaration clash: {0}", CONFLICTING_JVM_DECLARATIONS_DATA)
|
||||
map.put(KtErrorsJvm.ACCIDENTAL_OVERRIDE, "Accidental override: {0}", CONFLICTING_JVM_DECLARATIONS_DATA)
|
||||
map.put(KtErrorsJvm.CONFLICTING_INHERITED_JVM_DECLARATIONS, "Inherited platform declarations clash: {0}", CONFLICTING_JVM_DECLARATIONS_DATA)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.diagnostics
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.KtDefaultErrorMessages
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.RootDiagnosticRendererFactory
|
||||
|
||||
object BackendErrors {
|
||||
|
||||
val NON_LOCAL_RETURN_IN_DISABLED_INLINE by error0<PsiElement>(SourceElementPositioningStrategies.DEFAULT) // need to reference SourceElementPositioningStrategies at least once to initialize properly
|
||||
|
||||
init {
|
||||
RootDiagnosticRendererFactory.registerFactory(KtDefaultErrorMessages)
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.diagnostics
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
|
||||
object KtErrors {
|
||||
|
||||
val NON_LOCAL_RETURN_IN_DISABLED_INLINE by error0<PsiElement>()
|
||||
val TYPEOF_SUSPEND_TYPE by error0<PsiElement>()
|
||||
val TYPEOF_EXTENSION_FUNCTION_TYPE by error0<PsiElement>()
|
||||
val TYPEOF_ANNOTATED_TYPE by error0<PsiElement>()
|
||||
val TYPEOF_NON_REIFIED_TYPE_PARAMETER_WITH_RECURSIVE_BOUND by error1<PsiElement, String>()
|
||||
|
||||
val SUSPENSION_POINT_INSIDE_MONITOR by error1<PsiElement, String>()
|
||||
}
|
||||
+6
-19
@@ -5,26 +5,13 @@
|
||||
|
||||
package org.jetbrains.kotlin.diagnostics.rendering
|
||||
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.CommonRenderers.STRING
|
||||
import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactoryToRendererMap
|
||||
import org.jetbrains.kotlin.diagnostics.KtErrors.NON_LOCAL_RETURN_IN_DISABLED_INLINE
|
||||
import org.jetbrains.kotlin.diagnostics.KtErrors.SUSPENSION_POINT_INSIDE_MONITOR
|
||||
import org.jetbrains.kotlin.diagnostics.KtErrors.TYPEOF_ANNOTATED_TYPE
|
||||
import org.jetbrains.kotlin.diagnostics.KtErrors.TYPEOF_EXTENSION_FUNCTION_TYPE
|
||||
import org.jetbrains.kotlin.diagnostics.KtErrors.TYPEOF_NON_REIFIED_TYPE_PARAMETER_WITH_RECURSIVE_BOUND
|
||||
import org.jetbrains.kotlin.diagnostics.KtErrors.TYPEOF_SUSPEND_TYPE
|
||||
import org.jetbrains.kotlin.diagnostics.BackendErrors
|
||||
|
||||
class KtDefaultErrorMessages {
|
||||
companion object {
|
||||
object KtDefaultErrorMessages : BaseDiagnosticRendererFactory() {
|
||||
|
||||
val MAP = KtDiagnosticFactoryToRendererMap("KT").also { map ->
|
||||
map.put(NON_LOCAL_RETURN_IN_DISABLED_INLINE, "Non-local returns are not allowed with inlining disabled")
|
||||
map.put(TYPEOF_SUSPEND_TYPE, "Suspend functional types are not supported in typeOf")
|
||||
map.put(TYPEOF_EXTENSION_FUNCTION_TYPE, "Extension function types are not supported in typeOf")
|
||||
map.put(TYPEOF_ANNOTATED_TYPE, "Annotated types are not supported in typeOf")
|
||||
map.put(TYPEOF_NON_REIFIED_TYPE_PARAMETER_WITH_RECURSIVE_BOUND, "Non-reified type parameters with recursive bounds are not supported yet: {0}", STRING)
|
||||
|
||||
map.put(SUSPENSION_POINT_INSIDE_MONITOR, "A suspension point at {0} is inside a critical section", STRING)
|
||||
}
|
||||
override val MAP = KtDiagnosticFactoryToRendererMap("KT").also { map ->
|
||||
map.put(BackendErrors.NON_LOCAL_RETURN_IN_DISABLED_INLINE, "Non-local returns are not allowed with inlining disabled")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+22
-46
@@ -5,64 +5,40 @@
|
||||
|
||||
package org.jetbrains.kotlin
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.psi.PsiSourceManager
|
||||
import org.jetbrains.kotlin.backend.common.sourceElement
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.diagnostics.*
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.declarations.name
|
||||
import org.jetbrains.kotlin.ir.declarations.path
|
||||
import org.jetbrains.kotlin.ir.util.file
|
||||
|
||||
class KtDiagnosticReporterWithImplicitIrBasedContext(
|
||||
val diagnosticReporter: DiagnosticReporter,
|
||||
val languageVersionSettings: LanguageVersionSettings
|
||||
) : DiagnosticReporter() {
|
||||
override fun report(diagnostic: KtDiagnostic?, context: DiagnosticContext) = diagnosticReporter.report(diagnostic, context)
|
||||
diagnosticReporter: DiagnosticReporter,
|
||||
languageVersionSettings: LanguageVersionSettings
|
||||
) : KtDiagnosticReporterWithContext(diagnosticReporter, languageVersionSettings) {
|
||||
|
||||
fun at(irElement: IrElement, containingIrFile: IrFile): DiagnosticContextOverIr =
|
||||
DiagnosticContextOverIr(irElement, containingIrFile)
|
||||
fun at(irElement: IrElement, containingIrFile: IrFile): DiagnosticContextImpl =
|
||||
at(
|
||||
PsiSourceManager.findPsiElement(irElement, containingIrFile)?.let(::KtRealPsiSourceElement)
|
||||
?: irElement.sourceElement(),
|
||||
containingIrFile.path
|
||||
)
|
||||
|
||||
fun at(irElement: IrElement, containingIrDeclaration: IrDeclaration): DiagnosticContextOverIr =
|
||||
DiagnosticContextOverIr(irElement, containingIrDeclaration)
|
||||
|
||||
fun at(irDeclaration: IrDeclaration): DiagnosticContextOverIr =
|
||||
DiagnosticContextOverIr(irDeclaration, irDeclaration)
|
||||
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
inner class DiagnosticContextOverIr(irElement: IrElement, containingIrFile: IrFile) : DiagnosticContext {
|
||||
|
||||
constructor(irElement: IrElement, containingIrDeclaration: IrDeclaration): this(irElement, containingIrDeclaration.file)
|
||||
|
||||
val sourceElement = irElement.sourceElement()
|
||||
|
||||
override fun isDiagnosticSuppressed(diagnostic: KtDiagnostic): Boolean {
|
||||
return false
|
||||
// TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override val languageVersionSettings: LanguageVersionSettings
|
||||
get() = this@KtDiagnosticReporterWithImplicitIrBasedContext.languageVersionSettings
|
||||
|
||||
override val containingFilePath: String = containingIrFile.path
|
||||
|
||||
@OptIn(InternalDiagnosticFactoryMethod::class)
|
||||
fun report(
|
||||
factory: KtDiagnosticFactory0,
|
||||
positioningStrategy: AbstractSourceElementPositioningStrategy? = null
|
||||
) {
|
||||
sourceElement?.let { report(factory.on(it, positioningStrategy), this) }
|
||||
}
|
||||
|
||||
@OptIn(InternalDiagnosticFactoryMethod::class)
|
||||
fun <A : Any> report(
|
||||
factory: KtDiagnosticFactory1<A>,
|
||||
a: A,
|
||||
positioningStrategy: AbstractSourceElementPositioningStrategy? = null
|
||||
) {
|
||||
sourceElement?.let { report(factory.on(it, a, positioningStrategy), this) }
|
||||
}
|
||||
fun atFirstValidFrom(vararg irElements: IrElement, containingIrFile: IrFile): DiagnosticContextImpl {
|
||||
require(irElements.isNotEmpty())
|
||||
val sourceElement =
|
||||
irElements.firstNotNullOfOrNull { PsiSourceManager.findPsiElement(it, containingIrFile) }?.let(::KtRealPsiSourceElement)
|
||||
?: (irElements.find { it.startOffset >= 0 } ?: irElements.first()).sourceElement()
|
||||
return at(sourceElement, containingIrFile.path)
|
||||
}
|
||||
|
||||
fun at(irElement: IrElement, containingIrDeclaration: IrDeclaration): DiagnosticContextImpl =
|
||||
at(irElement, containingIrDeclaration.file)
|
||||
|
||||
fun at(irDeclaration: IrDeclaration): DiagnosticContextImpl =
|
||||
at(irDeclaration, irDeclaration)
|
||||
}
|
||||
|
||||
|
||||
+2
-4
@@ -5,7 +5,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.jvm.codegen
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.findKtSourceElement
|
||||
import org.jetbrains.kotlin.backend.common.lower.BOUND_RECEIVER_PARAMETER
|
||||
import org.jetbrains.kotlin.backend.common.lower.LoweredStatementOrigins
|
||||
import org.jetbrains.kotlin.backend.jvm.*
|
||||
@@ -31,8 +30,7 @@ import org.jetbrains.kotlin.codegen.signature.BothSignatureWriter
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.config.languageVersionSettings
|
||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.diagnostics.KtErrors
|
||||
import org.jetbrains.kotlin.diagnostics.BackendErrors
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl
|
||||
@@ -915,7 +913,7 @@ class ExpressionCodegen(
|
||||
|
||||
private fun generateGlobalReturnFlagIfPossible(expression: IrExpression, label: String) {
|
||||
if (state.isInlineDisabled) {
|
||||
context.ktDiagnosticReporter.at(expression, irFunction).report(KtErrors.NON_LOCAL_RETURN_IN_DISABLED_INLINE)
|
||||
context.ktDiagnosticReporter.at(expression, irFunction).report(BackendErrors.NON_LOCAL_RETURN_IN_DISABLED_INLINE)
|
||||
genThrow(mv, "java/lang/UnsupportedOperationException", "Non-local returns are not allowed with inlining disabled")
|
||||
} else {
|
||||
generateGlobalReturnFlag(mv, label)
|
||||
|
||||
+5
-5
@@ -16,7 +16,6 @@ import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap
|
||||
import org.jetbrains.kotlin.codegen.AsmUtil
|
||||
import org.jetbrains.kotlin.codegen.inline.ReifiedTypeInliner
|
||||
import org.jetbrains.kotlin.codegen.state.GenerationState
|
||||
import org.jetbrains.kotlin.diagnostics.KtErrors
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.descriptors.toIrBasedKotlinType
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
@@ -27,6 +26,7 @@ import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.jvm.AsmTypes.*
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmBackendErrors
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.model.TypeParameterMarker
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
@@ -117,9 +117,9 @@ class IrInlineIntrinsicsSupport(
|
||||
|
||||
override fun checkAnnotatedType(type: IrType) {
|
||||
if (type.hasAnnotation(StandardNames.FqNames.extensionFunctionType)) {
|
||||
context.ktDiagnosticReporter.at(reportErrorsOn, containingFile).report(KtErrors.TYPEOF_EXTENSION_FUNCTION_TYPE)
|
||||
context.ktDiagnosticReporter.at(reportErrorsOn, containingFile).report(JvmBackendErrors.TYPEOF_EXTENSION_FUNCTION_TYPE)
|
||||
} else if (type.annotations.any { !it.symbol.owner.constructedClass.isSpecialAnnotation() }) {
|
||||
context.ktDiagnosticReporter.at(reportErrorsOn, containingFile).report(KtErrors.TYPEOF_ANNOTATED_TYPE)
|
||||
context.ktDiagnosticReporter.at(reportErrorsOn, containingFile).report(JvmBackendErrors.TYPEOF_ANNOTATED_TYPE)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,11 +131,11 @@ class IrInlineIntrinsicsSupport(
|
||||
hasEqualFqName(JvmSymbols.RAW_TYPE_ANNOTATION_FQ_NAME)
|
||||
|
||||
override fun reportSuspendTypeUnsupported() {
|
||||
context.ktDiagnosticReporter.at(reportErrorsOn, containingFile).report(KtErrors.TYPEOF_SUSPEND_TYPE)
|
||||
context.ktDiagnosticReporter.at(reportErrorsOn, containingFile).report(JvmBackendErrors.TYPEOF_SUSPEND_TYPE)
|
||||
}
|
||||
|
||||
override fun reportNonReifiedTypeParameterWithRecursiveBoundUnsupported(typeParameterName: Name) {
|
||||
context.ktDiagnosticReporter.at(reportErrorsOn, containingFile)
|
||||
.report(KtErrors.TYPEOF_NON_REIFIED_TYPE_PARAMETER_WITH_RECURSIVE_BOUND, typeParameterName.asString())
|
||||
.report(JvmBackendErrors.TYPEOF_NON_REIFIED_TYPE_PARAMETER_WITH_RECURSIVE_BOUND, typeParameterName.asString())
|
||||
}
|
||||
}
|
||||
|
||||
+2
-3
@@ -14,7 +14,6 @@ import org.jetbrains.kotlin.backend.jvm.ir.inlineScopeVisibility
|
||||
import org.jetbrains.kotlin.codegen.inline.*
|
||||
import org.jetbrains.kotlin.codegen.state.GenerationState
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticUtils
|
||||
import org.jetbrains.kotlin.diagnostics.KtErrors
|
||||
import org.jetbrains.kotlin.incremental.components.LocationInfo
|
||||
import org.jetbrains.kotlin.incremental.components.Position
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
@@ -28,7 +27,7 @@ import org.jetbrains.kotlin.ir.util.kotlinFqName
|
||||
import org.jetbrains.kotlin.ir.util.module
|
||||
import org.jetbrains.kotlin.ir.util.parentAsClass
|
||||
import org.jetbrains.kotlin.psi.doNotAnalyze
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm.SUSPENSION_POINT_INSIDE_MONITOR
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmBackendErrors
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
||||
import org.jetbrains.org.objectweb.asm.Label
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
@@ -130,7 +129,7 @@ class IrSourceCompilerForInline(
|
||||
override fun reportSuspensionPointInsideMonitor(stackTraceElement: String) {
|
||||
codegen.context.ktDiagnosticReporter
|
||||
.at(callElement.symbol.owner as IrDeclaration)
|
||||
.report(KtErrors.SUSPENSION_POINT_INSIDE_MONITOR, stackTraceElement)
|
||||
.report(JvmBackendErrors.SUSPENSION_POINT_INSIDE_MONITOR, stackTraceElement)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+7
-6
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
||||
import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactory1
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.descriptors.toIrBasedDescriptor
|
||||
import org.jetbrains.kotlin.ir.util.file
|
||||
import org.jetbrains.kotlin.ir.util.isFakeOverride
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.*
|
||||
import org.jetbrains.kotlin.utils.SmartSet
|
||||
@@ -88,7 +89,7 @@ class JvmSignatureClashDetector(
|
||||
realMethodsCount == 0 && (fakeOverridesCount > 1 || specialOverridesCount > 1) ->
|
||||
if (irClass.origin != JvmLoweredDeclarationOrigin.DEFAULT_IMPLS) {
|
||||
reportJvmSignatureClash(
|
||||
KtErrorsJvm.CONFLICTING_INHERITED_JVM_DECLARATIONS,
|
||||
JvmBackendErrors.CONFLICTING_INHERITED_JVM_DECLARATIONS,
|
||||
listOf(irClass),
|
||||
conflictingJvmDeclarationsData
|
||||
)
|
||||
@@ -101,7 +102,7 @@ class JvmSignatureClashDetector(
|
||||
methods.any { DescriptorVisibilities.isPrivate(it.visibility) }
|
||||
) {
|
||||
reportJvmSignatureClash(
|
||||
KtErrorsJvm.CONFLICTING_JVM_DECLARATIONS,
|
||||
JvmBackendErrors.CONFLICTING_JVM_DECLARATIONS,
|
||||
methods,
|
||||
conflictingJvmDeclarationsData
|
||||
)
|
||||
@@ -111,7 +112,7 @@ class JvmSignatureClashDetector(
|
||||
else ->
|
||||
if (irClass.origin != JvmLoweredDeclarationOrigin.DEFAULT_IMPLS) {
|
||||
reportJvmSignatureClash(
|
||||
KtErrorsJvm.ACCIDENTAL_OVERRIDE,
|
||||
JvmBackendErrors.ACCIDENTAL_OVERRIDE,
|
||||
methods.filter { !it.isFakeOverride && !it.isSpecialOverride() },
|
||||
conflictingJvmDeclarationsData
|
||||
)
|
||||
@@ -129,7 +130,7 @@ class JvmSignatureClashDetector(
|
||||
type.internalName, classOrigin, predefinedSignature,
|
||||
methods.map { it.getJvmDeclarationOrigin() } + JvmDeclarationOrigin(JvmDeclarationOriginKind.OTHER, null, null)
|
||||
)
|
||||
reportJvmSignatureClash(KtErrorsJvm.ACCIDENTAL_OVERRIDE, methods, conflictingJvmDeclarationsData)
|
||||
reportJvmSignatureClash(JvmBackendErrors.ACCIDENTAL_OVERRIDE, methods, conflictingJvmDeclarationsData)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,7 +138,7 @@ class JvmSignatureClashDetector(
|
||||
for ((rawSignature, fields) in fieldsBySignature) {
|
||||
if (fields.size <= 1) continue
|
||||
val conflictingJvmDeclarationsData = getConflictingJvmDeclarationsData(classOrigin, rawSignature, fields)
|
||||
reportJvmSignatureClash(KtErrorsJvm.CONFLICTING_JVM_DECLARATIONS, fields, conflictingJvmDeclarationsData)
|
||||
reportJvmSignatureClash(JvmBackendErrors.CONFLICTING_JVM_DECLARATIONS, fields, conflictingJvmDeclarationsData)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,7 +148,7 @@ class JvmSignatureClashDetector(
|
||||
conflictingJvmDeclarationsData: ConflictingJvmDeclarationsData
|
||||
) {
|
||||
for (irDeclaration in irDeclarations) {
|
||||
context.ktDiagnosticReporter.at(irDeclaration)
|
||||
context.ktDiagnosticReporter.atFirstValidFrom(irDeclaration, irClass, containingIrFile = irDeclaration.file)
|
||||
.report(diagnosticFactory1, conflictingJvmDeclarationsData)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user