aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/src/beam_validator.erl
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2018-09-07 12:39:30 +0200
committerBjörn Gustavsson <[email protected]>2018-09-12 14:19:04 +0200
commite2a939dc4d23d75a0588722d0a08aef129b4c0be (patch)
tree3b664a9e1ea62100caf12fe1e0615773e9df4897 /lib/compiler/src/beam_validator.erl
parent0975c1e3fc4e05a9b4eb12ce91e240cdebc28d04 (diff)
downloadotp-e2a939dc4d23d75a0588722d0a08aef129b4c0be.tar.gz
otp-e2a939dc4d23d75a0588722d0a08aef129b4c0be.tar.bz2
otp-e2a939dc4d23d75a0588722d0a08aef129b4c0be.zip
beam_validator: Infer more types
When optimizations get more powerful, beam_validator must keep up.
Diffstat (limited to 'lib/compiler/src/beam_validator.erl')
-rw-r--r--lib/compiler/src/beam_validator.erl16
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/compiler/src/beam_validator.erl b/lib/compiler/src/beam_validator.erl
index 9fa55c5b4c..8d699f2abd 100644
--- a/lib/compiler/src/beam_validator.erl
+++ b/lib/compiler/src/beam_validator.erl
@@ -598,6 +598,14 @@ valfun_4({bif,is_map_key,{f,Fail},[_Key,Map]=Src,Dst}, Vst0) ->
Vst = set_type(map, Map, Vst1),
Type = propagate_fragility(bool, Src, Vst),
set_type_reg(Type, Dst, Vst);
+valfun_4({bif,Op,{f,Fail},[Cons]=Src,Dst}, Vst0)
+ when Op =:= hd; Op =:= tl ->
+ validate_src(Src, Vst0),
+ Vst1 = branch_state(Fail, Vst0),
+ Vst = set_type(cons, Cons, Vst1),
+ Type0 = bif_type(Op, Src, Vst),
+ Type = propagate_fragility(Type0, Src, Vst),
+ set_type_reg(Type, Dst, Vst);
valfun_4({bif,Op,{f,Fail},Src,Dst}, Vst0) ->
validate_src(Src, Vst0),
Vst = branch_state(Fail, Vst0),
@@ -610,7 +618,13 @@ valfun_4({gc_bif,Op,{f,Fail},Live,Src,Dst}, #vst{current=St0}=Vst0) ->
St = kill_heap_allocation(St0),
Vst1 = Vst0#vst{current=St},
Vst2 = branch_state(Fail, Vst1),
- Vst = prune_x_regs(Live, Vst2),
+ Vst3 = prune_x_regs(Live, Vst2),
+ Vst = case Op of
+ map_size ->
+ set_type(map, hd(Src), Vst3);
+ _ ->
+ Vst3
+ end,
validate_src(Src, Vst),
Type0 = bif_type(Op, Src, Vst),
Type = propagate_fragility(Type0, Src, Vst),