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

Extraction generates invalid code for primitive records in functors #16288

Closed
JasonGross opened this issue Jul 5, 2022 · 1 comment · Fixed by #17321
Closed

Extraction generates invalid code for primitive records in functors #16288

JasonGross opened this issue Jul 5, 2022 · 1 comment · Fixed by #17321
Labels
kind: bug An error, flaw, fault or unintended behaviour. part: extraction The extraction mechanism. part: primitive records The primitive record and primitive projection mechanism.
Projects
Milestone

Comments

@JasonGross
Copy link
Member

Description of the problem

Module Type Nop. End Nop.
Module Empty. End Empty.
Module M (N : Nop).
  Local Set Primitive Projections.
  Record M_t_NonEmpty elt := { M_m :> list elt }.
End M.
Module M' := M Empty.
Require Import Coq.extraction.Extraction.
Require Import Coq.extraction.ExtrOcamlBasic.
Extraction Language OCaml.
Recursive Extraction M'.
(*
module type Nop =
 sig
 end

module Empty =
 struct
 end

module M =
 functor (N:Nop) ->
 struct
  type 'elt coq_M_t_NonEmpty = 'elt list
    (* singleton inductive, whose constructor was Build_M_t_NonEmpty *)

  (** val coq_M_m : 'a1 coq_M_t_NonEmpty -> 'a1 list **)

  let coq_M_m =
    coq_M_m
 end

module M' = M(Empty)

*)
Extraction TestCompile M'.
(* Error: Unbound value coq_M_m *)

Coq Version

8.14.0

@JasonGross JasonGross added part: extraction The extraction mechanism. part: primitive records The primitive record and primitive projection mechanism. kind: bug An error, flaw, fault or unintended behaviour. labels Jul 5, 2022
JasonGross added a commit to JasonGross/fiat-crypto that referenced this issue Jul 5, 2022
COQBUG(coq/coq#16288) means we can't use
extraction with primitive records inside functors
JasonGross added a commit to mit-plv/fiat-crypto that referenced this issue Jul 5, 2022
COQBUG(coq/coq#16288) means we can't use
extraction with primitive records inside functors
@Alizter Alizter added this to OCaml in Extraction Oct 16, 2022
@Alizter Alizter moved this from OCaml to Haskell in Extraction Oct 16, 2022
OwenConoly pushed a commit to mit-plv/fiat-crypto that referenced this issue Nov 13, 2022
COQBUG(coq/coq#16288) means we can't use
extraction with primitive records inside functors
herbelin added a commit to herbelin/github-coq that referenced this issue Mar 1, 2023
- The code for extracting a primitive projection was referencing the
  constant form of the projection.
- The code for compiling the constant form of the projection was doing
  a call to the global table of projections which is however not fed in
  functors.
- The declaration of constants bound to a projection had a small size
  and were then inlined.

Instead of relying on the table of projections, we use the
"match"-expanded form of the projections which has the advantage of be
valid in all target languages. In particular, in OCaml extraction,
this is anyway reprinted as a field.

Note: we need to move the fake_match_projection function a bit
earlier.
herbelin added a commit to herbelin/github-coq that referenced this issue Mar 1, 2023
herbelin added a commit to herbelin/github-coq that referenced this issue Mar 1, 2023
- The code for extracting a primitive projection was referencing the
  constant form of the projection.
- The code for compiling the constant form of the projection was doing
  a call to the global table of projections which is however not fed in
  functors.
- The declaration of constants bound to a projection had a small size
  and were then inlined.

Instead of relying on the table of projections, we use the
"match"-expanded form of the projections which has the advantage of be
valid in all target languages. In particular, in OCaml extraction,
this is anyway reprinted as a field.

Note: we need to move the fake_match_projection function a bit
earlier.
herbelin added a commit to herbelin/github-coq that referenced this issue Mar 1, 2023
@herbelin
Copy link
Member

herbelin commented Mar 1, 2023

Problem was a standard one: the code was relying on a imperative state which is unknown when inside a functor, leading to a self-referencing extraction.

Fixed in #17321.

herbelin added a commit to herbelin/github-coq that referenced this issue Mar 6, 2023
- The code for extracting a primitive projection was referencing the
  constant form of the projection.
- The code for compiling the constant form of the projection was doing
  a call to the global table of projections which is however not fed in
  functors.
- The declaration of constants bound to a projection had a small size
  and were then inlined.

Instead of relying on the table of projections, we use the
"match"-expanded form of the projections which has the advantage of be
valid in all target languages. In particular, in OCaml extraction,
this is anyway reprinted as a field.

Note: we need to move the fake_match_projection function a bit
earlier.
herbelin added a commit to herbelin/github-coq that referenced this issue Mar 6, 2023
herbelin added a commit to herbelin/github-coq that referenced this issue Mar 6, 2023
herbelin added a commit to herbelin/github-coq that referenced this issue Dec 8, 2023
- The code for extracting a primitive projection was referencing the
  constant form of the projection.
- The code for compiling the constant form of the projection was doing
  a call to the global table of projections which is however not fed in
  functors.
- The declaration of constants bound to a projection had a small size
  and were then inlined.

Instead of relying on the table of projections, we use the
"match"-expanded form of the projections which has the advantage of be
valid in all target languages. In particular, in OCaml extraction,
this is anyway reprinted as a field.

Note: we need to move the fake_match_projection function a bit
earlier.
herbelin added a commit to herbelin/github-coq that referenced this issue Dec 8, 2023
herbelin added a commit to herbelin/github-coq that referenced this issue Dec 10, 2023
- The code for extracting a primitive projection was referencing the
  constant form of the projection.
- The code for compiling the constant form of the projection was doing
  a call to the global table of projections which is however not fed in
  functors.
- The declaration of constants bound to a projection had a small size
  and were then inlined.

Instead of relying on the table of projections, we use the
"match"-expanded form of the projections which has the advantage of be
valid in all target languages. In particular, in OCaml extraction,
this is anyway reprinted as a field.

Note: we need to move the fake_match_projection function a bit
earlier.
herbelin added a commit to herbelin/github-coq that referenced this issue Dec 10, 2023
coqbot-app bot added a commit that referenced this issue Feb 23, 2024
…rimitive projections in functors

Reviewed-by: ppedrot
Co-authored-by: ppedrot <ppedrot@users.noreply.github.com>
@coqbot-app coqbot-app bot added this to the 8.20+rc1 milestone Feb 23, 2024
louiseddp pushed a commit to louiseddp/coq that referenced this issue Feb 27, 2024
- The code for extracting a primitive projection was referencing the
  constant form of the projection.
- The code for compiling the constant form of the projection was doing
  a call to the global table of projections which is however not fed in
  functors.
- The declaration of constants bound to a projection had a small size
  and were then inlined.

Instead of relying on the table of projections, we use the
"match"-expanded form of the projections which has the advantage of be
valid in all target languages. In particular, in OCaml extraction,
this is anyway reprinted as a field.

Note: we need to move the fake_match_projection function a bit
earlier.
louiseddp pushed a commit to louiseddp/coq that referenced this issue Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug An error, flaw, fault or unintended behaviour. part: extraction The extraction mechanism. part: primitive records The primitive record and primitive projection mechanism.
Projects
Archived in project
Extraction
  
Haskell
2 participants