Added an annotation for function positioning in K2 TargetMarker #73
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Added an annotation for function positioning in K2:
TargetMarker
.It is defined in the
annotation
module and can be customised through configuration itemtargetMarker
.What it does
Previously, in K2 mode, to generate a bridge function for a pending function, you needed to generate the symbol of the bridge function in the FIR stage and then generate the Body of the bridge function in the IR stage.
In the IR stage I need to know who the source function corresponding to the bridge function is.
But the source function is located in the FIR stage, so we need to pass some uniquely located information about the source function with the help of
PluginKey
, which includes its function name and a list of the parameter types. (I haven't found a safe, direct way to determine whether FIR and IR are the same by using==
)Previously, this solution was basically possible because the function name and the list of types could identify a unique function.
But this does not work in the case of #72.
The combination of
expect/actual
andtypealias
is used in #72. At the FIR stage, theMoneyValue
is alwaysMoneyValue
type, and since it's expected, I've never been able to find out how to get its real type, whether it's actual or typealias. I tried a number of ways, such asexpectForActual
,memberExpectForActual
,fullyExpandedType
, and other seemingly related functions I could find. But they either getMoneyValue
itself ornull
, there is no available solution.As for other options, after all, KCP is not fully documented and I can't get started at the moment.
And after the FIR, in the IR stage,
MoneyValue
has completely changed toBigDecimal
, which is why it is impossible to locate the source function: the FIR stage and the IR stage, the same function has a different parameter type.errorReproduction
errorReproduction
MoneyValue
java.math.BigDecimal
How to fix
Rather than fixing it, I think it's more like circumventing the problem outright. Since I can't locate the source function via the argument type list, I'll just locate it in a different way.
The new annotation
TargetMarket
does just that. In the FIR stage, a unique ID is generated from the function name and the list of parameter types (that's the base64 string with the name and type spliced in order)Mark this ID and annotation on the source function. Then, only this ID is passed to the IR, not the list of types. Afterwards, in the IR stage, only the function with a matching value needs to be found.
errorReproduction(MoneyValue)
abcd1234
abcd1234
errorReproduction(BigDecimal)
caution
By default,
targetMarker
is specified as an annotationTargetMarker
in theannotation
module.When the
targetMarker
annotation is specified, there will be no matching based on other ways. So please note that if you customise antargetMarker
annotation and it is not available, or if you disable references to theannotation
module (includeAnnotation = false
), this may cause problems.If you specify
targetMarker
asnull
, then the matching is done using the original scheme: using the function name and argument type list.It's not clear to me at the moment if there's a better solution to the problem of finding some function from IR that is identified in FIR, or to the problem of
expect/actual
+typealias
.resolve #72