Commit 0d0fb06
committed
Add
Alternative to JuliaLang#58146.
We want to compile a subset of the possible specializations of a
function. To this end, we have a number of manually written `precompile`
statements. Creating this list is, unfortunately, error-prone, and the
list is also liable to going stale. Thus we'd like to validate each
`precompile` statement in the list.
The simple answer is, of course, to actually run the `precompile`s, and
we naturally do so, but this takes time.
We would like a relatively quick way to check the validity of a
`precompile` statement.
This is a dev-loop optimization, to allow us to check "is-precompilable"
in unit tests.
We can't use `hasmethod` as it has both false positives (too loose):
```julia
julia> hasmethod(sum, (AbstractVector,))
true
julia> precompile(sum, (AbstractVector,))
false
julia> Base.isprecompilable(sum, (AbstractVector,)) # <- this PR
false
```
and also false negatives (too strict):
```julia
julia> bar(@nospecialize(x::AbstractVector{Int})) = 42
bar (generic function with 1 method)
julia> hasmethod(bar, (AbstractVector,))
false
julia> precompile(bar, (AbstractVector,))
true
julia> Base.isprecompilable(bar, (AbstractVector,)) # <- this PR
true
```
We can't use `hasmethod && isconcretetype` as it has false negatives
(too strict):
```julia
julia> has_concrete_method(f, argtypes) = all(isconcretetype, argtypes) && hasmethod(f, argtypes)
has_concrete_method (generic function with 1 method)
julia> has_concrete_method(bar, (AbstractVector,))
false
julia> has_concrete_method(convert, (Type{Int}, Int32))
false
julia> precompile(convert, (Type{Int}, Int32))
true
julia> Base.isprecompilable(convert, (Type{Int}, Int32)) # <- this PR
true
```
`Base.isprecompilable` is essentially `precompile` without the actual
compilation.Base.isprecompilable (JuliaLang#58805)1 parent 58ebdb3 commit 0d0fb06
3 files changed
+24
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4178 | 4178 | | |
4179 | 4179 | | |
4180 | 4180 | | |
| 4181 | + | |
| 4182 | + | |
| 4183 | + | |
| 4184 | + | |
| 4185 | + | |
| 4186 | + | |
| 4187 | + | |
| 4188 | + | |
| 4189 | + | |
| 4190 | + | |
| 4191 | + | |
| 4192 | + | |
| 4193 | + | |
| 4194 | + | |
4181 | 4195 | | |
4182 | 4196 | | |
4183 | 4197 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3681 | 3681 | | |
3682 | 3682 | | |
3683 | 3683 | | |
| 3684 | + | |
| 3685 | + | |
| 3686 | + | |
| 3687 | + | |
| 3688 | + | |
| 3689 | + | |
| 3690 | + | |
| 3691 | + | |
| 3692 | + | |
3684 | 3693 | | |
3685 | 3694 | | |
3686 | 3695 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
270 | 270 | | |
271 | 271 | | |
272 | 272 | | |
| 273 | + | |
273 | 274 | | |
274 | 275 | | |
275 | 276 | | |
| |||
0 commit comments