julia
6b93a8d3 - Add `_precompile` and `_precompile_method_instance` intrinsics

Commit
1 year ago
Add `_precompile` and `_precompile_method_instance` intrinsics The purpose of this is to be able to intercept precompile statements (currently in codegen and eventually also in inference/inlining), so that the compiler can respond to these as a "compilation obligation". For example, consider something like `setindex!(Dict{Any,Int}, ...)`: ``` function setindex!(d::Dict{Any,Int}, obj::Any, idx::Int) ... # make sure we have `hash!(obj)` ready for us later Core._precompile(Tuple{typeof(hash!), typeof(obj)}) if (capacity_low) rehash_all_elements!(d) # this ends up calling `hash!(::Any)` end ... return obj end ``` There is an inherently dynamic dispatch in this code, where we iterate over all the objects that were _already_ inserted. However, each particular insertion generally knows what object it is inserting. The `Core._precompile` statement allows the compiler to use this type-information at each insertion site and guarantee that we've compiled sufficient code. At the dynamic dispatch call-site, `@assert_precompiled hash!(...)` is used, but we know that the code is available (even in `juliac`) thanks to the `precompile(...)` statements.
Author
Committer
Parents
Loading