I'm soliciting ideas from people who know the Scala compiler better than I do! How might I get nsc to invoke some custom code at some point (not too important when) after typer has run, but before compilation finishes? Are there any hooks available to me?
-
-
Replying to @propensive
A Scala compiler plugin can hook in after any of these stages: https://typelevel.org/scala/docs/phases.html … The API is a bit gnarly and almost certainly will need huge changes to work with Scala 3. But it's there and you can do pretty much anything you want
1 reply 0 retweets 2 likes -
Replying to @stephenjudkins
I'm keen to avoid a compiler plugin if possible, though it would be a valid way to do this. To elaborate on the problem, I have an unknown number of macro expansions happening during typer, and I want to print a report (once only) when all of them have run.
1 reply 1 retweet 1 like -
Replying to @propensive
Hmm. Been thinking on this, and here's what I'd do: have some sort of global state that's cleared/initialized by a plugin that runs before macro expansion; macros report to that global state during expansion; plugin runs following expansion that triggers generation of the report
1 reply 0 retweets 0 likes -
Replying to @stephenjudkins
That's not far off my plan, though we can just keep the state in some global singleton object, and it doesn't need to be init'd... we can assume it gets cleaned up by the post-typer code that runs once for every compilation. (My use-case can assume compiles are successful).
2 replies 0 retweets 0 likes -
Replying to @propensive @stephenjudkins
But I'd like to do with without compiler plugins, i.e. "just a library". The ability to do hacky things in the JVM like return instances of anonymous subclasses with overridden methods suggests tantalizing opportunities for getting a fragment of code to run after typer...
1 reply 0 retweets 0 likes
It doesn't even matter if it gets run more than once in the same compilation. We could just synchronize it and flag some mutable state when the report has run. This is horrible horrible hacky stuff, though... ;)
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.