Skip to content

Commit dfb1a4a

Browse files
authored
Merge pull request #64524 from DougGregor/macro-expand-conformances-multi
Expand conformance macros within the conformance lookup table
2 parents 294342a + 906033a commit dfb1a4a

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

lib/AST/ConformanceLookupTable.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "swift/AST/SourceFile.h"
2626
#include "swift/AST/ProtocolConformance.h"
2727
#include "swift/AST/ProtocolConformanceRef.h"
28+
#include "swift/AST/TypeCheckRequests.h"
2829
#include "llvm/Support/SaveAndRestore.h"
2930

3031
using namespace swift;
@@ -280,6 +281,11 @@ void ConformanceLookupTable::updateLookupTable(NominalTypeDecl *nominal,
280281
[&](NominalTypeDecl *nominal) {
281282
addInheritedProtocols(nominal,
282283
ConformanceSource::forExplicit(nominal));
284+
285+
// Expand conformance macros.
286+
ASTContext &ctx = nominal->getASTContext();
287+
(void)evaluateOrDefault(
288+
ctx.evaluator, ExpandConformanceMacros{nominal}, { });
283289
},
284290
[&](ExtensionDecl *ext,
285291
ArrayRef<ConformanceConstructionInfo> protos) {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
struct STest {
2+
var x = requireEquatable(S())
3+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift -swift-version 5 -I %swift-host-lib-dir -L %swift-host-lib-dir -emit-library -o %t/%target-library-name(MacroDefinition) -module-name=MacroDefinition %S/Inputs/syntax_macro_definitions.swift -g -no-toolchain-stdlib-rpath
3+
4+
// Make sure we see the conformances from another file.
5+
// RUN: %target-typecheck-verify-swift -swift-version 5 -load-plugin-library %t/%target-library-name(MacroDefinition) -I %swift-host-lib-dir -module-name MacroUser -swift-version 5 -primary-file %S/Inputs/macro_expand_conformances_other.swift -DDISABLE_TOP_LEVEL_CODE
6+
7+
8+
// REQUIRES: executable_test
9+
10+
// FIXME: Swift parser is not enabled on Linux CI yet.
11+
// REQUIRES: OS=macosx
12+
13+
@attached(conformance)
14+
macro Equatable() = #externalMacro(module: "MacroDefinition", type: "EquatableMacro")
15+
16+
@attached(conformance)
17+
macro Hashable() = #externalMacro(module: "MacroDefinition", type: "HashableMacro")
18+
19+
func requireEquatable(_ value: some Equatable) -> Int {
20+
print(value == value)
21+
return 0
22+
}
23+
24+
func requireHashable(_ value: some Hashable) {
25+
print(value.hashValue)
26+
}
27+
28+
@Equatable
29+
struct S {}
30+

0 commit comments

Comments
 (0)