Skip to content

Commit 6fa7a3f

Browse files
committed
AST: Introduce GenericSignatureImpl::getRequirementMachine()
1 parent f28d9b3 commit 6fa7a3f

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

include/swift/AST/GenericSignature.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ namespace swift {
3333
class GenericSignatureBuilder;
3434
class ProtocolConformanceRef;
3535
class ProtocolType;
36+
class RequirementMachine;
3637
class SubstitutionMap;
3738
class GenericEnvironment;
3839

@@ -303,6 +304,9 @@ class alignas(1 << TypeAlignInBits) GenericSignatureImpl final
303304
/// Retrieve the generic signature builder for the given generic signature.
304305
GenericSignatureBuilder *getGenericSignatureBuilder() const;
305306

307+
/// Retrieve the requirement machine for the given generic signature.
308+
RequirementMachine *getRequirementMachine() const;
309+
306310
/// Returns the generic environment that provides fresh contextual types
307311
/// (archetypes) that correspond to the interface types in this generic
308312
/// signature.

lib/AST/GenericSignature.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "swift/AST/GenericEnvironment.h"
2323
#include "swift/AST/Module.h"
2424
#include "swift/AST/PrettyStackTrace.h"
25+
#include "swift/AST/RequirementMachine.h"
2526
#include "swift/AST/Types.h"
2627
#include "swift/Basic/STLExtras.h"
2728
#include <functional>
@@ -166,6 +167,17 @@ GenericSignatureImpl::getGenericSignatureBuilder() const {
166167
CanGenericSignature(this));
167168
}
168169

170+
RequirementMachine *
171+
GenericSignatureImpl::getRequirementMachine() const {
172+
// The requirement machine is associated with the canonical signature.
173+
if (!isCanonical())
174+
return getCanonicalSignature()->getRequirementMachine();
175+
176+
// Requirement machines are stored on the ASTContext.
177+
return getASTContext().getOrCreateRequirementMachine(
178+
CanGenericSignature(this));
179+
}
180+
169181
bool GenericSignatureImpl::isEqual(GenericSignature Other) const {
170182
return getCanonicalSignature() == Other.getCanonicalSignature();
171183
}

0 commit comments

Comments
 (0)