Caleb B
10/22/2026, 7:18 PMFirDeclarationGenerationExtension? Can you just emit an unbound FIR symbol with a name only and fill out the rest in IR, or do you need to have a backing FIR function/class/property? If it's the latter, just how much information do you need in FIR? (e.g. do you need supertypes for classes, a fully-resolvable function signature, return type for properties, etc.)
I'm trying to figure out the least amount of information I can get away with, even if it means I have to do more work during IR.Youssef Shoaib [MOD]
10/22/2026, 7:24 PMBODY_RESOLVE phase) FIR, but you can skip function bodies.
The purpose of FirDeclarationGenerationExtension is to emit things that the same compilation (and further consumers of the compiled code) can see. So, if you were able to emit a function with just a name, that wouldn't be super useful, would it now?
If you want to add private functions and such for your plugin's purposes, definitely do that in IR.
Fun fact, you can emit things in IR that can be seen by other compilations by making them metadata-visible. More info: https://kotlinlang.slack.com/archives/C7L3JB43G/p1791977988326849?thread_ts=1791883135.742039&cid=C7L3JB43GCaleb B
10/22/2026, 7:26 PMCaleb B
10/22/2026, 7:27 PMYoussef Shoaib [MOD]
10/22/2026, 7:29 PMFirDeclarationGenerationExtension is called very early on, earlier than the bodies of functions are ever resolvedCaleb B
10/22/2026, 7:29 PMYoussef Shoaib [MOD]
10/22/2026, 7:30 PMCaleb B
10/22/2026, 7:31 PMCaleb B
10/22/2026, 7:31 PMYoussef Shoaib [MOD]
10/22/2026, 7:39 PMFirExtension s you can try and use, especially some of the more internal/experimental ones. FirFunctionCallRefinementExtension in particular can do a lot of crazy things, especially if you throw caution to the wind and start modifying FIR (Not supported, obviously).
Another favorite of mine is FirAssignExpressionAltererExtension. It seems really simple on the surface, but it's (to my knowledge) the only "non-internal" extension that lets you generate unresolved FIR (which is pretty close to source code, meaning you can trigger call resolution and smart casts and such). Combined with more hackery and FIR modification, you can do some stupid but fun things.
I know less about these, but there are a few scripting-related `FirExtension`s, which give you a lot of freedom (it seems).
That was a bit tangential, so to get back to the main point: try and narrow down what your use case really is (generating any declaration at compile time might be too much to approach at once), then you can start experimenting and (optionally) doing unsupported things.
If this isn't just experimentation, then please ignore all the bad advice I've provided above 😅.
If this is experimentation, I have some hacky code I can share, but it isn't well-commented.Caleb B
10/22/2026, 7:49 PMCaleb B
10/22/2026, 7:50 PMYoussef Shoaib [MOD]
10/22/2026, 7:59 PMCaleb B
10/22/2026, 8:02 PMin other, other words, it makes the type system Turing completeHold the phone. Does it support variable-arity types?
Caleb B
10/22/2026, 8:03 PMYoussef Shoaib [MOD]
10/22/2026, 8:03 PMList, for instance, using Church encodingYoussef Shoaib [MOD]
10/22/2026, 8:04 PMCaleb B
10/22/2026, 8:05 PMYoussef Shoaib [MOD]
10/22/2026, 8:06 PMCaleb B
10/22/2026, 8:09 PMCaleb B
10/22/2026, 8:09 PMYoussef Shoaib [MOD]
10/22/2026, 8:10 PMCaleb B
10/22/2026, 8:12 PMhere's a "proof" that "a monad is a monoid in the category of endofunctors"It's absolutely unreadable and completely nonsensical, but I can't help but get some overwhelming bliss at seeing it. It's just so stupid that it works, but it's so cool.
Caleb B
10/22/2026, 8:14 PMCaleb B
10/22/2026, 8:14 PMCaleb B
10/22/2026, 8:15 PMCaleb B
10/22/2026, 8:16 PMYoussef Shoaib [MOD]
10/22/2026, 8:18 PMYoussef Shoaib [MOD]
10/22/2026, 8:19 PMCaleb B
10/22/2026, 8:19 PMCaleb B
10/22/2026, 8:24 PMSomeCalculationTrue.value = x SomeCalculationFalse.value = yYoussef Shoaib [MOD]
10/22/2026, 8:30 PMfun <T: True> foo(x: String) {}
fun <F: False> foo(x: String) {}
foo<SomeTypeCalculation<True>>(x)
foo<SomeTypeCalculation<False>>(y)
and get different results