Skip to content

Add check_only option to precompile #58146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Add check_only option to precompile #58146

wants to merge 1 commit into from

Conversation

kpamnany
Copy link
Contributor

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 precompiles, and we naturally do so, but this takes time.

We would like a relatively quick way to check the validity of a precompile statement.

We can't use hasmethod as it has both false positives (too loose):

julia> hasmethod(sum, (AbstractVector,))
true

julia> precompile(sum, (AbstractVector,))
false

julia> precompile(sum, (AbstractVector,); check_only=true) # <- this PR
false

and also false negatives (too strict):

julia> bar(@nospecialize(x::AbstractVector{Int})) = 42
bar (generic function with 1 method)

julia> hasmethod(bar, (AbstractVector,))
false

julia> precompile(bar, (AbstractVector,))
true

julia> precompile(bar, (AbstractVector,); check_only=true) # <- this PR
true

We can't use hasmethod && isconcretetype as it has false negatives (too strict):

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> precompile(convert, (Type{Int}, Int32); check_only=true)  # <- this PR
true

This PR adds the check_only Bool keyword argument to precompile; if true, the method instance isn't actually compiled. We can, of course, add a new isprecompilable instead, or move things around.

Cc: @nickrobinson251 whose idea this is, @gbaraldi who suggested opening the PR for discussion, and @JeffBezanson who had some thoughts on "compilability".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant