Skip to content

Commit 1775576

Browse files
committed
snapshot
1 parent 5daa9b1 commit 1775576

File tree

4 files changed

+99
-166
lines changed

4 files changed

+99
-166
lines changed

lib/4.06.1/bsb.ml

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12317,7 +12317,7 @@ let nl buf =
1231712317
- not readable
1231812318
*)
1231912319

12320-
let make_encoding length buf =
12320+
let make_encoding length buf : Ext_buffer.t -> int -> unit =
1232112321
let max_range = length lsl 1 + 1 in
1232212322
if max_range <= 0xff then begin
1232312323
Ext_buffer.add_char buf '1';
@@ -12340,44 +12340,46 @@ let make_encoding length buf =
1234012340
Strictly speaking, [tmp_buf1] is not needed
1234112341
*)
1234212342
let encode_single (db : Bsb_db.map) (buf : Ext_buffer.t) =
12343-
nl buf ; (* module name section *)
12343+
(* module name section *)
1234412344
let len = Map_string.cardinal db in
1234512345
Ext_buffer.add_string_char buf (string_of_int len) '\n';
12346-
let mapping = Hash_string.create 50 in
12347-
Map_string.iter db (fun name {dir} ->
12348-
Ext_buffer.add_string_char buf name '\n';
12349-
if not (Hash_string.mem mapping dir) then
12350-
Hash_string.add mapping dir (Hash_string.length mapping)
12351-
);
12352-
let length = Hash_string.length mapping in
12353-
let rev_mapping = Array.make length "" in
12354-
Hash_string.iter mapping (fun k i -> Array.unsafe_set rev_mapping i k);
12355-
(* directory name section *)
12356-
Ext_array.iter rev_mapping (fun s -> Ext_buffer.add_string_char buf s '\t');
12357-
nl buf; (* module name info section *)
12358-
let len_encoding = make_encoding length buf in
12359-
Map_string.iter db (fun _ module_info ->
12360-
len_encoding buf
12361-
(Hash_string.find_exn mapping module_info.dir lsl 1 + Obj.magic module_info.case ))
12362-
12346+
if len <> 0 then begin
12347+
let mapping = Hash_string.create 50 in
12348+
Map_string.iter db (fun name {dir} ->
12349+
Ext_buffer.add_string_char buf name '\n';
12350+
if not (Hash_string.mem mapping dir) then
12351+
Hash_string.add mapping dir (Hash_string.length mapping)
12352+
);
12353+
let length = Hash_string.length mapping in
12354+
let rev_mapping = Array.make length "" in
12355+
Hash_string.iter mapping (fun k i -> Array.unsafe_set rev_mapping i k);
12356+
(* directory name section *)
12357+
Ext_array.iter rev_mapping (fun s -> Ext_buffer.add_string_char buf s '\t');
12358+
nl buf; (* module name info section *)
12359+
let len_encoding = make_encoding length buf in
12360+
Map_string.iter db (fun _ module_info ->
12361+
len_encoding buf
12362+
(Hash_string.find_exn mapping module_info.dir lsl 1 + Obj.magic module_info.case ));
12363+
nl buf
12364+
end
1236312365
let encode (dbs : Bsb_db.t) buf =
1236412366
encode_single dbs.lib buf ;
1236512367
encode_single dbs.dev buf
12366-
(* Ext_buffer.add_char_string buf '\n' (string_of_int (Array.length dbs));
12367-
Ext_array.iter dbs (fun x -> encode_single x buf) *)
12368-
1236912368

12370-
(* TODO: shall we avoid writing such file (checking the digest) *)
12369+
12370+
(* shall we avoid writing such file (checking the digest)?
12371+
It is expensive to start scanning the whole code base,
12372+
we should we avoid it in the first place, if we do start scanning,
12373+
this operation seems affordable
12374+
*)
1237112375
let write_build_cache ~dir (bs_files : Bsb_db.t) : string =
1237212376
let oc = open_out_bin (Filename.concat dir bsbuild_cache) in
1237312377
let buf = Ext_buffer.create 100_000 in
1237412378
encode bs_files buf ;
12375-
let digest = Ext_buffer.digest buf in
12376-
let hex_digest = Digest.to_hex digest in
12377-
output_string oc digest;
1237812379
Ext_buffer.output_buffer oc buf;
1237912380
close_out oc;
12380-
hex_digest
12381+
let digest = Ext_buffer.digest buf in
12382+
Digest.to_hex digest
1238112383

1238212384
end
1238312385
module Ext_digest : sig

lib/4.06.1/bsb_helper.ml

Lines changed: 40 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,67 +1787,6 @@ let parse_exn (speclist : t) anonfun errmsg =
17871787
*)
17881788

17891789
end
1790-
module Ext_digest : sig
1791-
#1 "ext_digest.mli"
1792-
(* Copyright (C) 2019- Authors of BuckleScript
1793-
*
1794-
* This program is free software: you can redistribute it and/or modify
1795-
* it under the terms of the GNU Lesser General Public License as published by
1796-
* the Free Software Foundation, either version 3 of the License, or
1797-
* (at your option) any later version.
1798-
*
1799-
* In addition to the permissions granted to you by the LGPL, you may combine
1800-
* or link a "work that uses the Library" with a publicly distributed version
1801-
* of this file to produce a combined library or application, then distribute
1802-
* that combined work under the terms of your choosing, with no requirement
1803-
* to comply with the obligations normally placed on you by section 4 of the
1804-
* LGPL version 3 (or the corresponding section of a later version of the LGPL
1805-
* should you choose to use a later version).
1806-
*
1807-
* This program is distributed in the hope that it will be useful,
1808-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1809-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1810-
* GNU Lesser General Public License for more details.
1811-
*
1812-
* You should have received a copy of the GNU Lesser General Public License
1813-
* along with this program; if not, write to the Free Software
1814-
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
1815-
1816-
1817-
val length : int
1818-
1819-
val hex_length : int
1820-
end = struct
1821-
#1 "ext_digest.ml"
1822-
(* Copyright (C) 2019- Authors of BuckleScript
1823-
*
1824-
* This program is free software: you can redistribute it and/or modify
1825-
* it under the terms of the GNU Lesser General Public License as published by
1826-
* the Free Software Foundation, either version 3 of the License, or
1827-
* (at your option) any later version.
1828-
*
1829-
* In addition to the permissions granted to you by the LGPL, you may combine
1830-
* or link a "work that uses the Library" with a publicly distributed version
1831-
* of this file to produce a combined library or application, then distribute
1832-
* that combined work under the terms of your choosing, with no requirement
1833-
* to comply with the obligations normally placed on you by section 4 of the
1834-
* LGPL version 3 (or the corresponding section of a later version of the LGPL
1835-
* should you choose to use a later version).
1836-
*
1837-
* This program is distributed in the hope that it will be useful,
1838-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1839-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1840-
* GNU Lesser General Public License for more details.
1841-
*
1842-
* You should have received a copy of the GNU Lesser General Public License
1843-
* along with this program; if not, write to the Free Software
1844-
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
1845-
1846-
1847-
let length = 16
1848-
1849-
let hex_length = 32
1850-
end
18511790
module Ext_pervasives : sig
18521791
#1 "ext_pervasives.mli"
18531792
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -3304,19 +3243,7 @@ module Bsb_db_decode : sig
33043243

33053244
type t
33063245

3307-
type group = {
3308-
modules : string array ;
3309-
dir_length : int ;
3310-
dir_info_offset : int ;
3311-
module_info_offset : int ;
3312-
}
3313-
3314-
(* exposed only for testing *)
3315-
val decode_internal :
3316-
string ->
3317-
int ref ->
3318-
group array
3319-
3246+
type group
33203247

33213248

33223249
val read_build_cache :
@@ -3363,49 +3290,49 @@ end = struct
33633290
let bsbuild_cache = Literals.bsbuild_cache
33643291

33653292

3366-
type group = {
3367-
modules : string array ;
3368-
dir_length : int;
3369-
dir_info_offset : int ;
3370-
module_info_offset : int;
3371-
}
3293+
type group =
3294+
| Dummy
3295+
| Group of {
3296+
modules : string array ;
3297+
dir_length : int;
3298+
dir_info_offset : int ;
3299+
module_info_offset : int;
3300+
}
33723301

3373-
type t = group array * string (* string is whole content*)
3302+
type t = {
3303+
lib : group ;
3304+
dev : group ;
3305+
content : string (* string is whole content*)
3306+
}
33743307

33753308

33763309
type cursor = int ref
33773310

33783311

33793312
(*TODO: special case when module_count is zero *)
3380-
let rec decode_internal (x : string) (offset : cursor) =
3381-
(* let len = Ext_pervasives.parse_nat_of_string x offset in
3382-
incr offset; *)
3313+
let rec decode_internal (x : string) : t =
3314+
let (offset : cursor) = ref 0 in
33833315
let lib = decode_single x offset in
33843316
let dev = decode_single x offset in
3385-
[|lib;dev|]
3386-
(* if len = 1 then [|first|]
3387-
else
3388-
let result = Array.make len first in
3389-
for i = 1 to len - 1 do
3390-
Array.unsafe_set result i (decode_single x offset)
3391-
done ;
3392-
result
3393-
*)
3317+
{lib; dev; content = x}
3318+
33943319
and decode_single (x : string) (offset : cursor) : group =
33953320
let module_number = Ext_pervasives.parse_nat_of_string x offset in
33963321
incr offset;
3397-
let modules = decode_modules x offset module_number in
3398-
let dir_info_offset = !offset in
3399-
let module_info_offset =
3400-
String.index_from x dir_info_offset '\n' + 1 in
3401-
let dir_length = Char.code x.[module_info_offset] - 48 (* Char.code '0'*) in
3402-
offset :=
3403-
module_info_offset +
3404-
1 +
3405-
dir_length * module_number +
3406-
1
3322+
if module_number <> 0 then begin
3323+
let modules = decode_modules x offset module_number in
3324+
let dir_info_offset = !offset in
3325+
let module_info_offset =
3326+
String.index_from x dir_info_offset '\n' + 1 in
3327+
let dir_length = Char.code x.[module_info_offset] - 48 (* Char.code '0'*) in
3328+
offset :=
3329+
module_info_offset +
3330+
1 +
3331+
dir_length * module_number +
3332+
1
34073333
;
3408-
{ modules ; dir_info_offset; module_info_offset ; dir_length}
3334+
Group { modules ; dir_info_offset; module_info_offset ; dir_length}
3335+
end else Dummy
34093336
and decode_modules (x : string) (offset : cursor) module_number : string array =
34103337
let result = Array.make module_number "" in
34113338
let last = ref !offset in
@@ -3431,7 +3358,7 @@ and decode_modules (x : string) (offset : cursor) module_number : string array =
34313358
let read_build_cache ~dir : t =
34323359
let all_content =
34333360
Ext_io.load_file (Filename.concat dir bsbuild_cache) in
3434-
decode_internal all_content (ref (Ext_digest.length + 1)), all_content
3361+
decode_internal all_content
34353362

34363363

34373364

@@ -3442,11 +3369,13 @@ type module_info = {
34423369

34433370

34443371
let find_opt
3445-
((sorteds,whole) : t )
3446-
(i : int) (key : string)
3372+
({content = whole} as db : t )
3373+
lib (key : string)
34473374
: module_info option =
3448-
let group = sorteds.(i) in
3449-
let i = Ext_string_array.find_sorted group.modules key in
3375+
match if lib then db.lib else db.dev with
3376+
| Dummy -> None
3377+
| Group ({modules ;} as group) ->
3378+
let i = Ext_string_array.find_sorted modules key in
34503379
match i with
34513380
| None -> None
34523381
| Some count ->
@@ -3472,12 +3401,12 @@ let find_opt
34723401
Some {case ; dir_name = String.sub whole dir_name_start (dir_name_finish - dir_name_start)}
34733402

34743403
let find db dependent_module is_not_lib_dir =
3475-
let opt = find_opt db 0 dependent_module in
3404+
let opt = find_opt db true dependent_module in
34763405
match opt with
34773406
| Some _ -> opt
34783407
| None ->
34793408
if is_not_lib_dir then
3480-
find_opt db 1 dependent_module
3409+
find_opt db false dependent_module
34813410
else None
34823411
end
34833412
module Ext_filename : sig

lib/4.06.1/bsb_helper.ml.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
../lib/4.06.1/bsb_helper.ml: ./bsb_helper/bsb_db_decode.ml ./bsb_helper/bsb_db_decode.mli ./bsb_helper/bsb_helper_arg.ml ./bsb_helper/bsb_helper_arg.mli ./bsb_helper/bsb_helper_depfile_gen.ml ./bsb_helper/bsb_helper_depfile_gen.mli ./ext/ext_buffer.ml ./ext/ext_buffer.mli ./ext/ext_bytes.ml ./ext/ext_bytes.mli ./ext/ext_digest.ml ./ext/ext_digest.mli ./ext/ext_filename.ml ./ext/ext_filename.mli ./ext/ext_io.ml ./ext/ext_io.mli ./ext/ext_list.ml ./ext/ext_list.mli ./ext/ext_namespace_encode.ml ./ext/ext_namespace_encode.mli ./ext/ext_pervasives.ml ./ext/ext_pervasives.mli ./ext/ext_string.ml ./ext/ext_string.mli ./ext/ext_string_array.ml ./ext/ext_string_array.mli ./ext/literals.ml ./ext/literals.mli ./main/bsb_helper_main.ml ./main/bsb_helper_main.mli
1+
../lib/4.06.1/bsb_helper.ml: ./bsb_helper/bsb_db_decode.ml ./bsb_helper/bsb_db_decode.mli ./bsb_helper/bsb_helper_arg.ml ./bsb_helper/bsb_helper_arg.mli ./bsb_helper/bsb_helper_depfile_gen.ml ./bsb_helper/bsb_helper_depfile_gen.mli ./ext/ext_buffer.ml ./ext/ext_buffer.mli ./ext/ext_bytes.ml ./ext/ext_bytes.mli ./ext/ext_filename.ml ./ext/ext_filename.mli ./ext/ext_io.ml ./ext/ext_io.mli ./ext/ext_list.ml ./ext/ext_list.mli ./ext/ext_namespace_encode.ml ./ext/ext_namespace_encode.mli ./ext/ext_pervasives.ml ./ext/ext_pervasives.mli ./ext/ext_string.ml ./ext/ext_string.mli ./ext/ext_string_array.ml ./ext/ext_string_array.mli ./ext/literals.ml ./ext/literals.mli ./main/bsb_helper_main.ml ./main/bsb_helper_main.mli

lib/4.06.1/unstable/bsb_native.ml

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12466,7 +12466,7 @@ let nl buf =
1246612466
- not readable
1246712467
*)
1246812468

12469-
let make_encoding length buf =
12469+
let make_encoding length buf : Ext_buffer.t -> int -> unit =
1247012470
let max_range = length lsl 1 + 1 in
1247112471
if max_range <= 0xff then begin
1247212472
Ext_buffer.add_char buf '1';
@@ -12489,44 +12489,46 @@ let make_encoding length buf =
1248912489
Strictly speaking, [tmp_buf1] is not needed
1249012490
*)
1249112491
let encode_single (db : Bsb_db.map) (buf : Ext_buffer.t) =
12492-
nl buf ; (* module name section *)
12492+
(* module name section *)
1249312493
let len = Map_string.cardinal db in
1249412494
Ext_buffer.add_string_char buf (string_of_int len) '\n';
12495-
let mapping = Hash_string.create 50 in
12496-
Map_string.iter db (fun name {dir} ->
12497-
Ext_buffer.add_string_char buf name '\n';
12498-
if not (Hash_string.mem mapping dir) then
12499-
Hash_string.add mapping dir (Hash_string.length mapping)
12500-
);
12501-
let length = Hash_string.length mapping in
12502-
let rev_mapping = Array.make length "" in
12503-
Hash_string.iter mapping (fun k i -> Array.unsafe_set rev_mapping i k);
12504-
(* directory name section *)
12505-
Ext_array.iter rev_mapping (fun s -> Ext_buffer.add_string_char buf s '\t');
12506-
nl buf; (* module name info section *)
12507-
let len_encoding = make_encoding length buf in
12508-
Map_string.iter db (fun _ module_info ->
12509-
len_encoding buf
12510-
(Hash_string.find_exn mapping module_info.dir lsl 1 + Obj.magic module_info.case ))
12511-
12495+
if len <> 0 then begin
12496+
let mapping = Hash_string.create 50 in
12497+
Map_string.iter db (fun name {dir} ->
12498+
Ext_buffer.add_string_char buf name '\n';
12499+
if not (Hash_string.mem mapping dir) then
12500+
Hash_string.add mapping dir (Hash_string.length mapping)
12501+
);
12502+
let length = Hash_string.length mapping in
12503+
let rev_mapping = Array.make length "" in
12504+
Hash_string.iter mapping (fun k i -> Array.unsafe_set rev_mapping i k);
12505+
(* directory name section *)
12506+
Ext_array.iter rev_mapping (fun s -> Ext_buffer.add_string_char buf s '\t');
12507+
nl buf; (* module name info section *)
12508+
let len_encoding = make_encoding length buf in
12509+
Map_string.iter db (fun _ module_info ->
12510+
len_encoding buf
12511+
(Hash_string.find_exn mapping module_info.dir lsl 1 + Obj.magic module_info.case ));
12512+
nl buf
12513+
end
1251212514
let encode (dbs : Bsb_db.t) buf =
1251312515
encode_single dbs.lib buf ;
1251412516
encode_single dbs.dev buf
12515-
(* Ext_buffer.add_char_string buf '\n' (string_of_int (Array.length dbs));
12516-
Ext_array.iter dbs (fun x -> encode_single x buf) *)
12517-
1251812517

12519-
(* TODO: shall we avoid writing such file (checking the digest) *)
12518+
12519+
(* shall we avoid writing such file (checking the digest)?
12520+
It is expensive to start scanning the whole code base,
12521+
we should we avoid it in the first place, if we do start scanning,
12522+
this operation seems affordable
12523+
*)
1252012524
let write_build_cache ~dir (bs_files : Bsb_db.t) : string =
1252112525
let oc = open_out_bin (Filename.concat dir bsbuild_cache) in
1252212526
let buf = Ext_buffer.create 100_000 in
1252312527
encode bs_files buf ;
12524-
let digest = Ext_buffer.digest buf in
12525-
let hex_digest = Digest.to_hex digest in
12526-
output_string oc digest;
1252712528
Ext_buffer.output_buffer oc buf;
1252812529
close_out oc;
12529-
hex_digest
12530+
let digest = Ext_buffer.digest buf in
12531+
Digest.to_hex digest
1253012532

1253112533
end
1253212534
module Ext_digest : sig

0 commit comments

Comments
 (0)