Stream: Coq Hackathon and Working Group, Winter 2022

Topic: Dune session


view this post on Zulip Paolo Giarrusso (Feb 15 2022 at 11:34):

Didn't find a topic here yet for dune

view this post on Zulip Emilio Jesús Gallego Arias (Feb 15 2022 at 13:10):

Indeed, thanks @Paolo Giarrusso

view this post on Zulip Emilio Jesús Gallego Arias (Feb 15 2022 at 13:10):

if you see the schedule we put it in a core slot as there was a lot of interest

view this post on Zulip Paolo Giarrusso (Feb 15 2022 at 13:36):

I added a few things under https://github.com/coq/coq/wiki/CoqWG-2022-02#a-preliminary-program-is-feel-free-to-add-your-topic. I labeled them as BedRock because I felt a bit bad about adding so many topics :-)

view this post on Zulip Emilio Jesús Gallego Arias (Feb 15 2022 at 13:37):

Great thanks!

view this post on Zulip Rodolphe Lepigre (Feb 16 2022 at 10:47):

I'm planning to spend a bit of time on trying to add something like dune coqtop (as I heard @Emilio Jesús Gallego Arias suggest at some point). This seems like the right thing to do to me, but it is also not completely trivial. I spent an hour or so looking into making a rough prototype, but I got quickly stuck on when trying to run a dummy version (just calling coqtop) from PG.

As far as I can tell, PG invokes coqtop following three variables: coq-prog-name (the program to invoke, does not accept arguments), coq-prog-args and coq-prog-env. What I did was set coq-prog-name to dune, and then add coqtop as first argument in coq-prog-args. However, this fails since PG keeps overwriting coq-prog-args (moving -emacs to first position). I'm not sure how to proceed form here: I was hoping to not have to hack PG at the same time...

Another question I have on the design of coqtop is: why does it not take care applying the options given in _CoqProject? To me, it seems a bit weird that the editors would each have to look for this file, and apply the arguments on their own. That seems like a work that could be shared rather easily, and the editors would only have to care about specific options (e.g., adding -emacs for PG).

Another issue I thought about is source code location when using dune: maybe there should be a generalised -Q PATH MOD_PATH option, say -QG SRC_PATH BUILD_PATH MOD_PATH which also maps the module path to where the compiled files are placed. This way, dune coqtop could simply set the paths correctly, and no hack would be required on the editor side.

(Some of the above was discussed by in https://github.com/ProofGeneral/PG/issues/477 at least, and some hack to strip the _build/default here https://github.com/cpitclaudel/company-coq/pull/257.)

view this post on Zulip Emilio Jesús Gallego Arias (Feb 16 2022 at 10:47):

Hi @Rodolphe Lepigre , that's a superb project!

view this post on Zulip Emilio Jesús Gallego Arias (Feb 16 2022 at 10:48):

I have a couple of pointers w.r.t. that, but I suggest we discuss them in the dune session

view this post on Zulip Emilio Jesús Gallego Arias (Feb 16 2022 at 10:48):

I also have a tree with an skeleton implementation of dune coqtop

view this post on Zulip Rodolphe Lepigre (Feb 16 2022 at 10:48):

Sure, sounds good!

view this post on Zulip Emilio Jesús Gallego Arias (Feb 16 2022 at 10:48):

will share later as I'm going for lunch now, and need to work a bit on my slides for the diversity session

view this post on Zulip Emilio Jesús Gallego Arias (Feb 16 2022 at 10:49):

I will answer the rest of your questions later

view this post on Zulip Emilio Jesús Gallego Arias (Feb 16 2022 at 10:49):

but for the arguments, dune already knows that to pass to them

view this post on Zulip Emilio Jesús Gallego Arias (Feb 16 2022 at 10:49):

exactly, the idea is that you do dune coqtop foo.v and two things happne

view this post on Zulip Emilio Jesús Gallego Arias (Feb 16 2022 at 10:49):

view this post on Zulip Emilio Jesús Gallego Arias (Feb 16 2022 at 10:50):

view this post on Zulip Emilio Jesús Gallego Arias (Feb 16 2022 at 10:50):

the inspiration is from the way dune utop works

view this post on Zulip Paolo Giarrusso (Feb 16 2022 at 17:27):

For @Emilio Jesús Gallego Arias when you're back: do you still think there will be a dune hacking session tomorrow?

view this post on Zulip Emilio Jesús Gallego Arias (Feb 16 2022 at 17:27):

I will try to do the second part showing the implementation of the coqdoc rules

view this post on Zulip Emilio Jesús Gallego Arias (Feb 16 2022 at 17:27):

if it doesn't happen tomorrow

view this post on Zulip Emilio Jesús Gallego Arias (Feb 16 2022 at 17:27):

I will find a date next week and record it

view this post on Zulip Emilio Jesús Gallego Arias (Feb 16 2022 at 17:28):

or Friday

view this post on Zulip Emilio Jesús Gallego Arias (Feb 16 2022 at 17:28):

Scheduling needs work, ideas are welcome

view this post on Zulip MackieLoeffel (Feb 17 2022 at 08:28):

I would be interested in solving the issue described here: https://coq.zulipchat.com/#narrow/stream/240550-Dune-devs.20.26.20users/topic/Multi-package.20repositories But I don't really know enough dune to understand what exactly the problem is and how it could be fixed. @Emilio Jesús Gallego Arias Do you have some time to look into this together today or are you already fully booked?

view this post on Zulip Rodolphe Lepigre (Feb 17 2022 at 08:53):

Would you say this is more important than looking into proper editor support (i.e., the dune coqtop thing) @MackieLoeffel? If not, we could try looking at the dune coqtop thing together (hopefully with Emilio as well), and then try to fix the other issue once we get some more understanding of dune.

view this post on Zulip MackieLoeffel (Feb 17 2022 at 08:57):

I think dune coqtop / better editor support is more important than my issue. So If there is not enough time for both, I think it is better to look into dune coqtop. I would also be happy to help with dune coqtop.

view this post on Zulip Paolo Giarrusso (Feb 17 2022 at 09:03):

I'm coming in 5 minutes, but Emilio wrote he's away...

view this post on Zulip Rodolphe Lepigre (Feb 17 2022 at 09:05):

MackieLoeffel said:

I think dune coqtop / better editor support is more important than my issue. So If there is not enough time for both, I think it is better to look into dune coqtop. I would also be happy to help with dune coqtop.

My hope is that we can join efforts, and I need somebody that can help hack emacs and PG. And you know way more about these than I do. I hate emacs.

view this post on Zulip Rodolphe Lepigre (Feb 17 2022 at 09:06):

I'd say, let's meet in some breakout room 7. ;)

view this post on Zulip MackieLoeffel (Feb 17 2022 at 09:06):

I see. I am happy to help with emacs hacking. Let's join efforts then :+1: I'll be in the breakout room in a minute.

view this post on Zulip Janno (Feb 17 2022 at 09:21):

I've been looking into the PG issue and it seems that it overrides coq-prog-args with options extracted from _CoqProject if it finds that file. It also conses -emacs to that list, thus making it impossible to get any other first argument even when you modify _CoqProject by adding -arg.

view this post on Zulip Janno (Feb 17 2022 at 09:22):

Interestingly there are options in the code to skip that step (which would be annoying in many other ways) but the option is unused.

view this post on Zulip MackieLoeffel (Feb 17 2022 at 10:30):

We figured out how to call dune from emacs:

(setq coq-prog-name "opam")
(defun coq-prog-args-advice (res)
  `("exec" "--" "dune" "coqtop" ,buffer-file-name "--" "-emacs"))
(advice-add 'coq-prog-args :filter-return #'coq-prog-args-advice)

view this post on Zulip Kenji Maillard (Feb 17 2022 at 12:08):

This snippet looks worthy to be kept on the coq wiki but I don't find any page on dune.
Should there be a section getting started in the Coq FAQ listing this kind of advices ?

view this post on Zulip Rodolphe Lepigre (Feb 17 2022 at 12:13):

Turns out this does not quite work yet, but we'll indeed need to find where we want to put this. But we are still in the process of patching dune, so the proof general tweaks are not really useful to anyone but us yet.

view this post on Zulip MackieLoeffel (Feb 17 2022 at 12:14):

I adapted the snippet above such that it uses opam exec to find the right coqtop even when one has multiple switches. I needed to add another advice since proof general hardcodes coqtop in one place. Use with care, this might break at any time.

  ; setup proof general to use opam exec -- coqtop such that it always
  ; finds the right coqtop. Note that it does not help to override the
  ; coq-prog-args variable (not to be confused with the coq-prog-args
  ; function) as proof general calls the coq-prog-args function in the
  ; end and basically ignores the variable. So we advice the
  ; coq-prog-args function.
  (setq coq-prog-name "opam")
  (defun coq-prog-args-advice (res)
    ;; (message "coq-prog-args returned: %S" res)
    (append '("exec" "--" "coqtop") res))
  (advice-add 'coq-prog-args :filter-return #'coq-prog-args-advice)

  ; coq-callcoq uses only coq-prog-name and ignores coq-prog-args so
  ; we have to override it
  (defvar coq-callcoq-additional-args nil)
  (setq coq-callcoq-args '("exec" "--" "coqtop"))
  (defun coq-callcoq-advice (option &optional expectedretv)
    "Call coqtop with the given OPTION and return the output.
    The given option should make coqtop return immediately.
    Optionally check the return code and return nil if the check
    fails.  Return also nil on other kinds of errors (e.g., `coq-prog-name'
    not found).
    This function supports calling coqtop via tramp."
    (let ((coq-command (or coq-prog-name "coqtop"))
          retv)
      (condition-case nil
          (with-temp-buffer
            ; the following line is modified compared to the original
            (setq retv (apply 'process-file coq-command nil t nil
                              (append coq-callcoq-args (if option (cons option nil) nil))))
            (if (or (not expectedretv) (equal retv expectedretv))
                (buffer-string)))
        (error nil))))
  (advice-add 'coq-callcoq :override #'coq-callcoq-advice)

view this post on Zulip MackieLoeffel (Feb 17 2022 at 12:18):

Actually, there is a significantly simpler solution: Just create a file opam-coqtop with the following contents and put it into the path.

#!/bin/sh
opam exec -- coqtop "$@"

Then one just needs to do

  (setq coq-prog-name "opam-coqtop")

view this post on Zulip Paolo Giarrusso (Feb 17 2022 at 12:20):

but this script wouldn't work for dune coqtop, unless you parse cmdline args in shell to rearrange them, right?

view this post on Zulip MackieLoeffel (Feb 17 2022 at 12:22):

That depends on how dune coqtop expects its arguments. If it accepts the arguments the same way as coqtop it would work. Otherwise one would need to add some hacks to the shell script. But I see this as an argument why dune coqtop should accept the arguments in the same format as coqtop.

view this post on Zulip Paolo Giarrusso (Feb 17 2022 at 12:31):

That's not quite possible: at the very least, the caller shouldn't supply the -Q and -w options.

view this post on Zulip Paolo Giarrusso (Feb 17 2022 at 12:32):

so either you filter those out in shell, or you patch Proof General; I'd hope the original patch is enough for now, and for upstream or somebody with a clue to do the Emacs part properly :-)

view this post on Zulip MackieLoeffel (Feb 17 2022 at 12:33):

dune coqtop could also just ignore the additional options (maybe with a special flag on the commandline).

view this post on Zulip MackieLoeffel (Feb 17 2022 at 12:35):

But I don't know what the right option is.My feeling at the moment is that having a shell script (or python script) that filters out the options might be easier than patching PG but that is mostly because I've written more shell scripts than elisp.

view this post on Zulip Paolo Giarrusso (Feb 17 2022 at 12:37):

BTW I also posted the API question here: https://coq.zulipchat.com/#narrow/stream/240550-Dune-devs.20.26.20users/topic/Dune.20internals.3A.20build.20a.20target.20.60--only-deps.60

view this post on Zulip Paolo Giarrusso (Feb 17 2022 at 12:37):

I did it on the other stream in case the discussion exceeds the CoqWG

view this post on Zulip Paolo Giarrusso (Feb 17 2022 at 12:47):

oh @Emilio Jesús Gallego Arias is back! :-)

view this post on Zulip Emilio Jesús Gallego Arias (Feb 17 2022 at 12:47):

Hi folks, yes I'm back!

view this post on Zulip Emilio Jesús Gallego Arias (Feb 17 2022 at 12:47):

I had a long doctor appt this morning + lunch

view this post on Zulip Emilio Jesús Gallego Arias (Feb 17 2022 at 12:48):

give me 10 minutes to catch up

view this post on Zulip Emilio Jesús Gallego Arias (Feb 17 2022 at 12:48):

but see what I wrote in the jsCoq topic

view this post on Zulip Emilio Jesús Gallego Arias (Feb 17 2022 at 12:48):

it seems to me that we could do a more thematic day

view this post on Zulip Emilio Jesús Gallego Arias (Feb 17 2022 at 12:48):

half a day like "dune hacking day"

view this post on Zulip Emilio Jesús Gallego Arias (Feb 17 2022 at 12:48):

schedule it some day, announce it, and focus solely on dune work

view this post on Zulip Emilio Jesús Gallego Arias (Feb 17 2022 at 12:49):

because now as organizer I have a few things to do too, and I feel we got so many ideas as to cover them in a one hour breakout session

view this post on Zulip Emilio Jesús Gallego Arias (Feb 17 2022 at 12:49):

but for sure let's try to do a breakout todya

view this post on Zulip Emilio Jesús Gallego Arias (Feb 17 2022 at 12:49):

even if just to start things

view this post on Zulip Tomás Díaz (Feb 17 2022 at 13:02):

Kenji Maillard said:

This snippet looks worthy to be kept on the coq wiki but I don't find any page on dune.
Should there be a section getting started in the Coq FAQ listing this kind of advices ?

Maybe this one could go in the environment setup doc?

view this post on Zulip Kenji Maillard (Feb 17 2022 at 13:09):

yep exactly, thanks for digging that page up, I added a link in the FAQ so that it's easier to access

view this post on Zulip Emilio Jesús Gallego Arias (Feb 17 2022 at 13:16):

Ok I'm good if you folks wanna do a Dune breakout

view this post on Zulip MackieLoeffel (Feb 17 2022 at 13:17):

I would be available now as well. How about @Rodolphe Lepigre ?

view this post on Zulip Emilio Jesús Gallego Arias (Feb 17 2022 at 13:19):

Ok let's go to room 2

view this post on Zulip MackieLoeffel (Feb 17 2022 at 13:19):

:+1: Give me one minute

view this post on Zulip Paolo Giarrusso (Feb 17 2022 at 13:21):

coming!

view this post on Zulip Emilio Jesús Gallego Arias (Feb 17 2022 at 13:58):

@Rudi Grinberg , we have one question, we want to implement dune coqtop foo.v which basically builds all deps of foo.v and calls coqtop with the right flags.

view this post on Zulip Emilio Jesús Gallego Arias (Feb 17 2022 at 13:59):

Does it make sense to add an alias @deps-foo.v as to implement the build deps step?

view this post on Zulip Emilio Jesús Gallego Arias (Feb 17 2022 at 13:59):

Otherwise we could introduce like a file with the hashes, but seems strange

view this post on Zulip Emilio Jesús Gallego Arias (Feb 17 2022 at 13:59):

or export directly the deps action, maybe that's best

view this post on Zulip Emilio Jesús Gallego Arias (Feb 17 2022 at 13:59):

?

view this post on Zulip Rudi Grinberg (Feb 17 2022 at 15:30):

why do you need the intermediate file or alias dependency at all?

view this post on Zulip Rodolphe Lepigre (Feb 17 2022 at 16:02):

When we run dune coqtop foo.v we need to make sure that all dependencies of foo.v are compiled.

view this post on Zulip Rodolphe Lepigre (Feb 17 2022 at 16:02):

(But we do not need to compile foo.v itself.)

view this post on Zulip Emilio Jesús Gallego Arias (Feb 17 2022 at 16:02):

folks let's move the discussion to the Dune subtopic as I see there are several topics

view this post on Zulip Emilio Jesús Gallego Arias (Feb 17 2022 at 16:03):

but indeed @Rudi Grinberg that's the reason

view this post on Zulip Rudi Grinberg (Feb 17 2022 at 16:03):

Sure, I can reply in the subtopic

view this post on Zulip Rodolphe Lepigre (Feb 17 2022 at 16:19):

@Emilio Jesús Gallego Arias would you have a bit of time to look into things with me? I think I just need some help to get started, I'm still quite confused about how dune works.

view this post on Zulip Rudi Grinberg (Feb 17 2022 at 17:06):

Is the hackathon in session now?

view this post on Zulip Emilio Jesús Gallego Arias (Feb 17 2022 at 17:08):

@Rodolphe Lepigre I have to leave now, my week got a bit unlucky due to many personal constraints

view this post on Zulip Emilio Jesús Gallego Arias (Feb 17 2022 at 17:08):

tomorrow too

view this post on Zulip Rodolphe Lepigre (Feb 17 2022 at 17:09):

No worries @Emilio Jesús Gallego Arias!

view this post on Zulip Emilio Jesús Gallego Arias (Feb 17 2022 at 17:09):

Next week I should have plenty of time, maybe Rudi is around tho, the rooms are open

view this post on Zulip Rodolphe Lepigre (Feb 17 2022 at 17:10):

Sure, if you are up to join the session @Rudi Grinberg we can perhaps have a chat in a breakout room?

view this post on Zulip Rodolphe Lepigre (Feb 17 2022 at 17:12):

I'm gonna go to room 7 just in case anyone wants to join.

view this post on Zulip Rudi Grinberg (Feb 17 2022 at 17:13):

ok let me join


Last updated: Jun 10 2023 at 23:01 UTC