Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/compiler/hxb/hxbData.ml
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,23 @@ let error (s : string) =
Printf.eprintf "[error] %s\n" s;
raise (HxbFailure s)

let hxb_version = 1
(*
Major versions are incompatible with each other, while minor version mismatch
will be handled by the reader (for retro compatibility only)

When further bumping hxb major:
- all minor checks in hxb reader become obsolete and can be dropped
- (only when moving to 3.0) hxb_major checks in hxbReader can be removed
- (only when moving to 3.0) hxb_major check in HxbReader.read must be uncommented
*)
let hxb_major = 2
let hxb_minor = 0

let write_header ch =
IO.nwrite_string ch "hxb";
IO.write_byte ch hxb_version
IO.write_byte ch hxb_major;
IO.write_byte ch hxb_minor

let write_chunk_prefix kind length ch =
IO.nwrite ch (Bytes.unsafe_of_string (string_of_chunk_kind kind));
IO.write_real_i32 ch (Int32.of_int length)
IO.write_real_i32 ch (Int32.of_int length)
26 changes: 19 additions & 7 deletions src/compiler/hxb/hxbReader.ml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ class hxb_reader
= object(self)
val mutable api = Obj.magic ""
val mutable full_restore = true
val mutable hxb_major = HxbData.hxb_major (* can be removed once we move to version 3.0 *)
val mutable hxb_minor = HxbData.hxb_minor
val mutable current_module = null_module

val mutable ch = BytesWithPosition.create (Bytes.create 0)
Expand Down Expand Up @@ -1583,10 +1585,13 @@ class hxb_reader
a.a_write <- self#read_option (fun () -> self#read_field_ref);
a.a_call <- self#read_option (fun () -> self#read_field_ref);
a.a_constructor <- self#read_option (fun () -> self#read_field_ref);
a.a_default <- self#read_option (fun () ->
let fctx = self#start_texpr in
let e = self#read_texpr fctx in
Lazy.from_val e);
(* Note: this special case uses a hxb_major check, but all future checks should compare hxb_minor instead. *)
(* See https://github.com/HaxeFoundation/haxe/pull/12365 *)
if hxb_major >= 2 then
a.a_default <- self#read_option (fun () ->
let fctx = self#start_texpr in
let e = self#read_texpr fctx in
Lazy.from_val e);

a.a_ops <- self#read_list (fun () ->
let i = read_byte ch in
Expand Down Expand Up @@ -2113,9 +2118,16 @@ class hxb_reader
ch <- BytesWithPosition.create bytes;
if (Bytes.to_string (read_bytes ch 3)) <> "hxb" then
raise (HxbFailure "magic");
let version = read_byte ch in
if version <> hxb_version then
raise (HxbFailure (Printf.sprintf "version mismatch: hxb version %i, reader version %i" version hxb_version));

hxb_major <- read_byte ch;
hxb_minor <- if hxb_major == 1 then 0 else read_byte ch; (* minor version was only added in 2.0 *)

(* Disabled for retro compatibility with haxe 5.0-preview.1 *)
(* Must be uncommented when we move to hxb version 3.0 *)
(* See https://github.com/HaxeFoundation/haxe/pull/12365 *)
(* if hxb_major <> HxbData.hxb_major || hxb_minor > HxbData.hxb_minor then *)
(* raise (HxbFailure (Printf.sprintf "version mismatch: hxb version %i.%i, reader version %i.%i" major hxb_minor HxbData.hxb_major HxbData.hxb_minor)); *)

(fun end_chunk ->
let rec loop () =
let (name,size) = self#read_chunk_prefix in
Expand Down
17 changes: 13 additions & 4 deletions src/compiler/hxb/hxbWriterConfig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ type writer_target_config = {
mutable generate : bool;
mutable exclude : string list list;
mutable include' : string list list;
mutable hxb_version : int;
mutable hxb_major : int;
mutable hxb_minor : int;
mutable generate_docs : bool;
}

Expand All @@ -19,7 +20,8 @@ let create_target_config () = {
generate = true;
exclude = [];
include'= [];
hxb_version = HxbData.hxb_version;
hxb_major = HxbData.hxb_major;
hxb_minor = HxbData.hxb_minor;
generate_docs = true;
}

Expand Down Expand Up @@ -47,7 +49,12 @@ module WriterConfigReader (API : DataReaderApi.DataReaderApi) = struct
config.include'<- List.map (fun data -> ExtString.String.nsplit (API.read_string data) ".") l
)
| "hxbVersion" ->
config.hxb_version <- API.read_int data
config.hxb_major <- API.read_int data;
config.hxb_minor <- 0
| "hxbMajor" ->
config.hxb_major <- API.read_int data
| "hxbMinor" ->
config.hxb_minor <- API.read_int data
| "generateDocumentation" ->
config.generate_docs <- API.read_bool data
| s ->
Expand Down Expand Up @@ -80,7 +87,9 @@ module WriterConfigWriter (API : DataWriterApi.DataWriterApi) = struct
"generate",API.write_bool config.generate;
"exclude",API.write_array (List.map (fun sl -> API.write_string (String.concat "." sl)) config.exclude);
"include",API.write_array (List.map (fun sl -> API.write_string (String.concat "." sl)) config.include');
"hxbVersion",API.write_int config.hxb_version;
"hxbVersion",API.write_int config.hxb_major;
"hxbMajor",API.write_int config.hxb_major;
"hxbMinor",API.write_int config.hxb_minor;
"generateDocumentation",API.write_bool config.generate_docs;
]

Expand Down
Loading