mirror of
https://github.com/apple/swift.git
synced 2026-06-20 15:42:51 +02:00
425cd0ebd7
**Overview**: This PR introduces the basic infrastructure needed to eventually migrate derived macros generation from hand-crafted AST nodes to macros. No conformance have been migrated yet. **Motivation**: Derived conformances (e.g. `Equatable`, `Hashable`, `Codable`, ...) are currently implemented as a special case in the compiler, producing synthetic AST nodes directly. Migrating this to macros will hopefully unify the code path with the existing macro expansion infrastructure, make conformance synthesis easier to extend and test as well as reducing the amount of special cases in the compiler. **Changes**: - New experimental feature flag `DeriveConformancesViaMacros`: Introduces the flag that will eventually gate the new derived conformance code paths. It does not control any behaviour for the moment as none have been migrated yet but this enables future changes to be built incrementally. - New GeneratedSourceInfo and SourceFile kinds `SyntheticMacro`: Introduces new GSI and SourceFile kinds named `SyntheticMacro` to represent macros synthesized by the compiler. Since macros need a real buffer to expand, this is the kind of source file and GSI associated with those buffers. - Conformance derivation via macros API: Introduces the `deriveRequirementViaMacro` function that produces the required witness via macro expansion. See https://github.com/swiftlang/llvm-project/pull/13124 for llvm-related changes. **Next steps**: - Macros do not contain any semantic information, especially regarding types. Therefore it is necessary to provide them with type information as an argument so they can eventually derive the conformances. A separate PR is being created to generate this type information as strings containing swift-parsable code for easy parsing on the macro end. - Implement derived conformance synthesis for individual protocols using the new infrastructure, like `Equatable` or `Hashable` for starters. - Wire the experimental flag to gate the new path once an implementation exists --------- Co-authored-by: Hamish Knight <hamish_knight@apple.com>