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

coq: test and fix duplicate theory prefix in COQPATH bug #7790

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 4 additions & 8 deletions src/dune_rules/coq/coq_lib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -647,14 +647,10 @@ module DB = struct
(* Map is eager, this may not be very convenient in large trees,
but should be fine for now *)
let map =
match
Coq_lib_name.Map.of_list_map cps ~f:(fun cp -> (Coq_path.name cp, cp))
with
| Ok m -> m
| Error (name, cp1, cp2) ->
let id1 = Id.create ~path:(Coq_path.path cp1) ~name:(Loc.none, name) in
let id2 = Id.create ~path:(Coq_path.path cp2) ~name:(Loc.none, name) in
Error.duplicate_theory_name id1 id2
List.rev_map cps ~f:(fun cp -> (Coq_path.name cp, cp))
(* Since we reversed the order, the second coqpath should take
precedence. This is in line with Coq semantics. *)
|> Coq_lib_name.Map.of_list_reducei ~f:(fun _name _cp1 cp2 -> cp2)
in
let resolve name : t Resolve_result.t =
match Coq_lib_name.Map.find map name with
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Inductive b := .
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(coq.theory
(name A.B)
(package Theory1))
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(lang dune 3.8)
(using coq 0.8)
(package (name Theory1))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Inductive c := .
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(coq.theory
(name A.C)
(package Theory2))
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(lang dune 3.8)
(using coq 0.8)
(package (name Theory2))
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
If we have installed theories A.B and A.C then Dune should not complain that A
is a duplicate theory.

First we install our two theories with the conflicting name prefix.

$ (cd B && dune build @install && dune install --prefix .)
$ (cd C && dune build @install && dune install --prefix .)

We add these to COQPATH

$ export COQPATH=../B/lib/coq/user-contrib:../C/lib/coq/user-contrib:$COQPATH

Now we create a theory that depends on both

$ mkdir mytheory && cd mytheory

$ cat > dune-project << EOF
> (lang dune 3.8)
> (using coq 0.8)
> EOF

$ cat > dune << EOF
> (coq.theory
> (name mytheory)
> (theories A.B A.C))
> EOF

$ cat > a.v << EOF
> From A.B Require Import a.
> From A.C Require Import a.
> Print b.
> EOF

$ dune build a.vo
Inductive b : Prop := .

Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ We test updating the dune file for user to use the super-theory works:
Leaving directory 'user'

We test whether installing `global` again in user-contrib will cause Dune to reject the
build.
build. Currently this is not the case and the first theory is preferred inline
with the loadpath semantics of Coq.

$ dune install --root global --prefix=$PWD --display=short
Installing $TESTCASE_ROOT/lib/global/META
Expand All @@ -203,10 +204,4 @@ build.

$ dune build --root user
Entering directory 'user'
Error: Coq theory global is defined twice:
- theory global in
$TESTCASE_ROOT/another-place/lib/coq/user-contrib/global
- theory global in
$TESTCASE_ROOT/lib/coq/user-contrib/global
Leaving directory 'user'
[1]
9 changes: 2 additions & 7 deletions test/blackbox-tests/test-cases/coq/compose-installed.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ any problems. It shouldn't do, as the workspace should take precedence.
I : hello | am : hello | an : hello | install : hello | loc : hello.

We test whether installing B again in user-contrib will cause Dune to reject the
build.
build. Currently this is not the case and the first theory is preferred inline
with the loadpath semantics of Coq.

$ dune install --root B --prefix=$PWD --display=short
Installing $TESTCASE_ROOT/lib/B/META
Expand All @@ -115,10 +116,4 @@ build.

$ dune build --root A
Entering directory 'A'
Error: Coq theory B is defined twice:
- theory B in
$TESTCASE_ROOT/another-place/lib/coq/user-contrib/B
- theory B in
$TESTCASE_ROOT/lib/coq/user-contrib/B
Leaving directory 'A'
[1]