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

test: demonstrate crash in modules.ml when (stdlib .. ) used with (wrapped false) #7139

Merged
merged 4 commits into from
Feb 28, 2023
Merged
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
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ Unreleased
- Added a new user action `(concurrent )` which is like `(progn )` but runs the
actions concurrently. (#6933, @Alizter)

- Allow `(stdlib ...)` to be used with `(wrapped false)` in library stanzas
(#7139, @anmonteiro).

3.7.0 (2023-02-17)
------------------

Expand Down
5 changes: 4 additions & 1 deletion src/dune_rules/dune_file.ml
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,10 @@ module Library = struct
| Some x, From _ -> From x
| Some _, This _ (* cannot specify for wrapped for implements *)
| None, From _ -> assert false (* cannot inherit for normal libs *)
| None, This (Simple false) -> This None
| None, This (Simple false) -> (
match t.stdlib with
| None -> This None
| Some _ -> This (Some (Module_name.of_local_lib_name t.name)))
| None, This (Simple true | Yes_with_transition _) ->
This (Some (Module_name.of_local_lib_name t.name))

Expand Down
24 changes: 14 additions & 10 deletions src/dune_rules/modules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,20 @@ module Stdlib = struct
| None -> false
| Some n -> n = name

let make ~(stdlib : Ocaml_stdlib.t) ~modules ~main_module_name =
let make ~(stdlib : Ocaml_stdlib.t) ~modules ~wrapped ~main_module_name =
let modules =
Module_name.Map.map modules ~f:(fun m ->
if
Module.name m = main_module_name || special_compiler_module stdlib m
then m
else
let path = [ main_module_name; Module.name m ] in
let m = Module.set_path m path in
Module.set_obj_name m (Module_name.Path.wrap path))
match wrapped with
| Wrapped.Simple true | Yes_with_transition _ ->
Module_name.Map.map modules ~f:(fun m ->
if
Module.name m = main_module_name
|| special_compiler_module stdlib m
then m
else
let path = [ main_module_name; Module.name m ] in
let m = Module.set_path m path in
Module.set_obj_name m (Module_name.Path.wrap path))
| Simple false -> modules
in
let unwrapped = stdlib.modules_before_stdlib in
let exit_module = stdlib.exit_module in
Expand Down Expand Up @@ -805,7 +809,7 @@ let lib ~obj_dir ~main_module_name ~wrapped ~stdlib ~lib_name ~implements
| Some stdlib ->
let main_module_name = Option.value_exn main_module_name in
let modules = Module_trie.to_map modules in
Stdlib (Stdlib.make ~stdlib ~modules ~main_module_name)
Stdlib (Stdlib.make ~stdlib ~modules ~wrapped ~main_module_name)
| None -> (
match (wrapped, main_module_name, Module_trie.as_singleton modules) with
| Simple false, _, Some m -> Singleton m
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Compile a library with `(stdlib ..)` and wrapped settings

$ cat > dune-project <<EOF
> (lang dune 3.7)
> (using experimental_building_ocaml_compiler_with_dune 0.1)
> EOF

$ mkdir stdlib
$ runtest() {
> cat >stdlib/dune <<EOF
> (library
> (name mystdlib)
> (wrapped $1)
> (stdlib
> (internal_modules Camlinternal*)))
> EOF
> dune build
> find _build/default/stdlib -iname '*.cmi' | sort;
> }

$ cat > stdlib/other.ml <<EOF
> let other () = Mystdlib.defined_in_stdlib
> EOF
$ cat > stdlib/one_module.ml <<EOF
> let foo = "foo"
> EOF
$ cat > stdlib/mystdlib.ml <<EOF
> let defined_in_stdlib = "defined"
> module One_module = One_module
> module Other = Other
> EOF

First we test wrapped:

$ runtest "true"
_build/default/stdlib/.mystdlib.objs/byte/mystdlib.cmi
_build/default/stdlib/.mystdlib.objs/byte/mystdlib__One_module.cmi
_build/default/stdlib/.mystdlib.objs/byte/mystdlib__Other.cmi

And now unwrapped:

$ runtest "false"
_build/default/stdlib/.mystdlib.objs/byte/mystdlib.cmi
_build/default/stdlib/.mystdlib.objs/byte/one_module.cmi
_build/default/stdlib/.mystdlib.objs/byte/other.cmi