Description
Invalidation is the major threat to useful precompilation, and aside from outright piracy (which is rare) it overwhelmingly comes from poorly-inferred calls that are handled without using runtime dispatch. For example, for method definitions
f(::Int) = 1
f(::String) = "hello"
g(c) = f(c[1])
a check with @code_typed
reveals that g(Any[0])
performs "world-splitting" to look up the callees in advance. The problem arises for a package that defines a new method of f
, forcing invalidation of the previously-compiled code for g
. There are analogs of this behavior for packages that define new subtypes of abstract types, too.
Currently, we can use @invokelatest
to force runtime dispatch at the call site. However, it would be nice to be able to say "use runtime dispatch unless the argument types are known concretely, in which case you can use ordinary dispatch." Moreover, it might be nice to be able to mark certain methods as being inferrable only for concrete arg types, so that you avoid any kind of abstract inference (which is itself slow as well as introducing vulnerability to invalidation). A possible demo of syntax:
To mark a call as requiring runtime dispatch if any of the arguments are not concretely-inferred:
x, y = @concrete(f(a, b, c))
To mark a method as dispatchable only with concretely-inferred argtypes:
@concrete f(a, b, c) = ...
Discussed with @aviatesk