So I’ve been looking into the 1.4 changes and rega...
# pattern-matching
m
So I’ve been looking into the 1.4 changes and regarding
_
and here’s where I’m at so far. I’ve started moving pattern matching back to generalized
case
expression as the resolution starting-point. From there it will check to see the context it’s in (
where
expression,
if
expression, etc…) and then do the tree transform later in IR. However, with 1.4 of the Kotlin compiler, after I’ve suppressed the “unresolved” errors, I’m now receiving a “unbound symbols not allowed” error. Tracing this back I see this is where a check is done for
context.symbolTable.allUnbound
https://github.com/JetBrains/kotlin/blob/v1.4.10/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/Psi2IrTranslator.kt#L96 What would be the appropriate way to bind
_
to another semantically valid symbol? I’m already using
BindingContext
to do a
record
(which then shows up in the binding context). Since the file above is called
Psi2IrTranslator
and the function is
generateModuleFragment
I’m guessing I need to either generate IR or map this to the IR that for the semantically valid symbols that I’m attempting to reference with
_
. In this scenario, I want the symbol
_
to be bound to a
KtNameReferenceExpression
, as it would refer to a data class argument.
r
I think as you mentioned you may have to bind the resulting
IrExpression
associated to
_
to a symbol in IR with the PluginContext
At some point the IR backend requires all symbols to be bound.
m
Yeah that makes sense. Thanks for the thread! I read through it and makes a little sense but I'll confess I'm still a bit unsure about how to do the binding to IR for
_
. Is this done by creating a new descriptor and then recording that call in the binding trace? Or would this be done at the time
IRCodegen
runs? If
IRCodegen
is where I'd need to generate the IR to then point to, the
allUnbound
check doesn't finish until analysis phase finishes and then goes to
IRCodegen
- or at least I think that's the way it works - my mental model might be wrong though. Hopefully that makes sense. My code on this so far is in quite a mess while commenting out and experimenting with new changes, but here's the original code Andrei Shikov committed a while back that I'm looking at as a starting guide to understanding where next to go: https://github.com/mattmoore/arrow-meta/blob/pattern-matching/compiler-plugin/src/[…]plugins/patternMatching/phases/analysis/CapturedCallResolver.kt
r
I think there are a couple of ways you can go: 1. declare
object _
or similar
val _ : Nothing get() = ...
quoted so it’s a valid identifier and it’s already bound. 2. Instead bind it yourself by creating a IrFunctionSymbol or similar and then using
PluginContext.referenceFunction
or similar methods to bind it yourself as they do in the thread.