Skip to content

Commit

Permalink
Merge branch 'development' into out_of_curiosity
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/codegen/gencommon/closuresToClass.ml
#	src/codegen/gencommon/gencommon.ml
#	src/filters/filters.ml
#	src/typing/typeloadFields.ml
#	src/typing/typeloadModule.ml
#	src/typing/typer.ml
#	tests/misc/projects/Issue10844/user-defined-define-json-fail.hxml.stderr
#	tests/misc/projects/Issue10844/user-defined-meta-json-fail.hxml.stderr
#	tests/misc/projects/Issue10844/user-defined-meta-json-indent-fail.hxml.stderr
#	tests/misc/projects/Issue10844/user-defined-meta-json-pretty-fail.hxml.stderr
  • Loading branch information
Simn committed Feb 4, 2024
2 parents a107fa6 + c55da75 commit f439aeb
Show file tree
Hide file tree
Showing 68 changed files with 865 additions and 1,095 deletions.
1 change: 1 addition & 0 deletions extra/release-checklist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- Update https://github.com/HaxeFoundation/haxe.org/blob/staging/downloads/versions.json
- Wait for staging to update, check everything related to release and merge to master
- Update https://github.com/HaxeFoundation/api.haxe.org/blob/master/theme/templates/topbar.mtt
- Update https://github.com/HaxeFoundation/code-cookbook/blob/master/assets/content/index.mtt#L62-L63

# Cleanup

Expand Down
4 changes: 2 additions & 2 deletions src/compiler/compilationCache.ml
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ class context_cache (index : int) (sign : Digest.t) = object(self)
method find_module_extra path =
try (Hashtbl.find modules path).m_extra with Not_found -> (Hashtbl.find binary_cache path).mc_extra

method cache_module config warn anon_identification hxb_writer_stats path m =
method cache_module config warn anon_identification path m =
match m.m_extra.m_kind with
| MImport ->
Hashtbl.add modules m.m_path m
| _ ->
let writer = HxbWriter.create config warn anon_identification hxb_writer_stats in
let writer = HxbWriter.create config warn anon_identification in
HxbWriter.write_module writer m;
let chunks = HxbWriter.get_chunks writer in
Hashtbl.replace binary_cache path {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/generate.ml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ let export_hxb com config cc platform zip m =
with Not_found ->
let anon_identification = new tanon_identification in
let warn w s p = com.Common.warning w com.warning_options s p in
let writer = HxbWriter.create config warn anon_identification com.hxb_writer_stats in
let writer = HxbWriter.create config warn anon_identification in
HxbWriter.write_module writer m;
let out = IO.output_string () in
HxbWriter.export writer out;
Expand Down
4 changes: 1 addition & 3 deletions src/compiler/hxb/hxbReader.ml
Original file line number Diff line number Diff line change
Expand Up @@ -899,9 +899,7 @@ class hxb_reader
| i -> die (Printf.sprintf "Invalid type paramter host: %i" i) __LOC__
in
let c = mk_class current_module path pos pos in
let ttp = mk_type_param c host None None in
c.cl_kind <- KTypeParameter ttp;
ttp
mk_type_param c host None None
)

method read_type_parameters_data (a : typed_type_param array) =
Expand Down
83 changes: 5 additions & 78 deletions src/compiler/hxb/hxbWriter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -45,63 +45,6 @@ let unop_index op flag = match op,flag with
| NegBits,Postfix -> 10
| Spread,Postfix -> 11

type hxb_writer_stats = {
type_instance_kind_writes : int array;
texpr_writes : int array;
type_instance_immediate : int ref;
type_instance_cache_hits : int ref;
type_instance_cache_misses : int ref;
pos_writes_full : int ref;
pos_writes_min : int ref;
pos_writes_max : int ref;
pos_writes_minmax : int ref;
pos_writes_eq : int ref;
chunk_sizes : (string,int ref * int ref) Hashtbl.t;
}

let create_hxb_writer_stats () = {
type_instance_kind_writes = Array.make 255 0;
texpr_writes = Array.make 255 0;
type_instance_immediate = ref 0;
type_instance_cache_hits = ref 0;
type_instance_cache_misses = ref 0;
pos_writes_full = ref 0;
pos_writes_min = ref 0;
pos_writes_max = ref 0;
pos_writes_minmax = ref 0;
pos_writes_eq = ref 0;
chunk_sizes = Hashtbl.create 0;
}

let dump_stats name stats =
let sort_and_filter_array a =
let _,kind_writes = Array.fold_left (fun (index,acc) writes ->
(index + 1,if writes = 0 then acc else (index,writes) :: acc)
) (0,[]) a in
let kind_writes = List.sort (fun (_,writes1) (_,writes2) -> compare writes2 writes1) kind_writes in
List.map (fun (index,writes) -> Printf.sprintf " %3i: %9i" index writes) kind_writes
in
let t_kind_writes = sort_and_filter_array stats.type_instance_kind_writes in
print_endline (Printf.sprintf "hxb_writer stats for %s" name);
print_endline " type instance kind writes:";
List.iter print_endline t_kind_writes;
let texpr_writes = sort_and_filter_array stats.texpr_writes in
print_endline " texpr writes:";
List.iter print_endline texpr_writes;

print_endline " type instance writes:";
print_endline (Printf.sprintf " immediate: %9i" !(stats.type_instance_immediate));
print_endline (Printf.sprintf " cache hits: %9i" !(stats.type_instance_cache_hits));
print_endline (Printf.sprintf " cache miss: %9i" !(stats.type_instance_cache_misses));
print_endline " pos writes:";
print_endline (Printf.sprintf " full: %9i\n min: %9i\n max: %9i\n minmax: %9i\n equal: %9i" !(stats.pos_writes_full) !(stats.pos_writes_min) !(stats.pos_writes_max) !(stats.pos_writes_minmax) !(stats.pos_writes_eq));
(* let chunk_sizes = Hashtbl.fold (fun name (imin,imax) acc -> (name,!imin,!imax) :: acc) stats.chunk_sizes [] in
let chunk_sizes = List.sort (fun (_,imin1,imax1) (_,imin2,imax2) -> compare imax1 imax2) chunk_sizes in
print_endline "chunk sizes:";
List.iter (fun (name,imin,imax) ->
print_endline (Printf.sprintf " %s: %i - %i" name imin imax)
) chunk_sizes *)

module StringHashtbl = Hashtbl.Make(struct
type t = string

Expand Down Expand Up @@ -400,17 +343,10 @@ module Chunk = struct
let write_bool io b =
write_u8 io (if b then 1 else 0)

let export : 'a . hxb_writer_stats -> t -> 'a IO.output -> unit = fun stats io chex ->
let export : 'a . t -> 'a IO.output -> unit = fun io chex ->
let bytes = get_bytes io in
let length = Bytes.length bytes in
write_chunk_prefix io.kind length chex;
(* begin try
let (imin,imax) = Hashtbl.find stats.chunk_sizes io.name in
if length < !imin then imin := length;
if length > !imax then imax := length
with Not_found ->
Hashtbl.add stats.chunk_sizes io.name (ref length,ref length);
end; *)
IO.nwrite chex bytes

let write_string chunk s =
Expand Down Expand Up @@ -438,22 +374,19 @@ end

module PosWriter = struct
type t = {
stats : hxb_writer_stats;
mutable p_file : string;
mutable p_min : int;
mutable p_max : int;
}

let do_write_pos (chunk : Chunk.t) (p : pos) =
(* incr stats.pos_writes_full; *)
Chunk.write_string chunk p.pfile;
Chunk.write_leb128 chunk p.pmin;
Chunk.write_leb128 chunk p.pmax

let create stats chunk p =
let create chunk p =
do_write_pos chunk p;
{
stats;
p_file = p.pfile;
p_min = p.pmin;
p_max = p.pmax;
Expand All @@ -470,27 +403,23 @@ module PosWriter = struct
end else if p.pmin <> pw.p_min then begin
if p.pmax <> pw.p_max then begin
(* pmin and pmax changed *)
(* incr stats.pos_writes_minmax; *)
Chunk.write_u8 chunk (3 + offset);
Chunk.write_leb128 chunk p.pmin;
Chunk.write_leb128 chunk p.pmax;
pw.p_min <- p.pmin;
pw.p_max <- p.pmax;
end else begin
(* pmin changed *)
(* incr stats.pos_writes_min; *)
Chunk.write_u8 chunk (1 + offset);
Chunk.write_leb128 chunk p.pmin;
pw.p_min <- p.pmin;
end
end else if p.pmax <> pw.p_max then begin
(* pmax changed *)
(* incr stats.pos_writes_max; *)
Chunk.write_u8 chunk (2 + offset);
Chunk.write_leb128 chunk p.pmax;
pw.p_max <- p.pmax;
end else begin
(* incr stats.pos_writes_eq; *)
if write_equal then
Chunk.write_u8 chunk offset;
end
Expand All @@ -514,7 +443,6 @@ type hxb_writer = {
config : HxbWriterConfig.writer_target_config;
warn : Warning.warning -> string -> Globals.pos -> unit;
anon_id : Type.t Tanon_identification.tanon_identification;
stats : hxb_writer_stats;
mutable current_module : module_def;
chunks : Chunk.t DynArray.t;
cp : StringPool.t;
Expand Down Expand Up @@ -1794,7 +1722,7 @@ module HxbWriter = struct

and start_texpr writer (p: pos) =
let restore = start_temporary_chunk writer 512 in
let fctx = create_field_writer_context (PosWriter.create writer.stats writer.chunk p) in
let fctx = create_field_writer_context (PosWriter.create writer.chunk p) in
fctx,(fun () ->
restore(fun new_chunk ->
let restore = start_temporary_chunk writer 512 in
Expand Down Expand Up @@ -2287,13 +2215,12 @@ module HxbWriter = struct
l
end

let create config warn anon_id stats =
let create config warn anon_id =
let cp = StringPool.create () in
{
config;
warn;
anon_id;
stats;
current_module = null_module;
chunks = DynArray.create ();
cp = cp;
Expand Down Expand Up @@ -2333,5 +2260,5 @@ let export : 'a . hxb_writer -> 'a IO.output -> unit = fun writer ch ->
write_header ch;
let l = HxbWriter.get_sorted_chunks writer in
List.iter (fun io ->
Chunk.export writer.stats io ch
Chunk.export io ch
) l
15 changes: 13 additions & 2 deletions src/compiler/server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -923,8 +923,19 @@ and init_wait_socket ip port =
end
in
let read = fun _ -> (let s = read_loop 0 in Unix.clear_nonblock sin; Some s) in
let write s = ssend sin (Bytes.unsafe_of_string s) in
let close() = Unix.close sin in
let closed = ref false in
let close() =
if not !closed then begin
try Unix.close sin with Unix.Unix_error _ -> trace "Error while closing socket.";
closed := true;
end
in
let write s =
if not !closed then
match Unix.getsockopt_error sin with
| Some _ -> close()
| None -> ssend sin (Bytes.unsafe_of_string s);
in
false, read, write, close
) in
accept
8 changes: 4 additions & 4 deletions src/context/abstractCast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ let rec make_static_call ctx c cf a pl args t p =
match args with
| [e] ->
let e,f = push_this ctx e in
ctx.with_type_stack <- (WithType.with_type t) :: ctx.with_type_stack;
ctx.e.with_type_stack <- (WithType.with_type t) :: ctx.e.with_type_stack;
let e = match ctx.g.do_macro ctx MExpr c.cl_path cf.cf_name [e] p with
| MSuccess e -> type_expr ctx e (WithType.with_type t)
| _ -> type_expr ctx (EConst (Ident "null"),p) WithType.value
in
ctx.with_type_stack <- List.tl ctx.with_type_stack;
ctx.e.with_type_stack <- List.tl ctx.e.with_type_stack;
let e = try cast_or_unify_raise ctx t e p with Error { err_message = Unify _ } -> raise Not_found in
f();
e
Expand All @@ -40,7 +40,7 @@ and do_check_cast ctx uctx tleft eright p =
raise_error_msg (Unify l) eright.epos)
| _ -> ()
end;
if cf == ctx.curfield || rec_stack_memq cf cast_stack then raise_typing_error "Recursive implicit cast" p;
if cf == ctx.f.curfield || rec_stack_memq cf cast_stack then raise_typing_error "Recursive implicit cast" p;
rec_stack_loop cast_stack cf f ()
in
let make (a,tl,(tcf,cf)) =
Expand Down Expand Up @@ -118,7 +118,7 @@ and cast_or_unify ctx tleft eright p =
eright

let prepare_array_access_field ctx a pl cf p =
let monos = List.map (fun _ -> spawn_monomorph ctx p) cf.cf_params in
let monos = List.map (fun _ -> spawn_monomorph ctx.e p) cf.cf_params in
let map t = apply_params a.a_params pl (apply_params cf.cf_params monos t) in
let check_constraints () =
List.iter2 (fun m ttp -> match get_constraints ttp with
Expand Down
3 changes: 0 additions & 3 deletions src/context/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,6 @@ type context = {
mutable basic : basic_types;
memory_marker : float array;
hxb_reader_stats : HxbReader.hxb_reader_stats;
hxb_writer_stats : HxbWriter.hxb_writer_stats;
mutable hxb_writer_config : HxbWriterConfig.t option;
}

Expand Down Expand Up @@ -844,7 +843,6 @@ let create compilation_step cs version args display_mode =
report_mode = RMNone;
is_macro_context = false;
hxb_reader_stats = HxbReader.create_hxb_reader_stats ();
hxb_writer_stats = HxbWriter.create_hxb_writer_stats ();
hxb_writer_config = None;
} in
com
Expand Down Expand Up @@ -896,7 +894,6 @@ let clone com is_macro_context =
overload_cache = new hashtbl_lookup;
module_lut = new module_lut;
hxb_reader_stats = HxbReader.create_hxb_reader_stats ();
hxb_writer_stats = HxbWriter.create_hxb_writer_stats ();
std = null_class;
empty_class_path = new ClassPath.directory_class_path "" User;
class_paths = new ClassPaths.class_paths;
Expand Down
3 changes: 1 addition & 2 deletions src/context/commonCache.ml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ let rec cache_context cs com =
(* If we have a signature mismatch, look-up cache for module. Physical equality check is fine as a heueristic. *)
let cc = if m.m_extra.m_sign = sign then cc else cs#get_context m.m_extra.m_sign in
let warn w s p = com.warning w com.warning_options s p in
cc#cache_module config warn anon_identification com.hxb_writer_stats m.m_path m;
cc#cache_module config warn anon_identification m.m_path m;
in
List.iter cache_module com.modules;
begin match com.get_macros() with
Expand All @@ -104,7 +104,6 @@ let rec cache_context cs com =
end;
if Define.raw_defined com.defines "hxb.stats" then begin
HxbReader.dump_stats (platform_name com.platform) com.hxb_reader_stats;
HxbWriter.dump_stats (platform_name com.platform) com.hxb_writer_stats
end

let maybe_add_context_sign cs com desc =
Expand Down
2 changes: 1 addition & 1 deletion src/context/display/displayEmitter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ let check_display_type ctx t ptp =
ctx.g.type_hints <- (ctx.m.curmod.m_extra.m_display,ptp.pos_full,t) :: ctx.g.type_hints;
in
let maybe_display_type () =
if ctx.is_display_file && display_position#enclosed_in ptp.pos_full then
if ctx.m.is_display_file && display_position#enclosed_in ptp.pos_full then
display_type ctx t ptp.pos_path
in
add_type_hint();
Expand Down
10 changes: 5 additions & 5 deletions src/context/display/displayFields.ml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ let collect_static_extensions ctx items e p =
let rec dup t = Type.map dup t in
let handle_field c f acc =
let f = { f with cf_type = opt_type f.cf_type } in
let monos = List.map (fun _ -> spawn_monomorph ctx p) f.cf_params in
let monos = List.map (fun _ -> spawn_monomorph ctx.e p) f.cf_params in
let map = apply_params f.cf_params monos in
match follow (map f.cf_type) with
| TFun((_,_,TType({t_path=["haxe";"macro"], "ExprOf"}, [t])) :: args, ret)
Expand Down Expand Up @@ -112,7 +112,7 @@ let collect ctx e_ast e dk with_type p =
let opt_args args ret = TFun(List.map(fun (n,o,t) -> n,true,t) args,ret) in
let should_access c cf stat =
if Meta.has Meta.NoCompletion cf.cf_meta then false
else if c != ctx.curclass && not (has_class_field_flag cf CfPublic) && String.length cf.cf_name > 4 then begin match String.sub cf.cf_name 0 4 with
else if c != ctx.c.curclass && not (has_class_field_flag cf CfPublic) && String.length cf.cf_name > 4 then begin match String.sub cf.cf_name 0 4 with
| "get_" | "set_" -> false
| _ -> can_access ctx c cf stat
end else
Expand Down Expand Up @@ -402,17 +402,17 @@ let handle_missing_field_raise ctx tthis i mode with_type pfield =
display.module_diagnostics <- MissingFields diag :: display.module_diagnostics

let handle_missing_ident ctx i mode with_type p =
match ctx.curfun with
match ctx.e.curfun with
| FunStatic ->
let e_self = Texpr.Builder.make_static_this ctx.curclass p in
let e_self = Texpr.Builder.make_static_this ctx.c.curclass p in
begin try
handle_missing_field_raise ctx e_self.etype i mode with_type p
with Exit ->
()
end
| _ ->
begin try
handle_missing_field_raise ctx ctx.tthis i mode with_type p
handle_missing_field_raise ctx ctx.c.tthis i mode with_type p
with Exit ->
()
end
1 change: 0 additions & 1 deletion src/context/display/displayPath.ml
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ let resolve_position_by_path ctx path p =
let p = (t_infos mt).mt_pos in
raise_positions [p]


let handle_path_display ctx path p =
let class_field c name =
ignore(c.cl_build());
Expand Down
Loading

0 comments on commit f439aeb

Please sign in to comment.