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 #781 PG does not position to error. #782

Merged
merged 2 commits into from
Sep 5, 2024

Conversation

Matafou
Copy link
Contributor

@Matafou Matafou commented Jul 9, 2024

We cannot use the " ^^^ " thing to compute the error location because commands are not stripped of newlines anymore (#774).

Solution: use the character position information with the following subtleties

  • position are given by coq as bytes positions.
  • position given by coq is the position from the previous "." fed to coq. I.e. we must be careful to strip any blank after the final "." ofthe previous (hence from all) commands.

@Matafou
Copy link
Contributor Author

Matafou commented Jul 9, 2024

This needs a bit of a test and discussion.

It seems to work but it is difficult to be sure.

Things to check that I can think of.

  • Is the computation of position robust to any encoding?
  • Currently I strip trailing spaces of all commands otherwise coq's error location are wrong. Should we make this an option (in case it is not suitable for other provers)?
  • test error highlighting in CI? This would need to check temporary overlays (they last 2 sec) which is not great.

@Matafou
Copy link
Contributor Author

Matafou commented Jul 10, 2024

I just added a test that checks that the correct region is highlighted.
@Hendrik or @erikmd can you review pls? I sum up the fix:

Note: testing this I found something strange in error location info from coq

@Matafou
Copy link
Contributor Author

Matafou commented Jul 23, 2024

This is not ready yet. I will try to fix this by the end of the summer.

@erikmd
Copy link
Member

erikmd commented Aug 25, 2024

Hi @Matafou, thanks a lot for working on this!

It seems to work but it is difficult to be sure.

OK, I wouldn't have foreseen that fixing #781 would be that involved.

But anyway, if it works in practice and we can get a good CI tests coverage, that'll already be pretty good!

Is the computation of position robust to any encoding?

I saw you used byte-to-position so that should be Okay, anyway we'll be able to CI-test with a few standard encodings.

Currently I strip trailing spaces of all commands otherwise coq's error location are wrong. Should we make this an option (in case it is not suitable for other provers)?

Good question; this needs some discussion I guess, since your PR mainly touches coq.el, but also proof-shell.el.

Anyway, we don't have a CI testsuite for other provers (I had opened this issue: #505 but it stalled).

test error highlighting in CI? This would need to check temporary overlays (they last 2 sec) which is not great.

I believe this is testable, and actually you already tested it IIUC:

I just added a test that checks that the correct region is highlighted.

@Hendrik or @erikmd can you review pls? I sum up the fix:

there was no sentence after your comment's colon ↑

Note: testing this I found something coq/coq#19355

Does this mean that this PG PR will only work for Coq ≥ 8.20 ?

in this case, should we revert #774 for Coq ≤ 8.19 ?

I believe the start-of-term will be dense for you as well @Matafou, but let me know (Cc @hendriktews) if you have a free slot in the upcoming days and would like to video-meet to discuss this, I'll try to join.

@erikmd erikmd added pg: proof-shell Related to (default) master PG using proof-shell priority: high kind: fix labels Aug 25, 2024
@Matafou
Copy link
Contributor Author

Matafou commented Sep 2, 2024

The two failing tests are on coq-8.11. I will try to investigate but maybe this is not blocking.
One problem remains: support the coq bug that has just been fixed in coq master?

@Matafou Matafou force-pushed the fix-no-strip-newlines branch 2 times, most recently from 48b0afc to 6b4fbdc Compare September 4, 2024 09:13
@Matafou
Copy link
Contributor Author

Matafou commented Sep 4, 2024

This seems ready. I will merge this tomorrow if no one objects.
@erikmd this is an important fix imho, is there something to do to update pg distributed packages?

@Matafou Matafou force-pushed the fix-no-strip-newlines branch 2 times, most recently from 0c6589b to 61f8ab6 Compare September 5, 2024 06:11
@Matafou
Copy link
Contributor Author

Matafou commented Sep 5, 2024

This PR

  • fixes PG does not position to error #781
  • makes use of the character location given by coq instead of the "^^^^"
  • revealed Strange error location in coqtop coq/coq#19355 in coq wrt to error location of curly braces.
  • works around it by detecting suspicious locations (probably almost 100% accurate) and defaulting to something reasonable (beginning of command).
  • introduces 2 tests of error highlighting including one specific to the workaround.
  • has not been tested very widely, I guess users will complain if something is wrong.

Tests is also added to check the exact position of the error
highlighting.

Description of the fix.

We cannot use the " ^^^ " thing to compute the error location because
commands are not stripped of newlines anymore (ProofGeneral#774).

Solution: use the character position information given in the error
message with the following subtleties:

- position are given by coq **bytes** positions.
- position given by coq is the position from the previous "." fed to
  coq. I.e. we must be careful to strip any blank after the final "." of
  a command.
- Coq < 8.11 has a small glitch on positions, the test is compatible
  with both behaviour.
- coq <= 8.20 has a bug on position for curly braces.

In the test we make the disappearing timeout of overlay bigger
so that tests don't fail on slow VMs (maybe useless).

NOTE: coq error locations are quite wrong when we insert
spaces (instead of a newline) after a command. PG was wrongly
inserting a space after Set Silent./ Unset Silent, which triggered
this problem. This is fixed by this PR. But other silent commends
should triped of trailing blanks. I leave it to another PR.
@Matafou
Copy link
Contributor Author

Matafou commented Sep 5, 2024

  • re-introduced removal of error location from the response buffer.
  • understood and partially fixed an old small bug on error locations: coq gives wrong location if one insert spaces at the end of a command (before the newline). We used to insert "Set/Unset Silent. " with a trailing space. I leave to another PR the removal of other similar wrong strings. I only fix this one because it happens all the time.

@Matafou
Copy link
Contributor Author

Matafou commented Sep 5, 2024

I decided to add the fix of hardwired command strings (removing trailing spaces) in a separate commit of this same PR.

@Matafou
Copy link
Contributor Author

Matafou commented Sep 5, 2024

The failed CI is not related (reached VM limit). I merge now.

@Matafou Matafou merged commit 067bffa into ProofGeneral:master Sep 5, 2024
151 of 152 checks passed
@erikmd
Copy link
Member

erikmd commented Sep 9, 2024

Thanks a lot @Matafou !

sorry for replying late

@erikmd this is an important fix imho, is there something to do to update pg distributed packages?

It depends on the distribution you think of:

  • for MELPA, as soon as the PR has been merged in PG master, it is rebuilt later on during the same day
  • for NonGNU-devel ELPA, this is the same
  • for NonGNU ELPA (stable releases), we will need to do a release — note that a tag is not enough, see this comment by Stefan: Minor tweaks and cleanups opam-switch-mode#10 (comment)

hendriktews added a commit to hendriktews/PG that referenced this pull request Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: fix pg: proof-shell Related to (default) master PG using proof-shell priority: high
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants