Commit Graph

10 Commits

Author SHA1 Message Date
Doug Gregor
f88d2c638f Clean up feature flags for macros.
Enable expression macros by default, and add separate feature flags for
attached and freestanding macros.
2023-03-02 14:34:59 -08:00
Doug Gregor
04eca73d60 [Macros] Stop parsing the ": <type>" syntax. We always require parameters 2023-02-09 22:11:23 -08:00
Doug Gregor
85ba74b812 Introduce a separate feature to cover @freestanding(expression) 2023-02-08 11:26:14 -08:00
Doug Gregor
5a9a654adb Adopt @freestanding(expression) for all @expression macros 2023-01-25 17:07:38 -08:00
Doug Gregor
43cadcad3a [Macros] Serialization and printing for @attached. 2023-01-14 21:48:43 -08:00
Doug Gregor
7000969f14 Introduce and use #externalMacro for externally-defined macros.
Align the grammar of macro declarations with SE-0382, so that macro
definitions are parsed as an expression. External macro definitions
are referenced via a referenced to the macro `#externalMacro`. Define
that macro in the standard library, and recognize uses of it as the
definition of other macros to use externally-defined macros. For
example, this means that the "stringify" macro used in a lot of
examples is now defined as something like this:

    @expression macro stringify<T>(_ value: T) -> (T, String) =
        #externalMacro(module: "MyMacros", type: "StringifyMacro")

We still parse the old "A.B" syntax for two reasons. First, it's
helpful to anyone who has existing code using the prior syntax, so they
get a warning + Fix-It to rewrite to the new syntax. Second, we use it
to define builtin macros like `externalMacro` itself, which looks like this:

    @expression
    public macro externalMacro<T>(module: String, type: String) -> T =
        Builtin.ExternalMacro

This uses the same virtual `Builtin` module as other library builtins,
and we can expand it to handle other builtin macro implementations
(such as #line) over time.
2023-01-02 21:22:05 -08:00
Doug Gregor
f78f5729c3 Start requiring expression macros to be marked with @expression 2022-12-22 09:18:05 -08:00
Doug Gregor
3be6344619 Eliminate dependencies on _SwiftSyntaxMacros having actual macros in it 2022-12-14 16:13:48 -08:00
Evan Wilde
5f9ac391be Requires-asserts macro tests
Macros are an experimental feature, as such are not available on
non-asserts compilers.

Adding requires asserts to remaining experimental macro tests.
 - ModuleInterface/macros.swift
 - Serialization/macros.swift
2022-12-01 11:18:10 -08:00
Doug Gregor
1a124e71d6 [Macros] Implement AST printing and module interface generation for macros 2022-11-28 18:33:10 -08:00