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

Fix byte-compilation problems #643

Merged
merged 6 commits into from
Mar 10, 2022
Merged

Conversation

dominique-unruh
Copy link
Contributor

@dominique-unruh dominique-unruh commented Mar 8, 2022

The current MELPA version does not work properly:

  • error byte-code: Symbol’s function definition is void: proof-easy-config-check-setup Seems solved by 124db99
  • Byte compiling gives errors when compiling qrhl-input-25.el in Emacs 26+ (and vice verse for qrhl-input.el) even though will never be included.

@dominique-unruh
Copy link
Contributor Author

One idea for solving the compilation errors would be to merge the Emacs 25 & 26 files into a single .el file.
Upon second thoughts, I don't think this works:
Even if we make the Emacs 26-incompatible code conditional in that file, it will still be compiled.
What we need is a way to conditionally exclude a file or a code block from compilation in the first place.
I don't know a way for that.

The only solution I can see at the moment is to disable the compilation of the code completely (wrapping everything in Emacs macro dont-compile). But that means that we do not get byte-compilation advantages for that file (even in the file that is actually loaded).

@erikmd mentions (eval-when-compile …) but I don't understand how this can be used here.

@erikmd
Copy link
Member

erikmd commented Mar 8, 2022

To suggest a slightly different idea using eval-when-compile,
I'm wondering whether some global #ifdef-like elisp form would be possible to address item 2?

cf. https://www.gnu.org/software/emacs/manual/html_node/elisp/Eval-During-Compile.html

(eval-when-compile
  (unless (fboundp 'some-new-thing)
    (defmacro 'some-new-thing ()
      (compatibility code))))

"This is often good for code that’s only a fallback for compatibility with other versions of Emacs. "

So my suggestion would be to:

Enclose the forms of qrhl-input-25.el in:

(eval-when-compile
  (when (version< emacs-version "26")
  
    (require 'quail)
    (quail-define-package
    … etc.
))

and enclose the forms of qrhl-input.el in:

(eval-when-compile
  (unless (version< emacs-version "26")

    (require 'quail)
    (quail-define-package
    … etc.
))

@monnier @Matafou @hendriktews do you think that this could work without breaking other things?

@dominique-unruh
Copy link
Contributor Author

dominique-unruh commented Mar 8, 2022

@erikmd mentions (eval-when-compile …) but I don't understand how this can be used here.

I just realized what @erikmd means. There is already an eval-when-compile in the source file! (Since I just copied this from the Emacs dist, I didn't really know what's in there.) So I think the solution is to make the code inside eval-when-compile conditional, and that might well work. Will try to do so later.

EDIT: This was written before seeing the preceding message by @erikmd. So "@erikmd means" refers to #636 (comment)

@dominique-unruh
Copy link
Contributor Author

  • I tried @erikmd 's suggestion, it didn't work. (I put the whole code within (eval-when-compile (when false ...)) and still got the compilation error.)
  • I tried removing the existing eval-when-compile (under the assumption that I get a compile-time listp error only in code that is actually executed during compilation). Still I get the compilation error.
  • I put the whole file into dont-compile. That works. But it means the code will be interpreted each time it is loaded.

Any ideas? Otherwise I will go with the dont-compile approach. @erikmd @monnier @Matafou @hendriktews

@dominique-unruh
Copy link
Contributor Author

Slightly related: I saw this in proof-general.el:

  (let ((byte-compile-directories
         '("generic" "lib"
           "coq" "easycrypt" "pghaskell" "pgocaml" "pgshell" "phox"
           )))
    (dolist (dir byte-compile-directories)
      (add-to-list 'load-path (expand-file-name dir pg-init--pg-root)))))

Here qrhl is not included. I assume it should be but I thought I'd check just in case. (After all, the error shows that the qrhl code is actually byte compiled, so I don't understand what this fragment does.)

@erikmd
Copy link
Member

erikmd commented Mar 8, 2022

I tried @erikmd 's #643 (comment), it didn't work. (I put the whole code within (eval-when-compile (when false ...)) and still got the compilation error.)

could you try again with something like (eval-when-compile (when nil … )) ?

because just to recall, false is a truthy value (everything ≠ nil does so actually)

@erikmd
Copy link
Member

erikmd commented Mar 8, 2022

Slightly related: I saw this in proof-general.el:

  (let ((byte-compile-directories
         '("generic" "lib"
           "coq" "easycrypt" "pghaskell" "pgocaml" "pgshell" "phox"
           )))
    (dolist (dir byte-compile-directories)
      (add-to-list 'load-path (expand-file-name dir pg-init--pg-root)))))

Here qrhl is not included. I assume it should be but I thought I'd check just in case. (After all, the error shows that the qrhl code is actually byte compiled, so I don't understand what this fragment does.)

Good question. Actually this code had been devised by @cpitclaudel so he'd certainly summarize this much better than me
(IIRC, this code was intended to workaround a flaw of MELPA and/or package.el when some files are not in toplevel folder)

But in any case, "qrhl" should definitely be listed there…

@dominique-unruh
Copy link
Contributor Author

@erikmd

could you try again with something like (eval-when-compile (when nil … )) ?
Sorry. nil was what I used. I wrote false in the comment accidentally.

dominique-unruh added a commit to dominique-unruh/proofgeneral that referenced this pull request Mar 8, 2022
@erikmd
Copy link
Member

erikmd commented Mar 8, 2022

@dominique-unruh you may want to test and integrate the patch suggested in the other PR:

#636 (comment)

Thanks a lot @monnier for your input ! 👍

@dominique-unruh
Copy link
Contributor Author

Checks fail after 6cf7d1d but this is positive: It means the qrhl-input compilation issue is now detected by the CI.

@dominique-unruh
Copy link
Contributor Author

Question: Where should I add my test case? @erikmd

I created a test case to see whether qrhl-input loads correctly on all Emacses (especially because I don't have an Emacs 25 instance). I put it in ci/simple-tests because that sounded logical. But in CI, simple-tests are only tested with a single Emacs (but with many coqs). It seems the tests in test-indent are tested with all Emacses, but the directory name indicates that it's not the right place. So how should I include test-qrhl.el so that it is tested with all Emacses?

PS: The test case is currently intentionally broken to check whether testing occurs.

@erikmd
Copy link
Member

erikmd commented Mar 10, 2022

Hi @dominique-unruh, thanks for your question!

I created a test case to see whether qrhl-input loads correctly on all Emacses (especially because I don't have an Emacs 25 instance). I put it in ci/simple-tests because that sounded logical. But in CI, simple-tests are only tested with a single Emacs (but with many coqs). It seems the tests in test-indent are tested with all Emacses, but the directory name indicates that it's not the right place. So how should I include test-qrhl.el so that it is tested with all Emacses?

You precisely pinpointed a limitation of the current CI that we are currently working on with @hendriktews;
Namely, it is easy to test test-indent with several Emacsen because indentation does not depend on Coq,
while the tests involved in folders that possibly require Coq use a debian-based Docker image where there is currently only one version of emacs.
it's not an issue if the test you add now is not "comprehensive" because we have a PG maintainers telco next week
where we'll be able to start doing further CI tweaks.

So I'd suggest that:

  • either you just put the test in ci/simple-tests, and if the Ci is green, I'll merge it today (the sooner, the better)
  • or you try to do something more involved if you have some time (because I suspect that the test you'll add don't use Coq :) and thereby should be separated from simple-tests where Coq is needed)

@dominique-unruh
Copy link
Contributor Author

dominique-unruh commented Mar 10, 2022

@erikmd
Your message exactly coincided with my push right now.

Just adding to simple-tests is not enough because this specific issue needs testing in different Emacs versions (because the code is different in Emacs 25 and Emacs 26.) And I don't have Emacs 25 available for testing locally.

So what I did as a stopgap is to include the test in simple-tests, but to add it in test test-indent job in test.yml. (See 876629e) A bit untidy, but until you decide how to structure the tests, it will do.

Now I can continue to fix the issues in this pull request.

@erikmd
Copy link
Member

erikmd commented Mar 10, 2022

@dominique-unruh OK, LGTM! thank you

@dominique-unruh
Copy link
Contributor Author

dominique-unruh commented Mar 10, 2022

@monnier
I incorporated your patch from #636 (comment) for the files qrhl.el and qrhl-input-25.el and those parts work fine.

I have not included the patch for proof-easy-config.el because I am not sure what it does (the problem related to easy-config was resolved by (require proof-easy-config)) and because it also got corrupted by copy-and-pasting it into the comment. (The line containing ***@***.***) I think we can leave it out at least from the pull request.

My main problem is qrhl-input.el: I also incorporated your patch there (b1e3780) but it does not work. Compilation on Emacs 25 still fails (see the CI). I do not understand enough Elisp-magic to figure out what needs to be done to make it work the same as in qrhl-input-25.el. Can you help with this one?

@monnier
Copy link
Contributor

monnier commented Mar 10, 2022 via email

The first was accidentally removed in 847492f.

The second is necessary running PG from byte-compiled code.
Otherwise we get the error `byte-code: Symbol’s function definition is void: proof-easy-config-check-setup` when loading PG with prover qrhl.
Surprisingly, the error does not occur when PG is not byte-compiled.
@dominique-unruh
Copy link
Contributor Author

Thanks @monnier, your patch seems to work fine. (I tested in my local Emacs, and the CI checks at least whether loading the input methods raises any error on all supported Emacses)

I rebased everything on master, and the CI passes. @erikmd

From my side, this fix is ready for merging.

@dominique-unruh dominique-unruh marked this pull request as ready for review March 10, 2022 14:12
Copy link
Member

@erikmd erikmd left a comment

Choose a reason for hiding this comment

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

👍 Many thanks @dominique-unruh for this very tidy fixup PR.

@erikmd erikmd merged commit a5021b9 into ProofGeneral:master Mar 10, 2022
@dominique-unruh
Copy link
Contributor Author

@erikmd The new version is already on MELPA and I verified that it now installs fine (in Emacs 27.1). :)

@dominique-unruh dominique-unruh deleted the qrhl-tool branch March 10, 2022 15:41
@monnier
Copy link
Contributor

monnier commented Mar 10, 2022 via email

@monnier
Copy link
Contributor

monnier commented Oct 11, 2022 via email

@dominique-unruh
Copy link
Contributor Author

Oh, I didn't think about the case where we compile with Emacs-25. The patch below might fix it.

@monnier
I'm not sure there is an outstanding bug to fix here. Your earlier patch (#643 (comment)) seems to already address the issue (and is, I think, conflicting with your new patch).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants