[inferbo] generalise `prune_comp` to `prune_binop`

Summary:
This exposes a more general interface to other modules, at the cost of
hiding the fact that it won't deal with all binary operations with equal
precision.

Reviewed By: ezgicicek

Differential Revision: D18908095

fbshipit-source-id: 0c0653bb6
master
Jules Villard 5 years ago committed by Facebook Github Bot
parent 6edf037659
commit fd9d963b1c

@ -189,8 +189,8 @@ module ArrInfo = struct
arr1
let prune_comp : Binop.t -> t -> t -> t =
fun c arr1 arr2 -> prune_offset arr1 arr2 ~f:(Itv.prune_comp c)
let prune_binop : Binop.t -> t -> t -> t =
fun c arr1 arr2 -> prune_offset arr1 arr2 ~f:(Itv.prune_binop c)
let prune_eq : t -> t -> t = fun arr1 arr2 -> prune_offset arr1 arr2 ~f:Itv.prune_eq
@ -378,7 +378,7 @@ let do_prune : (ArrInfo.t -> ArrInfo.t -> ArrInfo.t) -> t -> t -> t =
a1
let prune_comp : Binop.t -> t -> t -> t = fun c a1 a2 -> do_prune (ArrInfo.prune_comp c) a1 a2
let prune_binop : Binop.t -> t -> t -> t = fun c a1 a2 -> do_prune (ArrInfo.prune_binop c) a1 a2
let prune_eq : t -> t -> t = fun a1 a2 -> do_prune ArrInfo.prune_eq a1 a2

@ -49,9 +49,8 @@ val lift_cmp_itv : (Itv.t -> Itv.t -> Boolean.t) -> Boolean.EqualOrder.t -> t ->
val transform_length : f:(Itv.t -> Itv.t) -> t -> t
(** Apply [f] to all sizes *)
val prune_comp : Binop.t -> t -> t -> t
(** [prune_comp comp x y] returns a pruned value of [x] by [comp] and [y]. [comp] should be
[Binop.Le], [Ge], [Lt], or [Gt]. *)
val prune_binop : Binop.t -> t -> t -> t
(** [prune_binop bop x y] returns a pruned value of [x] by [bop] and [y]. *)
val prune_eq : t -> t -> t
(** [prune_eq x y] returns a pruned value of [x] by [== y]. *)

@ -432,8 +432,8 @@ module Val = struct
let prune_length_ge_one : t -> t = lift_prune_length1 Itv.prune_ge_one
let prune_comp : Binop.t -> t -> t -> t =
fun c -> lift_prune2 (Itv.prune_comp c) (ArrayBlk.prune_comp c)
let prune_binop : Binop.t -> t -> t -> t =
fun c -> lift_prune2 (Itv.prune_binop c) (ArrayBlk.prune_binop c)
let is_null : t -> bool =

@ -589,27 +589,27 @@ module Prune = struct
let gen_prune_alias_functions ~prune_alias_core integer_type_widths comp x e astate =
(* [val_prune_eq] is applied when the alias type is [AliasTarget.Eq]. *)
let val_prune_eq =
match comp with
| Binop.Lt | Binop.Gt | Binop.Le | Binop.Ge ->
Val.prune_comp comp
| Binop.Eq ->
match (comp : Binop.t) with
| Lt | Gt | Le | Ge ->
Val.prune_binop comp
| Eq ->
Val.prune_eq
| Binop.Ne ->
| Ne ->
Val.prune_ne
| _ ->
assert false
in
(* [val_prune_le] is applied when the alias type is [AliasTarget.Le]. *)
let val_prune_le =
match comp with
| Binop.Lt ->
match (comp : Binop.t) with
| Lt ->
(* when [alias_target <= alias_key < e], prune [alias_target] with [alias_target < e] *)
Some (Val.prune_comp comp)
| Binop.Le | Binop.Eq ->
Some (Val.prune_binop comp)
| Le | Eq ->
(* when [alias_target <= alias_key = e] or [alias_target <= alias_key <= e], prune
[alias_target] with [alias_target <= e] *)
Some (Val.prune_comp Binop.Le)
| Binop.Ne | Binop.Gt | Binop.Ge ->
Some (Val.prune_binop Le)
| Ne | Gt | Ge ->
(* when [alias_target <= alias_key != e], [alias_target <= alias_key > e] or [alias_target
<= alias_key >= e], no prune *)
None

@ -484,13 +484,13 @@ module ItvPure = struct
else
let x =
match c with
| Binop.Le ->
| Le ->
prune_le x y
| Binop.Ge ->
| Ge ->
prune_ge x y
| Binop.Lt ->
| Lt ->
prune_lt x y
| Binop.Gt ->
| Gt ->
prune_gt x y
| _ ->
assert false
@ -516,6 +516,33 @@ module ItvPure = struct
let prune_ge_one : t -> t bottom_lifted = fun x -> prune_comp Binop.Ge x one
let prune_binop : Binop.t -> t -> t -> t bottom_lifted =
fun bop x y ->
match bop with
| Lt | Gt | Le | Ge ->
prune_comp bop x y
| Eq ->
prune_eq x y
| Ne ->
prune_ne x y
| PlusA _
| PlusPI
| MinusA _
| MinusPI
| MinusPP
| Mult _
| Div
| Mod
| Shiftlt
| Shiftrt
| BAnd
| BXor
| BOr
| LAnd
| LOr ->
NonBottom x
let get_symbols : t -> SymbolSet.t =
fun (l, u) -> SymbolSet.union (Bound.get_symbols l) (Bound.get_symbols u)
@ -772,7 +799,7 @@ let prune_ne_zero : t -> t = bind1 ItvPure.prune_ne_zero
let prune_ge_one : t -> t = bind1 ItvPure.prune_ge_one
let prune_comp : Binop.t -> t -> t -> t = fun comp -> bind2 (ItvPure.prune_comp comp)
let prune_binop : Binop.t -> t -> t -> t = fun comp -> bind2 (ItvPure.prune_binop comp)
let prune_lt : t -> t -> t = lift2 ItvPure.prune_lt

@ -245,7 +245,7 @@ val prune_ne_zero : t -> t
val prune_ge_one : t -> t
val prune_comp : Binop.t -> t -> t -> t
val prune_binop : Binop.t -> t -> t -> t
val prune_eq : t -> t -> t

Loading…
Cancel
Save