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

module extraction sometimes incorrectly prefixes record fields with generated file-module names #3846

Closed
coqbot opened this issue Dec 10, 2014 · 2 comments · Fixed by #17324
Labels
part: extraction The extraction mechanism.
Projects
Milestone

Comments

@coqbot
Copy link
Contributor

coqbot commented Dec 10, 2014

Note: the issue was created automatically with bugzilla2github tool

Original bug ID: BZ#3846
From: @JasonGross
Reported version: 8.4
CC: coq-bugs-redist@lists.gforge.inria.fr

@coqbot
Copy link
Contributor Author

coqbot commented Dec 10, 2014

Comment author: @JasonGross

This occurs in both 8.4 and trunk:

$ cat A.v

Record aR := { aF : nat ; another : nat }.

$ cat B.v

Require Import A.

Module Bar.
  Definition foo (x : aR) := x.(aF).
End Bar.

Module Application.
  Include A.
  Include Bar.
End Application.

Extraction "B" Application.

$ coq_makefile -R . Top A.v B.v B.ml B.mli | make -f - all COQSRCLIBS=
ocamldep -slash "B.mli" > "B.mli.d" || ( RV=$?; rm -f "B.mli.d"; exit ${RV} )
ocamldep -slash "B.ml" > "B.ml.d" || ( RV=$?; rm -f "B.ml.d"; exit ${RV} )
"coqdep" -c -R "." Top "B.v" > "B.v.d" || ( RV=$?; rm -f "B.v.d"; exit ${RV} )
"coqdep" -c -R "." Top "A.v" > "A.v.d" || ( RV=$?; rm -f "A.v.d"; exit ${RV} )
"coqc" -q -R "." Top A
"coqc" -q -R "." Top B
ocamlc -c -rectypes -thread -I /afs/csail.mit.edu/u/j/jgross/.local64/lib/ocaml/camlp5 B.mli
ocamlc -c -rectypes -thread -I /afs/csail.mit.edu/u/j/jgross/.local64/lib/ocaml/camlp5 B.ml
File "B.ml", line 34, characters 6-15:
Error: Unbound record field Coq__2.aF
make: *** [B.cmo] Error 2

$ cat B.ml

type nat =
| O
| S of nat

module Coq__1 = struct
 type aR = { aF : nat; another : nat }
end
type aR = Coq__1.aR = { aF : nat; another : nat }

module Coq__2 = struct
 (** val aF : aR -> nat **)

 let aF x = x.aF
end
let aF = Coq__2.aF

module Application =
 struct
  type aR = Coq__1.aR = { aF : nat; another : nat }

  (** val aF : aR -> nat **)

  let aF a =
    a.aF

  (** val another : aR -> nat **)

  let another a =
    a.another

  (** val foo : Coq__1.aR -> nat **)

  let foo x =
    x.Coq__2.aF
 end

From what I can tell, Coq decides to wrap top-level file-modules in their own generate modules when they are later [Include]d (why does Coq do this?). It incorrectly decides to prefix record field names with the name of the generated module when they are later used.

@coqbot coqbot added the part: extraction The extraction mechanism. label Oct 18, 2017
@letouzey letouzey removed their assignment Jun 25, 2018
@pi8027 pi8027 self-assigned this Aug 26, 2019
@Alizter Alizter added this to Bugs in Extraction May 31, 2022
herbelin added a commit to herbelin/github-coq that referenced this issue Mar 4, 2023
…eld names.

Fixes coq#3846
Fixes coq#14843
Fixes coq#16677
Fixes coq#12813

When dealing with collisions by means of encapsulation in a Coq_XX
module, a field name should be bound to the name of the corresponding
inductive type declaration.

We use Table.repr_of_r to do that, but early enough to have the
relevant information on how to bind a field to the name of the
inductive that declares it. (In particular, we cannot rely on the
global tables in structures.ml because they are not valid when inside
a functor, see coq#17321.)

Note that Haskell and Scheme do not use records and it is ok on their
side.
@herbelin
Copy link
Member

herbelin commented Mar 4, 2023

Fixed in #17324.

@coqbot-app coqbot-app bot added this to the 8.17.1 milestone May 24, 2023
Zimmi48 pushed a commit to Zimmi48/coq that referenced this issue Jun 19, 2023
…eld names.

Fixes coq#3846
Fixes coq#14843
Fixes coq#16677
Fixes coq#12813

When dealing with collisions by means of encapsulation in a Coq_XX
module, a field name should be bound to the name of the corresponding
inductive type declaration.

We use Table.repr_of_r to do that, but early enough to have the
relevant information on how to bind a field to the name of the
inductive that declares it. (In particular, we cannot rely on the
global tables in structures.ml because they are not valid when inside
a functor, see coq#17321.)

Note that Haskell and Scheme do not use records and it is ok on their
side.

(cherry picked from commit c19b2cd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
part: extraction The extraction mechanism.
Projects
Archived in project
Extraction
  
Bugs
Development

Successfully merging a pull request may close this issue.

4 participants