PR#6604: Only allow directives with filename and at the beginning of the line#931
PR#6604: Only allow directives with filename and at the beginning of the line#931dra27 merged 7 commits intoocaml:trunkfrom
Conversation
|
would you add a test case for the first line? |
|
Added it. Also included a couple more directives to test the non-first line case and two consecutive directives (which was the reason I had to add the code to "put back" the newline at the end of a directive). |
|
Could you add an entry to the |
|
Oops, forgot about it, sorry. I was unsure under which section to add it, so I just added to "Bug fixes", let me know if that's not the best place for it. I'm also not sure whether the name of the reporter is correct, from Mantis I can only see the username, yet everyone seems to use real names in the changelog. |
|
Regarding the Changelog:
Regarding the patch itself: the position handling is non-trivial and would need a careful review. In particular, we should make sure that the change does not affect the lexing positions of other tokens (than the lexer directives) in the source. |
|
I've updated the changelog, thanks. With regards to the position handling, my thinking was that: as long as the |
|
Agreed - I've been staring at the position manipulation code for a while, trying to convince myself it's definitely correct! |
|
I'm not a big fan of pushing back already-read data by tweaking fields of a lexbuf. Is there no other way? I was not expecting to have an error if a directive is recognized not at beginning of line. It would feel more natural to me to just analyze it as if it was not a directive, but instead |
|
Thanks for the feedback. I think I found a cleaner solution, the only problem is that the "line out of bounds" errors will be reported as starting on column 1 rather than 0, as the hash was matched first. Not sure if this is a problem though. |
|
@tadeuzagallo Is this ready for review? If so please rebase. |
|
It's really not a problem that the error report is off by 1 character. |
xavierleroy
left a comment
There was a problem hiding this comment.
This looks good to me and could be merged as is. I wonder if a slightly simpler implementation is possible, see comment in code.
| { update_loc lexbuf None 1 false 1; | ||
| try directive lexbuf | ||
| with Failure(_) -> HASH | ||
| } |
There was a problem hiding this comment.
This looks reasonable, but is there any chance of unifying these two cases? Something like
if not (at_beginning_of_line lexbuf.lex_start_p)
then HASH
else try directive lexbuf with Failure _ -> HASH
where, tentatively,
let at_beginning_of_line pos = (pos.pos_cnum = pos.pos_bol)
Just a suggestion: I didn't try and I'm not sure it would work.
There was a problem hiding this comment.
This worked perfectly, thanks.
|
Sorry for the delay, I have rebase and updated the code with the suggestions. |
|
Looks good to me @gasche/@damiendoligez - is this definitely OK for 4.06? |
|
I appreciate the change, but I'm not convinced that it is totally without risk, and I think the issue it is fixing can tolerate a delay. (I think the cost of a potential regression noticed only after the second beta offset the gains.) I would personally vote for inclusion (now) in trunk, but not in the release branch. |
|
@gasche - that was my feeling too. So let's remove it from the milestone but merge to trunk now |
|
Thanks! And thanks again @tadeuzagallo. |
|
Since this PR was merged the CI at Inria is broken but only under OpenBSD (i386). The breakage is in ocamldoc/: Probably a bad interaction with the |
|
This is what the file looks like after |
|
Plausible fix in [trunk 801993d] . Waiting for a round of CI to confirm. |
|
CI looks happy. |
|
Excellent - though unexpected, it's sort of evidence that it's working, right? Before long, that script needs to be changed anyway - when we start building OCaml using the Linux subsystem on Windows, using scripts with |
* Fix problems with character literals in comments * Do not parse unclosed comments and quoted strings * Update known failures * Only allow line number directives with filename (ocaml/ocaml#931) * Rename dot_operator to indexing_operator * Disallow .~ in indexing operator (ocaml/ocaml#2106) * Add test for indexing operator * Support empty variants (ocaml/ocaml#1546) * Support binding operators (ocaml/ocaml#1947) * Use tree-sitter 0.14.0 * Cleanup trvis config
reflects the change from ocaml#931 / ocaml#6604
reflects the change from ocaml#931 / ocaml#6604
reflects the change from ocaml#931 / ocaml#6604
* Add -basic-block-sections compiler flag. Requires compiler configured with function sections. * Don't elide labels and jumps to fallthrough with basic_block_section * Move code earlier in emit.mlp * Emit section name for each Llabel and handle size and cfi directives * Assign blocks to sections * Don't emit jumps for fallthroughs between blocks in the same section * Add section_name field to Llabel * Emit section names associated with labels instead of emitting each basic block label in its own section * Don't need to pass -function-sections to enable basic block sections * Fix bug: Don't use labelled_insn_end.label = -1 * Rework section names to allow "." suffix * Add field Linear.fundecl.fun_section_name * Emit function or basic block section name correctly for fun entry * Entry label of cfg should be unique, add CR but validator tests fail and I'm not sure if 1 is explicitly used elsewhere, so keep it for now. * Add CR regarding checking sections of Cfg_with_layout as part of Cfg_equivalence. * Format * Flag for -basic-block-sections should be separate from -ocamlcfg * Improve comment * cross_section with dst = labelled_insn_end.label is not an error * Fix corner case label handling * Use Label.equal * Format
This updates the lexer to enforce that directives have a filename and are placed at the beginning of the line, as suggested in the comments in the Mantis PR referred to in the title.
I had to update one existing test, and added 2 more to verify the new intended behaviour.