Hey everyone :wave: I'd be interested in experimen...
# compiler
f
Hey everyone 👋 I'd be interested in experimenting in with the new analysis API, are the JARs for the new standalone analysis API already hosted on some Maven repo?
r
hi @fwcd, some discussion about that topic here https://kotlinlang.slack.com/archives/C7L3JB43G/p1654873239205629
d
BTW Analysis API and FIR/K2 compiler API are two different APIs for different purposes
r
@dmitriy.novozhilov Is there a new Analysis API or is it going to remain as
AnalysisHandlerExtension.registerExtension
?
d
Not exactly (I'm working right now of replacement for
AnalysisHandlerExtension
as part of migration of KAPT to FIR) @Ilya Kirillov [JB] can share details about Analysis API
👍 1
y
Would such a FIR replacement give us access to
BodyResolveComponents
or a
BodyResolveContext
? And would it be an "expression-by-expression" kind of API or would it only run at the start and end of analysis? I would much prefer an expression-by-expression one (similar to
addNewImplicitReceivers
) IMHO
d
@Youssef Shoaib [MOD] Please describe what exactly do you want to do with such API
y
Well, for instance I could see if a `FirFunctionCall`has an error, get that diagnostic, and respond accordingly. In other words, if it has a `FirErrorNamedReference`as its callee reference, I can use `calleeReference.diagnostic`to then see if it's missing a parameter or a context receiver or something and accordingly change its arguments or the towerDataContext so that the function would be resolved. I just want an extension that would be called whenever a `FirFunctionCall`is resolved (no matter successful or not) so that I can get to transform it however I wish. I'm doing that currently in a plugin with quite a few terrible hacks to give me access to
BodyResolveComponents
, so I'd love a way to access them directly.
d
Got it There are no plans to add such API, because of two main reasons: 1. Call is resolved (candidate symbol is found) != call is completed (all lambda arguments are analyzed and all generics are inferred), and changing something between those two stage can break some non-trivial contracts of compiler internals 2. Restart of resolution can lead to exponential resolution because of lambdas: lambdas are analyzed depending on which candidate function was chosen, so if you will chose another function after completion is over it will require to reanalyze all lambda arguments
y
Well, can there be such an API for the case of a call that cannot be properly resolved, though? As in, making red code green while leaving green code as is. Potentially, it could also only run if the call is completed, for point 1. For point 2, is restarting resolution for only red code that terrible for performance?
d
Let's move to another thread
👍 1
i
@fwcd Hey! The Analysis API and its dependencies are published at https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap. See https://github.com/google/ksp/blob/main/kotlin-analysis-api/build.gradle.kts#L33-L56 as an example how to add Analysis API to the Gradle project Please, note that Analysis API is not stable and may be changed in any way
👍 2
f
Thanks, I'll have a look at that!
Are there any special dependencies needed to use the IntelliJ APIs outside of e.g. plugins in a standalone application? E.g. I am getting a
NoClassDefFoundError
for
com.intellij.openapi.application.ApplicationListener
when running
StandaloneModeUtilsKt.configureProjectEnvironment
i
Yeap, you also need intellij-core (part of IntelliJ IDEA which is distributed as library) you may find it here https://www.jetbrains.com/intellij-repository/releases
Ksp repository may also have some examples how to setup it up
f
Thanks,
com.jetbrains.intellij.platform:core
and
core.jetbrains.intellij.platform:core-impl
were the ones I needed, the app now boots up without errors!
🙂 1