|
27 | 27 | #include "swift/AST/TypeAlignments.h"
|
28 | 28 | #include "swift/Basic/OptionalEnum.h"
|
29 | 29 | #include "swift/Basic/Range.h"
|
| 30 | +#include "llvm/ADT/DenseMap.h" |
30 | 31 | #include "llvm/ADT/DenseSet.h"
|
31 | 32 | #include "llvm/ADT/SmallPtrSet.h"
|
32 | 33 | #include "llvm/Support/TrailingObjects.h"
|
@@ -3350,6 +3351,8 @@ class ProtocolDecl : public NominalTypeDecl {
|
3350 | 3351 |
|
3351 | 3352 | ArrayRef<ProtocolDecl *> InheritedProtocols;
|
3352 | 3353 |
|
| 3354 | + llvm::DenseMap<ValueDecl *, ConcreteDeclRef> DefaultWitnesses; |
| 3355 | + |
3353 | 3356 | /// True if the protocol has requirements that cannot be satisfied (e.g.
|
3354 | 3357 | /// because they could not be imported from Objective-C).
|
3355 | 3358 | unsigned HasMissingRequirements : 1;
|
@@ -3494,6 +3497,23 @@ class ProtocolDecl : public NominalTypeDecl {
|
3494 | 3497 | HasMissingRequirements = newValue;
|
3495 | 3498 | }
|
3496 | 3499 |
|
| 3500 | + /// Returns the default witness for a requirement, or nullptr if there is |
| 3501 | + /// no default. |
| 3502 | + ConcreteDeclRef getDefaultWitness(ValueDecl *requirement) { |
| 3503 | + auto found = DefaultWitnesses.find(requirement); |
| 3504 | + if (found == DefaultWitnesses.end()) |
| 3505 | + return nullptr; |
| 3506 | + return found->second; |
| 3507 | + } |
| 3508 | + |
| 3509 | + /// Record the default witness for a requirement. |
| 3510 | + void setDefaultWitness(ValueDecl *requirement, ConcreteDeclRef witness) { |
| 3511 | + assert(witness); |
| 3512 | + auto pair = DefaultWitnesses.insert(std::make_pair(requirement, witness)); |
| 3513 | + assert(pair.second && "Already have a default witness!"); |
| 3514 | + (void) pair; |
| 3515 | + } |
| 3516 | + |
3497 | 3517 | /// Set the list of inherited protocols.
|
3498 | 3518 | void setInheritedProtocols(ArrayRef<ProtocolDecl *> protocols) {
|
3499 | 3519 | assert(!InheritedProtocolsSet && "protocols already set");
|
|
0 commit comments