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

[coq 8.7] [serious] errors don't block proof-assert-next and we can continue asserting after error. #175

Closed
ejgallego opened this issue Apr 7, 2017 · 33 comments

Comments

@ejgallego
Copy link

ejgallego commented Apr 7, 2017

I would reopen #173 but I don't have the rights.

After coq/coq#530, Coq will always wrap errors in the markers, and put position information before. However, PG fails with this setting as now errors don't stop the buffer anymore.

So it seems I tried to guess wrong here; I am OK implementing whatever error output specification you want for -emacs, just let me know.

@ejgallego ejgallego changed the title In coq 8.7, errors don't proof-assert-next In coq 8.7, errors don't block proof-assert-next and we can continue asserting after error. Apr 7, 2017
@ejgallego ejgallego changed the title In coq 8.7, errors don't block proof-assert-next and we can continue asserting after error. [coq 8.7] [serious] errors don't block proof-assert-next and we can continue asserting after error. Apr 7, 2017
@ejgallego
Copy link
Author

Indeed removing the "emacs specific quoting" around the error fixed this problem:

diff --git a/vernac/topfmt.ml b/vernac/topfmt.ml
index ee55366..0b8d3a5 100644
--- a/vernac/topfmt.ml
+++ b/vernac/topfmt.ml
@@ -259,7 +259,7 @@ let init_color_output () =
    - Warning/Error: emacs_quote_err
    - Notice: unquoted
  *)
-let emacs_logger = gen_logger emacs_quote_info emacs_quote_err
+let emacs_logger = gen_logger emacs_quote_info (fun x -> x)
 
 (* Output to file, used only in extraction so a candidate for removal *)
 let ft_logger old_logger ft ?loc level mesg =

still waiting to see what you folks want before committing any further change to Coq.

@cpitclaudel
Copy link
Member

I'm not sure I understand the problem, unfortunately. @Matafou, do you know what the issue is?

@ejgallego
Copy link
Author

@cpitclaudel I think the issue is simple: what is the error format PG expects from Coq?

Once you let us know, we will implement that in Coq. In the past, Coq emitted errors in 2 different ways when -emacs was enabled, sometimes without "quoting" , and sometimes with it.

@JasonGross has suggested that maybe the markers maybe should not be present, but I am not sure anymore.

Thanks for having a look to this.

@ejgallego
Copy link
Author

BTW I'll be happy to chat on Coq's gitter if you folks think we can make progress that way.

@cpitclaudel
Copy link
Member

Ah, got it. Pierre introduced these markers, IIRC, so he'll know better than me. My understanding was that some things were to be displayed in real time, and other were to be displayed once processing was complete, and that was why there were two kinds?

@ejgallego
Copy link
Author

ejgallego commented Apr 12, 2017

I can't tell. Al Coq error messages in -emacs currently follow the pattern:

(location_info\n)?
(program_caret\n)?
MARKER[254]Error: msgMARKER[255]

where A? is an optional component (may not be present) and MARKER[X] is ASCII X. We can tweak that as needed. location_info is the typical

Toplevel input, characters 5-6: 

and program_caret is:

> Goal I.
>      ^

Note that in the past, such messages where also produced without the markers (*), hence the bug as PG seems to handle only those correctly.

(*) Whether an error message contained the marker used to depend on the Coq component originating it.

@cpitclaudel
Copy link
Member

Ok. I don't know enough about this then. Let's wait for @Matafou

@Matafou
Copy link
Contributor

Matafou commented Apr 13, 2017 via email

@ejgallego
Copy link
Author

A good example of the discrepancy in 8.6 is Print a vs Print Module a.

@Matafou
Copy link
Contributor

Matafou commented Apr 19, 2017

OK I am currently looking at this.

They are two different issues IIUW:

  1. detecting error messages
  2. parsing error location for highlighting the source

point 2) should rework once 1) is solved but it uses space counting whereas now toplevel gives a position which is easier to parse. So I may switch to this and let the space counting code for compatibility. No hurry though.

point 1) is broken because indeed error where not tagged at all before (It was only for warnings). The regexp detecting errors are not triggered anymore because they assume that for instance "Error:" appears at the beginning of a line, but now the special character is make this fail.

So yes removing the special characters is OK.

By the way @ejgallego why is "really painful" in topfmt.ml?

(* XXX: This is really painful! *)
module Emacs = struct

  (* Special chars for emacs, to detect warnings inside goal output *)
  let emacs_quote_start = String.make 1 (Char.chr 254)
  let emacs_quote_end   = String.make 1 (Char.chr 255)

  let emacs_quote_err g =
    hov 0 (str emacs_quote_start ++ g ++ str emacs_quote_end)

  let emacs_quote_info_start = "<infomsg>"
  let emacs_quote_info_end = "</infomsg>"

  let emacs_quote_info g =
    hov 0 (str emacs_quote_info_start++ brk(0,0) ++ g ++ brk(0,0) ++ str emacs_quote_info_end)

end

@ejgallego
Copy link
Author

ejgallego commented Apr 19, 2017

@Matafou ok, let me know the desired specification in terms of the components I described in my previous messages and I'll update the printing system immediately.

why is "really painful"

This comment was added back in 8.5 -> 8.6 , but IIRC it was not particularly aimed at the emacs stuff but indeed at the general feedback/pp situation at the time. -emacs mode was indeed problematic to handle for:

  • no documentation or specification wrt to what emacs expects,
  • same errors printed in different ways (see again Print vs Print Module),
  • global flag print_emacs scattered over all the system,
  • the quoting is arbitrary (special chars vs tags vs nothing) and doesn't follow message structure,
  • emacs output format is not designed to be parsed back, (what happens if the error msg contains ^Error ?)
  • duplicate loggers.

@Matafou
Copy link
Contributor

Matafou commented Apr 20, 2017

@Matafou ok, let me know the desired specification in terms of the components I described in my previous messages and I'll update the printing system immediately.

Thanks Emilio.

You mean this?:

(location_info\n)?
(program_caret\n)?
MARKER[254]Error: msgMARKER[255]

Please just remove MARKER[254] and MERGKER[255] for now.

I will ask for removal of program_caret once I have implement the parsing of location_info.

I may ask for a special tag ahead of Error: but I need to modify pg generic code to hide it from response buffer first.

why is "really painful"
This comment was added back in 8.5 -> 8.6 , but IIRC it was not particularly aimed at the emacs stuff but indeed at the general feedback/pp situation at the time. -emacs mode was indeed problematic to handle for:

no documentation or specification wrt to what emacs expects,

Indeed it is poorly documented. You can find a bit in coqloop@193 about prompts.

same errors printed in different ways (see again Print vs Print Module),

Indeed, currently pg regexp for coq errors is:

"^\\(In nested Ltac call\\|Error:\\|Discarding pattern\\|Syntax error:\\|System Error:\\|User Error:\\|User error:\\|Anomaly[:.]\\|Toplevel input[,]\\)"

If you simplify this i am all for it.

global flag print_emacs scattered over all the system,

True.

the quoting is arbitrary (special chars vs tags vs nothing) and doesn't follow message structure,

The generic mechanism of pg needs tags around warnings if one wants to see them when scritping several commands at once. On the contrary errors are considered to stop at the next prompt so we only need to recognize the beginning of an error message. Again this comes from he minimlity principle.

emacs output format is not designed to be parsed back

Indeed, only the content of goals and response buffers try to be parseable, not the content of coq session.

, (what happens if the error msg contains ^Error ?)

Not sure to understand what you mean here. If you mean that error message are not recognizable enough I agree.

duplicate loggers.

Isn't the whole point of loggers to have several ones?

@Matafou
Copy link
Contributor

Matafou commented Apr 20, 2017

Sorry now that I tested things by myself I think we need to do something a bit more complex because the current behaviour of pg is not satisfying concerning the display of all kinds of messages.

In loggers there are 5 kinds of messages. Debug, Info, Notice, Warning and Error.

In pg we have 3 levels of messages:

  1. messages that correspond to a real error that interrupted pg script processing, always display everything from that message to the next prompt.
  2. warning messages that must be printed even during the processing of several commands
  3. Other informational messages that should be hidden when not processing the last command of a group of commands.

Let us make this clean on pg side and adapt the emacs logger to that, I propose that the 5 coq levels are displayed like this 3 pg levels:

  1. Errors:
    (location_info\n)?
    (program_caret\n)?
    Error: msg

  2. Warnings:
    (location_info\n)?
    (program_caret\n)?
    Error: msg

  3. Notice and info and debug:
    (location_info\n)?
    (program_caret\n)?
    Error: msg

@ejgallego I can do it if you want.

@ejgallego what is the meaning of these negative locations? I have seen acomment about that elsewhere but can't remember

@Matafou
Copy link
Contributor

Matafou commented Apr 20, 2017

Should info be hidden when "Set Silent" is set? Currently I see these messages.

@Matafou
Copy link
Contributor

Matafou commented Apr 20, 2017

Eeeeh and why are goals diplayed as "Debug" messages???

Sorry but I am a bit puzzled by the current state of loggers...

@Matafou
Copy link
Contributor

Matafou commented Apr 20, 2017

@ejgallego I think we need to meet IRL for this. I will be at Sophie Germain friday 28 maybe we can have 30 minutes discussion at that moment?

@ejgallego
Copy link
Author

Indeed, currently pg regexp for coq errors is:

"^\\(In nested Ltac call\\|Error:\\|Discarding pattern\\|Syntax error:\\|System Error:\\|User Error:\\|User error:\\|Anomaly[:.]\\|Toplevel input[,]\\)"
If you simplify this i am all for it.

Indeed now all the errors are of that form, and always include the header Error: .

The generic mechanism of pg needs tags around warnings if one wants to see them when scritping several commands at once.

Note again that some errors (such as Print Module a where quoted as warnings, this is where the problem originates, as in resolving the duality of errors I chose to follow the behavior of Print Module a.

Not sure to understand what you mean here. If you mean that error message are not recognizable enough I agree.

I meant this. This is in fact the reason I resolved the ambiguity opting to add the markers. I didn't realize PG was already buggy for errors with markers (such as Print Module a).

Isn't the whole point of loggers to have several ones?

Well that has to be handled with care, in the past in particular we had several loggers and different paths were taken for errors even under the same flags. There are some examples in the bugzilla.

Let us make this clean on pg side and adapt the emacs logger to that, I propose that the 5 coq levels are displayed like this 3 pg levels:

Sorry I don't understand what you mean here as all the levels are similar, note that PG in the past used at least 4 modes not 3. [<infomsg> tag, nothing, marker, Error + misc headers]

Feel free to submit a PR of course.

@ejgallego what is the meaning of these negative locations? I have seen acomment about that elsewhere but can't remember

This is due to ltac semantics reporting the error in the definition of tactics. Previously these messages were reported as unlocated or with the wrong location. Now the offset to the current sentence is computed accurately wrt the input buffer.

Should info be hidden when "Set Silent" is set? Currently I see these messages.

That is a good question, do you have an example illustrating a change of behavior wrt 8.6?

Eeeeh and why are goals diplayed as "Debug" messages???

Are you sure you are in trunk?

@ejgallego I think we need to meet IRL for this. I will be at Sophie Germain friday 28 maybe we can have 30 minutes discussion at that moment?

I think 28 may work for me.

@Matafou
Copy link
Contributor

Matafou commented Apr 20, 2017

Eeeeh and why are goals diplayed as "Debug" messages???
Are you sure you are in trunk?

This one was my fault.

@ejgallego
Copy link
Author

This one was my fault.

Well, it was my fault but I fixed it quickly :D anyways we've merged quite a few commits trying to consolidate the printing structure and indeed some new bugs have been exposed, please bear with us, it is basically very hard to test this kind of interactive use.

ejgallego added a commit to ejgallego/coq that referenced this issue Apr 21, 2017
In 8.6 + emacs, errors were quoted sometimes with special
markers (e.g. `Print Module foo.` for a non-existing `foo`)

In 8.7 we uniformized error handling and now all errors are quoted,
however, this behavior confuses emacs as it seems that the quotes are
meant to be applied only to warnings.

We thus reflect the de-facto situation, removing quoting for errors
and updating the code so it is clear that the quoter is a warnings
quoter.

This fixes ProofGeneral for trunk users.

c.f. ProofGeneral/PG#175
@ejgallego
Copy link
Author

ejgallego commented Apr 21, 2017

Ok I've submitted coq/coq#581 so Coq trunk becomes usable to PG users. IMHO the current rules are pretty clear from the code itself:

let gen_logger dbg warn ?pre_hdr level msg = match level with
  | Debug   -> msgnl_with !std_ft (make_body dbg   dbg_hdr ?pre_hdr msg)
  | Info    -> msgnl_with !std_ft (make_body dbg  info_hdr ?pre_hdr msg)
  | Notice  -> msgnl_with !std_ft (make_body noq  info_hdr ?pre_hdr msg)
  | Warning -> Flags.if_warn (fun () ->
               msgnl_with !err_ft (make_body warn warn_hdr ?pre_hdr msg)) ()
  | Error   -> msgnl_with !err_ft (make_body noq   err_hdr ?pre_hdr msg)

that is to say, Debug and Info get treated by the dbg quoter, warnings by the warn one, and Error and Notice are left untreated.

@Matafou
Copy link
Contributor

Matafou commented Apr 21, 2017

Looks good to me. Thanks @ejgallego !

Now that we are back to previous behavour (fixed and more uniform), I must say that don't like those special chars because they may confuse emacs in presence of unicode. I would like to replace them by <warning></warning>.

@ejgallego
Copy link
Author

Your call folks, I thought that the quoting behavior of the past would make more sense.

I would like to replace them by .

by?

@Matafou
Copy link
Contributor

Matafou commented Apr 22, 2017

Sorry, edited my last message.

@ejgallego
Copy link
Author

<warning></warning> sounds fine, do you want that change pushed now?

@Matafou
Copy link
Contributor

Matafou commented Apr 23, 2017 via email

ejgallego added a commit to ejgallego/coq that referenced this issue Apr 23, 2017
In 8.6 + emacs, errors were quoted sometimes with special
markers (e.g. `Print Module foo.` for a non-existing `foo`)

In 8.7 we uniformized error handling and now all errors are quoted,
however, this behavior confuses emacs as it seems that the quotes are
meant to be applied only to warnings.

We thus reflect the de-facto situation, removing quoting for errors
and updating the code so it is clear that the quoter is a warnings
quoter.

This fixes ProofGeneral for trunk users.

c.f. ProofGeneral/PG#175
ejgallego added a commit to ejgallego/coq that referenced this issue Apr 23, 2017
In 8.6 + emacs, errors were quoted sometimes with special
markers (e.g. `Print Module foo.` for a non-existing `foo`)

In 8.7 we uniformized error handling and now all errors are quoted,
however, this behavior confuses emacs as it seems that the quotes are
meant to be applied only to warnings.

We thus reflect the de-facto situation, removing quoting for errors
and updating the code so it is clear that the quoter is a warnings
quoter. We also update the warnings quoter to use a warning tag
instead of a non-printable char.

This fixes ProofGeneral for trunk users.

c.f. ProofGeneral/PG#175
@ejgallego
Copy link
Author

PR updated.

ejgallego added a commit to ejgallego/coq that referenced this issue Apr 23, 2017
In 8.6 + emacs, errors were quoted sometimes with special
markers (e.g. `Print Module foo.` for a non-existing `foo`)

In 8.7 we uniformized error handling and now all errors are quoted,
however, this behavior confuses emacs as it seems that the quotes are
meant to be applied only to warnings.

We thus reflect the de-facto situation, removing quoting for errors
and updating the code so it is clear that the quoter is a warnings
quoter. We also update the warnings quoter to use a warning tag
instead of a non-printable char.

This fixes ProofGeneral for trunk users.

c.f. ProofGeneral/PG#175
@Matafou
Copy link
Contributor

Matafou commented Apr 24, 2017

Ready for merging imho.

@ejgallego
Copy link
Author

ejgallego commented Apr 24, 2017

@Matafou did you mean to comment on coq/coq#581 ?

@Matafou
Copy link
Contributor

Matafou commented Apr 24, 2017

Yes sorry.

@ejgallego
Copy link
Author

Ok so I think we can consider this fixed for now, it works for me! However you may want to update the warning detection code in PG I guess.

@Matafou
Copy link
Contributor

Matafou commented Apr 24, 2017 via email

@ejgallego
Copy link
Author

Cool thanks. There is still time to improve -emacs if you feel like needing some other stuff.

@Matafou
Copy link
Contributor

Matafou commented Apr 24, 2017

Hopefully Proofgeneral/xml will replace -emacs soon and we may remove -emacs option in a near future.

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

No branches or pull requests

3 participants