Skip to content

Commit fcf8315

Browse files
committed
remove magic number for cmj too
every time we bump the version, ast got to be rebuilt, trigger cmj rebuilt another protection: it will be removed
1 parent 4e741c4 commit fcf8315

8 files changed

+102
-187
lines changed

jscomp/core/js_cmj_format.ml

+3-17
Original file line numberDiff line numberDiff line change
@@ -72,47 +72,33 @@ let make
7272
}
7373

7474

75-
let verify_magic_in_beg ic =
76-
let buffer = really_input_string ic Ext_cmj_magic.cmj_magic_number_length in
77-
if buffer <> Ext_cmj_magic.cmj_magic_number then
78-
Ext_fmt.failwithf ~loc:__LOC__
79-
"cmj files have incompatible versions, please rebuilt using the new compiler : %s"
80-
__LOC__
8175

8276

8377
(* Serialization .. *)
8478
let from_file name : t =
8579
let ic = open_in_bin name in
86-
verify_magic_in_beg ic ;
8780
let _digest = Digest.input ic in
8881
let v : t = input_value ic in
8982
close_in ic ;
9083
v
9184

9285
let from_file_with_digest name : t * Digest.t =
9386
let ic = open_in_bin name in
94-
verify_magic_in_beg ic ;
9587
let digest = Digest.input ic in
9688
let v : t = input_value ic in
9789
close_in ic ;
9890
v,digest
9991

10092

10193
let from_string s : t =
102-
let magic_number = String.sub s 0 Ext_cmj_magic.cmj_magic_number_length in
103-
if magic_number = Ext_cmj_magic.cmj_magic_number then
104-
Marshal.from_string s Ext_cmj_magic.header_length
105-
else
106-
Ext_fmt.failwithf ~loc:__LOC__
107-
"cmj files have incompatible versions, please rebuilt using the new compiler : %s"
108-
__LOC__
94+
Marshal.from_string s Ext_digest.length
10995

11096

11197
let for_sure_not_changed (name : string) (header : string) =
11298
if Sys.file_exists name then
11399
let ic = open_in_bin name in
114100
let holder =
115-
really_input_string ic Ext_cmj_magic.header_length in
101+
really_input_string ic Ext_digest.length in
116102
close_in ic;
117103
holder = header
118104
else false
@@ -123,7 +109,7 @@ let for_sure_not_changed (name : string) (header : string) =
123109
let to_file name ~check_exists (v : t) =
124110
let s = Marshal.to_string v [] in
125111
let cur_digest = Digest.string s in
126-
let header = Ext_cmj_magic.cmj_magic_number ^ cur_digest in
112+
let header = cur_digest in
127113
if not (check_exists && for_sure_not_changed name header) then
128114
let oc = open_out_bin name in
129115
output_string oc header;

jscomp/ext/ext_cmj_magic.ml

-34
This file was deleted.

lib/4.06.1/unstable/js_compiler.ml

+35-27
Original file line numberDiff line numberDiff line change
@@ -95423,10 +95423,9 @@ let ffi_obj_create obj_params =
9542395423
let ffi_obj_as_prims obj_params =
9542495424
["";to_string (Ffi_obj_create obj_params)]
9542595425
end
95426-
module Ext_cmj_magic
95427-
= struct
95428-
#1 "ext_cmj_magic.ml"
95429-
(* Copyright (C) 2020 Authors of BuckleScript
95426+
module Ext_digest : sig
95427+
#1 "ext_digest.mli"
95428+
(* Copyright (C) 2019- Authors of BuckleScript
9543095429
*
9543195430
* This program is free software: you can redistribute it and/or modify
9543295431
* it under the terms of the GNU Lesser General Public License as published by
@@ -95451,16 +95450,39 @@ module Ext_cmj_magic
9545195450
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
9545295451

9545395452

95454-
let cmj_magic_number = "BUCKLE20200209"
95455-
let cmj_magic_number_length =
95456-
String.length cmj_magic_number
95457-
95453+
val length : int
9545895454

95455+
val hex_length : int
95456+
end = struct
95457+
#1 "ext_digest.ml"
95458+
(* Copyright (C) 2019- Authors of BuckleScript
95459+
*
95460+
* This program is free software: you can redistribute it and/or modify
95461+
* it under the terms of the GNU Lesser General Public License as published by
95462+
* the Free Software Foundation, either version 3 of the License, or
95463+
* (at your option) any later version.
95464+
*
95465+
* In addition to the permissions granted to you by the LGPL, you may combine
95466+
* or link a "work that uses the Library" with a publicly distributed version
95467+
* of this file to produce a combined library or application, then distribute
95468+
* that combined work under the terms of your choosing, with no requirement
95469+
* to comply with the obligations normally placed on you by section 4 of the
95470+
* LGPL version 3 (or the corresponding section of a later version of the LGPL
95471+
* should you choose to use a later version).
95472+
*
95473+
* This program is distributed in the hope that it will be useful,
95474+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
95475+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
95476+
* GNU Lesser General Public License for more details.
95477+
*
95478+
* You should have received a copy of the GNU Lesser General Public License
95479+
* along with this program; if not, write to the Free Software
95480+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
9545995481

95460-
let digest_length = 16 (*16 chars *)
9546195482

95462-
let header_length = cmj_magic_number_length + digest_length
95483+
let length = 16
9546395484

95485+
let hex_length = 32
9546495486
end
9546595487
module Lam_primitive : sig
9546695488
#1 "lam_primitive.mli"
@@ -97388,47 +97410,33 @@ let make
9738897410
}
9738997411

9739097412

97391-
let verify_magic_in_beg ic =
97392-
let buffer = really_input_string ic Ext_cmj_magic.cmj_magic_number_length in
97393-
if buffer <> Ext_cmj_magic.cmj_magic_number then
97394-
Ext_fmt.failwithf ~loc:__LOC__
97395-
"cmj files have incompatible versions, please rebuilt using the new compiler : %s"
97396-
__LOC__
9739797413

9739897414

9739997415
(* Serialization .. *)
9740097416
let from_file name : t =
9740197417
let ic = open_in_bin name in
97402-
verify_magic_in_beg ic ;
9740397418
let _digest = Digest.input ic in
9740497419
let v : t = input_value ic in
9740597420
close_in ic ;
9740697421
v
9740797422

9740897423
let from_file_with_digest name : t * Digest.t =
9740997424
let ic = open_in_bin name in
97410-
verify_magic_in_beg ic ;
9741197425
let digest = Digest.input ic in
9741297426
let v : t = input_value ic in
9741397427
close_in ic ;
9741497428
v,digest
9741597429

9741697430

9741797431
let from_string s : t =
97418-
let magic_number = String.sub s 0 Ext_cmj_magic.cmj_magic_number_length in
97419-
if magic_number = Ext_cmj_magic.cmj_magic_number then
97420-
Marshal.from_string s Ext_cmj_magic.header_length
97421-
else
97422-
Ext_fmt.failwithf ~loc:__LOC__
97423-
"cmj files have incompatible versions, please rebuilt using the new compiler : %s"
97424-
__LOC__
97432+
Marshal.from_string s Ext_digest.length
9742597433

9742697434

9742797435
let for_sure_not_changed (name : string) (header : string) =
9742897436
if Sys.file_exists name then
9742997437
let ic = open_in_bin name in
9743097438
let holder =
97431-
really_input_string ic Ext_cmj_magic.header_length in
97439+
really_input_string ic Ext_digest.length in
9743297440
close_in ic;
9743397441
holder = header
9743497442
else false
@@ -97439,7 +97447,7 @@ let for_sure_not_changed (name : string) (header : string) =
9743997447
let to_file name ~check_exists (v : t) =
9744097448
let s = Marshal.to_string v [] in
9744197449
let cur_digest = Digest.string s in
97442-
let header = Ext_cmj_magic.cmj_magic_number ^ cur_digest in
97450+
let header = cur_digest in
9744397451
if not (check_exists && for_sure_not_changed name header) then
9744497452
let oc = open_out_bin name in
9744597453
output_string oc header;

0 commit comments

Comments
 (0)