forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement
compilerbarrier
builtin (JuliaLang#46432)
This builtin is useful to control compiler behavior. It could be considered as a more robust and generalized version of `inferencebarrier`. I scratched the following docstring for `compilerbarrier`, that hopefully explains its purpose. Base.compilerbarrier(setting::Symbol, val) This function puts a barrier at a specified compilation phase. It is supposed to only influence the compilation behavior according to `setting`, and its runtime semantics is just to return the second argument `val` (except that this function will perform additional checks on `setting` in a case when `setting` isn't known precisely at compile-time.) Currently either of the following `setting`s is allowed: - Barriers on abstract interpretation: * `:type`: the return type of this function call will be inferred as `Any` always (the strongest barrier on abstract interpretation) * `:const`: the return type of this function call will be inferred with widening constant information on `val` * `:conditional`: the return type of this function call will be inferred with widening conditional information on `val` (see the example below) - Any barriers on optimization aren't implemented yet !!! note This function is supposed to be used _with `setting` known precisely at compile-time_. Note that in a case when the `setting` isn't known precisely at compile-time, the compiler currently will put the most strongest barrier(s) rather than emitting a compile-time warning. \# Examples ```julia julia> Base.return_types((Int,)) do a x = compilerbarrier(:type, a) # `x` won't be inferred as `x::Int` return x end |> only Any julia> Base.return_types() do x = compilerbarrier(:const, 42) if x == 42 # no constant information here, so inference also accounts for the else branch return x # but `x` is still inferred as `x::Int` at least here else return nothing end end |> only Union{Nothing, Int64} julia> Base.return_types((Union{Int,Nothing},)) do a if compilerbarrier(:conditional, isa(a, Int)) # the conditional information `a::Int` isn't available here (leading to less accurate return type inference) return a else return nothing end end |> only Union{Nothing, Int64} ``` As a result, `Base.inferencebarrier` is now defined as ```julia inferencebarrier(@nospecialize(x)) = compilerbarrier(:type, x) ```
- Loading branch information
Showing
9 changed files
with
172 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters