Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hxb #11266

Closed
wants to merge 83 commits into from
Closed

Hxb #11266

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
13d45de
2023
Simn Apr 11, 2023
715bfd0
Revive hxb output
kLabz May 18, 2023
9333288
[hxb] POC loader; currently chokes on Any, StdTypes, ArrayKeyValueIte…
kLabz May 18, 2023
4353f45
[hxb] use Meta.from_string to avoid double colon
kLabz May 19, 2023
aa1d262
[hxb] improve loading
kLabz May 19, 2023
5492a8b
[hxb] simplify logging
kLabz May 19, 2023
88aeeae
WIP don't push
kLabz May 31, 2023
19e6922
WIP don't push
kLabz May 31, 2023
5e0b9db
Progress
kLabz Jun 2, 2023
7c96d88
WIP
kLabz Jun 5, 2023
af45dbe
WIP - fields not working yet
kLabz Jun 8, 2023
4ec4653
WIP - typedef path issue
kLabz Jun 9, 2023
9bf1577
Save current state before reworking type/field refs
kLabz Jun 14, 2023
c51f438
[hxb] fix a_status tdefs, implement enum fields, improve debug printing
kLabz Jun 16, 2023
bbddcf7
[hxb] read TTry
kLabz Jun 16, 2023
b61a098
clean up a bit
kLabz Jun 16, 2023
7119bbb
[hxb] fix TCast(e,Some md)
kLabz Jun 16, 2023
2394c1b
[hxb] reenable doc
kLabz Jun 16, 2023
3bdf46a
[hxb] write hxb before filters to keep extern fields
kLabz Jun 16, 2023
3db71a3
[hxb] more cleanup / debug data
kLabz Jun 16, 2023
6908387
[hxb] anons / anon fields mostly working
kLabz Jun 23, 2023
6645fe4
[hxb] read/write for expr and various TODOs
kLabz Jun 27, 2023
cc21cac
[hxb] load hxb files from -bcp arg
kLabz Jun 28, 2023
4648fa3
[hxb] fix unops
kLabz Jun 28, 2023
9655a2d
[hxb] fix anon field reading
kLabz Jun 28, 2023
c788709
[hxb] write on after_save callback
kLabz Jun 29, 2023
dba0498
[hxb] modules should be considered as cached
kLabz Jun 29, 2023
d7c93b4
[hxb] fix enum.e_type
kLabz Jun 29, 2023
8ac7607
[hxb] write/read cl_init too
kLabz Jun 29, 2023
a11f7c9
[hxb] separate hxb output from json/xml output to run them at differe…
kLabz Jun 29, 2023
d6fd491
[hxb] cleanup
kLabz Jun 29, 2023
b7a5182
remove unused null_tvar
kLabz Jul 4, 2023
2ddc8ff
[hxb] handle more type parameter cases
kLabz Jul 4, 2023
a8f0d70
[hxb] restore function tvoid optimization
kLabz Jul 4, 2023
117fce1
[hxb] export/load macro context too
kLabz Jul 6, 2023
7dfdc97
[tests] disable tests failing with hxb
kLabz Jul 10, 2023
0fb02fe
[hxb] temp fix (import has not working currently)
kLabz Jul 10, 2023
434266f
[hxb] generate for MFake modules too
kLabz Jul 10, 2023
23e0d42
[tests] enable more tests
kLabz Jul 10, 2023
827dfb8
[hxb] module level fields
kLabz Jul 10, 2023
70b2fce
[tests] reenable some module level fields tests
kLabz Jul 10, 2023
26d6760
[hxb] unit tests hxml files
kLabz Jul 11, 2023
f9067d6
[hxb] don't abort on unbound type parameters
kLabz Jul 11, 2023
4df537a
run hxb tests only for now
Simn Jul 11, 2023
9f70eb4
less CI things
Simn Jul 11, 2023
8f3d276
[hxb] clean abstract fields a bit
kLabz Jul 11, 2023
af3d26c
[ci] less stuff on mac
kLabz Jul 11, 2023
26d7593
[hxb] clean field ref reading
kLabz Jul 11, 2023
018be4e
start working on local type parameters
Simn Jul 11, 2023
8f12268
handle local type parameters differently
Simn Jul 12, 2023
fb658e7
[awkward] deal with new TypeParam
Simn Jul 12, 2023
a5ce741
[hxb] catch not found errors
kLabz Jul 12, 2023
325bc4c
[tests] restore some tests
kLabz Jul 12, 2023
43c2b30
[tests] update disabled tests
kLabz Jul 12, 2023
7cdbab3
[tests] restore more tests
kLabz Jul 12, 2023
033e4b4
[hxb] naive resolution of KExpr
kLabz Jul 12, 2023
3b7f13c
[hxb] @:const type parameters
kLabz Jul 12, 2023
902fef6
[hxb] fix CTIntersection
kLabz Jul 12, 2023
f467a5d
[hxb] fix gadt
kLabz Jul 12, 2023
2d902b5
[tests] restore TestMain
kLabz Jul 12, 2023
768693a
keep module as instance variable
Simn Jul 13, 2023
5576e20
actually handle local type parameters locally
Simn Jul 13, 2023
3c6c0b4
[hxb] adjust debug, work on unbound type params
kLabz Jul 14, 2023
fcac54c
adjust to development changes
Simn Jul 14, 2023
aeaf67b
[hxb] carry local params in anons
kLabz Jul 14, 2023
8644990
Revert "[hxb] carry local params in anons"
kLabz Jul 14, 2023
529936c
[hxb] only write annd once
kLabz Jul 18, 2023
2605908
[hxb] no idea what that thing was there for
kLabz Jul 18, 2023
ab9a260
forward declare all local type parameters
Simn Jul 20, 2023
4c01062
use identity pool for anon fields too
Simn Jul 20, 2023
0097fda
make class field handling less clunky
Simn Jul 20, 2023
f3b8812
remove ANFR and ANFD, encode FAnon fields immediately
Simn Jul 21, 2023
5ca4865
[hxb] write/read overloads too
kLabz Jul 25, 2023
16ddf14
[ci] enable CI, disable tests that do not apply any more
kLabz Oct 10, 2023
e081b26
[hxb] writer: avoid side effects on TAnon fields type
kLabz Oct 11, 2023
43d09fe
[hxb] restore base hxb
kLabz Oct 11, 2023
b2cc9ef
Avoid stack overflow
kLabz Oct 11, 2023
cce7fac
Revert some changes
kLabz Oct 17, 2023
fb8d2cf
[tests] disable @:generic + @:const test for now
kLabz Nov 30, 2023
dc3dac7
[hxb] tanon changes, debug, prepare for server
kLabz Dec 6, 2023
26b9003
[hxb] generate hxb on after_save callback
kLabz Dec 6, 2023
9481308
[hxb] anons and type parameters
kLabz Dec 5, 2023
23b257e
[hxb] make tanon_identification.identify strict only for hxb
kLabz Dec 7, 2023
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
7 changes: 7 additions & 0 deletions src/compiler/args.ml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ let parse_args com =
let actx = {
classes = [([],"Std")];
xml_out = None;
hxb_out = None;
json_out = None;
cmds = [];
config_macros = [];
Expand Down Expand Up @@ -125,6 +126,9 @@ let parse_args com =
("Compilation",["-p";"--class-path"],["-cp"],Arg.String (fun path ->
com.class_path <- Path.add_trailing_slash path :: com.class_path
),"<path>","add a directory to find source files");
("Compilation",["--binary-class-path"],["-bcp"],Arg.String (fun path ->
com.binary_class_path <- Path.add_trailing_slash path :: com.binary_class_path
),"<path>","add a directory to find binary source files");
("Compilation",["-m";"--main"],["-main"],Arg.String (fun cl ->
if com.main_class <> None then raise (Arg.Bad "Multiple --main classes specified");
let cpath = Path.parse_type_path cl in
Expand Down Expand Up @@ -266,6 +270,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");
("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
2 changes: 2 additions & 0 deletions src/compiler/compilationContext.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type server_mode =
type arg_context = {
mutable classes : Globals.path list;
mutable xml_out : string option;
mutable hxb_out : string option;
mutable json_out : string option;
mutable cmds : string list;
mutable config_macros : string list;
Expand Down Expand Up @@ -45,6 +46,7 @@ and compilation_context = {
type compilation_callbacks = {
before_anything : compilation_context -> unit;
after_target_init : compilation_context -> unit;
after_save : compilation_context -> unit;
after_compilation : compilation_context -> unit;
}

Expand Down
6 changes: 6 additions & 0 deletions src/compiler/compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,12 @@ let compile ctx actx callbacks =
let (tctx,display_file_dot_path) = do_type ctx mctx actx display_file_dot_path macro_cache_enabled in
DisplayProcessing.handle_display_after_typing ctx tctx display_file_dot_path;
finalize_typing ctx tctx;
com.callbacks#add_after_save (fun () ->
(* TODO use hxb cache for hxb output *)
callbacks.after_save ctx;
Generate.check_hxb_output com actx;
);
com.callbacks#add_before_save (fun () -> Generate.check_hxb_output com actx);
if is_diagnostics com then
filter ctx tctx (fun () -> DisplayProcessing.handle_display_after_finalization ctx tctx display_file_dot_path)
else begin
Expand Down
60 changes: 60 additions & 0 deletions src/compiler/generate.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
open Globals
open CompilationContext
open TType
open Tanon_identification

let check_auxiliary_output com actx =
begin match actx.xml_out with
Expand All @@ -19,6 +21,64 @@ let check_auxiliary_output com actx =
Genjson.generate com.types file
end

let export_hxb root m =
match m.m_extra.m_kind with
| MCode | MMacro | MFake -> begin
(* Printf.eprintf "Export module %s\n" (s_type_path m.m_path); *)
let anon_identification = new tanon_identification ([],"") in
let writer = new HxbWriter.hxb_writer anon_identification in
writer#write_module m;
let ch = IO.output_bytes() in
writer#export ch;
let bytes_cp = IO.close_out ch in
let l = (root :: fst m.m_path @ [snd m.m_path]) in
let ch_file = Path.create_file true ".hxb" [] l in
output_bytes ch_file bytes_cp;
close_out ch_file
end
| _ -> ()

let check_hxb_output com actx =
begin match actx.hxb_out with
| None -> ()
| Some path ->
(* TODO move somewhere else *)
let clean_files path =
let rec iter_files pack dir path = try
let file = Unix.readdir dir in

if file <> "." && file <> ".." then begin
let filepath = path ^ "/" ^ file in
if (Unix.stat filepath).st_kind = S_DIR then
let pack = pack @ [file] in
iter_files (pack) (Unix.opendir filepath) filepath;
try Unix.rmdir filepath with Unix.Unix_error (ENOTEMPTY,_,_) -> ();
else
Sys.remove filepath
end;

iter_files pack dir path
with | End_of_file | Unix.Unix_error _ ->
Unix.closedir dir
in
iter_files [] (Unix.opendir path) path
in

let export com =
let path = Path.add_trailing_slash (path ^ Path.path_sep ^ (Common.platform_name_macro com)) in
Common.log com ("Generating hxb to " ^ path);
Printf.eprintf "Generating hxb to %s\n" path;
Path.mkdir_from_path path;
clean_files path;
let t = Timer.timer ["generate";"hxb"] in
Printf.eprintf "%d modules, %d types\n" (List.length com.modules) (List.length com.types);
List.iter (export_hxb path) com.modules;
t();
in

export com;
Option.may export (com.get_macros());
end

let parse_swf_header ctx h = match ExtString.String.nsplit h ":" with
| [width; height; fps] ->
Expand Down
57 changes: 57 additions & 0 deletions src/compiler/hxb/hxbData.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
exception HxbFailure of string

type chunk_kind =
| STRI (* string pool *)
| DOCS (* doc pool *)
| HHDR (* module header *)
| TYPF (* forward types *)
| CLSR (* class reference array *)
| ABSR (* abstract reference array *)
| TPDR (* typedef reference array *)
| ENMR (* enum reference array *)
| CLSD (* class definition *)
| ABSD (* abstract definition *)
| CFLD (* class fields *)
| TPDD (* typedef definition *)
| ENMD (* enum definition *)
| EFLD (* enum fields *)
| HEND (* the end *)

let string_of_chunk_kind = function
| STRI -> "STRI"
| DOCS -> "DOCS"
| HHDR -> "HHDR"
| TYPF -> "TYPF"
| CLSR -> "CLSR"
| ABSR -> "ABSR"
| TPDR -> "TPDR"
| ENMR -> "ENMR"
| CLSD -> "CLSD"
| ABSD -> "ABSD"
| CFLD -> "CFLD"
| TPDD -> "TPDD"
| ENMD -> "ENMD"
| EFLD -> "EFLD"
| HEND -> "HEND"

let chunk_kind_of_string = function
| "STRI" -> STRI
| "DOCS" -> DOCS
| "HHDR" -> HHDR
| "TYPF" -> TYPF
| "CLSR" -> CLSR
| "ABSR" -> ABSR
| "TPDR" -> TPDR
| "ENMR" -> ENMR
| "CLSD" -> CLSD
| "ABSD" -> ABSD
| "CFLD" -> CFLD
| "TPDD" -> TPDD
| "ENMD" -> ENMD
| "EFLD" -> EFLD
| "HEND" -> HEND
| name -> raise (HxbFailure ("Invalid chunk name: " ^ name))

let error (s : string) =
Printf.eprintf "[error] %s\n" s;
raise (HxbFailure s)
Loading