Skip to content

Commit

Permalink
also allow passing it to the reader
Browse files Browse the repository at this point in the history
  • Loading branch information
Simn committed Jan 28, 2024
1 parent 3e3fba9 commit 06c048b
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/compiler/hxb/hxbLib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class hxb_library file_path = object(self)
val modules = Hashtbl.create 0
val mutable closed = false
val mutable loaded = false
val mutable string_pool : string array option = None

method load =
if not loaded then begin
Expand Down Expand Up @@ -49,6 +50,7 @@ class hxb_library file_path = object(self)
end

method get_file_path = file_path
method get_string_pool = string_pool
end


Expand Down
6 changes: 5 additions & 1 deletion src/compiler/hxb/hxbReader.ml
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,14 @@ let dump_stats name stats =
class hxb_reader
(mpath : path)
(stats : hxb_reader_stats)
(string_pool : string array option)
= object(self)
val mutable api = Obj.magic ""
val mutable current_module = null_module

val mutable ch = BytesWithPosition.create (Bytes.create 0)
val mutable string_pool = Array.make 0 ""
val mutable has_string_pool = (string_pool <> None)
val mutable string_pool = (match string_pool with None -> Array.make 0 "" | Some pool -> pool)
val mutable doc_pool = Array.make 0 ""

val mutable classes = Array.make 0 null_class
Expand Down Expand Up @@ -1911,9 +1913,11 @@ class hxb_reader
match kind with
| STR ->
string_pool <- self#read_string_pool;
has_string_pool <- true;
| DOC ->
doc_pool <- self#read_string_pool;
| MDF ->
assert(has_string_pool);
current_module <- self#read_mdf;
| MTF ->
current_module.m_types <- self#read_mtf;
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ class hxb_reader_api_server
| GoodModule m ->
m
| BinaryModule mc ->
let reader = new HxbReader.hxb_reader path ctx.com.hxb_reader_stats in
let reader = new HxbReader.hxb_reader path ctx.com.hxb_reader_stats None 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
Expand Down Expand Up @@ -573,7 +573,7 @@ and type_module sctx (ctx:Typecore.typer) mpath p =
checking dependencies. This means that the actual decoding never has any reason to fail. *)
begin match check_module sctx ctx mpath mc.mc_extra p with
| None ->
let reader = new HxbReader.hxb_reader mpath com.hxb_reader_stats in
let reader = new HxbReader.hxb_reader mpath com.hxb_reader_stats None in
let api = (new hxb_reader_api_server ctx cc :> HxbReaderApi.hxb_reader_api) in
let f_next chunks until =
let t_hxb = Timer.timer ["server";"module cache";"hxb read"] in
Expand Down
1 change: 1 addition & 0 deletions src/context/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ class virtual abstract_hxb_lib = object(self)
method virtual get_bytes : string -> path -> bytes option
method virtual close : unit
method virtual get_file_path : string
method virtual get_string_pool : string array option
end

type context = {
Expand Down
2 changes: 1 addition & 1 deletion src/context/display/displayJson.ml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class hxb_reader_api_com
cc#find_module m_path
with Not_found ->
let mc = cc#get_hxb_module m_path in
let reader = new HxbReader.hxb_reader mc.mc_path com.hxb_reader_stats in
let reader = new HxbReader.hxb_reader mc.mc_path com.hxb_reader_stats None in
fst (reader#read_chunks_until (self :> HxbReaderApi.hxb_reader_api) mc.mc_chunks (if headers_only then MTF else EOM))

method basic_types =
Expand Down
2 changes: 1 addition & 1 deletion src/context/display/displayTexpr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ let check_display_file ctx cs =
| NoModule | BadModule _ -> raise Not_found
| BinaryModule mc ->
let api = (new TypeloadModule.hxb_reader_api_typeload ctx TypeloadModule.load_module' p :> HxbReaderApi.hxb_reader_api) in
let reader = new HxbReader.hxb_reader path ctx.com.hxb_reader_stats in
let reader = new HxbReader.hxb_reader path ctx.com.hxb_reader_stats None in
let m = reader#read_chunks api mc.mc_chunks in
m
| GoodModule m ->
Expand Down
6 changes: 3 additions & 3 deletions src/typing/typeloadModule.ml
Original file line number Diff line number Diff line change
Expand Up @@ -813,10 +813,10 @@ class hxb_reader_api_typeload
end

let rec load_hxb_module ctx path p =
let read file bytes =
let read file bytes string_pool =
try
let api = (new hxb_reader_api_typeload ctx load_module' p :> HxbReaderApi.hxb_reader_api) in
let reader = new HxbReader.hxb_reader path ctx.com.hxb_reader_stats in
let reader = new HxbReader.hxb_reader path ctx.com.hxb_reader_stats string_pool in
let read = reader#read api bytes in
let m = read MTF in
delay ctx PBuildClass (fun () ->
Expand All @@ -837,7 +837,7 @@ let rec load_hxb_module ctx path p =
| hxb_lib :: l ->
begin match hxb_lib#get_bytes target path with
| Some bytes ->
read hxb_lib#get_file_path bytes
read hxb_lib#get_file_path bytes hxb_lib#get_string_pool
| None ->
loop l
end
Expand Down

0 comments on commit 06c048b

Please sign in to comment.