Skip to content

Commit f33bef8

Browse files
committed
Separate rt/exct override in constprop
Currently, we cannot assume that the error type thrown from a concrete eval will be `:consistent`, so constprop often returns more precise rt information, but less precise exct information. To deal with the consider them separately, and only override exct if the constprop information was actually better.
1 parent 8a4e753 commit f33bef8

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

base/compiler/abstractinterpretation.jl

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,17 @@ function abstract_call_gf_by_type(interp::AbstractInterpreter, @nospecialize(f),
6969
if const_call_result !== nothing
7070
if const_call_result.rt ₚ rt
7171
rt = const_call_result.rt
72-
exct = const_call_result.exct
7372
(; effects, const_result, edge) = const_call_result
7473
elseif is_better_effects(const_call_result.effects, effects)
75-
exct = const_call_result.exct
7674
(; effects, const_result, edge) = const_call_result
77-
elseif !(exct ₚ const_call_result.exct)
75+
else
76+
add_remark!(interp, sv, "[constprop] Discarded because the result was wider than inference")
77+
end
78+
if !(exct ₚ const_call_result.exct)
7879
exct = const_call_result.exct
7980
(; const_result, edge) = const_call_result
8081
else
81-
add_remark!(interp, sv, "[constprop] Discarded because the result was wider than inference")
82+
add_remark!(interp, sv, "[constprop] Discarded exception type because result was wider than inference")
8283
end
8384
end
8485
all_effects = merge_effects(all_effects, effects)
@@ -123,16 +124,19 @@ function abstract_call_gf_by_type(interp::AbstractInterpreter, @nospecialize(f),
123124
# e.g. in cases when there are cycles but cached result is still accurate
124125
this_conditional = this_const_conditional
125126
this_rt = this_const_rt
126-
this_exct = const_call_result.exct
127127
(; effects, const_result, edge) = const_call_result
128128
elseif is_better_effects(const_call_result.effects, effects)
129-
this_exct = const_call_result.exct
130129
(; effects, const_result, edge) = const_call_result
131-
elseif !(this_exct ₚ const_call_result.exct)
130+
else
131+
add_remark!(interp, sv, "[constprop] Discarded because the result was wider than inference")
132+
end
133+
# Treat the exception type separately. Currently, constprop often cannot determine the exception type
134+
# because consistent-cy does not apply to exceptions.
135+
if !(this_exct ₚ const_call_result.exct)
132136
this_exct = const_call_result.exct
133137
(; const_result, edge) = const_call_result
134138
else
135-
add_remark!(interp, sv, "[constprop] Discarded because the result was wider than inference")
139+
add_remark!(interp, sv, "[constprop] Discarded exception type because result was wider than inference")
136140
end
137141
end
138142
all_effects = merge_effects(all_effects, effects)

0 commit comments

Comments
 (0)