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

Feature Request: Extending the list of opened libraries in extraction #11956

Closed
JasonGross opened this issue Mar 29, 2020 · 9 comments
Closed
Labels
kind: enhancement Enhancement to an existing user-facing feature, tactic, etc. kind: feature New user-facing feature request or implementation. part: extraction The extraction mechanism.
Projects

Comments

@JasonGross
Copy link
Member

Currently it's not possible to customize the imports in extracted Haskell code. This makes it hard to use things like Extract Inlined Constant, because it means either the file needs postprocessing, or else we can't use libraries in the extracted code. So it would be nice to be able to manually set the header, at least for Haskell, involving the compiler flags and imports.

@JasonGross JasonGross added kind: feature New user-facing feature request or implementation. part: extraction The extraction mechanism. kind: enhancement Enhancement to an existing user-facing feature, tactic, etc. labels Mar 29, 2020
@herbelin
Copy link
Member

Hi @JasonGross, I'm not familiar with extraction to Haskell. What would it mean in terms of Coq API. Would it be a new command say Add Extraction Header "some string".?

@JasonGross
Copy link
Member Author

Yes. In OCaml, the two things it'd probably be used for are open statements and comment/license headers. (In OCaml, open statements are not required, but in Haskell, import statements generally are required.) We'd probably want commands to set (or, ideally, to reset and to append), and (for debugging purposes) print. Note that it needs to be possible to insert newlines into the extraction header.

@Zimmi48
Copy link
Member

Zimmi48 commented Apr 1, 2020

Wouldn't it be simpler to handle this at the level of the build system? I.e. have the build system support adding headers / footers providing in other source files to the generated file?

@JasonGross
Copy link
Member Author

No, I don't think so. Handling it in the build system means relying on sed and forces copying of the generated file to another location (or else in-place modification). There are some programs that are literally impossible to extract valid Haskell code for at present.

@tchajed might have more thoughts on this.

@Zimmi48
Copy link
Member

Zimmi48 commented Apr 1, 2020

I thought that "header" meant "lines at the beginning of file". If that's the case, then you clearly do not need sed. Here's another suggestion that is more adapted to adding multi-line headers: Add Extraction Header "some_filename_containing_the_header.hs"

@ejgallego
Copy link
Member

Add Extraction Header "some_filename_containing_the_header.hs"

That's a bit messy I think precisely; it introduces a dependency so coqdep has to be adapted, etc... I guess that given this is a haskell-specific feature the best is to use the configuration of the Haskell extraction to perform the setup.

Tho, if many files share that setting then boilerplate becomes annoying. My general feeling is that extracion could use a bit of full revamp in terms of infrastructure, but yeah, that's a lot of work.

@JasonGross
Copy link
Member Author

I thought that "header" meant "lines at the beginning of file".

Almost. The Haskell file provided by extraction starts with

{-# OPTIONS_GHC -cpp -XMagicHash #-}
{- For Hugs, use the option -F"cpp -P -traditional" -}

module Main where

import qualified Prelude

I need to add some imports here, such as

import qualified Data.Bits
import qualified Data.Char
import qualified Text.Printf
import qualified System.Environment

After staring at the extraction code, it looks like there is Set Extraction File Comment; I was not aware of this.

My request is then just to be able to append to (and reset) the list of opened libraries accessed via

val opened_libraries : unit -> ModPath.t list

@tchajed would this also fit your needs, or do you need more than this?

@JasonGross JasonGross changed the title Feature Request: Extraction Header Feature Request: Extending the list of opened libraries in extraction Apr 1, 2020
@JasonGross
Copy link
Member Author

I've started some work on this at https://github.com/JasonGross/coq/tree/extraction-imports, but it doesn't compile yet and there's not too much there

@JasonGross
Copy link
Member Author

Duplicate of #4189

@JasonGross JasonGross marked this as a duplicate of #4189 May 6, 2020
@Alizter Alizter added this to Done in Extraction May 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: enhancement Enhancement to an existing user-facing feature, tactic, etc. kind: feature New user-facing feature request or implementation. part: extraction The extraction mechanism.
Projects
Archived in project
Extraction
  
Done
Development

No branches or pull requests

4 participants