Skip to content

feature(coq): add rules for coqffi#6248

Closed
Alizter wants to merge 1 commit intoocaml:mainfrom
Alizter:ps/rr/feature_coq___add_rules_for_coqffi
Closed

feature(coq): add rules for coqffi#6248
Alizter wants to merge 1 commit intoocaml:mainfrom
Alizter:ps/rr/feature_coq___add_rules_for_coqffi

Conversation

@Alizter
Copy link
Copy Markdown
Collaborator

@Alizter Alizter commented Oct 17, 2022

This adds a coq.ffi stanza with a (modules ) field which turns the cmis of specified modules of a library into .v files using coqffi.

Currently we only support cmi's from libraries in the workspace and those installed using Dune.

cc @lthms would appreciate if you could take a look.

@Alizter Alizter force-pushed the ps/rr/feature_coq___add_rules_for_coqffi branch 2 times, most recently from 02cb06d to fe6feee Compare October 24, 2022 20:51
@Alizter Alizter marked this pull request as ready for review October 24, 2022 20:52
@Alizter Alizter requested a review from ejgallego October 24, 2022 20:53
@Alizter Alizter added the coq label Oct 24, 2022
@Alizter Alizter assigned Alizter and unassigned Alizter Oct 24, 2022
@lthms
Copy link
Copy Markdown
Contributor

lthms commented Oct 25, 2022

Thanks a lot for this! I will try to have a look at this PR this week.

I’m a bit surprised by this:

The intended use case is for the .mli file to become the interface for the .ml file extracted from the .v file.

Though the idea is very nice, coqffi is not intended to do that. What coqffi does is ensuring that the Coq definitions which uses the axioms introduced in the FFI module it generates correctly use the implementation of the original mli file.

This is summarized by this graph introduced in a blogpost about how to use coqffi to implement en Echo server in Coq.

dependency graph in a typical coqffi based project

@Alizter
Copy link
Copy Markdown
Collaborator Author

Alizter commented Oct 25, 2022

@lthms Thank you very much for the detailed reply. It looks like I misunderstood what coqffi is doing. I will mark this PR as draft and study your blog post further so I can amend the implementation.

@Alizter Alizter marked this pull request as draft October 25, 2022 14:53
@Alizter Alizter force-pushed the ps/rr/feature_coq___add_rules_for_coqffi branch from fe6feee to 9571e96 Compare October 25, 2022 23:11
@Alizter
Copy link
Copy Markdown
Collaborator Author

Alizter commented Oct 25, 2022

@lthms I've updated this PR so that it now takes in the cmi of the specified module instead. In order to do this, the user must specify which library is being talked about. This allows for composition with libraries in a workspace or those that are installed. For now, only libraries installed using Dune are supported (due to the presence of cmi).

I thought about allowing for multiple libraries, but that would make resolving the module name trickier.

Another question: Do you want flag support?

@Alizter Alizter marked this pull request as ready for review October 25, 2022 23:20
@Alizter Alizter force-pushed the ps/rr/feature_coq___add_rules_for_coqffi branch from 9571e96 to 30cf20d Compare October 26, 2022 00:20
@Alizter Alizter force-pushed the ps/rr/feature_coq___add_rules_for_coqffi branch from 30cf20d to 89a095a Compare October 26, 2022 14:50
@Alizter Alizter force-pushed the ps/rr/feature_coq___add_rules_for_coqffi branch from 89a095a to b2a98ba Compare November 6, 2022 19:12
@ejgallego ejgallego self-assigned this Nov 6, 2022
@Alizter Alizter force-pushed the ps/rr/feature_coq___add_rules_for_coqffi branch from b2a98ba to b790764 Compare November 6, 2022 19:37
@Alizter
Copy link
Copy Markdown
Collaborator Author

Alizter commented Nov 6, 2022

I've added some basic flag support.

@lthms
Copy link
Copy Markdown
Contributor

lthms commented Nov 6, 2022

The support you are describing looks awesome, thank you so much for doing it. I on the other hand have not been the best reviewer you could have hoped for.

I had a quick look this evening, mostly the code part, and the tests. Looks good so far. I plan to have a test-run of my own this week.

@Alizter
Copy link
Copy Markdown
Collaborator Author

Alizter commented Nov 7, 2022

I've also added :standard support today which let's you coqffi an entire library.

@Alizter Alizter force-pushed the ps/rr/feature_coq___add_rules_for_coqffi branch 2 times, most recently from 96eca16 to 2e71dac Compare November 7, 2022 21:16
@Alizter Alizter requested a review from rgrinberg November 7, 2022 21:16
@Alizter
Copy link
Copy Markdown
Collaborator Author

Alizter commented Nov 8, 2022

OK so there is a huge issue with this PR atm, which is that coq.theory cannot pick up the output of the coq.ffi stanza. I will try to fix this, but if I don't finish this week, coq.ffi will have to miss 3.6.

@Alizter Alizter added this to the 3.6.0 milestone Nov 8, 2022
@Alizter Alizter force-pushed the ps/rr/feature_coq___add_rules_for_coqffi branch 2 times, most recently from b0be94b to 3d23123 Compare November 9, 2022 13:27
@Alizter
Copy link
Copy Markdown
Collaborator Author

Alizter commented Nov 9, 2022

I've fixed the ability for coq.theory to pick up the generated .v files. However I had to drop support for :standard since supporting dir_contents in this case is quite complicated. It is not a particularly important use case either.

@Alizter Alizter force-pushed the ps/rr/feature_coq___add_rules_for_coqffi branch from 3d23123 to df808fc Compare November 9, 2022 14:09
@lthms
Copy link
Copy Markdown
Contributor

lthms commented Nov 9, 2022

I agree. Besides, using coqffi on a hierarchy of modules is a bit more involved, and would require to generate a bunch more file, so I think it’s okay to not support it for now.

@emillon emillon modified the milestones: 3.6.0, 3.7.0 Nov 14, 2022
This adds a coq.ffi stanza with a (modules ) field which turns
specified .mli files into .v files using coqffi.

The intended use case is for the .mli file to become the interface for
the .ml file extracted from the .v file.

TODO: Add fields for more arguments to coqffi?

Signed-off-by: Ali Caglayan <alizter@gmail.com>

ps-id: 0347ad6c-3758-4184-8bcf-29fdee6b1f29
@Alizter Alizter force-pushed the ps/rr/feature_coq___add_rules_for_coqffi branch from df808fc to fec8a13 Compare November 15, 2022 17:36
Copy link
Copy Markdown
Collaborator

@ejgallego ejgallego left a comment

Choose a reason for hiding this comment

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

Rules look good, however coqffi is an independent tool and indeed the code this PR adds doesn't depend on anything from the Coq_* namespace, so I suggest to place the code instead into a Coqffi file (which submodules Sources, Stanza, etc...` if desired; similar for the tests.

@ejgallego
Copy link
Copy Markdown
Collaborator

Moreover this should maybe be guared with (using coqffi), it seems to me.

@lthms
Copy link
Copy Markdown
Contributor

lthms commented Nov 15, 2022

Can dune easily sort module by dependencies? Meaning, if i give (modules a b) but in practice b uses things introduced by a, then can we know that easily from dune?

If we do, I think it would make more sense taking the time to support this.

For a list of modules sorted by dependencies relation A, B, C, then it would mean

  • For each module, use the --witness flag: this will generate a .ffi file in addition to a .v file
  • For B, pass the -I A.ffi ; for C, pass -I A.ffi -I B.ffi

(with the correct path prefix)

By doing so, it’s possible to have C.v rely on a type introduced in either A or B.

Does it makes sense?

@ejgallego
Copy link
Copy Markdown
Collaborator

ejgallego commented Nov 15, 2022

@lthms , yes it makes sense, and Dune can do that. I guess in your case the dep information is what ocamldep would give. Then we just need to setup the rules as:

{ a.ml }       --{ coqffi }--> { a.v a.ffi }
{ b.ml a.ffi } --{ coqffi } --> { b.v b.ffi }

@lthms
Copy link
Copy Markdown
Contributor

lthms commented Nov 16, 2022

Exactly! The set of ffi files used as input for some rules will be an overset, but that is not an issue in practice.

@Alizter
Copy link
Copy Markdown
Collaborator Author

Alizter commented Nov 16, 2022

OK seems I need to do some more work on this. I have split coqffi into its own stanza/language/files so that we can easily work on it in the future. I need to understand how the .ffi file rules will work so I will open a new draft and close this PR.

#6489

@Alizter Alizter closed this Nov 16, 2022
@ejgallego
Copy link
Copy Markdown
Collaborator

Why do we need to close PRs just to reopen them again? It makes the dicussion harder to follow, and worse meta-data in general.

@Alizter
Copy link
Copy Markdown
Collaborator Author

Alizter commented Nov 16, 2022

@ejgallego because this is now a new feature and not an extension to Coq lang.

@ejgallego
Copy link
Copy Markdown
Collaborator

@ejgallego because this is now a new feature and not an extension to Coq lang.

We can just rename the PR? Anyways, not a big deal, just wondering about the logic as a curiosity.

@Alizter Alizter deleted the ps/rr/feature_coq___add_rules_for_coqffi branch January 25, 2023 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Abandoned

Development

Successfully merging this pull request may close these issues.

6 participants