Skip to content

Macro declarations #62204

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 21 commits into from
Nov 29, 2022
Merged

Macro declarations #62204

merged 21 commits into from
Nov 29, 2022

Conversation

DougGregor
Copy link
Member

@DougGregor DougGregor commented Nov 19, 2022

Introduce macro declarations and use them for the... declaration... of macros... with a way to specify the externally-provided definition of the macro. Macro declarations look like this:

macro stringify<T>(_ value: T) -> (T, String) = _SwiftSyntaxMacros.StringifyMacro

With these macro declarations, we no longer need to query the macro implementation for the type signature, because it's all available in the source. Nor do we need allMacros to help us find macros, because the macro module and type name is specified in the definition.

Macro declarations also make most of the other features one expects work easily, so wire up access control, code completion, and indexing in the process.

@DougGregor DougGregor force-pushed the macro-declarations branch 3 times, most recently from 07b4018 to 5b3c24f Compare November 25, 2022 06:20
@DougGregor
Copy link
Member Author

swiftlang/swift-syntax#1093

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

swiftlang/swift-syntax#1093

@swift-ci please test

@DougGregor DougGregor marked this pull request as ready for review November 28, 2022 05:04
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

swiftlang/swift-syntax#1093

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

swiftlang/swift-syntax#1093

@swift-ci please smoke test

1 similar comment
@DougGregor
Copy link
Member Author

swiftlang/swift-syntax#1093

@swift-ci please smoke test

Comment on lines 22 to 23
#include "swift/Demangling/Demangle.h"
#include "swift/Demangling/Demangler.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are probably no longer needed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do this in a follow-up PR, thanks.

free(const_cast<void *>((const void *)returnedName.data()));
kind = invokeKind();
}
if ((&swift_conformsToProtocol == nullptr) || !protocolDescriptor)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't &swift_conformsToProtocol never null since it's either a local variable or an extern declaration? swift_conformsToProtocol could be null.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah... yeah, I got sloppy here. I'll fix it in a follow-up.

@DougGregor
Copy link
Member Author

AARRGGGGHHHH silly conflict

@DougGregor
Copy link
Member Author

swiftlang/swift-syntax#1093

@swift-ci please smoke test

Enable type checking support for explicitly specifying generic arguments to
a macro, e.g., `#stringify<Double>(1 + 2)`. To do so, introduce a new
kind of constraint that performs explicit argument matching against the
generic parameters of a macro only after the overload is chosen.
…ion.

A macro declaration contains the external module and type name of the
macro's implementation. Use that information to find the macro type
(via its type metadata accessor) in a loaded plugin, so we no longer
require the "allMacros" array. Instead, each macro implementation type
must be a public struct.

Since we are now fully dependent on the macro declaration for
everything about a macro except its kind, remove most of the query
infrastructure for compiler plugins.

Replace the macro registration scheme based on the allMacros array with
Don't look up the macro name again when doing expansion; that's already
been done when we found the macro definition.
This approach works for both macros built into the compiler (e.g., the
builtin macros) as well as those that are loaded via plugin but don't
conform to the _CompilerPluginSupport protocol.

This eliminates all uses of the `MacroSystem` itself in ASTGen, and
pushes more of the implementation through ASTGen.
@DougGregor
Copy link
Member Author

swiftlang/swift-syntax#1093

@swift-ci please smoke test

@DougGregor DougGregor merged commit e1102cc into swiftlang:main Nov 29, 2022
@DougGregor DougGregor deleted the macro-declarations branch November 29, 2022 18:04
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.

2 participants