Skip to content

Commit

Permalink
Merge branch 'development' into server/resetCache
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/context/typecore.ml
  • Loading branch information
Simn committed Feb 3, 2024
2 parents 9125590 + 2b0e8ce commit 4f248af
Show file tree
Hide file tree
Showing 125 changed files with 1,939 additions and 1,267 deletions.
2 changes: 1 addition & 1 deletion extra/BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ You need to install some native libraries as well as some OCaml libraries.
To install the native libraries, use the appropriate system package manager.

* Mac OS X
* Use [Homebrew](https://brew.sh/), `brew install zlib pcre2 mbedtls@2`.
* Use [Homebrew](https://brew.sh/), `brew install zlib pcre2 mbedtls`.
* Debian / Ubuntu
* `sudo apt install libpcre2-dev zlib1g-dev libmbedtls-dev`.
* Windows (Cygwin)
Expand Down
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
7 changes: 6 additions & 1 deletion src/codegen/gencommon/closuresToClass.ml
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,12 @@ let configure gen ft =
in

(*let cltypes = List.map (fun cl -> (snd cl.cl_path, TInst(map_param cl, []) )) tparams in*)
let cltypes = List.map (fun cl -> mk_type_param cl TPHType None None) tparams in
let cltypes = List.map (fun cl ->
let lol = cl.cl_kind in
let ttp = mk_type_param cl TPHType None None in
cl.cl_kind <- lol;
ttp
) tparams in

(* create a new class that extends abstract function class, with a ctor implementation that will setup all captured variables *)
let cfield = match gen.gcurrent_classfield with
Expand Down
4 changes: 1 addition & 3 deletions src/codegen/gencommon/gencommon.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1142,9 +1142,7 @@ let clone_param ttp =
let ret = mk_class cl.cl_module (fst cl.cl_path, snd cl.cl_path ^ "_c") cl.cl_pos null_pos in
ret.cl_implements <- cl.cl_implements;
ret.cl_kind <- cl.cl_kind;
let ttp = mk_type_param ret ttp.ttp_host ttp.ttp_default ttp.ttp_constraints in
ret.cl_kind <- KTypeParameter ttp;
ttp
mk_type_param ret ttp.ttp_host ttp.ttp_default ttp.ttp_constraints

let get_cl_t t =
match follow t with | TInst (cl,_) -> cl | _ -> die "" __LOC__
Expand Down
14 changes: 7 additions & 7 deletions src/compiler/args.ml
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ let parse_args com =
),"<name[=path]>","generate code for a custom target");
("Target",[],["-x"], Arg.String (fun cl ->
let cpath = Path.parse_type_path cl in
(match com.main_class with
(match com.main.main_class with
| Some c -> if cpath <> c then raise (Arg.Bad "Multiple --main classes specified")
| None -> com.main_class <- Some cpath);
| None -> com.main.main_class <- Some cpath);
actx.classes <- cpath :: actx.classes;
Common.define com Define.Interp;
set_platform com Eval "";
Expand All @@ -138,9 +138,9 @@ let parse_args com =
actx.hxb_libs <- lib :: actx.hxb_libs
),"<path>","add a hxb library");
("Compilation",["-m";"--main"],["-main"],Arg.String (fun cl ->
if com.main_class <> None then raise (Arg.Bad "Multiple --main classes specified");
if com.main.main_class <> None then raise (Arg.Bad "Multiple --main classes specified");
let cpath = Path.parse_type_path cl in
com.main_class <- Some cpath;
com.main.main_class <- Some cpath;
actx.classes <- cpath :: actx.classes
),"<class>","select startup class");
("Compilation",["-L";"--library"],["-lib"],Arg.String (fun _ -> ()),"<name[:ver]>","use a haxelib library");
Expand Down Expand Up @@ -278,9 +278,9 @@ let parse_args com =
("Services",["--json"],[],Arg.String (fun file ->
actx.json_out <- Some file
),"<file>","generate JSON types description");
("Services",["--hxb"],[], Arg.String (fun dir ->
actx.hxb_out <- Some dir;
),"<directory>", "generate haxe binary representation in target directory");
("Services",["--hxb"],[], Arg.String (fun file ->
actx.hxb_out <- Some file;
),"<file>", "generate haxe binary representation to target archive");
("Optimization",["--no-output"],[], Arg.Unit (fun() -> actx.no_output <- true),"","compiles but does not generate any file");
("Debug",["--times"],[], Arg.Unit (fun() -> Timer.measure_times := true),"","measure compilation times");
("Optimization",["--no-inline"],[],Arg.Unit (fun () ->
Expand Down
6 changes: 3 additions & 3 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 warn anon_identification hxb_writer_stats path m =
method cache_module config warn anon_identification hxb_writer_stats path m =
match m.m_extra.m_kind with
| MImport ->
Hashtbl.add modules m.m_path m
| _ ->
let writer = HxbWriter.create warn anon_identification hxb_writer_stats in
let writer = HxbWriter.create config warn anon_identification hxb_writer_stats in
HxbWriter.write_module writer m;
let chunks = HxbWriter.get_chunks writer in
Hashtbl.replace binary_cache path {
Expand Down Expand Up @@ -108,7 +108,7 @@ class context_cache (index : int) (sign : Digest.t) = object(self)

(* Pointers for memory inspection. *)
method get_pointers : unit array =
[|Obj.magic files;Obj.magic modules|]
[|Obj.magic files;Obj.magic modules;Obj.magic binary_cache|]
end

let create_directory path mtime = {
Expand Down
1 change: 1 addition & 0 deletions src/compiler/compilationContext.ml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ and compilation_context = {
mutable has_next : bool;
mutable has_error : bool;
comm : communication;
mutable runtime_args : string list;
}

type compilation_callbacks = {
Expand Down
19 changes: 15 additions & 4 deletions src/compiler/compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -336,15 +336,15 @@ let finalize_typing ctx tctx =
enter_stage com CFilteringStart;
ServerMessage.compiler_stage com;
let main, types, modules = run_or_diagnose ctx (fun () -> Finalization.generate tctx) in
com.main <- main;
com.main.main_expr <- main;
com.types <- types;
com.modules <- modules;
t()

let filter ctx tctx before_destruction =
let t = Timer.timer ["filters"] in
DeprecationCheck.run ctx.com;
run_or_diagnose ctx (fun () -> Filters.run tctx ctx.com.main before_destruction);
run_or_diagnose ctx (fun () -> Filters.run tctx ctx.com.main.main_expr before_destruction);
t()

let compile ctx actx callbacks =
Expand All @@ -369,6 +369,12 @@ let compile ctx actx callbacks =
callbacks.after_target_init ctx;
let t = Timer.timer ["init"] in
List.iter (fun f -> f()) (List.rev (actx.pre_compilation));
begin match actx.hxb_out with
| None ->
()
| Some file ->
com.hxb_writer_config <- HxbWriterConfig.process_argument file
end;
t();
enter_stage com CInitialized;
ServerMessage.compiler_stage com;
Expand All @@ -382,7 +388,11 @@ let compile ctx actx callbacks =
let is_compilation = is_compilation com in
com.callbacks#add_after_save (fun () ->
callbacks.after_save ctx;
if is_compilation then Generate.check_hxb_output ctx actx;
if is_compilation then match com.hxb_writer_config with
| Some config ->
Generate.check_hxb_output ctx config;
| None ->
()
);
if is_diagnostics com then
filter ctx tctx (fun () -> DisplayProcessing.handle_display_after_finalization ctx tctx display_file_dot_path)
Expand Down Expand Up @@ -509,6 +519,7 @@ let create_context comm cs compilation_step params = {
has_next = false;
has_error = false;
comm = comm;
runtime_args = [];
}

module HighLevel = struct
Expand Down Expand Up @@ -614,7 +625,7 @@ module HighLevel = struct
| "--run" :: cl :: args ->
let acc = cl :: "-x" :: acc in
let ctx = create_context (List.rev acc) in
ctx.com.sys_args <- args;
ctx.runtime_args <- args;
[],Some ctx
| ("-L" | "--library" | "-lib") :: name :: args ->
let libs,args = find_subsequent_libs [name] args in
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/displayProcessing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ let process_display_file com actx =
DPKNone
| DFPOnly when (DisplayPosition.display_position#get).pfile = file_input_marker ->
actx.classes <- [];
com.main_class <- None;
com.main.main_class <- None;
begin match com.file_contents with
| [_, Some input] ->
com.file_contents <- [];
Expand All @@ -154,7 +154,7 @@ let process_display_file com actx =
| dfp ->
if dfp = DFPOnly then begin
actx.classes <- [];
com.main_class <- None;
com.main.main_class <- None;
end;
let real = Path.get_real_path (DisplayPosition.display_position#get).pfile in
let path = match get_module_path_from_file_path com real with
Expand Down
56 changes: 36 additions & 20 deletions src/compiler/generate.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let check_auxiliary_output com actx =
Genjson.generate com.types file
end

let export_hxb com cc platform zip m =
let export_hxb com config cc platform zip m =
let open HxbData in
match m.m_extra.m_kind with
| MCode | MMacro | MFake | MExtern -> begin
Expand All @@ -42,7 +42,7 @@ let export_hxb com 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 warn anon_identification com.hxb_writer_stats in
let writer = HxbWriter.create config warn anon_identification com.hxb_writer_stats in
HxbWriter.write_module writer m;
let out = IO.output_string () in
HxbWriter.export writer out;
Expand All @@ -51,37 +51,46 @@ let export_hxb com cc platform zip m =
| _ ->
()

let check_hxb_output ctx actx =
let check_hxb_output ctx config =
let open HxbWriterConfig in
let com = ctx.com in
let try_write path =
let match_path_list l sl_path =
List.exists (fun sl -> Ast.match_path true sl_path sl) l
in
let try_write () =
let path = config.HxbWriterConfig.archive_path in
let path = Str.global_replace (Str.regexp "\\$target") (platform_name ctx.com.platform) path in
let t = Timer.timer ["generate";"hxb"] in
Path.mkdir_from_path path;
let zip = new Zip_output.zip_output path 6 in
let export com =
let export com config =
let cc = CommonCache.get_cache com in
let target = Common.platform_name_macro com in
List.iter (fun m ->
let t = Timer.timer ["generate";"hxb";s_type_path m.m_path] in
Std.finally t (export_hxb com cc target zip) m
let sl_path = fst m.m_path @ [snd m.m_path] in
if not (match_path_list config.exclude sl_path) || match_path_list config.include' sl_path then
Std.finally t (export_hxb com config cc target zip) m
) com.modules;
in
Std.finally (fun () ->
zip#close;
t()
) (fun () ->
export com;
Option.may export (com.get_macros());
if config.target_config.generate then
export com config.target_config;
begin match com.get_macros() with
| Some mcom when config.macro_config.generate ->
export mcom config.macro_config
| _ ->
()
end;
) ()
in
begin match actx.hxb_out with
| None ->
()
| Some path ->
try
try_write path
with Sys_error s ->
error ctx (Printf.sprintf "Could not write to %s: %s" path s) null_pos
end
try
try_write ()
with Sys_error s ->
CompilationContext.error ctx (Printf.sprintf "Could not write to %s: %s" config.archive_path s) null_pos

let parse_swf_header ctx h = match ExtString.String.nsplit h ":" with
| [width; height; fps] ->
Expand Down Expand Up @@ -121,9 +130,16 @@ let generate ctx tctx ext actx =
| Java when not actx.jvm_flag -> Path.mkdir_from_path (com.file ^ "/.")
| _ -> Path.mkdir_from_path com.file
end;
if actx.interp then
Std.finally (Timer.timer ["interp"]) MacroContext.interpret tctx
else begin
if actx.interp then begin
let timer = Timer.timer ["interp"] in
let old = tctx.com.args in
tctx.com.args <- ctx.runtime_args;
let restore () =
tctx.com.args <- old;
timer ()
in
Std.finally restore MacroContext.interpret tctx
end else begin
let generate,name = match com.platform with
| Flash ->
let header = try
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
35 changes: 21 additions & 14 deletions src/compiler/hxb/hxbWriter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ let create_field_writer_context pos_writer = {
}

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;
Expand Down Expand Up @@ -601,13 +602,18 @@ module HxbWriter = struct
Chunk.write_string writer.chunk mname;
Chunk.write_string writer.chunk tname

let write_documentation writer (doc : doc_block) =
Chunk.write_option writer.chunk doc.doc_own (fun s ->
Chunk.write_uleb128 writer.chunk (StringPool.get_or_add writer.docs s)
);
Chunk.write_list writer.chunk doc.doc_inherited (fun s ->
Chunk.write_uleb128 writer.chunk (StringPool.get_or_add writer.docs s)
)
let maybe_write_documentation writer (doc : doc_block option) =
match doc with
| Some doc when writer.config.generate_docs ->
Chunk.write_u8 writer.chunk 1;
Chunk.write_option writer.chunk doc.doc_own (fun s ->
Chunk.write_uleb128 writer.chunk (StringPool.get_or_add writer.docs s)
);
Chunk.write_list writer.chunk doc.doc_inherited (fun s ->
Chunk.write_uleb128 writer.chunk (StringPool.get_or_add writer.docs s)
)
| _ ->
Chunk.write_u8 writer.chunk 0

let write_pos writer (p : pos) =
Chunk.write_string writer.chunk p.pfile;
Expand Down Expand Up @@ -753,7 +759,7 @@ module HxbWriter = struct

and write_cfield writer cff =
write_placed_name writer cff.cff_name;
Chunk.write_option writer.chunk cff.cff_doc (write_documentation writer);
maybe_write_documentation writer cff.cff_doc;
write_pos writer cff.cff_pos;
write_metadata writer cff.cff_meta;
Chunk.write_list writer.chunk cff.cff_access (write_placed_access writer);
Expand Down Expand Up @@ -1829,7 +1835,7 @@ module HxbWriter = struct
let restore = start_temporary_chunk writer 512 in
write_type_instance writer cf.cf_type;
Chunk.write_uleb128 writer.chunk cf.cf_flags;
Chunk.write_option writer.chunk cf.cf_doc (write_documentation writer);
maybe_write_documentation writer cf.cf_doc;
write_metadata writer cf.cf_meta;
write_field_kind writer cf.cf_kind;
let expr_chunk = match cf.cf_expr with
Expand Down Expand Up @@ -1876,7 +1882,7 @@ module HxbWriter = struct

let write_common_module_type writer (infos : tinfos) : unit =
Chunk.write_bool writer.chunk infos.mt_private;
Chunk.write_option writer.chunk infos.mt_doc (write_documentation writer);
maybe_write_documentation writer infos.mt_doc;
write_metadata writer infos.mt_meta;
write_type_parameters_data writer infos.mt_params;
Chunk.write_list writer.chunk infos.mt_using (fun (c,p) ->
Expand Down Expand Up @@ -2141,7 +2147,7 @@ module HxbWriter = struct
let t_bytes = restore (fun new_chunk -> Chunk.get_bytes new_chunk) in
commit_field_type_parameters writer ef.ef_params;
Chunk.write_bytes writer.chunk t_bytes;
Chunk.write_option writer.chunk ef.ef_doc (write_documentation writer);
maybe_write_documentation writer ef.ef_doc;
write_metadata writer ef.ef_meta;
close();
);
Expand Down Expand Up @@ -2237,8 +2243,8 @@ module HxbWriter = struct
let deps = DynArray.create () in
PMap.iter (fun _ mdep ->
match mdep.md_kind with
| MCode | MExtern | MFake when mdep.md_sign = m.m_extra.m_sign ->
DynArray.add deps mdep.md_path;
| MCode | MExtern when mdep.md_sign = m.m_extra.m_sign ->
DynArray.add deps mdep.md_path;
| _ ->
()
) m.m_extra.m_deps;
Expand Down Expand Up @@ -2281,9 +2287,10 @@ module HxbWriter = struct
l
end

let create warn anon_id stats =
let create config warn anon_id stats =
let cp = StringPool.create () in
{
config;
warn;
anon_id;
stats;
Expand Down
Loading

0 comments on commit 4f248af

Please sign in to comment.