|
24 | 24 | #include "swift/AST/Ownership.h"
|
25 | 25 | #include "swift/Basic/LLVM.h"
|
26 | 26 | #include "swift/Basic/FlagSet.h"
|
| 27 | +#include "llvm/ADT/ArrayRef.h" |
27 | 28 |
|
28 | 29 | #include <stdlib.h>
|
29 | 30 | #include <stdint.h>
|
@@ -55,6 +56,10 @@ enum {
|
55 | 56 |
|
56 | 57 | /// The number of words in an AsyncLet (flags + child task context & allocation)
|
57 | 58 | NumWords_AsyncLet = 80, // 640 bytes ought to be enough for anyone
|
| 59 | + |
| 60 | + /// The maximum number of generic parameters that can be |
| 61 | + /// implicitly declared, for generic signatures that support that. |
| 62 | + MaxNumImplicitGenericParamDescriptors = 64, |
58 | 63 | };
|
59 | 64 |
|
60 | 65 | struct InProcess;
|
@@ -1652,8 +1657,40 @@ class GenericParamDescriptor {
|
1652 | 1657 | constexpr uint8_t getIntValue() const {
|
1653 | 1658 | return Value;
|
1654 | 1659 | }
|
| 1660 | + |
| 1661 | + friend bool operator==(GenericParamDescriptor lhs, |
| 1662 | + GenericParamDescriptor rhs) { |
| 1663 | + return lhs.getIntValue() == rhs.getIntValue(); |
| 1664 | + } |
| 1665 | + friend bool operator!=(GenericParamDescriptor lhs, |
| 1666 | + GenericParamDescriptor rhs) { |
| 1667 | + return !(lhs == rhs); |
| 1668 | + } |
| 1669 | + |
| 1670 | + /// The default parameter descriptor for an implicit parameter. |
| 1671 | + static constexpr GenericParamDescriptor implicit() { |
| 1672 | + return GenericParamDescriptor(GenericParamKind::Type, |
| 1673 | + /*key argument*/ true, |
| 1674 | + /*extra argument*/ false); |
| 1675 | + } |
1655 | 1676 | };
|
1656 | 1677 |
|
| 1678 | +/// Can the given generic parameter array be implicit, for places in |
| 1679 | +/// the ABI which support that? |
| 1680 | +inline bool canGenericParamsBeImplicit( |
| 1681 | + llvm::ArrayRef<GenericParamDescriptor> params) { |
| 1682 | + // If there are more parameters than the maximum, they cannot be implicit. |
| 1683 | + if (params.size() > MaxNumImplicitGenericParamDescriptors) |
| 1684 | + return false; |
| 1685 | + |
| 1686 | + // If any parameter is not the implicit pattern, they cannot be implicit. |
| 1687 | + for (auto param : params) |
| 1688 | + if (param != GenericParamDescriptor::implicit()) |
| 1689 | + return false; |
| 1690 | + |
| 1691 | + return true; |
| 1692 | +} |
| 1693 | + |
1657 | 1694 | enum class GenericRequirementKind : uint8_t {
|
1658 | 1695 | /// A protocol requirement.
|
1659 | 1696 | Protocol = 0,
|
|
0 commit comments