SciML / RuntimeGeneratedFunctions.jl

Functions generated at runtime without world-age issues or overhead
https://docs.sciml.ai/RuntimeGeneratedFunctions/stable/
MIT License
100 stars 14 forks source link

Automatic initialization #31

Open 0x0f0f0f opened 3 years ago

0x0f0f0f commented 3 years ago

Is it technically possible?

!isdefined(mod, RGF._tagname) && RGF.init(mod)

If I do this right before generating a function I get a world age error.

c42f commented 3 years ago

Unfortunately I don't know how to do this in full generality, otherwise I'd already have done it. It's semi-possible to do as a side-effect at macro expansion time if people only use the single-argument @RuntimeGeneratedFunction constructor. These kind of side-effectful macros are somewhat evil, however ;-) Furthermore, this wouldn't work for the other constructor forms.

The ability of RGFs to avoid world age errors is entirely tied to running the init code early - the init code defines a generated function with an early world age which all dynamically generated RGFs will inherit.

c42f commented 3 years ago

So yeah, to be more blunt - I don't think this is possible :-)