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

inlining: add missing late special handling for UnionAll method call #43479

Merged
merged 2 commits into from
Dec 20, 2021

Conversation

aviatesk
Copy link
Member

Looking at the result of #43452 (comment),
I found that currently the inlinear sometimes fails to handle UnionAll
call (e.g. runtime dispatch detected: Core.UnionAll(%28::TypeVar, %29::Any)).

This commit adds a missing late special handling for UnionAll calls:

before

julia> code_typed((TypeVar,)) do tv
           UnionAll(tv, Type{tv})
       end
1-element Vector{Any}:
 CodeInfo(
1%1 = Core.apply_type(Main.Type, tv)::Type{Type{_A}} where _A
│   %2 = Main.UnionAll(tv, %1)::Any
└──      return %2
) => Any

after

julia> code_typed((TypeVar,)) do tv
           UnionAll(tv, Type{tv})
       end
1-element Vector{Any}:
 CodeInfo(
1%1 = Core.apply_type(Main.Type, tv)::Type{Type{_A}} where _A
│   %2 = $(Expr(:foreigncall, :(:jl_type_unionall), Any, svec(Any, Any), 0, :(:ccall), Core.Argument(2), :(%1)))::Any
└──      return %2
) => Any

@aviatesk aviatesk added the compiler:optimizer Optimization passes (mostly in base/compiler/ssair/) label Dec 19, 2021
Looking at the result of <#43452 (comment)>,
I found that currently the inlinear sometimes fails to handle `UnionAll`
call (e.g. runtime dispatch detected: Core.UnionAll(%28::TypeVar, %29::Any)).

This commit adds a missing late special handling for `UnionAll` calls:

> before
```julia
julia> code_typed((TypeVar,)) do tv
           UnionAll(tv, Type{tv})
       end
1-element Vector{Any}:
 CodeInfo(
1 ─ %1 = Core.apply_type(Main.Type, tv)::Type{Type{_A}} where _A
│   %2 = Main.UnionAll(tv, %1)::Any
└──      return %2
) => Any
```

> after
```julia
julia> code_typed((TypeVar,)) do tv
           UnionAll(tv, Type{tv})
       end
1-element Vector{Any}:
 CodeInfo(
1 ─ %1 = Core.apply_type(Main.Type, tv)::Type{Type{_A}} where _A
│   %2 = $(Expr(:foreigncall, :(:jl_type_unionall), Any, svec(Any, Any), 0, :(:ccall), Core.Argument(2), :(%1)))::Any
└──      return %2
) => Any
```
@aviatesk aviatesk force-pushed the avi/specialcase-unionall branch 4 times, most recently from 0b93f07 to f8316f3 Compare December 19, 2021 15:51
@aviatesk aviatesk force-pushed the avi/specialcase-unionall branch from f8316f3 to e2810a0 Compare December 20, 2021 06:10
@aviatesk aviatesk merged commit fb3ee73 into master Dec 20, 2021
@aviatesk aviatesk deleted the avi/specialcase-unionall branch December 20, 2021 08:44
aviatesk added a commit that referenced this pull request Jan 5, 2022
Comment on lines +444 to +447
newargexprs = Any[]
for i in 1:(nargs_def-1)
push!(newargexprs, argexprs[i])
end
Copy link
Member

Choose a reason for hiding this comment

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

why use such an awkward way to slice this array?

Suggested change
newargexprs = Any[]
for i in 1:(nargs_def-1)
push!(newargexprs, argexprs[i])
end
newargexprs = argexprs[1:(nargs_def-1)]

Copy link
Member Author

Choose a reason for hiding this comment

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

@vtjnash
Copy link
Member

vtjnash commented Jan 5, 2022

lgtm

LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Feb 22, 2022
JuliaLang#43479)

Looking at the result of <JuliaLang#43452 (comment)>,
I found that currently the inlinear sometimes fails to handle `UnionAll`
call (e.g. runtime dispatch detected: Core.UnionAll(%28::TypeVar, %29::Any)).

This commit adds a missing late special handling for `UnionAll` calls:

> before
```julia
julia> code_typed((TypeVar,)) do tv
           UnionAll(tv, Type{tv})
       end
1-element Vector{Any}:
 CodeInfo(
1 ─ %1 = Core.apply_type(Main.Type, tv)::Type{Type{_A}} where _A
│   %2 = Main.UnionAll(tv, %1)::Any
└──      return %2
) => Any
```

> after
```julia
julia> code_typed((TypeVar,)) do tv
           UnionAll(tv, Type{tv})
       end
1-element Vector{Any}:
 CodeInfo(
1 ─ %1 = Core.apply_type(Main.Type, tv)::Type{Type{_A}} where _A
│   %2 = $(Expr(:foreigncall, :(:jl_type_unionall), Any, svec(Any, Any), 0, :(:ccall), Core.Argument(2), :(%1)))::Any
└──      return %2
) => Any
```
LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Mar 8, 2022
JuliaLang#43479)

Looking at the result of <JuliaLang#43452 (comment)>,
I found that currently the inlinear sometimes fails to handle `UnionAll`
call (e.g. runtime dispatch detected: Core.UnionAll(%28::TypeVar, %29::Any)).

This commit adds a missing late special handling for `UnionAll` calls:

> before
```julia
julia> code_typed((TypeVar,)) do tv
           UnionAll(tv, Type{tv})
       end
1-element Vector{Any}:
 CodeInfo(
1 ─ %1 = Core.apply_type(Main.Type, tv)::Type{Type{_A}} where _A
│   %2 = Main.UnionAll(tv, %1)::Any
└──      return %2
) => Any
```

> after
```julia
julia> code_typed((TypeVar,)) do tv
           UnionAll(tv, Type{tv})
       end
1-element Vector{Any}:
 CodeInfo(
1 ─ %1 = Core.apply_type(Main.Type, tv)::Type{Type{_A}} where _A
│   %2 = $(Expr(:foreigncall, :(:jl_type_unionall), Any, svec(Any, Any), 0, :(:ccall), Core.Argument(2), :(%1)))::Any
└──      return %2
) => Any
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:optimizer Optimization passes (mostly in base/compiler/ssair/)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants