Skip to content

Commit

Permalink
[hxb] continue POC
Browse files Browse the repository at this point in the history
  • Loading branch information
kLabz committed Sep 10, 2024
1 parent fba11f7 commit bc1c1ce
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
12 changes: 7 additions & 5 deletions src/compiler/compilationCache.ml
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,22 @@ class context_cache (index : int) (sign : Digest.t) = object(self)
| _ ->
let writer = HxbWriter.create config (Some string_pool) warn anon_identification in
HxbWriter.write_module writer m;
let chunks = HxbWriter.get_chunks writer in

(* TODO: avoid running the whole writer again... *)
let anon_identification = new Tanon_identification.tanon_identification in
let min_writer = HxbWriter.create config None warn anon_identification in
min_writer.minimal <- true;
HxbWriter.write_module min_writer m;
let min_chunks = HxbWriter.get_chunks min_writer in

Hashtbl.replace binary_cache path {
mc_path = path;
mc_id = m.m_id;
mc_chunks = chunks;
mc_min_chunks = min_chunks;
mc_extra = { m.m_extra with m_cache_state = MSGood }
mc_chunks = HxbWriter.get_chunks writer;
mc_min_chunks = HxbWriter.get_chunks min_writer;
mc_extra = { m.m_extra with
m_cache_state = MSGood;
m_sig_deps = Some (HxbWriter.get_dependencies min_writer)
}
}

method cache_module_in_memory path m =
Expand Down
19 changes: 10 additions & 9 deletions src/compiler/hxb/hxbWriter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2260,15 +2260,6 @@ module HxbWriter = struct
end;
end;

(* Note: this is only a start, and is still including a lot of dependencies *)
(* that are not actually needed for signature only. *)
let deps = ref PMap.empty in
List.iter (fun mdep ->
let dep = {md_sign = mdep.m_extra.m_sign; md_path = mdep.m_path; md_kind = mdep.m_extra.m_kind; md_origin = MDepFromTyping} in
deps := PMap.add mdep.m_id dep !deps;
) writer.deps;
if writer.minimal then m.m_extra.m_sig_deps <- Some !deps;

start_chunk writer EOT;
start_chunk writer EOF;
start_chunk writer EOM;
Expand All @@ -2291,6 +2282,16 @@ module HxbWriter = struct
l
end

let get_dependencies writer =
let deps = ref PMap.empty in

List.iter (fun mdep ->
let dep = {md_sign = mdep.m_extra.m_sign; md_path = mdep.m_path; md_kind = mdep.m_extra.m_kind; md_origin = MDepFromTyping} in
deps := PMap.add mdep.m_id dep !deps;
) writer.deps;

!deps

let create config string_pool warn anon_id =
let cp,has_own_string_pool = match string_pool with
| None ->
Expand Down

0 comments on commit bc1c1ce

Please sign in to comment.