Daniil Elovkov
09/05/2023, 7:43 PMevant
09/05/2023, 7:53 PMDaniil Elovkov
09/06/2023, 8:08 AMIn my case, the dependency is not expressed well with the code generated by one generator, and the other one waiting for code to appear.
Mike Dawson
09/06/2023, 9:10 AMDaniil Elovkov
09/06/2023, 9:36 AMThere is no guarantee that I know of that the next rounds will run in the same JVM etcI think there is. Seems that SymbolProcessor is guaranteed to be the same instance from round to round (to be able to maintain the state), so it should be in the same JVM.
Also no guarantee that a JVM will not be re-usedThat’s a good catch, yes. I’m also thinking of a potential risk of gradle parallel build. However, speaking of recomputing the model argument, I would throw in another reason for me sharing the state between generators, for completeness. In my case, input for generators is a hierarchy of interfaces. Say, gen. A uses it to output something. But gen. B adds new interfaces to the hierarchy. I want to make sure A runs after B, so that it uses all interfaces including new ones. And, as a complication I might add more consuming generators and more producing generators later. And I don’t want to couple them tightly, so that all consumers know about all potential producers and wait for a specific “tag” in the generated sources to appear which would signal that now it’s ok to run the consumers. I want the code for a consumer generator to be unaware of how many potential producers/modifiers of the hierarchy there are. Back to technical nuances of using static data, seems it would be enough to have an object (just its identity is enough) which uniquely identifies the current KSP run (
AbstractKotlinSymbolProcessingExtension.doAnalysys()
) Then, it could be used as a key to some static map. As a matter of fact, now CodeGenerator and Resolver instances are already such objects (they are unique and stable for the given run), but there are definitely no guarantees to that. So, relying on that would be a hackMike Dawson
09/06/2023, 10:36 AMDaniil Elovkov
09/06/2023, 10:51 AMDaniil Elovkov
09/06/2023, 10:53 AMMike Dawson
09/06/2023, 11:55 AM