Reviewed By: ngorogiannis Differential Revision: D13164136 fbshipit-source-id: 7129e6ad7master
parent
72f6540893
commit
4860ab39a1
@ -0,0 +1,29 @@
|
||||
(*
|
||||
* Copyright (c) 2018-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*)
|
||||
|
||||
open! IStd
|
||||
|
||||
let rec compare_fields ox oy i =
|
||||
i < 0 || (phys_equal (Obj.field ox i) (Obj.field oy i) && compare_fields ox oy (i - 1))
|
||||
|
||||
|
||||
let shallow_compare x y =
|
||||
phys_equal x y
|
||||
||
|
||||
let ox = Obj.repr x in
|
||||
let oy = Obj.repr y in
|
||||
let tx = Obj.tag ox in
|
||||
let ty = Obj.tag oy in
|
||||
Int.equal tx ty && tx < Obj.no_scan_tag
|
||||
&&
|
||||
let sx = Obj.size ox in
|
||||
let sy = Obj.size oy in
|
||||
Int.equal sx sy && compare_fields ox oy (sx - 1)
|
||||
|
||||
|
||||
let optim2 ~res x1 x2 =
|
||||
if shallow_compare res x1 then x1 else if shallow_compare res x2 then x2 else res
|
@ -0,0 +1,27 @@
|
||||
(*
|
||||
* Copyright (c) 2018-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*)
|
||||
|
||||
open! IStd
|
||||
|
||||
(**
|
||||
Helpers function to enforce physical equality.
|
||||
|
||||
Let suppose [construct/deconstruct] is a 1-level-allocation OCaml construction/deconstruction,
|
||||
such as variant type, tuple or record construction.
|
||||
Instead of writing
|
||||
let a = deconstruct a0 in
|
||||
let b = deconstruct b0 in
|
||||
let res = f a b in
|
||||
if phys_equal res a then a0
|
||||
else if phys_equal res b then b0
|
||||
else construct res
|
||||
|
||||
Simply write
|
||||
PhysEqual.optim2 ~res:(construct (f a b)) a0 b0
|
||||
*)
|
||||
|
||||
val optim2 : res:'a -> 'a -> 'a -> 'a
|
Loading…
Reference in new issue