Commit Graph

28 Commits

Author SHA1 Message Date
Konrad `ktoso` Malawski
f03ddf728b [Macros] Reproduce issue with peer+extension macro extension's methods not being checked as witnesses (#71717)
Co-authored-by: Pavel Yaskevich <pyaskevich@apple.com>
2024-02-20 00:50:29 -08:00
Holly Borla
1707e76ba8 [Macros] Expand nested macros in qualified name lookup. (#71407) 2024-02-06 15:45:24 +09:00
Doug Gregor
292df02e8c Ensure that member macros can introduce subscripts and deinits
The only fix needed here was to the new Swift parser, but add some
tests to ensure everything else works. rdar://121687968
2024-01-30 10:40:57 -08:00
Ben Barham
18cb5f4f3d [Diagnostics] Update in_macro_expansion note for attached macros
Use the attached atttribute's location as the location of the macro,
rather than the location of the declaration it's attached to. Also add
the kind and name of that declaration to the note itself.
2023-07-25 16:03:52 -07:00
Holly Borla
a60b302754 [Macros] Diagnose invalid attached macros at the attribute location instead
of the declaration.
2023-07-21 16:31:10 -07:00
Doug Gregor
535b45c392 Stop treating macro declaring init identifier as producing initializers
Unwind a temporary workaround we put into the compiler that treated
the escaped identifier "init" as an initializer in the set of names
introduced by a macro. We've addressed the underlying issues.

Fixes rdar://108589649.
2023-07-17 22:44:43 -07:00
Holly Borla
04ea8b0a67 [Macros] Diagnose macros attached to declarations they cannot apply to. 2023-07-13 17:07:24 -07:00
Doug Gregor
072536791a [Macros] Allow the back-ticked named(init) to be treated like named(init).
My recent change to parse initializer names in the macro role
introduced names now correctly distinguishes between the two forms, but
this breaks any existing macros written with the back-ticked form.
Treat the former as the latter to provide a grace period for such
macros.

Fixes rdar://108571834.
2023-04-26 13:20:00 -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
Rintaro Ishizaki
02a604e7e7 [Tests/Macros] Add %target-codesign before %target-run
rdar://107658689
2023-04-05 12:48:09 -07:00
Ben Barham
e5a28caa9a [Test] Fix swift_swift_parser feature and use in tests
The macro tests were all using "REQUIRES: OS=macosx" as a proxy for
"have the Swift Swift parser". There was an existing feature for this,
but it was just checking whether the path was passed through. Fix that
to use the same variable as in CMake.

Also remove all extraneous `-I` and `-L` to the host libs in the target
invocations.
2023-04-03 09:25:03 -07:00
Doug Gregor
7dca692c01 Merge pull request #64840 from DougGregor/macro-lookup-in-types 2023-04-02 07:23:58 -07:00
Doug Gregor
5e4118ad97 Allow expansion of member macros on extensions and make those names visible.
Ensure that name lookup triggers the expansion of member macros on
extensions, so we can find those names. And fix a bug that caused
expansion of member macros to crash.
2023-03-31 23:29:40 -07:00
Rintaro Ishizaki
1d2fd4223f [Test] Add %host_triple and %host_sdkroot substitutions
Macro tests need to build host libraries/tools. We can't use %target-*
substitutions for that.

rdar://107398734
2023-03-31 07:41:41 -07:00
Doug Gregor
6ab3bc27f3 Ensure that we lazily find macro-unique names in nominal type context 2023-03-07 12:30:37 -08:00
Richard Wei
833338f9ce [Macros] Top-level freestanding macros (#63553)
Allow freestanding macros to be used at top-level.
- Parse top-level `#…` as `MacroExpansionDecl` when we are not in scripting mode.
- Add macro expansion decls to the source lookup cache with name-driven lazy expansion. Not supporting arbitrary name yet.
- Experimental support for script mode and brace-level declaration macro expansions: When type-checking a `MacroExpansionExpr`, assign it a substitute `MacroExpansionDecl` if the macro reference resolves to a declaration macro. This doesn’t work quite fully yet and will be enabled in a future fix.
2023-03-06 07:15:20 -08:00
Holly Borla
e4172055c3 [Macros] Allow any decl names in macro expansions when the macro covers arbitrary
names.
2023-03-04 15:31:24 -08:00
Holly Borla
c9a86ac4fa [Macros] Diagnose macro expansions containing invalid declarations, such as
new macro decls or value decls whose names are not covered by the macro.
2023-03-04 15:31:24 -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
Holly Borla
c33c925e81 [Macros] Remove the macro role argument to ResolveMacroRequest.
The macro role argument presented an opportunity for callers to accidentally
invoke this request twice for the same macro with slightly different macro
roles passed in, which resulted in re-typechecking the macro arguments.
Instead, derive the corresponding macro roles from the macro reference syntax.
2023-02-14 22:38:53 -08:00
Alex Hoppen
75771c1579 Merge pull request #63387 from ahoppen/ahoppen/macros-swift-5
[Macros] Compile Macros tests with swift-version 5 instead of swift-version 4
2023-02-07 09:16:44 +01:00
Holly Borla
09e34f274d [Macros] Apply generic arguments from attached macro custom attributes when
resolving the macro reference.
2023-02-06 18:45:26 -08:00
Alex Hoppen
ba5a727983 [Macros] Compile Macros tests with swift-version 5 instead of swift-version 4 2023-02-04 11:10:08 +01:00
Holly Borla
e6d7ea53ed [Parser] Use proper ParseDeclOptions when parsing the result of a member macro
expansion.
2023-01-27 22:37:22 -08:00
Holly Borla
f6f57a8099 [Macros] Rename "synthesized member macros" to "member macros". 2023-01-26 21:52:36 -08:00
Holly Borla
07319d0fdd [ASTScope] Teach ASTScope lookup to find source locations inside macro-expanded
scopes.

ASTScope lookup can no longer assume that all scopes are within the same source
file. Scope trees can now contain scopes that are in macro expansion buffers, which
live in different source files with independent source ranges from the root of a
given scope tree. To handle this when searching for a scope containing a given source
location, ASTScope lookup needs to walk up the chain of macro expansion buffers to find
the lowest common buffer in which to compare source locations.

This fixes a number of issues with unqualified lookup into and from within macro-expanded
code.
2023-01-25 23:19:33 -08:00
Holly Borla
14f11727f2 [ASTScopeCreation] Teach ASTScope to find the enclosing type context for
synthesized member macro expansion buffers.
2023-01-24 19:45:22 -08:00
Holly Borla
e04a791ad7 [Macros] Allow synthesized member macros to add member type and method decls. 2023-01-24 19:45:22 -08:00