Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006102OCamlOCaml generalpublic2013-07-29 18:322013-09-03 16:52
Reportergasche 
Assigned To 
PrioritylowSeverityfeatureReproducibilityN/A
StatusacknowledgedResolutionopen 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0006102: ocaml{c,opt}: Provide command-line options to stop compilation after any stage
DescriptionIt would be occasionally useful to stop compilation just after parsing, or just after type-checking but without outputting anything unless there are errors, etc. A regular way to support this would be to allow stopping after any phase of the compiler (or at least: parsing, typing, lambda and cmm).

Some use cases:

(1) ocamlfind does not provide an "ocamlfind camlp4 -package foo.syntax ..." option allowing to easily preprocess source files, as would be needed to solve PR#5548 (ocamlbuild -use-ocamlfind with a .pp.ml target). A workaround would be to use "ocamlfind ocamlc -dsource -package foo.syntax ..." (even better, -dsource would also take into account ppx rewriters), but that would fail if the source doesn't type-check, as there is currently no way to stop the compiler between parsing and type-checking.

(2) currently option -i both print interface information and stops the compiler after type-checking; if we had a proper option to stop after type-checking, we wouldn't need to mix those two different things, and could provide a -dintf command to satisfy the oddly phrase PR#3861

(3) when debugging bad behaviors of the compiler (exponential time consuption, stack overflow, etc.), it would be fairly useful to be able to stop at the phase just before the thing blows up.
Tagsjunior_job, patch
Attached Filespatch file icon pr6102.patch [^] (13,510 bytes) 2013-07-30 22:31 [Show Content]

- Relationships
related to 0005548assignedgasche ocamlbuild's ocamlfind integration doesn't support syntax extensions 

-  Notes
(0010040)
lpw25 (developer)
2013-07-31 14:52

Just a note to point out that Jon has attached a patch for this request
(0010042)
gasche (developer)
2013-07-31 18:02
edited on: 2013-07-31 18:33

Thanks for the note; I hadn't seen the patch indeed. And thanks Jon for the patch!

I have doubts about "exit 0" as an implementation technique for quitting early. Both in the frontend and the backend, there are resources to collect (for example in the frontend, the temporary preprocessing file, if any, must be removed after parsing).

It may work better to raise one specific exception (Exit should work if it isn't raised by the incumbent code, or a specifically defined exception) and handle it differently than the others. Another option (in the frontend case only, backend requires a bit more work, see below), which I think should be preferred because it is more clearly correct, would be to redefine the piping (++) used as:

  let (++) x f = match x with None -> () | Some v -> Some (f v)

and then have "quit_if" inject a None value (using a different can-fail piping operator). This works because those function piping always return a unit in the end, so there is no intermediate value to collect before quitting (remark: we should avoid using GADT hammers at this point in the compiler code, but it shouldn't be necessary here).

The backend is unfortunately a bit more delicate: both compile_genfuns and the later Cmm.reference_symbols may print cmm information which should be run before quit_after_cmm fires, so I guess some heavier reworking of the code would be required -- I initially hadn't planned for that when mentioning quitting after cmm, sorry. You should feel free to leave this part out of a patch: handling the frontend part is already very useful. If you manage to do a reworking that preserves the printing semantics without hurting readability, you should submit that as a separate patch to ease review.


- Issue History
Date Modified Username Field Change
2013-07-29 18:32 gasche New Issue
2013-07-29 18:32 gasche Tag Attached: junior_job
2013-07-29 18:36 gasche Relationship added related to 0005548
2013-07-30 22:31 jonludlam File Added: pr6102.patch
2013-07-31 14:52 lpw25 Note Added: 0010040
2013-07-31 18:02 gasche Note Added: 0010042
2013-07-31 18:33 gasche Note Edited: 0010042 View Revisions
2013-08-28 11:25 doligez Tag Attached: patch
2013-08-28 11:25 doligez Status new => acknowledged
2013-09-03 16:52 doligez Relationship added related to 0003861


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker