Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work around to specify cache module when building RuntimeGeneratedFunctions #769

Merged
merged 2 commits into from
Feb 5, 2021
Merged

Conversation

dpad
Copy link
Contributor

@dpad dpad commented Feb 5, 2021

The RuntimeGeneratedFunctions (RGF) macro @RuntimeGeneratedFunction allows the caller to specify the "context" module, but sets the "cache" module (i.e. which RGF cache will contain this function) to @__MODULE__, which ends up being ModelingToolkit.

However, if a user is indirectly calling ModelingToolkit's build_function at precompile time, ModelingToolkit's cache eventually disappears, and the resulting RGF cache lookup does not work.

Therefore, the user needs to set up an RGF cache in their own module, and ensure build_function is called with expression=false and expression_module=UserModule. The work-around in this PR then sets both the RGF's "cache" and "context" modules to be the UserModule.

@ChrisRackauckas
Copy link
Member

ChrisRackauckas commented Feb 5, 2021

It would be good to get @c42f's opinion here.

@c42f
Copy link

c42f commented Feb 6, 2021

This seems valid to me (getting the caching right is tricky).

We just need some support in RuntimeGeneratedFunctions to make it officially supported. See SciML/RuntimeGeneratedFunctions.jl#26

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants