MilesCranmer / DispatchDoctor.jl

The dispatch doctor prescribes type stability
Apache License 2.0
128 stars 6 forks source link

`@generated` functions lead to world age problems #6

Closed matthias314 closed 1 month ago

matthias314 commented 1 month ago

I have the impression that DispatchDoctor has problems with @generated functions. At present, I don't have anything close to an MWE. Nevertheless, I want to point out that this problem exists.

Here are the steps to reproduce it: Check out the branch dispatchdoctor-worldage of https://github.com/matthias314/SmallCollections.jl . Go to the src directory, start Julia and say:

julia> include("SmallCollections.jl")
Main.SmallCollections

julia> using .SmallCollections

julia> v = SmallVector{8,Int8}(1:3)
3-element SmallVector{8, Int8}:
 1
 2
 3

julia> fasthash(v)
ERROR: MethodError: no method matching bitsize(::Type{Int8})
The applicable method may be too new: running in world age 31520, while current world is 31833.

I believe the culprit is the @generated function bits starting at line 127 in staticvectors.jl . Needless to say, without DispatchDoctor is works.

MilesCranmer commented 1 month ago

i suppose @stable should skip @generated?

It should also skip @capture (MacroTools), @model (Turing) since they have custom syntax within functions.

MilesCranmer commented 1 month ago

Btw to test your hypothesis you should use @unstable on any blocks of code to turn it off.