Commit Graph

28 Commits

Author SHA1 Message Date
Allan Shortlidge
e1082bb8be AST: Promote various macro features to baseline. 2024-07-09 14:28:28 -07:00
Allan Shortlidge
2730c19891 Macros: Stop explicitly enabling accepted ExtensionMacros feature in tests.
NFC.
2023-12-10 10:10:15 -08:00
Rintaro Ishizaki
55144fb302 [Macros] Add test for macro expansion printing
* Macro expanded member decls in .swiftinterface (rdar://117374821)
* cursor-info on a decl with peer macro attribute (rdar://117374966)
2023-10-23 15:21:33 -07:00
Doug Gregor
ff8a1be972 [Swift interface] Print declarations produced by declaration macro expansion
Don't print the uses of freestanding declaration macros in Swift
interfaces. Instead, print the declarations they produce, as
appropriate.

Fixes rdar://113730928.
2023-08-21 23:31:47 -07:00
Holly Borla
61e5811d73 [NFC] Update IDE, Index, ModuleInterface, and SourceKit tests to remove
conformance macros.
2023-07-19 12:38:52 -07:00
Doug Gregor
940870e92a Print "conformances" in extension macro role
Fixes rdar://112297735.
2023-07-17 13:47:05 -07:00
Holly Borla
81a1f64811 [Macros] Allow @attached(extension) attributes to be suppressed in
module interfaces.
2023-06-28 14:53:16 -07:00
Doug Gregor
9606a9acfd [ASTPrinter] Stop unnecessary escaping of init in macro role attributes.
The excessive escaping of `init` in macro role attributes was a
workaround paired with https://github.com/apple/swift/pull/65442 to
smooth things over when working across Swift compiler versions.
However, it's causing problems for init accessors, so stop escaping.

Fixes rdar://111190084.
2023-06-23 10:18:26 -07:00
Doug Gregor
7fb1ba9798 [AST printer] Stop printing -> () types on all macro declarations. 2023-06-09 23:25:34 -07:00
Allan Shortlidge
020987a567 Macros: Escape init when printing names for attached macros.
Older compilers can't parse `name(init)`. Restore the call to
`escapeKeywordInContext()` to ensure special names get escaped.

Resolves rdar://108806697
2023-05-02 17:43:04 -07:00
Allan Shortlidge
dd5b934a41 Tests: Small updates to ModuleInterface/macros.swift test. 2023-05-01 19:44:57 -07:00
Allan Shortlidge
ffaa1d5dbc Revert "[Macros] Treat FreestandingExpressionMacros as a suppressible feature"
This reverts commit b412c6c884.

Resolves rdar://108591384
2023-05-01 19:44:39 -07:00
Doug Gregor
ae4a5ded8f [Macros] Improve parsing, representation, and serialization of role attributes
Parse compound and special names in the macro role attributes
(`@freestanding` and `@attached`). This allows both compound names and
initializers, e.g., `init(coding:)`.

Fixes rdar://107967344.
2023-04-21 11:36:06 -07:00
Doug Gregor
68b367b266 Disable macros-related tests harder 2023-03-29 16:32:32 -07:00
Doug Gregor
30f17940f9 Require the Swift swift parser for a few tests affected by macros 2023-03-29 16:32:32 -07:00
Doug Gregor
cfbdae586d [Macros] Add a test ensuring that we print expanded macro definitions
This should complete the implementation of expanded macro
definitions, rdar://104044325.
2023-03-29 16:32:32 -07:00
Doug Gregor
b412c6c884 [Macros] Treat FreestandingExpressionMacros as a suppressible feature
When the feature isn't available, use the older `@expression` syntax to
work around limitations of older compilers.
2023-03-09 20:33:30 -08:00
Doug Gregor
1a4d6b6519 [Macros] Ensure that we escape macro declared names in printing.
Fixes an issue where we couldn't round-trip macro declared names
2023-03-04 22:41:09 -08:00
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