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

is_primitive doesn't invalidate methods in TICache #120

Closed
jumerckx opened this issue Apr 11, 2024 · 1 comment
Closed

is_primitive doesn't invalidate methods in TICache #120

jumerckx opened this issue Apr 11, 2024 · 1 comment

Comments

@jumerckx
Copy link

jumerckx commented Apr 11, 2024

I was looking at how is_primitive is implemented because I need similar functionality in a project.
Currently, by default, a new TapirInterpreter gets a fresh new cache.
However, when reusing the same interpreter (with the same cache), redefinitions of is_primitive rules don't invalidate the methods in the cache:

using Tapir
@inline f(x) = g(x)
@inline g(x) = h(x)
@inline h(x) = sin(x)

interp = Tapir.TapirInterpreter()
sig = Tuple{typeof(f), Float64}

Tapir.is_primitive(::Type{Tapir.DefaultCtx}, ::Type{<:Tuple{typeof(h), Any}}) = true
Base.code_ircode_by_type(sig; interp)[1][1] # h is not inlined, good

Tapir.is_primitive(::Type{Tapir.DefaultCtx}, ::Type{<:Tuple{typeof(h), Any}}) = false
Base.code_ircode_by_type(sig; interp)[1][1] # h is *still* not inlined

I believe this is unexpected but could be wrong?
The tests only check nested calls one level deep but at that point, the problem doesn't seem to occur.

This is a related slack thread where I tried getting help for my problem, with an MWE in using Julia 1.11 that doesn't depend on Tapir

@willtebbutt
Copy link
Member

willtebbutt commented Apr 11, 2024

Yup, this is expected behaviour unfortunately. You need a fresh interp whenever you re-define is_primitive (and possibly anything else) because interp doesn't know about world age etc.

If you find a way to handle this in general, I would very much like to hear about it!

I'm going to close this for now because I don't anticipate that there's anything that I can do about this / it's a problem that I know about + plan to document, but please do feel free to re-open if you figure something out.

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

No branches or pull requests

2 participants