Skip to content

Commit 94cc996

Browse files
authored
inference: propagate more LimitedAccuracy information (#59187)
According to Jameson's comment, we should propagate `LimitedAccuracy` information not only when we actually use the type information of variables that are `LimitedAccuracy`, but also when we perform computations involving variables that are `LimitedAccuracy`. This commit implements that propagation in relation to #59182.
1 parent 9808816 commit 94cc996

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

Compiler/src/typelattice.jl

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@
88
# inside the global code cache.
99
import Core: Const, InterConditional, PartialStruct
1010

11+
function may_form_limited_typ(@nospecialize(aty), @nospecialize(bty), @nospecialize(xty))
12+
if aty isa LimitedAccuracy
13+
if bty isa LimitedAccuracy
14+
return LimitedAccuracy(xty, union!(copy(aty.causes), bty.causes))
15+
else
16+
return LimitedAccuracy(xty, copy(aty.causes))
17+
end
18+
elseif bty isa LimitedAccuracy
19+
return LimitedAccuracy(xty, copy(bty.causes))
20+
end
21+
return nothing
22+
end
23+
1124
"""
1225
cnd::Conditional
1326
@@ -40,9 +53,8 @@ struct Conditional
4053
isdefined::Bool=false)
4154
assert_nested_slotwrapper(thentype)
4255
assert_nested_slotwrapper(elsetype)
43-
if thentype isa LimitedAccuracy || elsetype isa LimitedAccuracy
44-
return Bool
45-
end
56+
limited = may_form_limited_typ(thentype, elsetype, Bool)
57+
limited !== nothing && return limited
4658
return new(slot, thentype, elsetype, isdefined)
4759
end
4860
end
@@ -86,9 +98,8 @@ struct MustAlias
8698
assert_nested_slotwrapper(fldtyp)
8799
# @assert !isalreadyconst(vartyp) "vartyp is already const"
88100
# @assert !isalreadyconst(fldtyp) "fldtyp is already const"
89-
if vartyp isa LimitedAccuracy || fldtyp isa LimitedAccuracy
90-
return fldtyp
91-
end
101+
limited = may_form_limited_typ(vartyp, fldtyp, fldtyp)
102+
limited !== nothing && return limited
92103
return new(slot, vartyp, fldidx, fldtyp)
93104
end
94105
end
@@ -110,9 +121,8 @@ struct InterMustAlias
110121
assert_nested_slotwrapper(fldtyp)
111122
# @assert !isalreadyconst(vartyp) "vartyp is already const"
112123
# @assert !isalreadyconst(fldtyp) "fldtyp is already const"
113-
if vartyp isa LimitedAccuracy || fldtyp isa LimitedAccuracy
114-
return fldtyp
115-
end
124+
limited = may_form_limited_typ(vartyp, fldtyp, fldtyp)
125+
limited !== nothing && return limited
116126
return new(slot, vartyp, fldidx, fldtyp)
117127
end
118128
end

0 commit comments

Comments
 (0)