diff options
author | John Högberg <[email protected]> | 2019-01-17 14:45:55 +0100 |
---|---|---|
committer | John Högberg <[email protected]> | 2019-01-21 07:51:06 +0100 |
commit | 53b46c186051e256a4238f4c4b75e3dcbf61a1b0 (patch) | |
tree | d6521712017053fe23fd07c19c257d4c64d144be /lib/compiler/src | |
parent | 2d96971a96868d70a750422788d1493a5cbed605 (diff) | |
download | otp-53b46c186051e256a4238f4c4b75e3dcbf61a1b0.tar.gz otp-53b46c186051e256a4238f4c4b75e3dcbf61a1b0.tar.bz2 otp-53b46c186051e256a4238f4c4b75e3dcbf61a1b0.zip |
beam_ssa_type: Fix type subtraction in #b_switch{}
A switch is equivalent to a series of '=:=', so we have to subtract
each value individually from the type. Subtracting a join risks
removing too much type information, and managed to narrow "number"
into "float" in the attached test case.
Diffstat (limited to 'lib/compiler/src')
-rw-r--r-- | lib/compiler/src/beam_ssa_type.erl | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/compiler/src/beam_ssa_type.erl b/lib/compiler/src/beam_ssa_type.erl index 7ef49fee64..fcfb7b86f6 100644 --- a/lib/compiler/src/beam_ssa_type.erl +++ b/lib/compiler/src/beam_ssa_type.erl @@ -478,7 +478,9 @@ update_successors(#b_switch{arg=#b_var{}=V,fail=Fail,list=List}, Ts0, D0) -> end, foldl(F, D, List); false -> - FailTs = subtract_types([{V,join_sw_list(List, Ts0, none)}], Ts0), + %% V can not be equal to any of the values in List at the fail + %% block. + FailTs = subtract_sw_list(V, List, Ts0), D = update_successor(Fail, FailTs, D0), F = fun({Val,S}, A) -> T = get_type(Val, Ts0), @@ -488,9 +490,14 @@ update_successors(#b_switch{arg=#b_var{}=V,fail=Fail,list=List}, Ts0, D0) -> end; update_successors(#b_ret{}, _Ts, D) -> D. -join_sw_list([{Val,_}|T], Ts, Type) -> - join_sw_list(T, Ts, join(Type, get_type(Val, Ts))); -join_sw_list([], _, Type) -> Type. +subtract_sw_list(V, List, Ts) -> + Ts#{ V := sub_sw_list_1(get_type(V, Ts), List, Ts) }. + +sub_sw_list_1(Type, [{Val,_}|T], Ts) -> + ValType = get_type(Val, Ts), + sub_sw_list_1(subtract(Type, ValType), T, Ts); +sub_sw_list_1(Type, [], _Ts) -> + Type. update_successor_bool(#b_var{}=Var, BoolValue, S, Ts, D) -> case t_is_boolean(get_type(Var, Ts)) of |