do not cache global functions during initialization anymore#2741
do not cache global functions during initialization anymore#2741jurgenvinju merged 3 commits intomainfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2741 +/- ##
=======================================
- Coverage 46% 46% -1%
- Complexity 6720 6725 +5
=======================================
Files 794 794
Lines 65910 65912 +2
Branches 9887 9888 +1
=======================================
- Hits 30826 30822 -4
Misses 32699 32699
- Partials 2385 2391 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Instrumented the slow path with a print. This is a small snippet of the result. It happens thousands of times during When they are constructor names, the cache would not be a problem. If they are function names (possibly overloaded), it could be an issue. |
|
This is the very first print: That is a global variable but lookup always first tries to resolve a variable name as a function name. If the result is empty, then a lookup follows in the variable environment. If the function cache is on, the empty result is cached anyway. This is tricky, but doesn't seem to produce real issues (only if there is an erroneous double declaration of a global variable and a module-level (overloaded) function. |
|
The second print is this: Triggered by this code: The pattern matching initialization code has to look up the constructors. Because constructors are declared first during pre-loading, this lookup always succeeds. If any later overloads are added, the pattern matcher does not care since it only matches on constructors. This is not an issue for the cache. |
|
Another instance that is not about constructors:
Here uuid() comes from an imported module, which has been initialized by induction, so this is not an issue. It would have been an issue if So the case of a global initializer, with calls to possibly overloaded functions declared in the current module is the most pressing we found so far. See also #2740 which addresses this issue on a different level. Both fixes are required to completely solve this. |
|
This is an interesting case with globals:
|
|
Finally, we have: and In this case overloading interacts with the cache. The use of |
|



This looks ok, but:
This PR partially fixes this situation:
Because at the time of running the initialization for
xthe second overload is not there yet, the answer tof(0)will be42. While the test is running, bothxandf(0)will return the wrong number.It is the goal of this PR to fix the value of
f(0). The fix forxin the test is in #2740