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

compiler: more accurate isdefined_tfunc for NamedTuple arg: #37830

Merged
merged 3 commits into from
Oct 8, 2020

Conversation

aviatesk
Copy link
Sponsor Member

@aviatesk aviatesk commented Oct 1, 2020

this will help the compiler, e.g. exclude unnecessary runtime calls of haskey when a keyword argument is inferred as non-concrete type

f(a; b = nothing, c = nothing) = return
let
    b = rand((nothing,1,1.))
    f(0; b) # <= now we don't need runtime `haskey(kwargs, :c)` call for this
end

else
ns = a1.parameters[1]
if isa(ns, Tuple)
return Const(val in ns)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this happens when the NamedTuple is not concrete (e.g. because the types are not known), but the field names are known? Seems reasonable to me, but please add a test that tests this codepath (i.e. fails without this commit and passes with it).

Copy link
Sponsor Member Author

@aviatesk aviatesk Oct 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this happens when the NamedTuple is not concrete (e.g. because the types are not known), but the field names are known?

yeah, exactly.

I will try to add a test later

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use 1 <= idx <= length(ns).

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, applied in 8823625

aviatesk added a commit to aviatesk/JET.jl that referenced this pull request Oct 1, 2020
once JuliaLang/julia#37830 gets merged, this 
test should pass
aviatesk added a commit to aviatesk/JET.jl that referenced this pull request Oct 2, 2020
once JuliaLang/julia#37830 gets merged, this 
test should pass
aviatesk added a commit to aviatesk/JET.jl that referenced this pull request Oct 3, 2020
once JuliaLang/julia#37830 gets merged, this 
test should pass
e.g.
this will exclude unnecessary runtime calls of `haskey` when a keyword 
argument is inferred as non-concrete type
```julia
f(a; b = nothing, c = nothing) = return
let
    b = rand((nothing,1,1.))
    f(0; b)
end
```
aviatesk added a commit to aviatesk/JET.jl that referenced this pull request Oct 8, 2020
once JuliaLang/julia#37830 gets merged, this 
test should pass
aviatesk added a commit to aviatesk/JET.jl that referenced this pull request Oct 8, 2020
once JuliaLang/julia#37830 gets merged, this 
test should pass
aviatesk added a commit to aviatesk/JET.jl that referenced this pull request Oct 8, 2020
once JuliaLang/julia#37830 gets merged, this 
test should pass
aviatesk added a commit to aviatesk/JET.jl that referenced this pull request Oct 8, 2020
once JuliaLang/julia#37830 gets merged, this 
test should pass
@aviatesk
Copy link
Sponsor Member Author

aviatesk commented Oct 8, 2020

@JeffBezanson @Keno can you have a review on this again ?

@JeffBezanson JeffBezanson merged commit 025d106 into JuliaLang:master Oct 8, 2020
@JeffBezanson JeffBezanson added the compiler:inference Type inference label Oct 8, 2020
@JeffBezanson
Copy link
Sponsor Member

Nice improvement!

@aviatesk aviatesk deleted the avi/isdefined4ntpl branch October 9, 2020 01:41
aviatesk added a commit to aviatesk/JET.jl that referenced this pull request Oct 9, 2020
once JuliaLang/julia#37830 gets merged, this 
test should pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:inference Type inference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants