Skip to content
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

InteractiveUtils: make code_llvm default atype work with no-arg functions #42496

Merged
merged 2 commits into from
Oct 18, 2021

Conversation

aviatesk
Copy link
Sponsor Member

@aviatesk aviatesk commented Oct 4, 2021

code_llvm and code_native expects a single matching method, but the
default value of their argument types=Tuple doesn't match with any
function signature and so we actually can't use the default value.

This PR changes the default argument type to Tuple{}, so that
code_llvm and code_native work with no-arg functions by default,
e.g. now we can use them like:

code_llvm() do # previously, we need to call `code_llvm(()) do ... end`
    sin(42)
end

One possible consideration is that now default types argument are
inconsistent between code_lowered/code_typed and code_llvm/code_native,
but I don't think it's confusing because in fact they work very differently,
i.e. they expect multiple vs. single matching methods, return result vs. print result.

@aviatesk aviatesk requested a review from vtjnash October 4, 2021 17:53
@JeffBezanson
Copy link
Sponsor Member

How about tuple_type_tail(only(methods(f)).sig) as the default, so it works for any function with one method?

`code_llvm` and `code_native` expects a single matching method, but the
default value of their argument `types=Tuple` doesn't match with any
function signature and so we actually can't use the default value.

This PR changes the default argument type to `Tuple{}`, so that
`code_llvm` and `code_native` work with no-arg functions by default,
e.g. now we can use them like:
```julia
code_llvm() do # previously, we need to call `code_llvm(()) do ... end`
    sin(42)
end
```

One possible consideration is that now default `types` argument are
inconsistent between `code_lowered`/`code_typed` and `code_llvm`/`code_native`,
but I don't think it's confusing because in fact they work very differently,
i.e. they expect multiple vs. single matching methods, return result vs. print result.
@aviatesk
Copy link
Sponsor Member Author

aviatesk commented Oct 5, 2021

Sounds reasonable. What do you think on 0f2d0e2 ?

@aviatesk
Copy link
Sponsor Member Author

@JeffBezanson can I move this forward ?

@aviatesk aviatesk merged commit cd19e97 into master Oct 18, 2021
@aviatesk aviatesk deleted the avi/defaulttt branch October 18, 2021 09:09
LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Feb 22, 2022
…functions with single method (JuliaLang#42496)

`code_llvm` and `code_native` expects a single matching method, but the
default value of `types=Tuple` argument doesn't match with any function 
signature and so we actually can't use that default value.

With this PR, the default argument type will be computed by `default_tt`,
which returns an appropriate signature if a function only has a single 
method, otherwise returns `Tuple` (which is the same default value as before).

Now `code_llvm` and `code_native` by default work with functions that 
have a single method, e.g.:
```julia
code_llvm() do # previously, we need to call `code_llvm(()) do ... end`
    sin(42)
end
```
LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Mar 8, 2022
…functions with single method (JuliaLang#42496)

`code_llvm` and `code_native` expects a single matching method, but the
default value of `types=Tuple` argument doesn't match with any function 
signature and so we actually can't use that default value.

With this PR, the default argument type will be computed by `default_tt`,
which returns an appropriate signature if a function only has a single 
method, otherwise returns `Tuple` (which is the same default value as before).

Now `code_llvm` and `code_native` by default work with functions that 
have a single method, e.g.:
```julia
code_llvm() do # previously, we need to call `code_llvm(()) do ... end`
    sin(42)
end
```
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.

None yet

2 participants