Zac Sweers
06/10/2025, 6:24 PMDiagnosticReporter
instead of MessageCollector
to report errors from my IR transformers, but all the reporting functions I see appear to only speak FIR symbols. Is there an example of using this in IR I could look at for inspiration?Zac Sweers
06/10/2025, 6:28 PMCommonConfigurationKeys
and the closest example I can find is DiagnosticReporterFactory.createReporter(messageCollector)
in compose-compiler, which just wraps a MessageCollector
Zac Sweers
06/10/2025, 6:31 PMdmitriy.novozhilov
06/11/2025, 6:37 AMZac Sweers
06/11/2025, 2:33 PMdmitriy.novozhilov
06/11/2025, 2:37 PMZac Sweers
06/11/2025, 3:25 PMopen class AbstractIrDiagnosticTest : AbstractPhasedJvmDiagnosticLightTreeTest()
but that seems to be more for frontend diagnosticsZac Sweers
06/11/2025, 3:25 PMdmitriy.novozhilov
06/11/2025, 4:21 PMdmitriy.novozhilov
06/12/2025, 7:53 AMRENDER_DIAGNOSTICS_FULL_TEXT
works for diagnostics reported frontend or backend, but plugins are executed at fir2ir stage, so they are skipped by the corresponding handler.
2. There is a trick which allows to render diagnostic arguments right inside the .kt
file. For that you need to add ("")
to the diagnostic tag and rerun the test: <!GRAPH_DEPENDENCY_CYCLE!>
-> <!GRAPH_DEPENDENCY_CYCLE("")!>
. But in your case it won't work also, as you have ReversibleSourceFilePreprocessor
registered (MetroDefaultImportPreprocessor
), which messes up offsets for meta-infos (test infra parses them not knowing about preprocessors, but plugin reports diagnostics against modified file)
So what can you do:
1. Introduce new fir2ir handler, similar to JvmBackendDiagnosticsHandler which will report diagnostics from fir2ir into .diag
file and use it (can be also contributed to kotlin.git)
2. Disable sources preprocessor for specific tests where you care about diagnostic message and use the trick with ("")
3. Teach GlobalMetadataInfoHandler
to work with `ReversibleSourceFilePreprocessor`s and contribute it to kotlin.gitdmitriy.novozhilov
06/12/2025, 7:54 AM...
interface <!GRAPH_DEPENDENCY_CYCLE("Graph dependency cycle detected! test.StringGraph is requested at [test.CharSequenceGraph] test.StringGraph.Factory#create() test.CharSequenceGraph is requested at [test.CharSequenceGraph] test.CharSequenceGraph.Factory#create()")!>CharSequenceGraph<!> {
...
dmitriy.novozhilov
06/12/2025, 12:11 PMRENDER_IR_DIAGNOSTICS_FULL_TEXT
, which does exactly what you need.Zac Sweers
06/12/2025, 8:48 PMRENDER_DIAGNOSTICS_FULL_TEXT
dmitriy.novozhilov
06/13/2025, 8:19 AM