Skip to content

Commit

Permalink
Merge branch 'development' into server/resetCache
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/compiler/server.ml
#	src/context/typecore.ml
  • Loading branch information
Simn committed Feb 5, 2024
2 parents 4f248af + a10790a commit 7d7ecee
Show file tree
Hide file tree
Showing 62 changed files with 635 additions and 858 deletions.
7 changes: 0 additions & 7 deletions src-json/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -295,13 +295,6 @@
"targets": ["TAbstract"],
"links": ["https://haxe.org/manual/types-abstract-enum.html"]
},
{
"name": "EnumConstructorParam",
"metadata": ":enumConstructorParam",
"doc": "Used internally to annotate GADT type parameters.",
"targets": ["TClass"],
"internal": true
},
{
"name": "Event",
"metadata": ":event",
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/gencommon/normalize.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ open Gencommon

let rec filter_param (stack:t list) t =
match t with
| TInst({ cl_kind = KTypeParameter _ } as c,_) when Meta.has Meta.EnumConstructorParam c.cl_meta ->
| TInst({ cl_kind = KTypeParameter ttp },_) when ttp.ttp_host = TPHEnumConstructor ->
t_dynamic
| TMono r ->
(match r.tm_type with
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
4 changes: 2 additions & 2 deletions src/compiler/displayProcessing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,15 @@ let load_display_file_standalone (ctx : Typecore.typer) file =
let dir = ExtString.String.join (if path.backslash then "\\" else "/") parts in
com.class_paths#add (new ClassPath.directory_class_path dir User)
end;
ignore(TypeloadModule.type_module ctx (pack,name) file ~dont_check_path:true decls null_pos)
ignore(TypeloadModule.type_module ctx.com ctx.g (pack,name) file ~dont_check_path:true decls null_pos)

let load_display_content_standalone (ctx : Typecore.typer) input =
let com = ctx.com in
let file = file_input_marker in
let p = {pfile = file; pmin = 0; pmax = 0} in
let parsed = TypeloadParse.parse_file_from_string com file p input in
let pack,decls = TypeloadParse.handle_parser_result com p parsed in
ignore(TypeloadModule.type_module ctx (pack,"?DISPLAY") file ~dont_check_path:true decls p)
ignore(TypeloadModule.type_module ctx.com ctx.g (pack,"?DISPLAY") file ~dont_check_path:true decls p)

(* 4. Display processing before typing *)

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
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
Loading

0 comments on commit 7d7ecee

Please sign in to comment.