diff --git a/lib/fuzz/src/path_filter.ml b/lib/fuzz/src/path_filter.ml index 61e5e252..c6fba971 100644 --- a/lib/fuzz/src/path_filter.ml +++ b/lib/fuzz/src/path_filter.ml @@ -125,13 +125,12 @@ let add_if (x : t) ~(when_ : bool) ~(add : t) : t = if when_ then x + add else x module Anchor_check = struct - type t = {is_nested: bool; pos: int; len: int; block_len: int} + type t = {is_nested: bool; span: Utils.My_list.Span.t; block_len: int} [@@deriving sexp] let of_path (path : Path.Stms.t) ~(block_len : int) : t = Path.Stms. - { pos= path.@(index) - ; len= len path + { span= {pos= path.@(index); len= len path} ; is_nested= is_nested path ; block_len } end @@ -140,8 +139,7 @@ let is_anchored (anc : Path_meta.Anchor.t) ~(check : Anchor_check.t) : bool = check.is_nested || Path_meta.Anchor.( incl_opt ~includes:anc - (of_dimensions ~index:check.pos ~len:check.len - ~block_len:check.block_len)) + (of_dimensions ~span:check.span ~block_len:check.block_len)) let check_anchor (anc : Path_meta.Anchor.t) ~(path : Path.Stms.t) ~(block_len : int) : unit Or_error.t = diff --git a/lib/fuzz/src/path_meta.ml b/lib/fuzz/src/path_meta.ml index 9bc54e9e..a338cfd2 100644 --- a/lib/fuzz/src/path_meta.ml +++ b/lib/fuzz/src/path_meta.ml @@ -74,10 +74,12 @@ module Anchor = struct let incl_opt ?(includes : t option) (x : t option) : bool = [%equal: t option] x (merge_opt x includes) - let of_dimensions ~(index : int) ~(len : int) ~(block_len : int) : t option - = - let top = Option.some_if (0 = index) Top in - let bot = Option.some_if (block_len <= index + len) Bottom in + let of_dimensions ~(span : Utils.My_list.Span.t) ~(block_len : int) : + t option = + let top = Option.some_if (0 = span.pos) Top in + let bot = + Option.some_if (block_len <= Utils.My_list.Span.end_pos span) Bottom + in merge_opt top bot end diff --git a/lib/fuzz/src/path_meta.mli b/lib/fuzz/src/path_meta.mli index 77acce7c..8c2eb4da 100644 --- a/lib/fuzz/src/path_meta.mli +++ b/lib/fuzz/src/path_meta.mli @@ -83,9 +83,9 @@ module Anchor : sig (** [merge_opt l r] merges two optional anchors, according to the lattice formed by [incl_opt]. *) - val of_dimensions : index:int -> len:int -> block_len:int -> t option - (** [of_dimensions ~index ~len ~block_len] determines the anchor, if any, - from the given dimensions. *) + val of_dimensions : span:Utils.My_list.Span.t -> block_len:int -> t option + (** [of_dimensions ~span ~block_len] determines the anchor, if any, from + the given dimensions. *) end (** {1 Metadata structures} *) diff --git a/lib/utils/src/my_list.ml b/lib/utils/src/my_list.ml index 15f80109..9b9bcdee 100644 --- a/lib/utils/src/my_list.ml +++ b/lib/utils/src/my_list.ml @@ -12,7 +12,9 @@ open Base module Span = struct - type t = {pos: int; len: int} + type t = {pos: int; len: int} [@@deriving sexp] + + let end_pos ({pos; len} : t) : int = pos + len end let find_at_most_one (type a b) ?(item_name : string = "item") diff --git a/lib/utils/src/my_list.mli b/lib/utils/src/my_list.mli index 148be340..db76a4d0 100644 --- a/lib/utils/src/my_list.mli +++ b/lib/utils/src/my_list.mli @@ -17,7 +17,10 @@ open Base module Span : sig (** A span, containing a position and length. *) - type t = {pos: int; len: int} + type t = {pos: int; len: int} [@@deriving sexp] + + val end_pos : t -> int + (** [end_pos] is the end position of the span: [pos + len]. *) end (** {1 Finding and transforming specific amounts of items} *)