uwiger / parse_trans

Parse transform utilities for Erlang
Apache License 2.0
230 stars 118 forks source link

Adapt codegen:exprs substitutions to Erlang 24 #50

Closed tomas-abrahamsson closed 3 years ago

tomas-abrahamsson commented 3 years ago

Substitutions in codegen:exprs/1 were expecting locations to be integers. But with Erlang 24, these are {Line, Column} instead. Handle both.

To illustrate the change, I'll use a function in mockgyver_xforms:

            [Form] = codegen:exprs(
                               fun() ->
                                       mockgyver:exec({'$var',  MockMfas},
                                                      {'$var',  TraceMfas},
                                                      {'$form', ExecFun})
                               end),

With Erlang 23, the parse_trans codegen:exprs it gets transformed to the following:

[{call,
  89,
  {remote, 89, {atom, 89, mockgyver}, {atom, 89, exec}},
  [erl_parse:abstract(MockMfas, 89),
   erl_parse:abstract(TraceMfas, 90),
   ExecFun]}]

With Erlang 24, before this PR, the expression transforms to this:

[{call,
  {89, 32},
  {remote,
   {89, 32},
   {atom, {89, 32}, mockgyver},
   {atom, {89, 42}, exec}},
  [{tuple,
    {89, 47},
    [{atom, {89, 48}, '$var'},
     {var, {89, 57}, 'MockMfas'}]},
   {tuple,
    {90, 47},
    [{atom, {90, 48}, '$var'},
     {var, {90, 57}, 'TraceMfas'}]},
   {tuple,
    {91, 47},
    [{atom, {91, 48}, '$form'},
     {var, {91, 57}, 'ExecFun'}]}]}]

With this PR, the expression now transforms to the following on Erlang 24:

[{call,
  {89, 32},
  {remote,
   {89, 32},
   {atom, {89, 32}, mockgyver},
   {atom, {89, 42}, exec}},
  [erl_parse:abstract(MockMfas, {89, 47}),
   erl_parse:abstract(TraceMfas, {90, 47}),
   ExecFun]}]

With this PR and Erlang 23, it still transforms as in the first case.

uwiger commented 3 years ago

Thanks. Merged.

tomas-abrahamsson commented 3 years ago

Would it be possible to get a release that includes this? It would enable dependent projects, to just bump their version of parse_trans, in order to support Erlang 24. One I have in mind is mockgyver. Otoh, if you want to hold off for a while, I guess it is possible for it to point to a specific git revision as well. Just wanted to know what your plans are.