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] only load up to EOF if at least one field is accessed #11927

Draft
wants to merge 1 commit into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 21 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 resolve_type pack mname tname =
try
let mt = api#resolve_type pack mname tname in
Expand Down Expand Up @@ -1933,7 +1937,22 @@ 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() ->
let rec loop = function
| [] -> []
| f :: l ->
f();
loop l
in
delayed_field_loading <- loop delayed_field_loading;
cf.cf_type
);
cf.cf_type <- TLazy r;
end;
cf
in

c.cl_constructor <- self#read_option read_field;
Expand All @@ -1943,7 +1962,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 @@ -453,7 +453,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 PConnectField (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 PConnectField (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
Loading