-
On v1.7.2, this phenomenon also happens when
Symbolicsis omitted and the globalzis changed toz=0, so the problem doesn’t seem to be inSymbolics. The rest of my comment is about thisz=0version. -
Changing
L2tosum([ ... ])doesn’t change anything, so this might be a matter of summing over a generator versus over an array (whichmapmakes). -
The same phenomenon also happens if you run either
Pⱼ(z,x,1,n),L1(z, x, y, n), orL2(z, x, y, n)instead of@code_warntype L2(z, x, y, n)between the 2 runs of@code_warntype L1(z,x,y,n). Runningδⱼ(z,x,1,3)was not enough. -
If you run
Pⱼ(z,x,1,n),L1(z, x, y, n),L2(z, x, y, n), or@code_warntype L2(z, x, y, n)in a fresh session first,@code_warntype L1(z,x,y,n)is type-stable on its first try afterward. -
These Github issues (18695, 43330) seem related, but I couldn’t find anything about
code_warntype“changing its mind” like this in those issues or other linked issues. I would really highlight that detail, you could even edit your post’s title to mention it. You could also open a new Github issue, see where it goes.
Due to work done in another thread about inconsistent inference, I also identified:
-
If
@code_warntype L1(z,x,y,n)reports type-stability, then you redefine eitherδⱼorPⱼ, it will cause the next@code_warntype L1(z,x,y,n)to report type-instability. This re-unstabilizing effect does NOT occur if you redefineL1orL2. -
Test.@inferred L1(z, x, y, n)can throw aERROR: return type Float64 does not match inferred return type Anyeven when@code_warntypeis inferring aFloat64return type.@inferredis successful only ifPⱼis compiled beforeL1is; switch the order (such as by only runningL1) and@inferredgets stuck at that error; if it gets stuck at that error, redefineL1to “undo”L1’s compilation and it infers successfully again. -
All of the above is reproducible on v1.4.1, so this isn’t a new regression.
My initial guess was that Pⱼ having been compiled seems to be a critical factor, but I could not claim that @code_warntype L2(z,x,y,n) compiles Pⱼ, let alone claim that’s how it triggers @code_warntype L1(z,x,y,n) to report type-stability.