Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a (very simple!) fix to a reflection caching bug that causes a range of convoluted bugs and weird behavior.
Anytime we look up a function, whether by name or by reflection, we construct a new cache key representing the function name and save the reflection for future lookups and hot reloads.
This causes a few problems:
int foo<int X>() { return X; }
, we can look up the specialized function"foo<5>"
. SlangPy checks the cache for prior lookups of"foo<5>"
, but saves it in the cache under the name"foo"
. This means lookups for specialized generics never hit the cache.Even weirder: Calling
foo()
directly is not allowed, sinceX
can't be inferred. But if you called or looked up"foo<5>"
at some earlier point, callingfoo()
now suddenly succeeds, because the cache returns the functionfoo<5>
instead when you look up"foo"
.void foo(int x) {} void foo(int2 x) {}
, reflecting"foo"
returns an overloaded reflection object. As a result of how the reflection API handles these, SlangPy instead caches this lookup underNone
. OTOH, when slangpy specializes the function to get a specific overload (e.g.foo(int)
), this one is cached under"foo"
. From then on, looking up the function"foo"
by name returns that specific specialization, not the overloaded function, and trying to call e.g.foo(int2)
after that could fail. It's surprising this hasn't caused issues before - our savior here is that theModule
keeps a separate_attr_cache
and avoids hitting the (incorrect) reflection cache most of the time.None
function name.The fix is very simple, and moves the by-name-caching into the functions that look up by name, and caches under the exact name used to query the reflection API.