Skip to content

fix(rocq): add error handling and hints for Rocq modules duplication#13733

Merged
Alizter merged 3 commits intoocaml:mainfrom
Durbatuluk1701:rocq_extr_dup_error
Mar 12, 2026
Merged

fix(rocq): add error handling and hints for Rocq modules duplication#13733
Alizter merged 3 commits intoocaml:mainfrom
Durbatuluk1701:rocq_extr_dup_error

Conversation

@Durbatuluk1701
Copy link
Copy Markdown
Contributor

Currently, if a rocq.theory stanza and rocq.extraction stanza use the same module, we can encounter an error due to the attempted duplicate add:

$ dune build
Internal error! Please report to https://github.com/ocaml/dune/issues,
providing the file _build/trace.csexp, if possible. This includes build
commands, message logs, and file paths.
Description:
  ("Map.add_exn: key already exists",
   { key =
       { source = In_build_dir "default/theories/FactExtr.v"
       ; prefix = []
       ; name = "FactExtr"
       }
   })

This PR addresses the issue by not performing an add_exn, as well as adding hints to the raised errors to provide more helpful guidance.

Example Code Not quite "minimal" example but hopefully good enough. Also note: this dune file will still not *fully* compile as there seems to be some issue with having a theory and extraction in the same folder?

FactProg.v:

From Stdlib Require Import Lia.

Fixpoint fact (n : nat) : nat :=
  match n with
  | 0 => 1
  | S n' => n * fact n'
  end.

Fixpoint fact_tail (acc : nat) (n : nat) : nat :=
  match n with
  | 0 => acc
  | S n' => fact_tail (acc * n) n'
  end.

FactExtr.v:

Require Import FactProg.

Require Extraction.
Separate Extraction fact_tail.

dune:

(include_subdirs qualified)

(rocq.theory
 (name TestPkg)
 (package test-pkg)
 (theories Stdlib)
 (synopsis "A test package"))

(rocq.extraction
 (prelude FactExtr)
 (theories Stdlib)
 (extracted_modules FactProg Datatypes Nat))

…raction and theory

Signed-off-by: Will Thomas <30wthomas@gmail.com>
Copy link
Copy Markdown
Collaborator

@rlepigre-skylabs-ai rlepigre-skylabs-ai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This looks good to me. I left a few minor comments.

Comment thread src/dune_rules/rocq/rocq_sources.ml Outdated
Comment thread src/dune_rules/rocq/rocq_sources.ml Outdated
Comment thread src/dune_rules/rocq/rocq_sources.ml Outdated
Comment thread test/blackbox-tests/test-cases/rocq/extraction/extract.t Outdated
Comment thread test/blackbox-tests/test-cases/rocq/extraction/extract.t Outdated
Comment thread test/blackbox-tests/test-cases/rocq/extraction/extract.t Outdated
@Alizter Alizter self-requested a review March 5, 2026 12:00
Signed-off-by: Will Thomas <30wthomas@gmail.com>
Copy link
Copy Markdown
Collaborator

@rlepigre-skylabs-ai rlepigre-skylabs-ai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes, I don't have any further comments.

@Alizter
Copy link
Copy Markdown
Collaborator

Alizter commented Mar 11, 2026

@Durbatuluk1701 Could you add a change log entry in doc/changes?

Signed-off-by: Will Thomas <30wthomas@gmail.com>
@Alizter Alizter merged commit 8259a0f into ocaml:main Mar 12, 2026
29 checks passed
@Alizter
Copy link
Copy Markdown
Collaborator

Alizter commented Mar 12, 2026

Thanks!

@Durbatuluk1701 Durbatuluk1701 deleted the rocq_extr_dup_error branch March 12, 2026 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants