Skip to content

Commit

Permalink
start working on delayed expression reading
Browse files Browse the repository at this point in the history
see #11498
  • Loading branch information
Simn committed Jan 19, 2024
1 parent e64cee5 commit 03182b1
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 12 deletions.
34 changes: 27 additions & 7 deletions src/compiler/hxb/hxbReader.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1612,15 +1612,35 @@ class hxb_reader
method read_exd =
ignore(self#read_list (fun () ->
let c = self#read_class_ref in
self#select_class_type_parameters c;
self#read_list (fun () ->
let cf = self#read_field_ref in
field_type_parameters <- List.assq cf awful;
field_type_parameter_offset <- 0;
let fctx = self#start_texpr in
let e,e_unopt = self#read_expression fctx in
cf.cf_expr <- Some e;
cf.cf_expr_unoptimized <- e_unopt
let length = read_uleb128 ch in
let bytes = read_bytes ch length in
let ch_cf = BytesWithPosition.create bytes in
let read_expressions () =
self#select_class_type_parameters c;
field_type_parameters <- List.assq cf awful;
field_type_parameter_offset <- 0;
let old = ch in
ch <- ch_cf;
let fctx = self#start_texpr in
let e,e_unopt = self#read_expression fctx in
ch <- old;
cf.cf_expr <- Some e;
cf.cf_expr_unoptimized <- e_unopt;
in
if true || api#read_expression_eagerly cf then
read_expressions ()
else begin
let t = cf.cf_type in
let r = ref (lazy_available t) in
r := lazy_wait (fun() ->
r := lazy_available t;
read_expressions ();
t
);
cf.cf_type <- TLazy r
end
)
))

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 @@ -7,4 +7,5 @@ class virtual hxb_reader_api = object(self)
method virtual resolve_type : string list -> string -> string -> module_type
method virtual basic_types : basic_types
method virtual get_var_id : int -> int
method virtual read_expression_eagerly : tclass_field -> bool
end
3 changes: 2 additions & 1 deletion src/compiler/hxb/hxbWriter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2083,7 +2083,8 @@ module HxbWriter = struct
write_class_ref writer c;
Chunk.write_list writer.chunk l (fun (cf,ref_kind,e) ->
write_field_ref writer c ref_kind cf;
Chunk.export_data e writer.chunk
let bytes = Chunk.get_bytes e in
Chunk.write_bytes_length_prefixed writer.chunk bytes;
)
)
end;
Expand Down
3 changes: 3 additions & 0 deletions src/compiler/server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,9 @@ class hxb_reader_api_server

method get_var_id (i : int) =
i

method read_expression_eagerly (cf : tclass_field) =
false (* TODO: Check this please Rudy! *)
end

let handle_cache_bound_objects com cbol =
Expand Down
3 changes: 3 additions & 0 deletions src/context/display/displayJson.ml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ class hxb_reader_api_com

method get_var_id (i : int) =
i

method read_expression_eagerly (cf : tclass_field) =
false
end

let find_module ~(headers_only : bool) com cc path =
Expand Down
8 changes: 4 additions & 4 deletions src/typing/typeloadModule.ml
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,9 @@ class hxb_reader_api_typeload
let uid = fst alloc_var' in
incr uid;
!uid

method read_expression_eagerly (cf : tclass_field) =
ctx.com.is_macro_context
end

let rec load_hxb_module ctx path p =
Expand All @@ -811,10 +814,7 @@ let rec load_hxb_module ctx path p =
delay ctx PBuildClass (fun () ->
ignore(read EOT);
delay ctx PConnectField (fun () ->
ignore(read EOF);
delay ctx PTypeField (fun () ->
ignore(read EOM)
)
ignore(read EOM);
);
);
m
Expand Down

0 comments on commit 03182b1

Please sign in to comment.