Commit 3136189
committed
inference: improve
Currently our inference isn't able to propagate `isa`-based type
constraint for cases like `isa(Type{<:...}, DataType)` since
`typeintersect` may return `Type` object itself when taking `Type`
object and `iskindtype`-object.
This case happens in the following kind of situation (motivated by the
discussion at <#46553 (comment)>):
```julia
julia> function isa_kindtype(T::Type{<:AbstractVector})
if isa(T, DataType)
# `T` here should be inferred as `DataType` rather than `Type{<:AbstractVector}`
return T.name.name # should be inferred as ::Symbol
end
return nothing
end
isa_kindtype (generic function with 1 method)
julia> only(code_typed(isa_kindtype; optimize=false))
CodeInfo(
1 ─ %1 = (T isa Main.DataType)::Bool
└── goto #3 if not %1
2 ─ %3 = Base.getproperty(T, :name)::Any
│ %4 = Base.getproperty(%3, :name)::Any
└── return %4
3 ─ return Main.nothing
) => Any
```
This commit improves the situation by adding a special casing for
abstract interpretation, rather than changing the behavior of
`typeintersect`.isa-constraint propagation for iskindtype objects1 parent 9e8fb63 commit 3136189
File tree
2 files changed
+28
-7
lines changed- base/compiler
- test/compiler
2 files changed
+28
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1538 | 1538 | | |
1539 | 1539 | | |
1540 | 1540 | | |
| 1541 | + | |
| 1542 | + | |
| 1543 | + | |
| 1544 | + | |
1541 | 1545 | | |
1542 | 1546 | | |
1543 | 1547 | | |
| |||
2678 | 2682 | | |
2679 | 2683 | | |
2680 | 2684 | | |
2681 | | - | |
2682 | | - | |
2683 | | - | |
2684 | | - | |
2685 | | - | |
2686 | | - | |
| 2685 | + | |
| 2686 | + | |
| 2687 | + | |
| 2688 | + | |
| 2689 | + | |
| 2690 | + | |
| 2691 | + | |
| 2692 | + | |
| 2693 | + | |
2687 | 2694 | | |
2688 | | - | |
| 2695 | + | |
| 2696 | + | |
| 2697 | + | |
| 2698 | + | |
| 2699 | + | |
| 2700 | + | |
2689 | 2701 | | |
2690 | 2702 | | |
2691 | 2703 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4202 | 4202 | | |
4203 | 4203 | | |
4204 | 4204 | | |
| 4205 | + | |
| 4206 | + | |
| 4207 | + | |
| 4208 | + | |
| 4209 | + | |
| 4210 | + | |
| 4211 | + | |
| 4212 | + | |
| 4213 | + | |
0 commit comments