Skip to content

Commit c468e55

Browse files
authored
Merge pull request #12587 from ElectreAAS/repro-include-subdir-bug
Fix difference between bootstrap & dune behaviour w.r.t include-subdirs ambiguity
2 parents 5724d33 + 5505247 commit c468e55

File tree

4 files changed

+78
-8
lines changed

4 files changed

+78
-8
lines changed

src/dune_rules/modules.ml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,9 @@ module Group = struct
410410
fun acc modules m -> loop acc modules (Module.path m)
411411
;;
412412

413-
let parents (t : t) m = parents_modules [ t ] t.modules m
413+
(* [parents acc modules m] returns [acc] followed by all parent groups of
414+
module [m], ordered from innermost to outermost parent. *)
415+
let parents (t : t) m = parents_modules [ t ] t.modules m |> List.rev
414416

415417
module Memo_traversals = struct
416418
let rec parallel_map ({ alias; modules; name = _ } as t) ~f =
@@ -485,7 +487,10 @@ module Group = struct
485487
Ok (if Module_name.equal name (Module.name li) then [ li ] else [])
486488
| _ ->
487489
(* TODO don't recompute this *)
488-
let parents = parents t of_ |> List.map ~f:(fun g -> g.modules, Some g.name) in
490+
let parents =
491+
parents_modules [ t ] t.modules of_
492+
|> List.map ~f:(fun g -> g.modules, Some g.name)
493+
in
489494
Find_dep.find_dep_of_parents parents name
490495
;;
491496

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Testing the bootstrap of a wrapped include subdirs qualified.
2+
There is ambiguity between the two different foo modules.
3+
We show that the behaviour is correct in the bootstrap process:
4+
it picks up the closest one.
5+
6+
$ . ./helpers.sh
7+
$ mkdir a
8+
9+
$ cat > a/foo.ml << EOF
10+
> let msg = "shouldn't be printed"
11+
> EOF
12+
13+
$ mkdir a/bar
14+
$ cat > a/bar/foo.ml << EOF
15+
> let msg = "the correct module"
16+
> EOF
17+
18+
$ cat > a/bar/baz.ml << EOF
19+
> let exported = Foo.msg ^ "!"
20+
> EOF
21+
22+
$ cat > a/dune <<EOF
23+
> (library
24+
> (name a))
25+
> (include_subdirs qualified)
26+
> EOF
27+
28+
$ create_dune a <<EOF
29+
> module M1 = A.Bar.Baz
30+
> let () = Printf.printf "Hello from %s\n" M1.exported
31+
> EOF
32+
ocamlc -output-complete-exe -intf-suffix .dummy -g -o .duneboot.exe -I boot -I +unix unix.cma boot/types.ml boot/libs.ml boot/duneboot.ml
33+
./.duneboot.exe
34+
Hello from the correct module!
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
There is ambiguity between the two different foo modules.
2+
The behaviour is now correct both in the bootstrap process, and in dune.
3+
It picks up the closest one.
4+
5+
$ echo "(lang dune 3.21)" > dune-project
6+
$ cat > dune << EOF
7+
> (include_subdirs qualified)
8+
> (executable
9+
> (name main))
10+
> EOF
11+
12+
$ cat > main.ml << EOF
13+
> let () = print_endline Bar.Baz.exported
14+
> EOF
15+
16+
$ cat > foo.ml << EOF
17+
> let msg = "Failure"
18+
> EOF
19+
20+
$ mkdir bar
21+
$ cat > bar/foo.ml << EOF
22+
> let msg = "Success"
23+
> EOF
24+
25+
$ cat > bar/baz.ml << EOF
26+
> let exported = Foo.msg ^ "!"
27+
> EOF
28+
29+
This is now fixed.
30+
$ dune exec ./main.exe
31+
Success!

test/blackbox-tests/test-cases/merlin/include-subdirs-qualified.t

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
(S $TESTCASE_ROOT/groupintf)
9898
(S $TESTCASE_ROOT/utils)
9999
(FLG (-w @1..3@5[email protected]@[email protected]@[email protected]@67@69-40 -strict-sequence -strict-formats -short-paths -keep-locs -g))
100-
(FLG (-open Foo__Groupintf__ -open Foo))
100+
(FLG (-open Foo -open Foo__Groupintf__))
101101
(UNIT_NAME foo__Groupintf__Calc))
102102
Calc: _build/default/groupintf/calc.ml
103103
((INDEX $TESTCASE_ROOT/_build/default/.foo.objs/cctx.ocaml-index)
@@ -109,7 +109,7 @@
109109
(S $TESTCASE_ROOT/groupintf)
110110
(S $TESTCASE_ROOT/utils)
111111
(FLG (-w @1..3@5[email protected]@[email protected]@[email protected]@67@69-40 -strict-sequence -strict-formats -short-paths -keep-locs -g))
112-
(FLG (-open Foo__Groupintf__ -open Foo))
112+
(FLG (-open Foo -open Foo__Groupintf__))
113113
(UNIT_NAME foo__Groupintf__Calc))
114114
Groupintf: _build/default/groupintf/groupintf
115115
((INDEX $TESTCASE_ROOT/_build/default/.foo.objs/cctx.ocaml-index)
@@ -121,7 +121,7 @@
121121
(S $TESTCASE_ROOT/groupintf)
122122
(S $TESTCASE_ROOT/utils)
123123
(FLG (-w @1..3@5[email protected]@[email protected]@[email protected]@67@69-40 -strict-sequence -strict-formats -short-paths -keep-locs -g))
124-
(FLG (-open Foo__Groupintf__ -open Foo))
124+
(FLG (-open Foo -open Foo__Groupintf__))
125125
(UNIT_NAME foo__Groupintf))
126126
Groupintf: _build/default/groupintf/groupintf.ml
127127
((INDEX $TESTCASE_ROOT/_build/default/.foo.objs/cctx.ocaml-index)
@@ -133,7 +133,7 @@
133133
(S $TESTCASE_ROOT/groupintf)
134134
(S $TESTCASE_ROOT/utils)
135135
(FLG (-w @1..3@5[email protected]@[email protected]@[email protected]@67@69-40 -strict-sequence -strict-formats -short-paths -keep-locs -g))
136-
(FLG (-open Foo__Groupintf__ -open Foo))
136+
(FLG (-open Foo -open Foo__Groupintf__))
137137
(UNIT_NAME foo__Groupintf))
138138
Main: _build/default/main
139139
((INDEX $TESTCASE_ROOT/_build/default/.foo.objs/cctx.ocaml-index)
@@ -169,7 +169,7 @@
169169
(S $TESTCASE_ROOT/groupintf)
170170
(S $TESTCASE_ROOT/utils)
171171
(FLG (-w @1..3@5[email protected]@[email protected]@[email protected]@67@69-40 -strict-sequence -strict-formats -short-paths -keep-locs -g))
172-
(FLG (-open Foo__Utils -open Foo))
172+
(FLG (-open Foo -open Foo__Utils))
173173
(UNIT_NAME foo__Utils__Calc))
174174
Calc: _build/default/utils/calc.ml
175175
((INDEX $TESTCASE_ROOT/_build/default/.foo.objs/cctx.ocaml-index)
@@ -181,6 +181,6 @@
181181
(S $TESTCASE_ROOT/groupintf)
182182
(S $TESTCASE_ROOT/utils)
183183
(FLG (-w @1..3@5[email protected]@[email protected]@[email protected]@67@69-40 -strict-sequence -strict-formats -short-paths -keep-locs -g))
184-
(FLG (-open Foo__Utils -open Foo))
184+
(FLG (-open Foo -open Foo__Utils))
185185
(UNIT_NAME foo__Utils__Calc))
186186
$ dune ocaml merlin dump-config utils

0 commit comments

Comments
 (0)