coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: Clément Pit-Claudel <cpitclaudel AT gmail.com>
- To: Coq Club <coq-club AT inria.fr>
- Subject: [Coq-Club] Separate/incremental extraction of parts of a Coq library
- Date: Wed, 30 Oct 2019 10:13:39 -0400
- Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=cpitclaudel AT gmail.com; spf=Pass smtp.mailfrom=cpitclaudel AT gmail.com; spf=None smtp.helo=postmaster AT mail-qk1-f177.google.com
- Ironport-phdr: 9a23:gWzeVB/Mwu265/9uRHKM819IXTAuvvDOBiVQ1KB20+kcTK2v8tzYMVDF4r011RmVBN6dsqofwLSO+4nbGkU4qa6bt34DdJEeHzQksu4x2zIaPcieFEfgJ+TrZSFpVO5LVVti4m3peRMNQJW2aFLduGC94iAPERvjKwV1Ov71GonPhMiryuy+4ZLebxhGiTanfL9+MBu7oQrQu8UKnIBvNrs/xhzVr3VSZu9Y33loJVWdnxb94se/4ptu+DlOtvwi6sBNT7z0c7w3QrJEAjsmNXs15NDwuhnYUQSP/HocXX4InRdOHgPI8Qv1Xpb1siv9q+p9xCyXNtD4QLwoRTiv6bpgRQT2gykbKTE27GDXitRxjK1FphKhuwd/yJPQbI2MKfZyYr/RcdYcSGFcXMheSjZBD5u8YYUSEeQPPuhWoIfyqFQSohWzHhWsCeD1xzNUmnP706833uI8Gg/GxgwgGNcOvWzKodXxLqASVP66zK/UzTrbdf1W2Cv95JHWfxAlu/6MQK9/ftTVyUIyEA7Kkk2QqY35PzyJ0uQCqXWb4Pd+WuKrkGMnpARxrSKuxscokIXGmoUVylXd+Ch/3Y07K9q4SEthbt6lFptdry+aN4xxQsw5WW5oojw2yrMBuZ68eiUB1ZcpxwbHZvCZb4SF5gjvWeWRLDtimn5pZqyziwyv/UWiyODwTte43VdWoiZYl9TAq3MA2hPW58WIV/dw/Vut1DOO2g3S9O5JI0U5mKnUJp4vwrM9k5oevVrMEyLzlkj5l7SZe0ch9+Wr5OnofKjpq5mBPIFukA7+KL4hmsmnDOQ4LAcOW2+b9Py51LL5/E35RKxGjuQ1kqXEqZzaK9kXq6y7DgNP3YYj7BG/Dzii0NsGh3UIMFVFeBefg4joPVHBPuz4AO+hj1iwlDpn3fPLM737DpnTMHTPjq3tcat/5kNe0AYzyMpQ55NQCrEPOvLzXUrxucTEAR8hMgy03/roCNFn2YMDRG2AHKuZPbjdsV+N/O0vIu2MaJUJtzb6Lvgp/+TugmMhmV8BYamp2oMaZ2y/HvR/OkmWfX7sgsoaHmoRpQo/TOnqiEWYXjJJZnayWbg85jAhB468A4fDXNPlvLvU9yCiVrZSe2oOXluLCDLjc5iOc/YKciObZMF7xG8qT7+kHqQlVBSjshPN87t7a8HQ8zAUuJargNNt5vHYkRgv+TFwJ8uY2mCJCWpzmzVbFHcNwKljrBklmR+42q9ijqkdTIQLvq4bYkIBLZfZitdCJZXyVwbGJInbTV+nRpC/Amh0QItunJkBZEFyH9jkhRfGjXLzX+0l0oeTDZlxyZrymmDrLp8kmXnD3aglyVIhR5kXbDz0tutE7wHWQrXxvQCcnqeue74b2XeUpmiGxGuK+kpfVVwpXA==
Hi all.
I'm running out of ideas regarding a tricky Coq extraction question.
I have a compiler from Foo to Bar written in Coq, then a compiler from Bar to
Baz written in OCaml. Foo and Bar are ASTs defined as `Inductive`s in Coq;
Baz is an AST defined in OCaml.
I don't write programs directly in Foo; instead I use Gallina as a
metaprogramming language to generate Foo ASTs. Then I extract these ASTs to
OCaml and use the BarBaz compiler written in OCaml to generate Baz ASTs and
write these to disk.
Currently, the FooBar compiler is bundled with all my example Foo programs
and extracted as one FooBar.ml file, and then the BarBaz compiler depends on
FooBar.ml and compiles all the example Foo programs.
I'm looking for a way to extract example programs separately from the
compiler itself. This would allow me to distribute an OPAM package FooBarBaz
including the whole compilation pipeline, and then users could write their
program in Coq, like this:
```
Definition prog : foo_ast := ….
Module FooBarBaz.
Axiom baz_ast: Type.
Extract Constant baz_ast => "FooBarBaz.BarBaz.baz_ast".
Axiom compile : forall (prog: foo_ast): baz_ast.
Extract Constant compile => "FooBarBaz.compile_foo".
Axiom write_to_disk : forall (compiled_prog: baz_ast): unit.
Extract Constant compile => "FooBarBaz.write_to_disk".
End FooBarBaz.
Definition main : unit := FooBarBaz.write_to_disk (FooBarBaz.compile_foo
prog) "prog.baz".
Extraction "prog.ml" main.
```
The generated prog.ml would be linked against the OPAM FooBarBaz package, and
running prog.ml would produce "prog.baz".
Unfortunately, this doesn't work: prog.ml has its own copy of the Foo and Bar
ASTs, and these are not nominally the same types as those in the FooBarBaz
package, so the call to FooBarBaz.compile_foo doesn't typecheck ("This
expression has type foo_ast but an expression was expected of type
FooBarBaz.FooBar.foo_ast)
Is there an easy way around this issue? I guess I'd need to either:
* Convince OCaml to accept to unify two structurally equal types; is this
possible without an unsafe cast?
* Tell Coq to extract only the definitions not provided by
`FooBarBaz.FooBar`, and to add `open FooBarBaz.FooBar` at the top of
`prog.ml`; is there a way to do that? Some form of incremental extraction?
* Add unsafe casts and hope for the best, which I think should work fine, but
won't detect issues like version mismatches between the FooBarBaz library
used on the OCaml and the FooBar library used on the Coq side.
I've also considered the following:
* Serializing Bar ASTs on the Coq side and reparsing them on the OCaml side,
but they contain functions, so that's not trivial.
* Marshalling the ASTs, but that's just as unsafe as Obj.magic, as far as I
understand
* Using library extraction and delete all modules already included in
FooBar.ml, then prefixing all references to these modules in the remaining
code with FooBarBaz.FooBar.
* Recompiling a fresh copy of the whole FooBarBaz library every time I need
to compile a Foo program, but that's inconvenient and heavy-handed.
Any advice?
Thanks!
Clément.
- [Coq-Club] Separate/incremental extraction of parts of a Coq library, Clément Pit-Claudel, 10/30/2019
- Re: [Coq-Club] Separate/incremental extraction of parts of a Coq library, Xavier Leroy, 10/30/2019
- Re: [Coq-Club] Separate/incremental extraction of parts of a Coq library, Clément Pit-Claudel, 10/30/2019
- Re: [Coq-Club] Separate/incremental extraction of parts of a Coq library, Xavier Leroy, 10/31/2019
- Re: [Coq-Club] Separate/incremental extraction of parts of a Coq library, Clément Pit-Claudel, 10/31/2019
- Re: [Coq-Club] Separate/incremental extraction of parts of a Coq library, Xavier Leroy, 10/31/2019
- Re: [Coq-Club] Separate/incremental extraction of parts of a Coq library, Stefan Monnier, 10/30/2019
- Re: [Coq-Club] Separate/incremental extraction of parts of a Coq library, Erik Martin-Dorel, 10/30/2019
- Re: [Coq-Club] Separate/incremental extraction of parts of a Coq library, Clément Pit-Claudel, 10/30/2019
- Re: [Coq-Club] Separate/incremental extraction of parts of a Coq library, Matthieu Sozeau, 10/31/2019
- Re: [Coq-Club] Separate/incremental extraction of parts of a Coq library, Clément Pit-Claudel, 10/31/2019
- Re: [Coq-Club] Separate/incremental extraction of parts of a Coq library, Matthieu Sozeau, 10/31/2019
- Re: [Coq-Club] Separate/incremental extraction of parts of a Coq library, Clément Pit-Claudel, 10/31/2019
- Re: [Coq-Club] Separate/incremental extraction of parts of a Coq library, Xavier Leroy, 10/30/2019
Archive powered by MHonArc 2.6.18.