Skip to content

Commit

Permalink
[hxb] only load up to EOF if at least one field is accessed (or full …
Browse files Browse the repository at this point in the history
…typing)
  • Loading branch information
kLabz committed Dec 13, 2024
1 parent e577d8c commit 091cd94
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
25 changes: 23 additions & 2 deletions src/compiler/hxb/hxbReader.ml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ class hxb_reader
val mutable api = Obj.magic ""
val mutable full_restore = true
val mutable current_module = null_module
val mutable delayed_field_loading : (unit->unit) list = []

val mutable ch = BytesWithPosition.create (Bytes.create 0)
val mutable has_string_pool = (string_pool <> None)
Expand All @@ -177,6 +178,9 @@ class hxb_reader
val mutable field_type_parameter_offset = 0
val empty_anon = mk_anon (ref Closed)

method set_delayed_field_loading f =
delayed_field_loading <- f :: delayed_field_loading

method add_dependency mdep =
match current_module.m_extra.m_display_deps with
| Some deps ->
Expand Down Expand Up @@ -1939,7 +1943,24 @@ class hxb_reader
c.cl_flags <- read_uleb128 ch;

let read_field () =
self#read_class_field_forward;
let cf = self#read_class_field_forward in
if not full_restore then begin
let r = ref (lazy_processing t_dynamic) in
r := lazy_wait (fun() ->
begin match delayed_field_loading with
| [] -> ()
| f :: [] ->
f();
delayed_field_loading <- []
| l ->
List.iter (fun f -> f()) l;
delayed_field_loading <- []
end;
cf.cf_type
);
cf.cf_type <- TLazy r;
end;
cf
in

c.cl_constructor <- self#read_option read_field;
Expand All @@ -1949,7 +1970,7 @@ class hxb_reader
if i = 0 then
acc_l,acc_pm
else begin
let cf = self#read_class_field_forward in
let cf = read_field () in
loop (cf :: acc_l) (PMap.add cf.cf_name cf acc_pm) (i - 1)
end
in
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ class hxb_reader_api_server
(* 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. *)
if full_restore then ignore(f_next chunks EOM)
else delay (fun () -> ignore(f_next chunks EOF));
else reader#set_delayed_field_loading (fun () -> ignore(f_next chunks EOF));
m
| BadModule reason ->
die (Printf.sprintf "Unexpected BadModule %s (%s)" (s_type_path path) (Printer.s_module_skip_reason reason)) __LOC__
Expand Down Expand Up @@ -605,7 +605,7 @@ and type_module sctx com delay mpath p =
(* 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. *)
if full_restore then ignore(f_next chunks EOM)
else delay (fun () -> ignore(f_next chunks EOF));
else reader#set_delayed_field_loading (fun () -> ignore(f_next chunks EOF));
add_modules true m;
| Some reason ->
skip mpath reason
Expand Down

0 comments on commit 091cd94

Please sign in to comment.