melt-umn / silver

An attribute grammar-based programming language for composable language extensions
http://melt.cs.umn.edu/silver/
GNU Lesser General Public License v3.0
58 stars 7 forks source link

Permit accessing the forward parent in implementation productions #842

Open krame505 opened 3 months ago

krame505 commented 3 months ago

In the process of refactoring Silver as a part of #751, I have noticed a recurring pattern:

aspect production functionInvocation
top::Expr ::= @e::Expr @es::AppExprs @anns::AnnoAppExprs
{
  forward t = application(new(e), '(', new(es), ',', new(anns), ')');

  top.merrors := t.merrors;
  top.mUpSubst = t.mUpSubst;
  top.mtyperep = t.mtyperep;
  top.monadRewritten = t.monadRewritten;
  top.monadicNames = t.monadicNames;
}

Here an extension wants to compute some synthesized attributes on the dispatch production (application here) and avoid writing the same equations in implementation productions. As previously discussed offline, it isn't feasible to allow synthesized equations on an implementation production to be omitted and implicitly defaulted to copy from the forward parent. However perhaps one should be able to write those copy equations explicitly. These equations should typically never be accessed, however one may also wish to make use of a synthesized equation in the dispatching production in a different attribute equation in an implementation production. The above approach requires re-decoration of children and re-computation of attributes; sharing isn't permitted in an extension context like this, as the application production does not itself implement the Application signature. Some other production may also have forwarded to functionInvocation, so this may not always give the desired result.

The fix is just to make the forward parent accessible, like how one can explicitly access e.g. forward.typerep. I'm not sure what the syntax for this should be - forwardParent, backward?