On Tuesday, 30 August 2016 at 16:12:19 UTC, Andrei Alexandrescu
wrote:
I'd like to initiate collaboration on an effort to do DIP1000
rigorously.
First we need to reduce D to a bare subset that only has
integers, structs, pointers, and functions. That's a working
subset of actual D code. The grammar I have in mind is at
http://erdani.com/d/DIP1000.html.
There is no type deduction, member functions, classes, arrays,
constructors, loops, etc. etc. etc. Only the ability to create
arbitrarily complex graphs containing integers and pointers to
other nodes.
On this language we need to define typing rules and evaluation
semantics. Once we have those, we need to prove what we want:
for scope variables the accessibility never outlives lifetime.
As a consequence we're good to deallocate them early etc.
The model for typing, evaluation, and proofs is at
https://www.cis.upenn.edu/~bcpierce/papers/fj-toplas.pdf. It
would be great if those interested in helping could give the
paper a close read.
Once we get this done we'll have a fantastic model for any
other language changes.
Andrei
BTW, the Rust Mid-level IR (MIR) has a similar purpose: it lowers
the complex AST to a sufficiently simpler one so that one can
more easily do things like lifetime analysis / borrow checking on
it. Similarly, Swift have a similar step in their compiler
pipeline for ARC.
I don't know if such intermediate representation in the DMD FE is
worth pursuing (obviously would be big development effort), but
it may be worth having a look to see how such IR analysis is done
in practice (on actual non-toy, non-purely academic languages),
even if only for checking that your theoretical model captures
sufficient information.
Here are some links, which I hope you would find helpful:
https://blog.rust-lang.org/2016/04/19/MIR.html (high-level
non-technical introduction)
https://github.com/rust-lang/rfcs/blob/master/text/1211-mir.md
(Rust RFC ~ equivalent of DIP)
https://news.ycombinator.com/item?id=10487502 (Presentation
slides about Swift's compiler pipeline)