Skip to content

manual, code example preprocessor : full conversion to compiler-libs#1863

Merged
Octachron merged 11 commits intoocaml:trunkfrom
Octachron:manual_camltex2_toploop
Jul 25, 2018
Merged

manual, code example preprocessor : full conversion to compiler-libs#1863
Octachron merged 11 commits intoocaml:trunkfrom
Octachron:manual_camltex2_toploop

Conversation

@Octachron
Copy link
Copy Markdown
Member

This is PR is essentially #1785 without the ellipses as extension nodes change: it replaces the uses of a separated toplevel process inside manual/tools/caml_tex2.ml by a direct use of Toploop 's api from the compiler-libs.

The main benefits of this change is that it enables a more precise control of the data flux from the toplevel: compiler error, compiler warnings, locations to underline, and the example stdout and stderr are now collected separately.

As a direct consequence of this change, all error and warnings related locations are now underlined, not only the first one.

Similarly, code examples now always print warnings and errors message even when the toplevel output is omitted, as wished by @gasche .

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Jun 27, 2018 via email

@Octachron Octachron force-pushed the manual_camltex2_toploop branch from c5bbe06 to 0cb0883 Compare June 27, 2018 16:35
@Octachron
Copy link
Copy Markdown
Member Author

I have fixed the author name and style issues.

Concerning performance, I did not really have performance in mind while writing the PR since the preprocessing phase is fast compared to hevea or latex.

It is true that using compiler-libs might introduce a stronger coupling with the toplevel inialization code, but it is also free us from parsing back the toplevel output to identify errors, warnings or locations.

Moreover, I am not sure how problematic hypothetical minute differences between ocaml, the manual code example preprocessor and utop would be.

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Jun 27, 2018 via email

Copy link
Copy Markdown
Member

@gasche gasche left a comment

Choose a reason for hiding this comment

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

The change looks reasonable to me, and I'm in favor of merging. (I think it's worth giving more leeway to less-critical parts of the compiler distribution where we have the opportunity to roll-back if something turns out to be not-perfect.)

Two comments:

  1. What you are doing, namely the awkward plumbing to reliably capture stdout/stderr, warnings and errors, is exactly what @diml had to do to start utop, and in general is logic that people reinvent in many different places. Long-term, it would be nicer to have a more robust approach, where the various parts of compiler-libs involved make it easy to virtualize these things, so that consumers don't have to jump through those hoops. No need to work on that for this PR, but if you have some ideas about what interface would have been convenient to you, maybe it is something to think about for later.

  2. I agree with @shindere's concern that the new code is intertwined tightly enough with the toplevel workings (and Location error formatters, etc.) that it may require to be changed from time to time -- it is a source of fragility. I think that this is fine as long as we make sure that it breaks sooner rather than later: people changing the compiler in way that break this should notice, and fix it along with the rest of the fixes, instead of having the breakage go unnoticed until the next good soul tries to build the manual. So I would suggest having some tests for this tool in the testsuite (checking that the various redirects work as intended). I don't think we have tests for anything in manual/ (pregen doesn't count); maybe it would be simpler to move caml_tex2 to tools to test it, in which case I would suggest to move it indeed.

if n = size then
(Buffer.add_bytes buffer b; loop max_retry)
else
Buffer.add_bytes buffer (Bytes.sub b 0 n)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This could be simpler with an un-conditional Buffer.add_subbytes buffer b 0 n.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed.

if newline then Printf.fprintf out "\n"
Format.fprintf out "%s%s" camlbegin s;
List.iter (Format.fprintf out "{%s}") args;
if newline then Format.fprintf out "\n"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wondered for a moment whether newline should be interpreted as @\n or @., but to by honest I don't really understand the differences here and I think that the current code is probably fine -- as long as it works...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The printing is basically bypassing the Format's layout engine since we are exactly mirroring the input, thus there is no pratical difference now. ( I made the switch to format to avoid mixing Format and Printf since the compiler's printing function were using Format).

@Octachron
Copy link
Copy Markdown
Member Author

I agree that adding tests for caml_tex2 is a good ideat at this point, it would also help for the ellipsis annotations/extensions. I am not sure where the tests should be located between testsuite or manual/test. Do you have an opinion on this matter @shindere ?

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Jun 29, 2018 via email

@damiendoligez
Copy link
Copy Markdown
Member

but I don't know whether such an argument is strong enough.

Seems good enough to me.

@Octachron
Copy link
Copy Markdown
Member Author

I have moved caml_tex2 from manual/tools/caml_tex2 to tools/caml_tex and added a new test in testsuite/tests/tool-caml-tex .

Copy link
Copy Markdown
Member

@gasche gasche left a comment

Choose a reason for hiding this comment

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

I think that the new state is nice, and I would be happy to merge quickly -- maybe leaving a day to have minor questions answered.

(* TEST
reference="${test_source_directory}/redirections.reference"
output="redirections.output"
script = "${ocamlrun} ${ocamlsrcdir}/tools/caml-tex -repo-root ${ocamlsrcdir} ${test_source_directory}/${test_file} -o ${output}"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

check-typo complains about that line being too long, can you use \ to break it after ${ocamlsrcdir} for example?

caml-tex: $(CAMLTEX)
$(CAMLC) $(LINKFLAGS) -I .. -linkall -o $@ $(CAMLTEX)

opt.opt:caml-tex
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is this target named opt.opt? I would expect maybe all:, but not opt.opt here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is due to conflicting dependencies: caml-tex depends on Str and Unix while the otherlibraries target depends on the ocamltools target.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you maybe have a comment to explain this tricky subtlety?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good point, I added a comment.

@Octachron
Copy link
Copy Markdown
Member Author

I would prefer to fix the build on AppVeyor first.

@Octachron Octachron force-pushed the manual_camltex2_toploop branch from 71057cf to 339273a Compare July 21, 2018 08:39
@Octachron
Copy link
Copy Markdown
Member Author

I have fixed the windows build by slightly reworking the redirection. Finally, check-typo is asking for a copyright header, should I credit @garrigue (5d6080a) and me?

@gasche
Copy link
Copy Markdown
Member

gasche commented Jul 21, 2018

Finally, check-typo is asking for a copyright header, should I credit @garrigue (5d6080a) and me?

Yes, and also @xavierleroy who apparently wrote the first Perl implementation ( https://github.com/FBoisson/Camllight/tree/master/contrib/caml-tex ) -- in particular, this correctly attributes part of the copyright to INRIA. I have vague memories of also seeing Roberto Di Cosmo's name attached to the tools as well (maybe for caml-tex2, as a second version of caml-tex?), maybe Xavier or Jacques can correct the record, but I feel good enough about a first copyright header with just Xavier, Jacques and you to merge the PR.

@Octachron Octachron force-pushed the manual_camltex2_toploop branch from 339273a to 4a21eec Compare July 24, 2018 13:14
@Octachron
Copy link
Copy Markdown
Member Author

I have added a basic copyright header and a Change entry.

@gasche
Copy link
Copy Markdown
Member

gasche commented Jul 24, 2018

This looks good to me. Would you prefer to rebase to have a history, or should I just squash when the CI passes?

@Octachron
Copy link
Copy Markdown
Member Author

Squashing is fine with me.

@Octachron Octachron merged commit 4be6caf into ocaml:trunk Jul 25, 2018
@shindere
Copy link
Copy Markdown
Contributor

This breaks Inria's CI because tools/caml-tex is not available when the
native compiler is disabled, leading to the failure of the
`tests/tool-caml-tex/redirections.ml' test.

@Octachron
Copy link
Copy Markdown
Member Author

Sorry, I think that the best immediate fix here is to skip the test when the native compiler is disabled.

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Jul 25, 2018 via email

@Octachron
Copy link
Copy Markdown
Member Author

If you have the time, gladly.

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Jul 25, 2018 via email

shindere added a commit that referenced this pull request Jul 25, 2018
…s disabled

This is a follow-up to GPR #1863. Without this commit, the
test in tests/tool-caml-tex/redirections.ml fails when the native
compiler is disabled.

This commit thus makes sure the native compiler is enabled before proceeding.
@shindere
Copy link
Copy Markdown
Contributor

shindere commented Jul 25, 2018 via email

@Octachron
Copy link
Copy Markdown
Member Author

Thanks! And sorry again for the breakage.

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Jul 25, 2018 via email

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Jul 25, 2018 via email

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

Successfully merging this pull request may close these issues.

4 participants