Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support syntactic/semantic macros at all locations #536

Closed
liufengyun opened this issue Nov 9, 2016 · 4 comments
Closed

Support syntactic/semantic macros at all locations #536

liufengyun opened this issue Nov 9, 2016 · 4 comments

Comments

@liufengyun
Copy link
Contributor

liufengyun commented Nov 9, 2016

Tonight I conducted a conversation with @olafurpg , we agreed that syntactic def macros can also be very useful in practice. At the same time, programmers may want to use semantic APIs for annotation macros.

To support the scenarios above, we can follow the capability metaphor of scala.meta:

inline def macros1(defn: Any): Any = meta { mirror =>       // able to use semantic APIs
    // macros definition
}

inline def macros2(defn: Any): Any = meta {                  // unable to use semantic APIs
    // macros definition
}

The syntactic APIs are imported by default via import scala.meta._, while semantic APIs can only be accessed via meta { mirror => }. This way, we can control whether a macros definition is semantic or syntactic, and expand them accordingly. In Dotty, this syntactical difference also tells macros authors whether the trees are desugared or not.

Usage of semantic APIs for annotation macros can be both useful and tricky, programmers use it at their own risk.

@olafurpg
Copy link
Member

olafurpg commented Nov 9, 2016

Some examples of useful def macros that can be done syntactically

@xeno-by
Copy link
Member

xeno-by commented Nov 11, 2016

I'd strongly advise against supporting semantic APIs for macro annotations. scalamacros/paradise#75 shows that it's too much trouble for too little gain.

@xeno-by
Copy link
Member

xeno-by commented Nov 11, 2016

I also have a comment about the proposed notation to distinguish syntactic and semantic meta blocks.

Strictly speaking, syntactic meta blocks should also take a capability, namely a dialect. This is currently not reflected in the prototype implementation, but I think that it should work like that for completeness.

@liufengyun
Copy link
Contributor Author

After implementing syntactic def macros in Eden, now I don't think syntatic def macros should have a different syntax from semantic ones. Close this for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants