-
-
Notifications
You must be signed in to change notification settings - Fork 773
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move from KtFile
to FirFile
#7404
Comments
Take a look at the Kotlin analysis API if you haven't yet - this might be an option, but the analysis API looks like the path forward with the most longevity. It should support both the old and new front-end from what I could gather - which is also important to make sure we support backwards compatibility with older language versions. |
Analysis API readme: https://github.com/JetBrains/kotlin/blob/master/docs/analysis/analysis-api/analysis-api.md There's an implementation for both the old and new compiler front ends. We'd likely integrate with the "standalone" module for the CLI (I believe this is what KSP is doing for KSP2). Also important to note is that the Kotlin plugin for IDEA is using this API. This should make IDEA inspections simple to port if we use this, and also guarantees that we can offer analysis capabilities that are equal to what the Kotlin IDEA plugin offers, i.e. fully comprehensive and taking care of things that are a bit tricky or hacky in detekt at the moment like dealing with smart casts. And the |
https://kotlin.github.io/analysis-api/migrating-from-k1.html I do wonder if |
@nebffa has expressed interest in uplifting compiler plugin support for K2. Before any work starts we should discuss the approach a bit further. Analysis API has a key limitation: it does not support compiler plugins at this stage. I'm not sure if it ever will. Based on the definitions of different components used by Analysis API, this is where the different components fit:
There's a good document with background on adding K2 support to KSP in KSP2: https://github.com/google/ksp/blob/2.0.20-1.0.25/docs/ksp2.md. Key points for KSP2:
The alternative is perhaps using FIR as originally proposed. @BraisGabin has done some work on this already. JetBrains is pushing the Analysis API for the detekt use case so I still believe it's the right path forward but it does have limitations that we'll need to accept. |
This change is going to be painful. The new compiler K2 comes with a new frontend:
FIR
. 2.0 still supportsPSI
but we should start thinking about moving fromPSI
toFIR
.We should find a way to transition from one to another. I see two main chunks of work:
detekt
engine that make the rules work.It will be great if we can change all the core without touching the rules, and it seems that it can be possible.
FirElement
has a property calledpsi
that should help us with this. Later, once we have the core stable would be the time to move the rules fromPSI
toFIR
. That seems like A LOT of work so probably we will need to ask help to the community to do it. For that reason I think that we should have our core kind of ready and the tests in place so a contributor can focus on the translation of the rules.I didn't check too much but I think that we are going to be lucky and we will not need to change our rule tests that much.
I'm working on this but any help is more than welcome.
The text was updated successfully, but these errors were encountered: