https://kotlinlang.org logo
#compiler
Title
# compiler
a

apatrida

09/22/2023, 6:35 PM
Hi, I've scanned back and have seen all the notes on setting up compiler projects, and there are mentions of being able to have Intellij use the same compiler as the one being built in the same project. So, pull intellij-community and run the K2 configuration, then build the compiler plugin there and you should have the same compiler plugin load into the IDE for the module that uses it. Use latest compiler as well (something like
1.9.30-dev-3330)
But, Taking existing compiler plugin projects found in open-source, and massaging them slightly, none of them work in this model. Compile/Run does the right thing. Gradle run does the right thing. IDE during editing, not the right thing. (I'm not yet modifying the FIR but instead modifying the file as a preprocessor to add a function, just to test that it shows up as known by the IDE) I've also checked all of the compiler plugin example, compiler plugin template, compiler plugin sample, crash course, etc. and none either do it all in one project, or don't work when converted to try and accompilsh this. One like Cite looked like a good test case, but didn't work either (added a small change here to make it more obvious if loaded). Is there really not 1 working repo that does this model that shows the best practice and works? Anyone have a repo to share?e @Justin Tullgren @leandro @Rick Clephas@natario1 @Vampire (people talking recently on similar topics)...?
j

Javier

09/22/2023, 6:46 PM
Personally I haven’t done everything in the IntelliJ Community. The setup I got working was: • Repo with the compiler plugin and a Gradle plugin applying it. Publish it locally or use included builds. • Consumer project which can be another repo applying the Gradle plugin • Run IntelliJ Community K2 build and open the consumer project. • Change the flag to allow k2 plugins that are not from JetBrains in the IntelliJ Community Registry
r

Rick Clephas

09/22/2023, 6:51 PM
Personally I haven't looked into this yet, sorry. But my understanding is that this should indeed work as @Javier described.
v

Vampire

09/22/2023, 6:52 PM
What in the name of the good lord makes you think it is a good idea to ping random people just because you want to get an answer faster? That is the second-most rude thing you can do in an open community. Worse is just DMing with a question that is neither confidential, nor personal.
And I for sure did not talk on similar topics. I have no idea at all waht you are talking about.
Pick one appropriate channel, post your question there and then wait whether anyone is in the mood to respond, without pinging anyone please.
a

apatrida

09/22/2023, 7:21 PM
I didn't mean to offend you Björn, and it didn't feel random when I saw you talking recently with knowledge related to the whole dynamic of compiler plugin, gradle plugin, getting them to load correctly, and so on. Maybe you don't remember or understand what I'm referring to but you added to the conversation. What I'm trying to do is get this information into one place to benefit the community, and I hope that isn't rude to try and do. There are at least 10 people talking about pieces of this puzzle here recently, and many suggest things, many sound like they have parts or all working, yet no one has contributed a solid complete picture back to the community. People will come and ask, and ask, and ask. So, I'm not being rude, I'm trying to find information and then make sure it is available to everyone, not just to solve a problem for myself and let the community fend for themselves 5 minutes later.
So, can we all work to update this community information for something we are all going to need to do FIR style plugins, and get a complete picture out there in the public, that is correct, up to date, and complete?
@Javier thanks. I think i was missing that last item, the switch. So what we have not yet seen, is all within one project and having Intelllij (community, k2 build, with switch) loading it into a module. That seems complicated as it would have to reload on changes, so not sure that is intended to work that way or not. But, at least your model gets the IDE working on the plugin. That's a huge bonus. I'll go back and find the switch, I remember seeing it referenced. And will try it on a few of the public sample repos cleaned up a bit, as well as Jake's Cite (not that he needs it, but it is a good test case of a more fully written project instead of toy-demo). Can issue PR's and create a new sample project if none of those are representative enough to help someone coming in for the future to get started.
The structure of the modules, include build or not, the settings, all seem to affect this and so trying it out on these various projects will help find what works and what to avoid.
I should probably also collect all of the topics about debugging for the README of the complete sample,
flag mentioned above:
So if you want to play with it you need to build IDEA from sources (there is a prepared
IDEA Community (K2 Kotlin)
run configuration for that. Also you will need to set
kotlin.k2.only.bundled.compiler.plugins.enabled
registry key to
true
in the IDE you built to enable plugins loading (there are not solved questions about binary compatibility, so by default only official plugins are loaded)
I think this actually should be
false
not
true
might be that compiler also needs free arg set of
-Xuse-fir
j

Javier

09/22/2023, 8:15 PM
I don’t remember needing
-Xuse-fir
using the Gradle plugin approach.
a

apatrida

09/23/2023, 1:42 AM
thanks
v

Vampire

09/23/2023, 12:07 PM
I saw you talking recently with knowledge related to the whole dynamic of compiler plugin, gradle plugin, getting them to load correctly, and so on.
No, I have no knowledge about compiler plugins at all, besides that they exist. All I contributed was how to use a composite build properly to substitute a dependency genetically which happens to be faintly related, as compiler plugins are resolved as dependencies.
What I'm trying to do is get this information into one place to benefit the community, and I hope that isn't rude to try and do.
It is not, to achieve this goal, best collect the information and write a blog post. :-) But pinging people to get an answer is. "Random" in that context doesn't mean you just pick any names. It means the pinged person is not part of this particular conversation and you ping them because you think they could answer your question.
People will come and ask, and ask, and ask.
That they will anyway unfortunately. For the next 90 days the few ones that do search before they ask will find it, all others will still ask. And after the 90 days even less people will search successfully as they are either not even aware of the linen archive or too lazy to switch to a different page to search. So while your intentions are of course great, your action is not. ;-)
e

ephemient

09/23/2023, 2:54 PM
https://kotlinlang.org/community/slackccugl.html
Please do not ping or mention someone directly to get your questions answered, specially project owners, whether the project is Kotlin or other, unless they specifically indicate that you can.
is explicitly listed in the guidelines you agreed to when joining this workspace
a

apatrida

09/23/2023, 7:00 PM
probably not as I joined the first day this workspace was created many years ago. and again I'm trying to collect partial answers into a full answer for the benefit of all. But I get it, I won't @ anyone ever again in my life here.
e

ephemient

09/23/2023, 7:02 PM
if you joined before, there was an announcement https://kotlinlang.slack.com/archives/C0922A726/p1496257411442973
the policy is not never-@, but only @ those who accept it
a

apatrida

09/23/2023, 7:04 PM
Given the reaction, I'll go zero-@, thanks.
(since everyone in this thread is being notified of every message, I think we can drop it, if your point is to not notify people)
j

Justin Tullgren

09/25/2023, 3:54 PM
@apatrida I do the same as @Javier but I have not gotten to the k2 portion yet
a

apatrida

09/25/2023, 8:07 PM
thanks Justin. I was able to get the compiler to load a plugin, but looks like the plugin is already out of date for current FIR so need to track down errors. For a part that does work, it does not always clear the false error in the editor until I touch the code again (small edit). But it is at least on the right track. I'll start over with a small plugin and current compiler to get a good flow working that I can publish. I also tried preprocessing of the input file and that works fine, BUT the editor and compiler in IDE don't react to the new code like they did to FIR changing. More to play with, but will be easier to start over with a small test case with no other errors or issues that is clean to work out everything.
a

Askhar Aydarov

09/29/2023, 8:00 PM
Were you able to run the frontend plugin with K2 IDEA? How? I tried before and described here, but it does not work for me https://kotlinlang.slack.com/archives/C7L3JB43G/p1693295640984609?thread_ts=1693295640.984609&cid=C7L3JB43G But i used kotlinCompilerPluignClasspath instead of gradle plugin
j

Javier

09/29/2023, 9:23 PM
I did a quick try and it is working for me
a

apatrida

10/10/2023, 5:20 PM
@Askhar Aydarov In the Arrow-reflect and Arrow-meta projects are pr's where I upgraded them to current versions (unlikely the pr's would be accepted, these were added mostly just for testing what needs to be done), and there you can see those plugins do load with their Gradle structure into the custom run of intellij-community with the K2 plugin. It's a larger codebase though to look at so might not be the easiest example. But it does work. See here: https://kotlinlang.slack.com/archives/CJ699L62W/p1695768333054549?thread_ts=1692617666.554269&cid=CJ699L62W and scroll up from there.
it is a bit fragile and something they do in Arrow-reflect really makes the compiler hate me (compiling during a compilation to insert the results of one into the other). So it at least shows things work, if not this particular use-case yet.