Skip to content

Simplify and rename macro API #11803

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

Merged
merged 1 commit into from
Jan 26, 2014
Merged

Simplify and rename macro API #11803

merged 1 commit into from
Jan 26, 2014

Conversation

sfackler
Copy link
Member

Now that procedural macros can be implemented outside of the compiler,
it's more important to have a reasonable API to work with. Here are the
basic changes:

  • Rename SyntaxExpanderTTTrait to MacroExpander, SyntaxExpanderTT to
    BasicMacroExpander, etc. I think "procedural macro" is the right
    term for these now, right? The other option would be SynExtExpander
    or something like that.
  • Stop passing the SyntaxContext to extensions. This was only ever used
    by macro_rules, which doesn't even use it anymore. I can't think of
    a context in which an external extension would need it, and removal
    allows the API to be significantly simpler - no more
    SyntaxExpanderTTItemExpanderWithoutContext wrappers to worry about.

Now that procedural macros can be implemented outside of the compiler,
it's more important to have a reasonable API to work with. Here are the
basic changes:

* Rename SyntaxExpanderTTTrait to MacroExpander, SyntaxExpanderTT to
    BasicMacroExpander, etc. I think "procedural macro" is the right
    term for these now, right? The other option would be SynExtExpander
    or something like that.

* Stop passing the SyntaxContext to extensions. This was only ever used
    by macro_rules, which doesn't even use it anymore. I can't think of
    a context in which an external extension would need it, and removal
    allows the API to be significantly simpler - no more
    SyntaxExpanderTTItemExpanderWithoutContext wrappers to worry about.
@brson
Copy link
Contributor

brson commented Jan 26, 2014

I wonder if it's possible to completely extract the public ext API from the syntax crate.

@sfackler
Copy link
Member Author

The surface of the ext API is pretty huge since it includes all of the AST, codemap, parser, and probably a bunch of utility stuff. The parts that could be removed would include all of the builtin procedural macros, possibly the pretty-printer and some random stuff like the crateid module.

bors added a commit that referenced this pull request Jan 26, 2014
Now that procedural macros can be implemented outside of the compiler,
it's more important to have a reasonable API to work with. Here are the
basic changes:

* Rename SyntaxExpanderTTTrait to MacroExpander, SyntaxExpanderTT to
    BasicMacroExpander, etc. I think "procedural macro" is the right
    term for these now, right? The other option would be SynExtExpander
    or something like that.

* Stop passing the SyntaxContext to extensions. This was only ever used
    by macro_rules, which doesn't even use it anymore. I can't think of
    a context in which an external extension would need it, and removal
    allows the API to be significantly simpler - no more
    SyntaxExpanderTTItemExpanderWithoutContext wrappers to worry about.
@brson
Copy link
Contributor

brson commented Jan 26, 2014

It's probably pretty huge, but if procedural macros are ever to be stable, it needs to be clean and intentionally-designed, and separated from the rest of the compiler in a way that can be specced and standardized.

@brson
Copy link
Contributor

brson commented Jan 26, 2014

e.g. the parser could be abstracted to just a few calls that input strings, and token-trees and outputs token-trees and ASTs; the AST can hopefully be wrapped in something opaque that doesn't expose the details.

@huonw
Copy link
Member

huonw commented Jan 26, 2014

Having quoting that's reliable and sensible would help. (I'm not saying that the current quoting isn't this, but from what I've see, it seems to be rather a hack; I wrote something about a possible solution here, no idea if that's actually at all feasible/workable.)

@bors bors closed this Jan 26, 2014
@bors bors merged commit ab5bbd3 into rust-lang:master Jan 26, 2014
@sfackler sfackler deleted the simple-mac branch January 26, 2014 04:48
flip1995 pushed a commit to flip1995/rust that referenced this pull request Nov 16, 2023
[`impl_trait_in_params`]: avoid ICE when function with `impl Trait` type has no parameters

Fixes rust-lang#11803

If I'm reading the old code correctly, it was taking the span of the first parameter (without checking that it exists, which caused the ICE) and uses that to figure out where the generic parameter to insert should go (cc `@blyxyas` you wrote the lint, is that correct?).
This seemed equivalent to just `generics.span`, which doesn't require calculating the spans like that and simplifies it a fair bit

changelog: don't ICE when function has no parameters but generics have an `impl Trait` type
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

Successfully merging this pull request may close these issues.

4 participants