Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Macro statics initilization #5746
Following conversation in #5676
In macro context (with compilation server), static variables:
Now in order to improve it, we could fix (a) by generating all statics initialization code in a separate function that would get called when reusing the macro context, so you would get a freshly initialized module. That should render useless the
For (b) the only solution would be to detect before reusing the macro context (so on the first called macro) if one of the modules of the macro context has been modified.
This would ensure the same statics behavior has you would get without macro context reuse, without the extra time required to initialize the context.
There's no much design decision here.
What would be complicated about haxe.macro.Storage ? It's just a Hashtbl stored in memory. The problem with statics is that you don't really control the initialization order which is quite hard to deal with.…
On Thu, Apr 19, 2018 at 12:02 AM, Simon Krajewski ***@***.***> wrote: Adding haxe.macro.Storage sounds complicated. How about supporting @:persistent static var x = 1; instead? I could support this easily by simply filtering these statics out so they are not reinitialized on context reuse, which would give the previous behavior. — You are receiving this because you were assigned. Reply to this email directly, view it on GitHub <#5746 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AA-bwAROKz307NNiyH23GfKFy1DKXaJGks5tp7gHgaJpZM4KVmTr> .
Hmm, I'm not sure what to make of this. If you run with the server, side effects are generally persisted.
For example in tink_macro, there's this thing called
So I guess my question is: Why isn't the macro context reused all the time? In my experience the need to reset global state on recompilation is the exception and not the norm, because most global state changes reflect code that has been generated and persisted, so in the vast majority of cases you don't want to lose the global state corresponding to the code. Using