Skip to content

Commit

Permalink
Compiler: fix link of packed modules
Browse files Browse the repository at this point in the history
  • Loading branch information
hhugo authored and vouillon committed Sep 20, 2024
1 parent 8a8664d commit d4853b3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
15 changes: 15 additions & 0 deletions compiler/lib/ocaml_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,21 @@ module Cmo_format = struct
let requires (t : t) = List.map t.cu_required_compunits ~f:(fun (Compunit u) -> u)
[@@if ocaml_version >= (5, 2, 0)]

let provides (t : t) =
List.filter_map t.cu_reloc ~f:(fun ((reloc : Cmo_format.reloc_info), _) ->
match reloc with
| Reloc_setglobal i -> Some (Ident.name i)
| Reloc_getglobal _ | Reloc_literal _ | Reloc_primitive _ -> None)
[@@if ocaml_version < (5, 2, 0)]

let provides (t : t) =
List.filter_map t.cu_reloc ~f:(fun ((reloc : Cmo_format.reloc_info), _) ->
match reloc with
| Reloc_setcompunit (Compunit u) -> Some u
| Reloc_getcompunit _ | Reloc_getpredef _ | Reloc_literal _ | Reloc_primitive _ ->
None)
[@@if ocaml_version >= (5, 2, 0)]

let primitives (t : t) = t.cu_primitives

let imports (t : t) = t.cu_imports
Expand Down
2 changes: 2 additions & 0 deletions compiler/lib/ocaml_compiler.mli
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ module Cmo_format : sig

val requires : t -> string list

val provides : t -> string list

val primitives : t -> string list

val force_link : t -> bool
Expand Down
3 changes: 2 additions & 1 deletion compiler/lib/unit_info.ml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ let of_primitives l =

let of_cmo (cmo : Cmo_format.compilation_unit) =
let open Ocaml_compiler in
let provides = StringSet.singleton (Cmo_format.name cmo) in
(* A packed librariy register global for packed modules. *)
let provides = StringSet.of_list (Cmo_format.name cmo :: Cmo_format.provides cmo) in
let requires = StringSet.of_list (Cmo_format.requires cmo) in
let requires = StringSet.diff requires provides in
let effects_without_cps =
Expand Down

0 comments on commit d4853b3

Please sign in to comment.