Skip to content

Commit

Permalink
add MDR to deal with import to @:keep
Browse files Browse the repository at this point in the history
  • Loading branch information
Simn committed Jan 20, 2024
1 parent 02055a0 commit 7603234
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 27 deletions.
3 changes: 3 additions & 0 deletions src/compiler/hxb/hxbData.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type chunk_kind =
| MDF (* module foward *)
| MTF (* module types forward *)
(* Module type references *)
| MDR (* module references *)
| CLR (* class references *)
| ENR (* enum references *)
| ABR (* abstract references *)
Expand Down Expand Up @@ -65,6 +66,7 @@ let string_of_chunk_kind = function
| DOC -> "DOC"
| MDF -> "MDF"
| MTF -> "MTF"
| MDR -> "MDR"
| CLR -> "CLR"
| ENR -> "ENR"
| ABR -> "ABR"
Expand All @@ -89,6 +91,7 @@ let chunk_kind_of_string = function
| "DOC" -> DOC
| "MDF" -> MDF
| "MTF" -> MTF
| "MDR" -> MDR
| "CLR" -> CLR
| "ENR" -> ENR
| "ABR" -> ABR
Expand Down
9 changes: 9 additions & 0 deletions src/compiler/hxb/hxbReader.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1765,6 +1765,13 @@ class hxb_reader
error ("Unexpected type where typedef was expected: " ^ (s_type_path (pack,tname)))
))

method read_mdr =
let length = read_uleb128 ch in
for i = 0 to length - 1 do
let path = self#read_path in
ignore(api#resolve_module path)
done

method read_mtf =
self#read_list (fun () ->
let kind = read_byte ch in
Expand Down Expand Up @@ -1871,6 +1878,8 @@ class hxb_reader
| MTF ->
current_module.m_types <- self#read_mtf;
api#add_module current_module;
| MDR ->
self#read_mdr;
| CLR ->
self#read_clr;
| ENR ->
Expand Down
1 change: 1 addition & 0 deletions src/compiler/hxb/hxbReaderApi.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class virtual hxb_reader_api = object(self)
method virtual make_module : path -> string -> module_def
method virtual add_module : module_def -> unit
method virtual resolve_type : string list -> string -> string -> module_type
method virtual resolve_module : path -> module_def
method virtual basic_types : basic_types
method virtual get_var_id : int -> int
method virtual read_expression_eagerly : tclass_field -> bool
Expand Down
21 changes: 20 additions & 1 deletion src/compiler/hxb/hxbWriter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ module HxbWriter = struct
let initial_size = match kind with
| EOT | EOF | EOM -> 0
| MDF -> 16
| MTF | CLR | END | ABD | ENR | ABR | TDR | EFR | CFR | AFD -> 64
| MTF | MDR | CLR | END | ABD | ENR | ABR | TDR | EFR | CFR | AFD -> 64
| AFR | CLD | TDD | EFD -> 128
| STR | DOC -> 256
| CFD | EXD -> 512
Expand Down Expand Up @@ -2204,6 +2204,25 @@ module HxbWriter = struct
Chunk.write_string writer.chunk (Path.UniqueKey.lazy_path m.m_extra.m_file);
Chunk.write_uleb128 writer.chunk (DynArray.length (Pool.items writer.anons));
Chunk.write_uleb128 writer.chunk (DynArray.length (IdentityPool.items writer.tmonos));

begin
let deps = DynArray.create () in
PMap.iter (fun _ (sign,path) ->
if sign = m.m_extra.m_sign then begin
(* TODO: We probably need module_kind in m_deps to handle this properly. *)
if not (ExtString.String.ends_with (snd path) "import.hx") then
DynArray.add deps path;
end
) m.m_extra.m_deps;
if DynArray.length deps > 0 then begin
start_chunk writer MDR;
Chunk.write_uleb128 writer.chunk (DynArray.length deps);
DynArray.iter (fun path ->
write_path writer path
) deps
end
end;

start_chunk writer EOT;
start_chunk writer EOF;
start_chunk writer EOM;
Expand Down
48 changes: 25 additions & 23 deletions src/compiler/server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -412,31 +412,33 @@ class hxb_reader_api_server

method resolve_type (pack : string list) (mname : string) (tname : string) =
let path = (pack,mname) in
let m = match self#find_module path with
| GoodModule m ->
m
| BinaryModule mc ->
let reader = new HxbReader.hxb_reader path ctx.com.hxb_reader_stats in
let f_next chunks until =
let t_hxb = Timer.timer ["server";"module cache";"hxb read"] in
let r = reader#read_chunks_until (self :> HxbReaderApi.hxb_reader_api) chunks until in
t_hxb();
r
in
let m,chunks = f_next mc.mc_chunks EOF in

(* We try to avoid reading expressions as much as possible, so we only do this for
our current display file if we're in display mode. *)
let is_display_file = DisplayPosition.display_position#is_in_file (Path.UniqueKey.lazy_key m.m_extra.m_file) in
if is_display_file || ctx.com.display.dms_full_typing then ignore(f_next chunks EOM);
m
| BadModule reason ->
die (Printf.sprintf "Unexpected BadModule %s" (s_type_path path)) __LOC__
| NoModule ->
die (Printf.sprintf "Unexpected NoModule %s" (s_type_path path)) __LOC__
in
let m = self#resolve_module path in
List.find (fun t -> snd (t_path t) = tname) m.m_types

method resolve_module (path : path) =
match self#find_module path with
| GoodModule m ->
m
| BinaryModule mc ->
let reader = new HxbReader.hxb_reader path ctx.com.hxb_reader_stats in
let f_next chunks until =
let t_hxb = Timer.timer ["server";"module cache";"hxb read"] in
let r = reader#read_chunks_until (self :> HxbReaderApi.hxb_reader_api) chunks until in
t_hxb();
r
in
let m,chunks = f_next mc.mc_chunks EOF in

(* We try to avoid reading expressions as much as possible, so we only do this for
our current display file if we're in display mode. *)
let is_display_file = DisplayPosition.display_position#is_in_file (Path.UniqueKey.lazy_key m.m_extra.m_file) in
if is_display_file || ctx.com.display.dms_full_typing then ignore(f_next chunks EOM);
m
| BadModule reason ->
die (Printf.sprintf "Unexpected BadModule %s" (s_type_path path)) __LOC__
| NoModule ->
die (Printf.sprintf "Unexpected NoModule %s" (s_type_path path)) __LOC__

method find_module (m_path : path) =
try
GoodModule (ctx.com.module_lut#find m_path)
Expand Down
4 changes: 3 additions & 1 deletion src/context/display/displayJson.ml
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,12 @@ class hxb_reader_api_com

method resolve_type (pack : string list) (mname : string) (tname : string) =
let path = (pack,mname) in

let m = self#find_module path in
List.find (fun t -> snd (t_path t) = tname) m.m_types

method resolve_module (path : path) =
self#find_module path

method find_module (m_path : path) =
try
com.module_lut#find m_path
Expand Down
3 changes: 3 additions & 0 deletions src/typing/typeloadModule.ml
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,9 @@ class hxb_reader_api_typeload
let m = load_module ctx (pack,mname) p in
List.find (fun t -> snd (t_path t) = tname) m.m_types

method resolve_module (path : path) =
load_module ctx path p

method basic_types =
ctx.com.basic

Expand Down
2 changes: 0 additions & 2 deletions std/jvm/Jvm.hx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ import jvm.annotation.EnumValueReflectionInformation;
@:keep
@:native('haxe.jvm.Jvm')
class Jvm {
extern static final init:java.Init;

extern static public function instanceof<S, T>(obj:S, type:T):Bool;

extern static public function referenceEquals<T>(v1:T, v2:T):Bool;
Expand Down

0 comments on commit 7603234

Please sign in to comment.