Skip to content

Allow collections of Identifiers, type literals, and literals in macro constructor parameters #2092

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

Closed
srawlins opened this issue Feb 3, 2022 · 2 comments
Labels
static-metaprogramming Issues related to static metaprogramming

Comments

@srawlins
Copy link
Member

srawlins commented Feb 3, 2022

The macro spec currently says:

[...] macros can also accept arguments as values. However, only built-in value types (int, bool, etc.) are allowed and arguments must be simple literal expressions.

I think we should support "collections" of built-in value types and (adjascent or as part of #2091) type literals and identifiers. "Collections" means Lists, Sets, and Maps, though I don't have thoughts on any type restrictions on the key of a Map (maybe just String? Maybe no restriction beyond "only built-in value types"?).

For example:

@GenerateSomething([Foo, Bar])

which allows access to Foo and Bar as Identifiers, or as type literals, etc.

This raises a question about spreads. Today, the typical way to write an annotation which includes a list literal which folds in elements from a constant defined elsewhere is a spread. Can we allow:

const classes = [Foo, Bar];
@GenerateSomething([...classes, Baz])

Allowing this would be consistent with the support that constant evaluation provides, but might be extremely difficult / impossible because it requires constant evaluation. Maybe we could sidestep constant evaluation by saying only a subset of constant values are supported in a collection of type literals or Identifiers...

cc @munificent @jakemac53

@srawlins srawlins added the static-metaprogramming Issues related to static metaprogramming label Feb 3, 2022
@jakemac53
Copy link
Contributor

Yep I was just about to file this same issue :)

jakemac53 added a commit that referenced this issue Feb 8, 2022
#2094)

Attempt to close #2093, and #2092. Related to #2012.

- Adds `Identifier`, `List`, and `Map` as valid parameter types for macro constructors (and thus valid arguments for macro applications).
  - List and Map are allowed to have type arguments that are any of the supported types. This allows for `List<Identifier>`, etc.
- Specify the scope for identifiers in macro application arguments better (both bare and in code objects).
- Some other unrelated cleanup (can remove if desired).
  - Fixed up some old links
  - Removed the section on `Fragment` (you can just use `Code` for this now).
@jakemac53
Copy link
Contributor

This is allowed now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
static-metaprogramming Issues related to static metaprogramming
Projects
Development

No branches or pull requests

2 participants