Skip to content

Conversation

@Simn
Copy link
Member

@Simn Simn commented Sep 30, 2018

This PR disallows calling a macro while in macro context. We do this by replacing macro calls with throw "macro-in-macro". This means that you get a proper eval exception with stacktraces and can also debug it.

Macro-in-macro has been a long standing problem for various reasons. Combined with the fact that I think nobody actually wants to use this as a feature and only does so accidentally, I propose that we remove it entirely for Haxe 4.

As for the benefits of this change, it

  • removes the last reason why inlining could still be canceled,
  • eliminates a cryptic cause of the compiler cache not working for certain modules and
  • probably addresses a leak due to the captured ctx that was used for typing the macro at macro run-time.

Please note that it doesn't complain about a macro-in-macro being typed. The error only triggers if it ends up actually being called. This is an important distinction because it means we don't need additional #if macro fencing.

@Simn Simn added discussion platform-macro Everything related to Haxe macros breaking-haxe4 labels Sep 30, 2018
@Simn Simn added this to the Release 4.0 milestone Sep 30, 2018
@ncannasse
Copy link
Member

Good for me, although I think we should be able to properly support macro-in-macro by creating a second macro context (which would use same interp because of cache), the only problem being infinite loops for which we should limit the depth and then fallback to your solution of a runtime error.

@Simn
Copy link
Member Author

Simn commented Oct 2, 2018

I experimented with this and I don't think it's a good idea. Properly supporting macro-in-macro would mean that we expand macros while typing the macro context. That would mean a huge shift in semantics because suddenly all your macros get called twice if you have the macro in the same class as the call.

@ncannasse
Copy link
Member

ncannasse commented Oct 2, 2018 via email

@Simn
Copy link
Member Author

Simn commented Oct 2, 2018

Well, they actually do get calls N times where N is the depth level we allow

That would only be true if we keep creating macro contexts, which doesn't sound like a good idea in the first place.

But what I really ask myself in all this is: Why? Does this bother you only on a technical level or do you see legitimate use-cases for macro-in-macro? I just don't think the complexity is worth it.

@ncannasse
Copy link
Member

ncannasse commented Oct 2, 2018 via email

@Simn
Copy link
Member Author

Simn commented Oct 2, 2018

I'll merge this for now. If we decide to support macro-in-macro in the future we can discuss this further.

@Simn Simn merged commit 00a3cb2 into HaxeFoundation:development Oct 2, 2018
@Simn Simn deleted the no_delayed_macros branch October 2, 2018 15:24
@skial skial mentioned this pull request Oct 3, 2018
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

discussion platform-macro Everything related to Haxe macros

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants