Skip to content
Open
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
(*
With the exception of 1.0 => 2.x because we introduced minor version in 2.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:
- code related to the 1.0 => 2.0 exception can be dropped (`if major == 1 then 2 else major` in `HxbReader.read`)
- all minor checks in hxb reader become obsolete and can be dropped too
*)
let hxb_major = 2
let hxb_minor = 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this start at 0?

Copy link
Contributor Author

@kLabz kLabz Sep 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hack for retro compatibility with preview1 is to consider preview1 to be 2.0 (instead of 1.0) so that we're back to comparing minor versions

So here we'd start with 2.1 for the 12351 change

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why do we check the minor version in the first place?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but then why not check hxb_major >= 2 for this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would work (well it wouldn't with current impl) too, but for the next changes we'll always want to check minor versions, never major (if the major version didn't match we wouldn't be in hxb reader in the first place).
I figured I'd use that same behavior from the beginning

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kind of get what you're saying, but this is completely internal and invisible. I'd find it more natural to go from version 1.0 (implied) to 2.0 instead of 2.1, and that's actually visible.


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)
22 changes: 15 additions & 7 deletions src/compiler/hxb/hxbReader.ml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class hxb_reader
= object(self)
val mutable api = Obj.magic ""
val mutable full_restore = true
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 +1584,11 @@ 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);
if hxb_minor >= 1 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 +2115,15 @@ 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));

(* Note: as minor version was only added in 2.1, version "1" is now considered to be "2.0" *)
(* Still displaying it as "1.0" in version mismatch error, hence `major` vs `hxb_major` vars *)
let major = read_byte ch in
hxb_minor <- if major == 1 then 0 else read_byte ch;
let hxb_major = if major == 1 then 2 else major in
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
2 changes: 0 additions & 2 deletions src/core/ds/atomicLazy.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
open Atomic

type 'a t = {
mutable value: 'a option;
mutex: Mutex.t;
Expand Down
1 change: 0 additions & 1 deletion src/filters/exception/exceptionInit.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ open Exceptions
open Type
open Typecore
open ExceptionFunctions
open AtomicLazy

let create_exception_context tctx =
match tctx.com.platform with (* TODO: implement for all targets *)
Expand Down
1 change: 0 additions & 1 deletion src/filters/exception/exceptions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ open Type
open PlatformConfig
open Error
open ExceptionFunctions
open AtomicLazy

type context = {
scom : SafeCom.t;
Expand Down
1 change: 0 additions & 1 deletion src/filters/exception/saveStacks.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ open Type
open Error
open ExceptionFunctions
open Exceptions
open AtomicLazy

(**
Inserts `haxe.NativeStackTrace.saveStack(e)` in non-haxe.Exception catches.
Expand Down
1 change: 0 additions & 1 deletion src/generators/genhl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ open Type
open Error
open Gctx
open Hlcode
open Semver

(* compiler *)

Expand Down
Loading