Skip to content

Commit

Permalink
Fix regression introduced in #420
Browse files Browse the repository at this point in the history
On base buffers (strings, cstruct), updates are idempotent, e.g. it is fine
if two concurrent branches make the same update.
  • Loading branch information
samoht committed Mar 22, 2017
1 parent a15fa0e commit 7f842e7
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/ir_contents.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,27 @@

open Lwt.Infix

let merge_state dt =
let (=) = Ir_type.equal dt in
let default = Ir_merge.default dt in
let f ~old x y =
if x = y then Ir_merge.ok x
else Ir_merge.f default ~old x y
in
Ir_merge.v dt f

module String = struct
type t = string
let t = Ir_type.string
let merge = Ir_merge.default Ir_type.(option string)
let merge = merge_state Ir_type.(option string)
let pp = Fmt.string
let of_string s = Ok s
end

module Cstruct = struct
type t = Cstruct.t
let t = Ir_type.(like string) (fun x -> Cstruct.of_string x) Cstruct.to_string
let merge = Ir_merge.default Ir_type.(option t)
let t = Ir_type.cstruct
let merge = merge_state Ir_type.(option t)
let pp = Ir_type.dump t
let of_string s = Ok (Cstruct.of_string s)
end
Expand Down

1 comment on commit 7f842e7

@kayceesrk
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

Please sign in to comment.