Skip to content

Commit 3be6867

Browse files
committed
use interned string tag for better debugging
performance wise it is not that slow since it is interned key name is renamed RE_LAZY
1 parent 96f7b07 commit 3be6867

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

jscomp/stdlib-406/camlinternalLazy.ml

+9-10
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@
1616

1717
(* Internals of forcing lazy values. *)
1818
type 'a t = {
19-
mutable tag : int [@bs.as "tag"] ;
19+
mutable tag : string [@bs.as "RE_LAZY"] ;
2020
(* Invariant: name *)
21-
mutable value : 'a (* [@bs.as "val"] *)
22-
(* its type is ['a] or [unit -> 'a ] *)
21+
mutable value : 'a (* its type is ['a] or [unit -> 'a ] *)
2322
}
2423

2524

26-
let%private lazy_tag = 246
27-
let%private forward_tag = 250
25+
let%private status_todo = "todo" (* used to be lazy tag in native *)
26+
let%private status_done = "done" (* used to be forward_tag in native *)
2827
external%private magic : 'a -> 'b = "%identity"
2928
external%private fnToVal : (unit -> 'a [@bs]) -> 'a = "%identity"
3029
external%private valToFn : 'a -> (unit -> 'a [@bs]) = "%identity"
@@ -37,18 +36,18 @@ let%private lazy_boxed (type a) (l : a ) : bool =
3736
if Js.testAny l then false
3837
else
3938
let t = (magic l : _ t ).tag in
40-
t = forward_tag || t = lazy_tag
39+
t = status_done || t = status_todo
4140

4241
let is_val (type a ) (l : a lazy_t) : bool =
43-
Js.testAny l || ((castToConcrete l ).tag <> lazy_tag)
42+
Js.testAny l || ((castToConcrete l ).tag <> status_todo)
4443

4544
let from_fun (type arg ) f : arg lazy_t =
46-
castToLazy {tag = lazy_tag; value = fnToVal f}
45+
castToLazy {tag = status_todo; value = fnToVal f}
4746

4847

4948
let from_val (type arg ) (v : arg) : arg lazy_t=
5049
if lazy_boxed v then begin
51-
castToLazy {tag = forward_tag ; value = v}
50+
castToLazy {tag = status_done ; value = v}
5251
end else begin
5352
lazyBox v
5453
end
@@ -59,7 +58,7 @@ let%private forward_with_closure (type a ) (blk : a t) (closure : unit -> a [@bs
5958
let result = closure () [@bs] in
6059
(* do set_field BEFORE set_tag *)
6160
blk.value <- result;
62-
blk.tag<- forward_tag;
61+
blk.tag<- status_done;
6362
result
6463

6564

0 commit comments

Comments
 (0)