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

Separate RGF code cache from context for variable lookup #22

Merged
merged 2 commits into from
Jan 4, 2021

Conversation

c42f
Copy link
Contributor

@c42f c42f commented Jan 4, 2021

The module for RGF code cache may be different from the context for lookup of global variables used in the function's AST. This change allows these to be separate.

Also fix a problem with show() mime type and REPL usage — use at the REPL was finding the definition for show(::IO, ::MIME"text/plain", ::Function) rather than ours.

Reverts #20 due to the issues discussed in #21. Fixes #21

c42f added 2 commits January 4, 2021 14:21
…acro"

This reverts commit ff1fd50.

As discussed in SciML#21, it's error prone for the user to control the module
used for the RGF cache. So it's easiest to keep the constructor macro.
The module for RGF code cache may be different from the context for
lookup of global variables used in the function's AST. This change
allows these to be separate.

Also fix a problem with `show()` mime type and REPL usage — use at the
REPL was finding the definition for `show(::IO, ::MIME"text/plain",
::Function)` rather than ours.
@codecov
Copy link

codecov bot commented Jan 4, 2021

Codecov Report

Merging #22 (2c3fbed) into master (cee1c8a) will decrease coverage by 2.94%.
The diff coverage is 86.36%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #22      +/-   ##
==========================================
- Coverage   92.30%   89.36%   -2.95%     
==========================================
  Files           1        1              
  Lines          39       47       +8     
==========================================
+ Hits           36       42       +6     
- Misses          3        5       +2     
Impacted Files Coverage Δ
src/RuntimeGeneratedFunctions.jl 89.36% <86.36%> (-2.95%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cee1c8a...2c3fbed. Read the comment docs.

@c42f
Copy link
Contributor Author

c42f commented Jan 4, 2021

codecov seems confused here, I think those lines are covered.

quote
RuntimeGeneratedFunction(@__MODULE__, $(esc(ex)))
code = $code
cache_module = @__MODULE__
Copy link

@dpad dpad Feb 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @c42f , could I ask if there's a specific reason for setting the cache_module to be @__MODULE__ here, rather than allowing the user to provide it? This unfortunately regresses the RGFPrecompConsumerTest I had in #19 (though it wasn't merged in). I've had to work around this in SciML/ModelingToolkit.jl#769 by manually calling the RuntimeGeneratedFunction constructor instead.
(Edit: just to make it clear, I don't mean for this to sound accusatory or anything, just genuinely wondering if there's some rationale for the cache to always be the calling module rather than user-specified.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No offense taken!

The thought was that we were protecting users from accidentally breaking the precompilation cache mechanism (see #21) — originally the function version of RuntimeGeneratedFunction wasn't meant to be used as a constructor; the thought was that the macro would be the official constructor.

However, this doesn't cover all use cases as you noticed. So I've created #26 to allow you to set what you need without messing with the tag struct (which is definitely meant to be internal).

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot mate for your explanation and the work in #26, that'll help simplify the workaround in ModelingToolkit for sure!

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.

Modules for caching RGF ASTs vs resolving global symbols
3 participants