diff --git a/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/context/CommonSkieContext.kt b/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/context/CommonSkieContext.kt index 3aa7b9d22..6eada3bba 100644 --- a/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/context/CommonSkieContext.kt +++ b/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/context/CommonSkieContext.kt @@ -8,7 +8,7 @@ import co.touchlab.skie.phases.SkiePhaseScheduler import co.touchlab.skie.plugin.analytics.AnalyticsCollector import co.touchlab.skie.util.CompilerShim import co.touchlab.skie.util.directory.FrameworkLayout -import co.touchlab.skie.util.Reporter +import co.touchlab.skie.util.KirReporter import co.touchlab.skie.util.directory.SkieBuildDirectory import co.touchlab.skie.util.directory.SkieDirectories @@ -28,7 +28,7 @@ interface CommonSkieContext { val skiePerformanceAnalyticsProducer: SkiePerformanceAnalytics.Producer - val reporter: Reporter + val kirReporter: KirReporter val skiePhaseScheduler: SkiePhaseScheduler diff --git a/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/util/KirReporter.kt b/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/util/KirReporter.kt new file mode 100644 index 000000000..939399005 --- /dev/null +++ b/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/util/KirReporter.kt @@ -0,0 +1,5 @@ +package co.touchlab.skie.util + +import co.touchlab.skie.kir.element.KirElement + +class KirReporter : Reporter() diff --git a/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/util/Reporter.kt b/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/util/Reporter.kt index e45e71217..8c9ca6724 100644 --- a/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/util/Reporter.kt +++ b/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/util/Reporter.kt @@ -1,23 +1,22 @@ package co.touchlab.skie.util -import co.touchlab.skie.kir.element.KirElement import java.util.Collections -class Reporter { +abstract class Reporter { - private val mutableReports = Collections.synchronizedList(mutableListOf()) + private val mutableReports = Collections.synchronizedList(mutableListOf>()) - val reports: List by ::mutableReports + val reports: List> by ::mutableReports - fun report(severity: Severity, message: String, source: KirElement? = null) { + fun report(severity: Severity, message: String, source: T? = null) { mutableReports.add(Report(message, severity, source)) } - fun error(message: String, source: KirElement? = null) { + fun error(message: String, source: T? = null) { report(Severity.Error, message, source) } - fun warning(message: String, source: KirElement? = null) { + fun warning(message: String, source: T? = null) { report(Severity.Warning, message, source) } @@ -25,5 +24,5 @@ class Reporter { Error, Warning } - data class Report(val message: String, val severity: Severity, val source: KirElement?) + data class Report(val message: String, val severity: Severity, val source: T?) } diff --git a/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/util/SirDeclaration+resolveCollision.kt b/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/util/SirDeclaration+resolveCollision.kt index 7c4009771..18f850403 100644 --- a/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/util/SirDeclaration+resolveCollision.kt +++ b/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/util/SirDeclaration+resolveCollision.kt @@ -138,7 +138,7 @@ private fun reportCollision( collisionReason: String, source: KirElement, ) { - reporter.warning( + kirReporter.warning( message = "'$originalName' was renamed to '$newName' because of a name collision with $collisionReason. " + "Consider resolving the conflict either by changing the name in Kotlin, or via the @ObjCName annotation. " + "You can also suppress this warning using the 'SuppressSkieWarning.NameCollision' configuration. " + diff --git a/SKIE/kotlin-compiler/linker-plugin/src/kgp_common/kotlin/co/touchlab/skie/context/ForegroundPhaseCompilerContext.kt b/SKIE/kotlin-compiler/linker-plugin/src/kgp_common/kotlin/co/touchlab/skie/context/ForegroundPhaseCompilerContext.kt index 578ee3109..5d039b2d1 100644 --- a/SKIE/kotlin-compiler/linker-plugin/src/kgp_common/kotlin/co/touchlab/skie/context/ForegroundPhaseCompilerContext.kt +++ b/SKIE/kotlin-compiler/linker-plugin/src/kgp_common/kotlin/co/touchlab/skie/context/ForegroundPhaseCompilerContext.kt @@ -3,6 +3,7 @@ package co.touchlab.skie.context import co.touchlab.skie.configuration.provider.descriptor.DescriptorConfigurationProvider import co.touchlab.skie.kir.descriptor.DescriptorProvider import co.touchlab.skie.phases.ForegroundPhase +import co.touchlab.skie.util.DescriptorReporter import org.jetbrains.kotlin.backend.konan.KonanConfig interface ForegroundPhaseCompilerContext : ForegroundPhase.Context { @@ -12,4 +13,6 @@ interface ForegroundPhaseCompilerContext : ForegroundPhase.Context { val descriptorConfigurationProvider: DescriptorConfigurationProvider val konanConfig: KonanConfig + + val descriptorReporter: DescriptorReporter } diff --git a/SKIE/kotlin-compiler/linker-plugin/src/kgp_common/kotlin/co/touchlab/skie/context/InitPhaseContext.kt b/SKIE/kotlin-compiler/linker-plugin/src/kgp_common/kotlin/co/touchlab/skie/context/InitPhaseContext.kt index 5720c21ab..4397eb6e3 100644 --- a/SKIE/kotlin-compiler/linker-plugin/src/kgp_common/kotlin/co/touchlab/skie/context/InitPhaseContext.kt +++ b/SKIE/kotlin-compiler/linker-plugin/src/kgp_common/kotlin/co/touchlab/skie/context/InitPhaseContext.kt @@ -14,8 +14,9 @@ import co.touchlab.skie.plugin.analytics.AnalyticsCollector import co.touchlab.skie.spi.SkiePluginRegistrar import co.touchlab.skie.util.ActualCompilerShim import co.touchlab.skie.util.CompilerShim +import co.touchlab.skie.util.DescriptorReporter import co.touchlab.skie.util.directory.FrameworkLayout -import co.touchlab.skie.util.Reporter +import co.touchlab.skie.util.KirReporter import co.touchlab.skie.util.directory.SkieDirectories import org.jetbrains.kotlin.backend.konan.KonanConfigKeys import org.jetbrains.kotlin.config.CompilerConfiguration @@ -52,7 +53,9 @@ class InitPhaseContext( override val skiePerformanceAnalyticsProducer: SkiePerformanceAnalytics.Producer = SkiePerformanceAnalytics.Producer(rootConfiguration) - override val reporter: Reporter = Reporter() + override val kirReporter: KirReporter = KirReporter() + + val descriptorReporter: DescriptorReporter = DescriptorReporter() override val compilerShim: CompilerShim = ActualCompilerShim() diff --git a/SKIE/kotlin-compiler/linker-plugin/src/kgp_common/kotlin/co/touchlab/skie/context/MainSkieContext.kt b/SKIE/kotlin-compiler/linker-plugin/src/kgp_common/kotlin/co/touchlab/skie/context/MainSkieContext.kt index fce9ad896..c0124b01c 100644 --- a/SKIE/kotlin-compiler/linker-plugin/src/kgp_common/kotlin/co/touchlab/skie/context/MainSkieContext.kt +++ b/SKIE/kotlin-compiler/linker-plugin/src/kgp_common/kotlin/co/touchlab/skie/context/MainSkieContext.kt @@ -14,9 +14,8 @@ import co.touchlab.skie.phases.BackgroundPhase import co.touchlab.skie.phases.ScheduledPhase import co.touchlab.skie.phases.configurables import co.touchlab.skie.phases.util.StatefulScheduledPhase -import co.touchlab.skie.util.KotlinCompilerVersion +import co.touchlab.skie.util.DescriptorReporter import co.touchlab.skie.util.TargetTriple -import co.touchlab.skie.util.current import kotlinx.coroutines.CoroutineExceptionHandler import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -60,6 +59,8 @@ class MainSkieContext internal constructor( val declarationBuilder: DeclarationBuilderImpl = DeclarationBuilderImpl(mainModuleDescriptor, descriptorProvider) + override val descriptorReporter: DescriptorReporter = initPhaseContext.descriptorReporter + lateinit var kirProvider: KirProvider lateinit var descriptorKirProvider: DescriptorKirProvider diff --git a/SKIE/kotlin-compiler/linker-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/ForegroundPhase+linker.kt b/SKIE/kotlin-compiler/linker-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/ForegroundPhase+linker.kt index 3bbba8d75..d33e5789c 100644 --- a/SKIE/kotlin-compiler/linker-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/ForegroundPhase+linker.kt +++ b/SKIE/kotlin-compiler/linker-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/ForegroundPhase+linker.kt @@ -5,6 +5,7 @@ import co.touchlab.skie.context.ForegroundPhaseCompilerContext import co.touchlab.skie.kir.descriptor.DescriptorProvider import co.touchlab.skie.kir.descriptor.ExtraDescriptorBuiltins import co.touchlab.skie.kir.descriptor.cache.CachedObjCExportMapper +import co.touchlab.skie.util.DescriptorReporter import org.jetbrains.kotlin.backend.konan.KonanConfig import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.konan.target.AppleConfigurables @@ -30,5 +31,8 @@ val ForegroundPhase.Context.extraDescriptorBuiltins: ExtraDescriptorBuiltins val ForegroundPhase.Context.configurables: AppleConfigurables get() = konanConfig.platform.configurables as AppleConfigurables +val ForegroundPhase.Context.descriptorReporter: DescriptorReporter + get() = typedContext.descriptorReporter + private val ForegroundPhase.Context.typedContext: ForegroundPhaseCompilerContext get() = context as ForegroundPhaseCompilerContext diff --git a/SKIE/kotlin-compiler/linker-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/InitPhase+linker.kt b/SKIE/kotlin-compiler/linker-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/InitPhase+linker.kt index 7a1bc4b0b..6092f23de 100644 --- a/SKIE/kotlin-compiler/linker-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/InitPhase+linker.kt +++ b/SKIE/kotlin-compiler/linker-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/InitPhase+linker.kt @@ -1,10 +1,14 @@ package co.touchlab.skie.phases import co.touchlab.skie.context.InitPhaseContext +import co.touchlab.skie.util.DescriptorReporter import org.jetbrains.kotlin.config.CompilerConfiguration val InitPhase.Context.compilerConfiguration: CompilerConfiguration get() = typedContext.compilerConfiguration +val InitPhase.Context.descriptorReporter: DescriptorReporter + get() = typedContext.descriptorReporter + private val InitPhase.Context.typedContext: InitPhaseContext get() = context as InitPhaseContext diff --git a/SKIE/kotlin-compiler/linker-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/other/ProcessReportedMessagesPhase.kt b/SKIE/kotlin-compiler/linker-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/other/ProcessReportedMessagesPhase.kt index c41f1f308..8ee21d2a7 100644 --- a/SKIE/kotlin-compiler/linker-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/other/ProcessReportedMessagesPhase.kt +++ b/SKIE/kotlin-compiler/linker-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/other/ProcessReportedMessagesPhase.kt @@ -2,13 +2,14 @@ package co.touchlab.skie.phases.other import co.touchlab.skie.phases.LinkPhase import co.touchlab.skie.phases.descriptorKirProvider +import co.touchlab.skie.phases.descriptorReporter import co.touchlab.skie.phases.konanConfig import co.touchlab.skie.util.Reporter -import co.touchlab.skie.util.Reporter.Severity import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity import org.jetbrains.kotlin.cli.common.messages.MessageUtil import org.jetbrains.kotlin.cli.jvm.compiler.report +import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.js.resolve.diagnostics.findPsi import org.jetbrains.kotlin.renderer.DescriptorRenderer @@ -16,15 +17,27 @@ object ProcessReportedMessagesPhase : LinkPhase { context(LinkPhase.Context) override suspend fun execute() { - reporter.reports.forEach { - report(it) + kirReporter.reportAll(descriptorKirProvider::findDeclarationDescriptor) + + descriptorReporter.reportAll { it } + } + + context(LinkPhase.Context) + private fun Reporter.reportAll(findDeclarationDescriptor: (T) -> DeclarationDescriptor?) { + this.reports.forEach { + report(it, findDeclarationDescriptor) } } context(LinkPhase.Context) - private fun report(report: Reporter.Report) { - val declaration = report.source?.let { descriptorKirProvider.findDeclarationDescriptor(it) } + private fun report(report: Reporter.Report, findDeclarationDescriptor: (T) -> DeclarationDescriptor?) { + val declarationDescriptor = report.source?.let { findDeclarationDescriptor(it) } + report(report, declarationDescriptor) + } + + context(LinkPhase.Context) + private fun report(report: Reporter.Report, declaration: DeclarationDescriptor?) { val location = MessageUtil.psiElementToMessageLocation(declaration?.findPsi())?.let { CompilerMessageLocation.create(it.path, it.line, it.column, it.lineContent) } @@ -36,8 +49,8 @@ object ProcessReportedMessagesPhase : LinkPhase { } when (report.severity) { - Severity.Error -> konanConfig.configuration.report(CompilerMessageSeverity.ERROR, message, location) - Severity.Warning -> konanConfig.configuration.report(CompilerMessageSeverity.WARNING, message, location) + Reporter.Severity.Error -> konanConfig.configuration.report(CompilerMessageSeverity.ERROR, message, location) + Reporter.Severity.Warning -> konanConfig.configuration.report(CompilerMessageSeverity.WARNING, message, location) } } } diff --git a/SKIE/kotlin-compiler/linker-plugin/src/kgp_common/kotlin/co/touchlab/skie/util/DescriptorReporter.kt b/SKIE/kotlin-compiler/linker-plugin/src/kgp_common/kotlin/co/touchlab/skie/util/DescriptorReporter.kt new file mode 100644 index 000000000..7fcb7feae --- /dev/null +++ b/SKIE/kotlin-compiler/linker-plugin/src/kgp_common/kotlin/co/touchlab/skie/util/DescriptorReporter.kt @@ -0,0 +1,5 @@ +package co.touchlab.skie.util + +import org.jetbrains.kotlin.descriptors.DeclarationDescriptor + +class DescriptorReporter : Reporter()