Skip to content

Commit e180e35

Browse files
authored
Merge pull request #4404 from BuckleScript/precise_field_info
precise & complete meta field info
2 parents 13344b8 + 64a5f0c commit e180e35

24 files changed

+992
-716
lines changed

jscomp/core/js_of_lam_block.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ let field (field_info : Lam_compat.field_dbg_info) e i =
5656
| Fld_poly_var_content
5757
| Fld_record_inline _
5858
| Fld_variant
59+
| Fld_array
5960
->
6061
E.array_index_by_int
6162
?comment:(Lam_compat.str_of_field_info field_info) e i

jscomp/core/lam_compat.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,11 @@ type field_dbg_info = Lambda.field_dbg_info =
171171
| Fld_poly_var_content
172172
| Fld_extension
173173
| Fld_variant
174-
174+
| Fld_array
175175
let str_of_field_info (x : field_dbg_info) : string option =
176176
match x with
177-
| Fld_na s -> Some s
177+
| Fld_na s -> if s = "" then None else Some s
178+
| Fld_array
178179
| Fld_extension
179180
| Fld_variant
180181
| Fld_poly_var_tag

jscomp/core/lam_compat.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ type field_dbg_info = Lambda.field_dbg_info =
8080
| Fld_poly_var_content
8181
| Fld_extension
8282
| Fld_variant
83+
| Fld_array
8384

8485
val str_of_field_info :
8586
field_dbg_info ->

jscomp/main/builtin_cmi_datasets.ml

Lines changed: 125 additions & 127 deletions
Large diffs are not rendered by default.

jscomp/main/builtin_cmj_datasets.ml

Lines changed: 9 additions & 11 deletions
Large diffs are not rendered by default.

jscomp/runtime/bs_stdlib_mini.mli

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ external not : bool -> bool = "%boolnot"
4141

4242
external raise : exn -> 'a = "%raise"
4343
external ignore : 'a -> unit = "%ignore"
44-
external fst : 'a * 'b -> 'a = "%field0"
45-
external snd : 'a * 'b -> 'b = "%field1"
4644
external ( |> ) : 'a -> ('a -> 'b) -> 'b = "%revapply"
4745
external ( @@ ) : ('a -> 'b) -> 'a -> 'b = "%apply"
4846

@@ -61,6 +59,7 @@ module Obj : sig
6159
(* The compiler ensures (|0) operation *)
6260
external set_tag : t -> int -> unit = "tag" [@@bs.set]
6361
external repr : 'a -> t = "%identity"
62+
external obj : t -> 'a = "%identity"
6463
external magic : 'a -> 'b = "%identity"
6564
external size : t -> int = "#obj_length"
6665
end

jscomp/runtime/caml_hash.ml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ let unsafe_pop (q : 'a t) =
7979
external ( +~ ) : nativeint -> nativeint -> nativeint =
8080
"caml_int32_add"
8181

82-
(*ATTENTION: refer {!Oo.id} *)
83-
external oo_id : Obj.t -> int = "%field1"
8482

8583
open Caml_hash_primitive
8684

@@ -134,7 +132,8 @@ let caml_hash (count : int) _limit (seed : nativeint)
134132
let obj_tag = Obj.tag obj in
135133
let tag = (size lsl 10) lor obj_tag in
136134
if tag = 248 (* Obj.object_tag*) then
137-
hash.contents <- caml_hash_mix_int hash.contents (Caml_nativeint_extern.of_int (oo_id obj))
135+
hash.contents <- caml_hash_mix_int hash.contents
136+
(Caml_nativeint_extern.of_int (Obj.obj (Obj.field obj 1) : int))
138137
else
139138
begin
140139
hash.contents <- caml_hash_mix_int hash.contents (Caml_nativeint_extern.of_int tag) ;

jscomp/runtime/caml_int64.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,8 +522,8 @@ let float_of_bits (Int64 x : t) : float =
522522
Float64_array.unsafe_get (Float64_array.fromBuffer (Int32_array.buffer int32)) 0 *)
523523

524524
let bits_of_float : float -> t = fun x ->
525-
let buf = ([%raw{|function(x){return new Int32Array(new Float64Array([x]).buffer)}|}] : _ -> _) x in
526-
mk ~lo:(fst buf) ~hi:(snd buf)
525+
let lo,hi = ([%raw{|function(x){return new Int32Array(new Float64Array([x]).buffer)}|}] : _ -> _) x in
526+
mk ~lo ~hi
527527
(* let to_nat (x : int32) = x |> Caml_int32_extern.to_int |> Caml_nativeint_extern.of_int in
528528
529529
let u = Float64_array.make [| x |] in

jscomp/runtime/caml_oo.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ let caml_methods_cache =
4646
Caml_array_extern.make 1000 0
4747

4848
(* refer to {!CamlinternalOO.create_obj_opt}*)
49-
external get_methods : obj -> closure array =
50-
"%field0"
49+
50+
5151

5252
(* see #251
5353
{[
@@ -71,7 +71,7 @@ let caml_get_public_method
7171
(obj : obj)
7272
(tag : int) (cacheid : int) : closure =
7373
let module Array = Caml_array_extern in
74-
let meths = get_methods obj in (* the first field of object is mehods *)
74+
let meths : closure array = Obj.obj (Obj.field (Obj.repr obj) 0) in (* the first field of object is mehods *)
7575
let offs = caml_methods_cache.(cacheid) in
7676
if (Obj.magic meths.(offs) : int) = tag then meths.(offs - 1)
7777
else

jscomp/runtime/caml_option.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

25-
let undefinedHeader = [| |]
25+
let undefinedHeader = [| |]
2626

2727
let some ( x : Obj.t) : Obj.t =
2828
if Obj.magic x = None then
2929
(let block = Obj.repr (undefinedHeader, 0) in
3030
Obj.set_tag block 256;
3131
block)
3232
else
33-
if x != Obj.repr Js.null && fst (Obj.magic x ) == Obj.repr undefinedHeader then
33+
if x != Obj.repr Js.null && match (Obj.magic x ) with (x,_) -> x == Obj.repr undefinedHeader then
3434
(
35-
let nid = snd (Obj.magic x) + 1 in
35+
let nid = match (Obj.magic x) with (_,x) -> x + 1 in
3636
let block = Obj.repr (undefinedHeader, nid) in
3737
Obj.set_tag block 256;
3838
block
@@ -60,11 +60,11 @@ let null_to_opt (type t ) ( x : t Js.null) : t option =
6060
(** The input is already of [Some] form, [x] is not None,
6161
make sure [x[0]] will not throw *)
6262
let valFromOption (x : Obj.t) : Obj.t =
63-
if x != Obj.repr Js.null && fst (Obj.magic x) == Obj.repr undefinedHeader
63+
if x != Obj.repr Js.null && match (Obj.magic x) with (x,_) -> x == Obj.repr undefinedHeader
6464
then
65-
let depth : int = snd (Obj.magic x) in
65+
(match (Obj.magic x) with (_, (depth : int)) ->
6666
if depth = 0 then Obj.magic None
67-
else Obj.magic (undefinedHeader, depth - 1)
67+
else Obj.magic (undefinedHeader, depth - 1))
6868
else Obj.magic x
6969

7070

0 commit comments

Comments
 (0)