caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Alain Frisch <alain.frisch@lexifi.com>
To: Yotam Barnoy <yotambarnoy@gmail.com>,
	Hongbo Zhang <hzhang295@bloomberg.net>
Cc: Ocaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] PPX is harmful to our community in the long term
Date: Fri, 21 Apr 2017 19:11:38 +0200	[thread overview]
Message-ID: <703d59cf-a1f9-c12f-9325-44aa23b03e36@lexifi.com> (raw)
In-Reply-To: <CAN6ygOn_UTcrwjXpZKSLOq6sHRupWZAT47=SEijL6z2BzuWg6g@mail.gmail.com>

On 21/04/2017 18:04, Yotam Barnoy wrote:
> My 2 cents: I personally think we did PPX wrong. PPX should have used
> the syntax as its starting point for full backwards compatibility.
> Currently, the PPX cycle is
>
> OCaml: { syntax -> AST -> serialized AST } -> PPX: {serialized AST ->
> AST -> PPX modification -> serialized AST} -> OCaml: {serialized AST
> -> AST -> ... }
>
> Exposing the AST is the cause of the problem you mention. If instead,
> every PPX extension had a particular OCaml compiler's syntax parser
> and syntax printer integrated into it, and the PPX cycle was:
>
> PPX: { syntax -> AST -> PPX modification -> syntax } -> compiler: {
> syntax -> AST -> ...}
>
> We would have far fewer issues with PPX plugins, since they would be
> as backwards-compatible as the syntax.

I think

   https://github.com/let-def/ocaml-migrate-parsetree

is a much stronger approach.  If I understand correctly, Jane Street 
moved from using a migration system based on concrete syntax to using 
this new project.


In your suggested approach, imagine you have a PPX processor written for 
OCaml 4.04.  It assumes that the Parsetree it works on is the one of 
4.04.  Sure, you can compile this PPX processor (+ embedded 
parser/printer) into a stand-alone executable, using OCaml 4.04, and 
then apply it as a preprocessor called from OCaml 4.05.  But this is 
very impractical: users would need to install OCaml 4.04 just to produce 
the PPX executable.  Moreover, you loose the ability to combine multiple 
rewritings in a single process, and you have to pay the price of 
multiple parsing/printing/processes.  On top of that:

   (i) you put in the critical loop "pprintast.ml", which has always 
been more or less buggy;

   (ii) there is no hope that an "old PPX" applies to source code using 
newest syntactic features;

   (iii) as you mention, locations would need to be added for each node 
in the AST, which makes the parsing/printing even slower;  moreover, it 
is not technically straightforward to do so, since many places in the 
AST contains locations but do not support attaching attributes;

   (iv) we loose the ability to change the concrete syntax of OCaml, 
either to use alternative syntaxes such as Reason, or to remove, at some 
point, weird corner cases in the current syntax.


With ocaml-migrate-parsetree, you can still compile your PPX written for 
4.04 with newer versions of OCaml.  And it would even be possible (I 
don't know if this is already the case) to apply it to source code using 
newer syntactic features, as long as the rewriting done by the PPX 
doesn't interact with those features.  (This could be achieved by 
turning new syntactic features into attributes/extension nodes when 
mapping to the older AST; and then recognizing these forms and 
reconstitute the correct new AST forms when mapping back to the new 
version.)


-- Alain

  parent reply	other threads:[~2017-04-21 17:11 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-21 15:41 Hongbo Zhang (BLOOMBERG/ 731 LEX)
2017-04-21 16:04 ` Yotam Barnoy
2017-04-21 16:43   ` Gerd Stolpmann
2017-04-21 17:11   ` Alain Frisch [this message]
2017-04-21 18:28     ` Jeremie Dimino
2017-04-21 16:55 ` Francois BERENGER
2017-04-21 19:11 ` Yaron Minsky
2017-04-21 19:22 ` Emilio Jesús Gallego Arias
2017-04-21 19:23 Hongbo Zhang (BLOOMBERG/ 731 LEX)
2017-04-21 21:17 ` Fabrice Le Fessant
2017-04-28 11:07   ` Olaf Hering
2017-04-28 13:04     ` Anil Madhavapeddy
2017-04-28 14:50       ` Yaron Minsky
2017-04-28 14:55         ` Jacques Carette
2017-05-11  9:37           ` Jeremie Dimino
2017-04-21 21:48 Hongbo Zhang (BLOOMBERG/ 731 LEX)
2017-04-21 23:10 ` Emilio Jesús Gallego Arias
2017-04-22 12:49   ` Serge Sivkov
2017-04-22 14:47 Hongbo Zhang (BLOOMBERG/ 731 LEX)
2017-04-22 19:47 ` Robert Muller
2017-04-23  1:30   ` Yaron Minsky
2017-04-23  0:06 Hongbo Zhang (BLOOMBERG/ 731 LEX)
2017-04-23  1:25 ` Yaron Minsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=703d59cf-a1f9-c12f-9325-44aa23b03e36@lexifi.com \
    --to=alain.frisch@lexifi.com \
    --cc=caml-list@inria.fr \
    --cc=hzhang295@bloomberg.net \
    --cc=yotambarnoy@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).