Rename "suppressible protocols" to "invertible protocols".

We've decided to use the "invertible protocols" terminology throughout
the runtime and compiler, so move over to that terminology
consistently.
This commit is contained in:
Doug Gregor
2024-03-29 10:09:48 -07:00
parent 79b78acdf6
commit b84f8ab080
16 changed files with 330 additions and 332 deletions

View File

@@ -21,7 +21,7 @@
#include "swift/ABI/TargetLayout.h"
#include "swift/ABI/MetadataValues.h"
#include "swift/ABI/MetadataRef.h"
#include "swift/ABI/SuppressibleProtocols.h"
#include "swift/ABI/InvertibleProtocols.h"
#include "swift/ABI/TrailingObjects.h"
#include "swift/Demangling/Demangle.h"
@@ -105,8 +105,8 @@ struct TargetGenericContextDescriptorHeader {
return getNumArguments() > 0;
}
bool hasConditionalSuppressedProtocols() const {
return Flags.hasConditionalSuppressedProtocols();
bool hasConditionalInvertedProtocols() const {
return Flags.hasConditionalInvertedProtocols();
}
};
using GenericContextDescriptorHeader =
@@ -143,19 +143,19 @@ public:
/// Only valid if the requirement has Layout kind.
GenericRequirementLayoutKind Layout;
/// The set of suppressible protocols whose check is suppressed, along
/// with the index of the generic parameter being suppressed.
/// The set of invertible protocols whose check is disabled, along
/// with the index of the generic parameter to which this applies.
///
/// The index is technically redundant with the subject type, but its
/// storage is effectively free because this union is 32 bits anyway. The
/// index 0xFFFF is reserved for "not a generic parameter", in case we
/// need to use that in the future.
/// index 0xFFFF is reserved for "not a generic parameter", in which case
/// the constraints are on the subject type.
///
/// Only valid if the requirement has SuppressedProtocols kind.
/// Only valid if the requirement has InvertedProtocols kind.
struct {
uint16_t GenericParamIndex;
SuppressibleProtocolSet Protocols;
} SuppressedProtocols;
InvertibleProtocolSet Protocols;
} InvertedProtocols;
};
constexpr GenericRequirementFlags getFlags() const {
@@ -223,16 +223,16 @@ public:
return Layout;
}
/// Retrieve the set of suppressed protocols.
SuppressibleProtocolSet getSuppressedProtocols() const {
assert(getKind() == GenericRequirementKind::SuppressedProtocols);
return SuppressedProtocols.Protocols;
/// Retrieve the set of inverted protocols.
InvertibleProtocolSet getInvertedProtocols() const {
assert(getKind() == GenericRequirementKind::InvertedProtocols);
return InvertedProtocols.Protocols;
}
/// Retrieve the suppressible protocol kind.
uint16_t getSuppressedProtocolsGenericParamIndex() const {
assert(getKind() == GenericRequirementKind::SuppressedProtocols);
return SuppressedProtocols.GenericParamIndex;
/// Retrieve the invertible protocol kind.
uint16_t getInvertedProtocolsGenericParamIndex() const {
assert(getKind() == GenericRequirementKind::InvertedProtocols);
return InvertedProtocols.GenericParamIndex;
}
/// Determine whether this generic requirement has a known kind.
@@ -246,7 +246,7 @@ public:
case GenericRequirementKind::SameConformance:
case GenericRequirementKind::SameType:
case GenericRequirementKind::SameShape:
case GenericRequirementKind::SuppressedProtocols:
case GenericRequirementKind::InvertedProtocols:
return true;
}
@@ -299,24 +299,24 @@ struct GenericPackShapeDescriptor {
};
/// A count for the number of requirements for the number of requirements
/// for a given conditional conformance to a suppressible protocols.
struct ConditionalSuppressibleProtocolsRequirementCount {
/// for a given conditional conformance to a invertible protocols.
struct ConditionalInvertibleProtocolsRequirementCount {
uint16_t count;
};
/// A suppressible protocol set used for the conditional conformances in a
/// A invertible protocol set used for the conditional conformances in a
/// generic context.
struct ConditionalSuppressibleProtocolSet: SuppressibleProtocolSet {
using SuppressibleProtocolSet::SuppressibleProtocolSet;
struct ConditionalInvertibleProtocolSet: InvertibleProtocolSet {
using InvertibleProtocolSet::InvertibleProtocolSet;
};
/// A generic requirement for describing a conditional conformance to a
/// suppressible protocol.
/// invertible protocol.
///
/// This type is equivalent to a `TargetGenericRequirementDescriptor`, and
/// differs only because it needs to occur alongside
template<typename Runtime>
struct TargetConditionalSuppressibleProtocolRequirement: TargetGenericRequirementDescriptor<Runtime> { };
struct TargetConditionalInvertibleProtocolRequirement: TargetGenericRequirementDescriptor<Runtime> { };
/// An array of generic parameter descriptors, all
/// GenericParamDescriptor::implicit(), which is by far
@@ -478,9 +478,9 @@ class TrailingGenericContextObjects<TargetSelf<Runtime>,
TargetGenericRequirementDescriptor<Runtime>,
GenericPackShapeHeader,
GenericPackShapeDescriptor,
ConditionalSuppressibleProtocolSet,
ConditionalSuppressibleProtocolsRequirementCount,
TargetConditionalSuppressibleProtocolRequirement<Runtime>,
ConditionalInvertibleProtocolSet,
ConditionalInvertibleProtocolsRequirementCount,
TargetConditionalInvertibleProtocolRequirement<Runtime>,
FollowingTrailingObjects...>
{
protected:
@@ -488,17 +488,17 @@ protected:
using GenericContextHeaderType = TargetGenericContextHeaderType<Runtime>;
using GenericRequirementDescriptor =
TargetGenericRequirementDescriptor<Runtime>;
using GenericConditionalSuppressibleProtocolRequirement =
TargetConditionalSuppressibleProtocolRequirement<Runtime>;
using GenericConditionalInvertibleProtocolRequirement =
TargetConditionalInvertibleProtocolRequirement<Runtime>;
using TrailingObjects = swift::ABI::TrailingObjects<Self,
GenericContextHeaderType,
GenericParamDescriptor,
GenericRequirementDescriptor,
GenericPackShapeHeader,
GenericPackShapeDescriptor,
ConditionalSuppressibleProtocolSet,
ConditionalSuppressibleProtocolsRequirementCount,
GenericConditionalSuppressibleProtocolRequirement,
ConditionalInvertibleProtocolSet,
ConditionalInvertibleProtocolsRequirementCount,
GenericConditionalInvertibleProtocolRequirement,
FollowingTrailingObjects...>;
friend TrailingObjects;
@@ -528,45 +528,45 @@ public:
return getFullGenericContextHeader();
}
bool hasConditionalSuppressedProtocols() const {
bool hasConditionalInvertedProtocols() const {
if (!asSelf()->isGeneric())
return false;
return getGenericContextHeader().hasConditionalSuppressedProtocols();
return getGenericContextHeader().hasConditionalInvertedProtocols();
}
const SuppressibleProtocolSet &
getConditionalSuppressedProtocols() const {
assert(hasConditionalSuppressedProtocols());
const InvertibleProtocolSet &
getConditionalInvertedProtocols() const {
assert(hasConditionalInvertedProtocols());
return *this->template
getTrailingObjects<ConditionalSuppressibleProtocolSet>();
getTrailingObjects<ConditionalInvertibleProtocolSet>();
}
/// Retrieve the counts for # of conditional suppressible protocols for each
/// conditional conformance to a suppressible protocol.
/// Retrieve the counts for # of conditional invertible protocols for each
/// conditional conformance to a invertible protocol.
///
/// The counts are cumulative, so the first entry in the array is the
/// number of requirements for the first conditional conformance. The
/// second entry in the array is the number of requirements in the first
/// and second conditional conformances. The last entry is, therefore, the
/// total count of requirements in the structure.
llvm::ArrayRef<ConditionalSuppressibleProtocolsRequirementCount>
getConditionalSuppressibleProtocolRequirementCounts() const {
if (!asSelf()->hasConditionalSuppressedProtocols())
llvm::ArrayRef<ConditionalInvertibleProtocolsRequirementCount>
getConditionalInvertibleProtocolRequirementCounts() const {
if (!asSelf()->hasConditionalInvertedProtocols())
return {};
return {
this->template
getTrailingObjects<ConditionalSuppressibleProtocolsRequirementCount>(),
getNumConditionalSuppressibleProtocolsRequirementCounts()
getTrailingObjects<ConditionalInvertibleProtocolsRequirementCount>(),
getNumConditionalInvertibleProtocolsRequirementCounts()
};
}
/// Retrieve the array of requirements for conditional conformances to
/// the ith conditional conformance to a suppressible protocol.
llvm::ArrayRef<GenericConditionalSuppressibleProtocolRequirement>
getConditionalSuppressibleProtocolRequirementsAt(unsigned i) const {
auto counts = getConditionalSuppressibleProtocolRequirementCounts();
/// the ith conditional conformance to a invertible protocol.
llvm::ArrayRef<GenericConditionalInvertibleProtocolRequirement>
getConditionalInvertibleProtocolRequirementsAt(unsigned i) const {
auto counts = getConditionalInvertibleProtocolRequirementCounts();
assert(i < counts.size());
unsigned startIndex = (i == 0) ? 0 : counts[i-1].count;
@@ -574,35 +574,35 @@ public:
auto basePtr =
this->template
getTrailingObjects<GenericConditionalSuppressibleProtocolRequirement>();
getTrailingObjects<GenericConditionalInvertibleProtocolRequirement>();
return { basePtr + startIndex, basePtr + endIndex };
}
/// Retrieve the array of requirements for conditional conformances to
/// the ith conditional conformance to a suppressible protocol.
llvm::ArrayRef<GenericConditionalSuppressibleProtocolRequirement>
getConditionalSuppressibleProtocolRequirementsFor(
SuppressibleProtocolKind kind
/// the ith conditional conformance to a invertible protocol.
llvm::ArrayRef<GenericConditionalInvertibleProtocolRequirement>
getConditionalInvertibleProtocolRequirementsFor(
InvertibleProtocolKind kind
) const {
if (!asSelf()->hasConditionalSuppressedProtocols())
if (!asSelf()->hasConditionalInvertedProtocols())
return { };
auto conditionallySuppressed = getConditionalSuppressedProtocols();
if (!conditionallySuppressed.contains(kind))
auto conditionallyInverted = getConditionalInvertedProtocols();
if (!conditionallyInverted.contains(kind))
return { };
// Count the number of "set" bits up to (but not including) the
// bit we're looking at.
unsigned targetBit = static_cast<uint8_t>(kind);
auto suppressedBits = conditionallySuppressed.rawBits();
auto invertedBits = conditionallyInverted.rawBits();
unsigned priorBits = 0;
for (unsigned i = 0; i != targetBit; ++i) {
if (suppressedBits & 0x01)
if (invertedBits & 0x01)
++priorBits;
suppressedBits = suppressedBits >> 1;
invertedBits = invertedBits >> 1;
}
return getConditionalSuppressibleProtocolRequirementsAt(priorBits);
return getConditionalInvertibleProtocolRequirementsAt(priorBits);
}
const TargetGenericContext<Runtime> *getGenericContext() const {
@@ -687,28 +687,28 @@ protected:
}
size_t numTrailingObjects(
OverloadToken<ConditionalSuppressibleProtocolSet>
OverloadToken<ConditionalInvertibleProtocolSet>
) const {
return asSelf()->hasConditionalSuppressedProtocols() ? 1 : 0;
return asSelf()->hasConditionalInvertedProtocols() ? 1 : 0;
}
unsigned getNumConditionalSuppressibleProtocolsRequirementCounts() const {
if (!asSelf()->hasConditionalSuppressedProtocols())
unsigned getNumConditionalInvertibleProtocolsRequirementCounts() const {
if (!asSelf()->hasConditionalInvertedProtocols())
return 0;
return countBitsUsed(getConditionalSuppressedProtocols().rawBits());
return countBitsUsed(getConditionalInvertedProtocols().rawBits());
}
size_t numTrailingObjects(
OverloadToken<ConditionalSuppressibleProtocolsRequirementCount>
OverloadToken<ConditionalInvertibleProtocolsRequirementCount>
) const {
return getNumConditionalSuppressibleProtocolsRequirementCounts();
return getNumConditionalInvertibleProtocolsRequirementCounts();
}
size_t numTrailingObjects(
OverloadToken<GenericConditionalSuppressibleProtocolRequirement>
OverloadToken<GenericConditionalInvertibleProtocolRequirement>
) const {
auto counts = getConditionalSuppressibleProtocolRequirementCounts();
auto counts = getConditionalInvertibleProtocolRequirementCounts();
return counts.empty() ? 0 : counts.back().count;
}

View File

@@ -1,4 +1,4 @@
//===--- SuppressibleProtocols.def - Suppressible protocol meta -*- C++ -*-===//
//===--- InvertibleProtocols.def - invertible protocol meta -*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
@@ -11,21 +11,21 @@
//===----------------------------------------------------------------------===//
//
// This file defines macros used for macro-metaprogramming with ABI-defined
// suppressible protocols.
// invertible protocols.
//
// The SUPPRESSIBLE_PROTOCOL(Name, Bit, MangleChar) macro is used to specify
// each suppressible protocol that's conceptually part of the ABI. The
// The INVERTIBLE_PROTOCOL(Name, Bit) macro is used to specify each
// each invertible protocol that's conceptually part of the ABI. The
// arguments are:
// Name: The name of the protocol, e.g., Copyable
// Bit: The bit in the set bitset of suppressible protocols that is used
// Bit: The bit in the set bitset of invertible protocols that is used
// to indicate this.
//===----------------------------------------------------------------------===//
#ifndef SUPPRESSIBLE_PROTOCOL
# error Must define SUPPRESSIBLE_PROTOCOL macro before including this file
#ifndef INVERTIBLE_PROTOCOL
# error Must define INVERTIBLE_PROTOCOL macro before including this file
#endif
SUPPRESSIBLE_PROTOCOL(Copyable, 0)
SUPPRESSIBLE_PROTOCOL(Escapable, 1)
INVERTIBLE_PROTOCOL(Copyable, 0)
INVERTIBLE_PROTOCOL(Escapable, 1)
#undef SUPPRESSIBLE_PROTOCOL
#undef INVERTIBLE_PROTOCOL

View File

@@ -1,4 +1,4 @@
//===--- SuppressibleProtocols.h - Suppressible protocol meta ---*- C++ -*-===//
//===--- InvertibleProtocols.h - invertible protocol meta ---*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
@@ -10,13 +10,13 @@
//
//===----------------------------------------------------------------------===//
//
// This header declares various types for suppressible protocols, such as
// This header declares various types for invertible protocols, such as
// Copyable.
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_ABI_SUPPRESSIBLEPROTOCOLS_H
#define SWIFT_ABI_SUPPRESSIBLEPROTOCOLS_H
#ifndef SWIFT_ABI_INVERTIBLEPROTOCOLS_H
#define SWIFT_ABI_INVERTIBLEPROTOCOLS_H
#include <cstdint>
#include <initializer_list>
@@ -24,34 +24,32 @@
namespace swift {
/// Describes a "suppressible" protocol, such as Copyable, which is assumed to
/// hold for all types unless explicitly suppressed.
enum class SuppressibleProtocolKind : uint8_t {
#define SUPPRESSIBLE_PROTOCOL(Name, Bit) Name = Bit,
#include "swift/ABI/SuppressibleProtocols.def"
/// Describes an "invertible" protocol, such as Copyable, which is assumed to
/// hold for all types unless explicitly indicated otherwise.
enum class InvertibleProtocolKind : uint8_t {
#define INVERTIBLE_PROTOCOL(Name, Bit) Name = Bit,
#include "swift/ABI/InvertibleProtocols.def"
};
typedef SuppressibleProtocolKind InvertibleProtocolKind;
/// A set of suppressible protocols, whose bits correspond to the cases of
/// SuppressibleProtocolKind.
class SuppressibleProtocolSet {
/// A set of invertible protocols, whose bits correspond to the cases of
/// InvertibleProtocolKind.
class InvertibleProtocolSet {
using StorageType = uint16_t;
/// The stored bits.
StorageType bits;
/// Retrieve the mask for this bit.
static StorageType getMask(SuppressibleProtocolKind kind) {
static StorageType getMask(InvertibleProtocolKind kind) {
return 1 << static_cast<uint8_t>(kind);
}
public:
explicit constexpr SuppressibleProtocolSet(StorageType bits) : bits(bits) {}
constexpr SuppressibleProtocolSet() : bits(0) {}
explicit constexpr InvertibleProtocolSet(StorageType bits) : bits(bits) {}
constexpr InvertibleProtocolSet() : bits(0) {}
SuppressibleProtocolSet(
std::initializer_list<SuppressibleProtocolKind> elements
InvertibleProtocolSet(
std::initializer_list<InvertibleProtocolKind> elements
) : bits(0) {
for (auto element : elements)
insert(element);
@@ -63,24 +61,24 @@ public:
/// Whether the set contains no protocols.
bool empty() const { return bits == 0; }
/// Check whether the set contains the specific suppressible protocol.
bool contains(SuppressibleProtocolKind kind) const {
/// Check whether the set contains the specific invertible protocol.
bool contains(InvertibleProtocolKind kind) const {
return bits & getMask(kind);
}
/// Insert the suppressible protocol into the set.
void insert(SuppressibleProtocolKind kind) {
/// Insert the invertible protocol into the set.
void insert(InvertibleProtocolKind kind) {
bits = bits | getMask(kind);
}
/// Insert all of the suppressible protocols from the other set into this
/// Insert all of the invertible protocols from the other set into this
/// one.
void insertAll(SuppressibleProtocolSet other) {
void insertAll(InvertibleProtocolSet other) {
bits |= other.bits;
}
/// Remove the given suppressible protocol from the set.
void remove(SuppressibleProtocolKind kind) {
/// Remove the given invertible protocol from the set.
void remove(InvertibleProtocolKind kind) {
uint16_t mask = getMask(kind);
bits = bits & ~mask;
}
@@ -88,19 +86,19 @@ public:
/// Clear out all of the protocols from the set.
void clear() { bits = 0; }
#define SUPPRESSIBLE_PROTOCOL(Name, Bit) \
#define INVERTIBLE_PROTOCOL(Name, Bit) \
bool contains##Name() const { \
return contains(SuppressibleProtocolKind::Name); \
return contains(InvertibleProtocolKind::Name); \
}
#include "swift/ABI/SuppressibleProtocols.def"
#include "swift/ABI/InvertibleProtocols.def"
/// Produce a suppressible protocol set containing all known suppressible
/// Produce a invertible protocol set containing all known invertible
/// protocols.
static SuppressibleProtocolSet allKnown() {
SuppressibleProtocolSet result;
#define SUPPRESSIBLE_PROTOCOL(Name, Bit) \
result.insert(SuppressibleProtocolKind::Name);
#include "swift/ABI/SuppressibleProtocols.def"
static InvertibleProtocolSet allKnown() {
InvertibleProtocolSet result;
#define INVERTIBLE_PROTOCOL(Name, Bit) \
result.insert(InvertibleProtocolKind::Name);
#include "swift/ABI/InvertibleProtocols.def"
return result;
}
@@ -108,7 +106,7 @@ public:
///
/// This can occur when an older Swift runtime is working with metadata
/// or mangled names generated by a newer compiler that has introduced
/// another kind of suppressible protocol. The Swift runtime will need to
/// another kind of invertible protocol. The Swift runtime will need to
/// step lightly around protocol sets with unknown protocols.
bool hasUnknownProtocols() const {
return !(*this - allKnown()).empty();
@@ -148,7 +146,7 @@ public:
public:
using difference_type = int;
using value_type = SuppressibleProtocolKind;
using value_type = InvertibleProtocolKind;
using pointer = void;
using reference = value_type;
using iterator_category = std::input_iterator_tag;
@@ -172,8 +170,8 @@ public:
return tmp;
}
SuppressibleProtocolKind operator*() const {
return static_cast<SuppressibleProtocolKind>(currentBitIndex);
InvertibleProtocolKind operator*() const {
return static_cast<InvertibleProtocolKind>(currentBitIndex);
}
friend bool operator ==(iterator lhs, iterator rhs) {
@@ -195,47 +193,47 @@ public:
iterator end() const { return iterator(0); }
friend bool operator==(
SuppressibleProtocolSet lhs, SuppressibleProtocolSet rhs) {
InvertibleProtocolSet lhs, InvertibleProtocolSet rhs) {
return lhs.bits == rhs.bits;
}
friend bool operator!=(
SuppressibleProtocolSet lhs, SuppressibleProtocolSet rhs) {
InvertibleProtocolSet lhs, InvertibleProtocolSet rhs) {
return lhs.bits != rhs.bits;
}
friend SuppressibleProtocolSet operator-(
SuppressibleProtocolSet lhs, SuppressibleProtocolSet rhs) {
return SuppressibleProtocolSet(lhs.bits & ~rhs.bits);
friend InvertibleProtocolSet operator-(
InvertibleProtocolSet lhs, InvertibleProtocolSet rhs) {
return InvertibleProtocolSet(lhs.bits & ~rhs.bits);
}
SuppressibleProtocolSet &operator-=(SuppressibleProtocolSet rhs) {
InvertibleProtocolSet &operator-=(InvertibleProtocolSet rhs) {
bits = bits & ~rhs.bits;
return *this;
}
friend SuppressibleProtocolSet operator|(
SuppressibleProtocolSet lhs, SuppressibleProtocolSet rhs) {
return SuppressibleProtocolSet(lhs.bits | rhs.bits);
friend InvertibleProtocolSet operator|(
InvertibleProtocolSet lhs, InvertibleProtocolSet rhs) {
return InvertibleProtocolSet(lhs.bits | rhs.bits);
}
SuppressibleProtocolSet &operator|=(SuppressibleProtocolSet rhs) {
InvertibleProtocolSet &operator|=(InvertibleProtocolSet rhs) {
bits |= rhs.bits;
return *this;
}
};
/// Retrieve the name for the given suppressible protocol.
/// Retrieve the name for the given invertible protocol.
static inline const char *
getSuppressibleProtocolKindName(SuppressibleProtocolKind kind) {
getInvertibleProtocolKindName(InvertibleProtocolKind kind) {
switch (kind) {
#define SUPPRESSIBLE_PROTOCOL(Name, Bit) \
case SuppressibleProtocolKind::Name: return #Name;
#include "swift/ABI/SuppressibleProtocols.def"
#define INVERTIBLE_PROTOCOL(Name, Bit) \
case InvertibleProtocolKind::Name: return #Name;
#include "swift/ABI/InvertibleProtocols.def"
}
return "<unknown suppressible protocol kind>";
return "<unknown invertible protocol kind>";
}
} // end namespace swift
#endif // SWIFT_ABI_SUPPRESSIBLEPROTOCOLS_H
#endif // SWIFT_ABI_INVERTIBLEPROTOCOLS_H

View File

@@ -2928,8 +2928,8 @@ struct swift_ptrauth_struct_context_descriptor(ContextDescriptor)
bool isGeneric() const { return Flags.isGeneric(); }
bool isUnique() const { return Flags.isUnique(); }
bool hasSuppressibleProtocols() const {
return Flags.hasSuppressibleProtocols();
bool hasInvertibleProtocols() const {
return Flags.hasInvertibleProtocols();
}
ContextDescriptorKind getKind() const { return Flags.getKind(); }
@@ -2940,14 +2940,14 @@ struct swift_ptrauth_struct_context_descriptor(ContextDescriptor)
/// Get the module context for this context.
const TargetModuleContextDescriptor<Runtime> *getModuleContext() const;
/// Retrieve the set of protocols that are suppressed by this type's
/// Retrieve the set of protocols that are inverted by this type's
/// primary definition.
///
/// This type might still conditionally conform to any of the protocols
/// that are suppressed here, but that information is recorded in the
/// conditional suppressed protocols of the corresponding `GenericContext`.
const SuppressibleProtocolSet *
getSuppressedProtocols() const;
/// that are inverted here, but that information is recorded in the
/// conditional inverted protocols of the corresponding `GenericContext`.
const InvertibleProtocolSet *
getInvertedProtocols() const;
/// Is this context part of a C-imported module?
bool isCImportedContext() const;
@@ -3250,14 +3250,14 @@ struct swift_ptrauth_struct_context_descriptor(OpaqueTypeDescriptor)
TrailingGenericContextObjects<TargetOpaqueTypeDescriptor<Runtime>,
TargetGenericContextDescriptorHeader,
RelativeDirectPointer<const char>,
SuppressibleProtocolSet>
InvertibleProtocolSet>
{
private:
using TrailingGenericContextObjects =
swift::TrailingGenericContextObjects<TargetOpaqueTypeDescriptor<Runtime>,
TargetGenericContextDescriptorHeader,
RelativeDirectPointer<const char>,
SuppressibleProtocolSet>;
InvertibleProtocolSet>;
using TrailingObjects =
typename TrailingGenericContextObjects::TrailingObjects;
friend TrailingObjects;
@@ -3295,21 +3295,21 @@ public:
return Demangle::makeSymbolicMangledNameStringRef(ptr);
}
/// Retrieve the set of protocols that are suppressed by this type's
/// Retrieve the set of protocols that are inverted by this type's
/// primary definition.
///
/// This type might still conditionally conform to any of the protocols
/// that are suppressed here, but that information is recorded in the
/// conditional suppressed protocols of the corresponding `GenericContext`.
const SuppressibleProtocolSet &
getSuppressedProtocols() const {
assert(this->hasSuppressibleProtocols());
/// that are inverted here, but that information is recorded in the
/// conditional inverted protocols of the corresponding `GenericContext`.
const InvertibleProtocolSet &
getInvertedProtocols() const {
assert(this->hasInvertibleProtocols());
return
*this->template getTrailingObjects<SuppressibleProtocolSet>();
*this->template getTrailingObjects<InvertibleProtocolSet>();
}
size_t numTrailingObjects(OverloadToken<SuppressibleProtocolSet>) const {
return this->hasSuppressibleProtocols() ? 1 : 0;
size_t numTrailingObjects(OverloadToken<InvertibleProtocolSet>) const {
return this->hasInvertibleProtocols() ? 1 : 0;
}
static bool classof(const TargetContextDescriptor<Runtime> *cd) {
@@ -4084,7 +4084,7 @@ class swift_ptrauth_struct_context_descriptor(ClassDescriptor)
TargetCanonicalSpecializedMetadatasListEntry<Runtime>,
TargetCanonicalSpecializedMetadataAccessorsListEntry<Runtime>,
TargetCanonicalSpecializedMetadatasCachingOnceToken<Runtime>,
SuppressibleProtocolSet> {
InvertibleProtocolSet> {
private:
using TrailingGenericContextObjects =
swift::TrailingGenericContextObjects<TargetClassDescriptor<Runtime>,
@@ -4101,7 +4101,7 @@ private:
TargetCanonicalSpecializedMetadatasListEntry<Runtime>,
TargetCanonicalSpecializedMetadataAccessorsListEntry<Runtime>,
TargetCanonicalSpecializedMetadatasCachingOnceToken<Runtime>,
SuppressibleProtocolSet>;
InvertibleProtocolSet>;
using TrailingObjects =
typename TrailingGenericContextObjects::TrailingObjects;
@@ -4451,21 +4451,21 @@ public:
return box->token.get();
}
/// Retrieve the set of protocols that are suppressed by this type's
/// Retrieve the set of protocols that are inverted by this type's
/// primary definition.
///
/// This type might still conditionally conform to any of the protocols
/// that are suppressed here, but that information is recorded in the
/// conditional suppressed protocols of the corresponding `GenericContext`.
const SuppressibleProtocolSet &
getSuppressedProtocols() const {
assert(this->hasSuppressibleProtocols());
/// that are inverted here, but that information is recorded in the
/// conditional inverted protocols of the corresponding `GenericContext`.
const InvertibleProtocolSet &
getInvertedProtocols() const {
assert(this->hasInvertibleProtocols());
return
*this->template getTrailingObjects<SuppressibleProtocolSet>();
*this->template getTrailingObjects<InvertibleProtocolSet>();
}
size_t numTrailingObjects(OverloadToken<SuppressibleProtocolSet>) const {
return this->hasSuppressibleProtocols() ? 1 : 0;
size_t numTrailingObjects(OverloadToken<InvertibleProtocolSet>) const {
return this->hasInvertibleProtocols() ? 1 : 0;
}
static bool classof(const TargetContextDescriptor<Runtime> *cd) {
@@ -4498,7 +4498,7 @@ class swift_ptrauth_struct_context_descriptor(StructDescriptor)
TargetCanonicalSpecializedMetadatasListCount<Runtime>,
TargetCanonicalSpecializedMetadatasListEntry<Runtime>,
TargetCanonicalSpecializedMetadatasCachingOnceToken<Runtime>,
SuppressibleProtocolSet> {
InvertibleProtocolSet> {
public:
using ForeignMetadataInitialization =
TargetForeignMetadataInitialization<Runtime>;
@@ -4522,7 +4522,7 @@ private:
MetadataListCount,
MetadataListEntry,
MetadataCachingOnceToken,
SuppressibleProtocolSet>;
InvertibleProtocolSet>;
using TrailingObjects =
typename TrailingGenericContextObjects::TrailingObjects;
@@ -4609,21 +4609,21 @@ public:
return box->token.get();
}
/// Retrieve the set of protocols that are suppressed by this type's
/// Retrieve the set of protocols that are inverted by this type's
/// primary definition.
///
/// This type might still conditionally conform to any of the protocols
/// that are suppressed here, but that information is recorded in the
/// conditional suppressed protocols of the corresponding `GenericContext`.
const SuppressibleProtocolSet &
getSuppressedProtocols() const {
assert(this->hasSuppressibleProtocols());
/// that are inverted here, but that information is recorded in the
/// conditional inverted protocols of the corresponding `GenericContext`.
const InvertibleProtocolSet &
getInvertedProtocols() const {
assert(this->hasInvertibleProtocols());
return
*this->template getTrailingObjects<SuppressibleProtocolSet>();
*this->template getTrailingObjects<InvertibleProtocolSet>();
}
size_t numTrailingObjects(OverloadToken<SuppressibleProtocolSet>) const {
return this->hasSuppressibleProtocols() ? 1 : 0;
size_t numTrailingObjects(OverloadToken<InvertibleProtocolSet>) const {
return this->hasInvertibleProtocols() ? 1 : 0;
}
static bool classof(const TargetContextDescriptor<Runtime> *cd) {
@@ -4645,7 +4645,7 @@ class swift_ptrauth_struct_context_descriptor(EnumDescriptor)
TargetCanonicalSpecializedMetadatasListCount<Runtime>,
TargetCanonicalSpecializedMetadatasListEntry<Runtime>,
TargetCanonicalSpecializedMetadatasCachingOnceToken<Runtime>,
SuppressibleProtocolSet> {
InvertibleProtocolSet> {
public:
using SingletonMetadataInitialization =
TargetSingletonMetadataInitialization<Runtime>;
@@ -4669,7 +4669,7 @@ private:
MetadataListCount,
MetadataListEntry,
MetadataCachingOnceToken,
SuppressibleProtocolSet>;
InvertibleProtocolSet>;
using TrailingObjects =
typename TrailingGenericContextObjects::TrailingObjects;
@@ -4770,21 +4770,21 @@ public:
return box->token.get();
}
/// Retrieve the set of protocols that are suppressed by this type's
/// Retrieve the set of protocols that are inverted by this type's
/// primary definition.
///
/// This type might still conditionally conform to any of the protocols
/// that are suppressed here, but that information is recorded in the
/// conditional suppressed protocols of the corresponding `GenericContext`.
const SuppressibleProtocolSet &
getSuppressedProtocols() const {
assert(this->hasSuppressibleProtocols());
/// that are inverted here, but that information is recorded in the
/// conditional inverted protocols of the corresponding `GenericContext`.
const InvertibleProtocolSet &
getInvertedProtocols() const {
assert(this->hasInvertibleProtocols());
return
*this->template getTrailingObjects<SuppressibleProtocolSet>();
*this->template getTrailingObjects<InvertibleProtocolSet>();
}
size_t numTrailingObjects(OverloadToken<SuppressibleProtocolSet>) const {
return this->hasSuppressibleProtocols() ? 1 : 0;
size_t numTrailingObjects(OverloadToken<InvertibleProtocolSet>) const {
return this->hasInvertibleProtocols() ? 1 : 0;
}
static bool classof(const TargetContextDescriptor<Runtime> *cd) {
@@ -4833,24 +4833,24 @@ TargetContextDescriptor<Runtime>::getGenericContext() const {
}
template<typename Runtime>
inline const SuppressibleProtocolSet *
TargetContextDescriptor<Runtime>::getSuppressedProtocols() const {
if (!this->hasSuppressibleProtocols())
inline const InvertibleProtocolSet *
TargetContextDescriptor<Runtime>::getInvertedProtocols() const {
if (!this->hasInvertibleProtocols())
return nullptr;
switch (getKind()) {
case ContextDescriptorKind::Class:
return &llvm::cast<TargetClassDescriptor<Runtime>>(this)
->getSuppressedProtocols();
->getInvertedProtocols();
case ContextDescriptorKind::Enum:
return &llvm::cast<TargetEnumDescriptor<Runtime>>(this)
->getSuppressedProtocols();
->getInvertedProtocols();
case ContextDescriptorKind::Struct:
return &llvm::cast<TargetStructDescriptor<Runtime>>(this)
->getSuppressedProtocols();
->getInvertedProtocols();
case ContextDescriptorKind::OpaqueType:
return &llvm::cast<TargetOpaqueTypeDescriptor<Runtime>>(this)
->getSuppressedProtocols();
->getInvertedProtocols();
default:
// We don't know about this kind of descriptor.
return nullptr;

View File

@@ -25,7 +25,7 @@
#include "swift/ABI/KeyPath.h"
#include "swift/ABI/ProtocolDispatchStrategy.h"
#include "swift/ABI/SuppressibleProtocols.h"
#include "swift/ABI/InvertibleProtocols.h"
// FIXME: this include shouldn't be here, but removing it causes symbol
// mangling mismatches on Windows for some reason?
@@ -1200,9 +1200,9 @@ class TargetExtendedFunctionTypeFlags {
// Values if we have a transferring result.
HasTransferringResult = 0x00000010U,
/// A SuppressibleProtocolSet in the high bits.
SuppressedProtocolShift = 16,
SuppressedProtocolMask = 0xFFFFU << SuppressedProtocolShift,
/// A InvertibleProtocolSet in the high bits.
InvertedProtocolshift = 16,
InvertedProtocolMask = 0xFFFFU << InvertedProtocolshift,
};
int_type Data;
@@ -1235,10 +1235,10 @@ public:
}
const TargetExtendedFunctionTypeFlags<int_type>
withSuppressedProtocols(SuppressibleProtocolSet suppressed) const {
withInvertedProtocols(InvertibleProtocolSet inverted) const {
return TargetExtendedFunctionTypeFlags<int_type>(
(Data & ~SuppressedProtocolMask) |
(suppressed.rawBits() << SuppressedProtocolShift));
(Data & ~InvertedProtocolMask) |
(inverted.rawBits() << InvertedProtocolshift));
}
bool isTypedThrows() const { return bool(Data & TypedThrowsMask); }
@@ -1255,8 +1255,8 @@ public:
return Data;
}
SuppressibleProtocolSet getSuppressedProtocols() const {
return SuppressibleProtocolSet(Data >> SuppressedProtocolShift);
InvertibleProtocolSet getInvertedProtocols() const {
return InvertibleProtocolSet(Data >> InvertedProtocolshift);
}
static TargetExtendedFunctionTypeFlags<int_type> fromIntValue(int_type Data) {
@@ -1704,14 +1704,14 @@ public:
constexpr ContextDescriptorFlags(ContextDescriptorKind kind,
bool isGeneric,
bool isUnique,
bool hasSuppressibleProtocols,
bool hasInvertibleProtocols,
uint16_t kindSpecificFlags)
: ContextDescriptorFlags(ContextDescriptorFlags()
.withKind(kind)
.withGeneric(isGeneric)
.withUnique(isUnique)
.withSuppressibleProtocols(
hasSuppressibleProtocols
.withInvertibleProtocols(
hasInvertibleProtocols
)
.withKindSpecificFlags(kindSpecificFlags))
{}
@@ -1731,9 +1731,9 @@ public:
return (Value & 0x40u) != 0;
}
/// Whether the context has information about suppressible protocols, which
/// Whether the context has information about invertible protocols, which
/// will show up as a trailing field in the context descriptor.
constexpr bool hasSuppressibleProtocols() const {
constexpr bool hasInvertibleProtocols() const {
return (Value & 0x20u) != 0;
}
@@ -1758,11 +1758,11 @@ public:
| (isUnique ? 0x40u : 0));
}
constexpr ContextDescriptorFlags withSuppressibleProtocols(
bool hasSuppressibleProtocols
constexpr ContextDescriptorFlags withInvertibleProtocols(
bool hasInvertibleProtocols
) const {
return ContextDescriptorFlags((Value & ~0x20u)
| (hasSuppressibleProtocols ? 0x20u : 0));
| (hasInvertibleProtocols ? 0x20u : 0));
}
constexpr ContextDescriptorFlags
@@ -2003,12 +2003,12 @@ public:
: Value(value) {}
constexpr GenericContextDescriptorFlags(
bool hasTypePacks, bool hasConditionalSuppressedProtocols
bool hasTypePacks, bool hasConditionalInvertedProtocols
) : GenericContextDescriptorFlags(
GenericContextDescriptorFlags((uint16_t)0)
.withHasTypePacks(hasTypePacks)
.withConditionalSuppressedProtocols(
hasConditionalSuppressedProtocols)) {}
.withConditionalInvertedProtocols(
hasConditionalInvertedProtocols)) {}
/// Whether this generic context has at least one type parameter
/// pack, in which case the generic context will have a trailing
@@ -2018,9 +2018,9 @@ public:
}
/// Whether this generic context has any conditional conformances to
/// suppressed protocols, in which case the generic context will have a
/// trailing SuppressibleProtocolSet and conditional requirements.
constexpr bool hasConditionalSuppressedProtocols() const {
/// inverted protocols, in which case the generic context will have a
/// trailing InvertibleProtocolSet and conditional requirements.
constexpr bool hasConditionalInvertedProtocols() const {
return (Value & 0x2) != 0;
}
@@ -2031,7 +2031,7 @@ public:
}
constexpr GenericContextDescriptorFlags
withConditionalSuppressedProtocols(bool value) const {
withConditionalInvertedProtocols(bool value) const {
return GenericContextDescriptorFlags((uint16_t)(
(Value & ~0x2) | (value ? 0x2 : 0)));
}
@@ -2132,12 +2132,12 @@ enum class GenericRequirementKind : uint8_t {
SameConformance = 3,
/// A same-shape requirement between generic parameter packs.
SameShape = 4,
/// A requirement stating which suppressible protocol checks are
/// suppressed.
/// A requirement stating which invertible protocol checks are
/// inverted.
///
/// This is more of an "anti-requirement", specifing which checks don't need
/// to happen for a given type.
SuppressedProtocols = 5,
InvertedProtocols = 5,
/// A layout requirement.
Layout = 0x1F,
};

View File

@@ -4405,7 +4405,7 @@ public:
/// Returns null if the type is a class, or does not have a declared `deinit`.
DestructorDecl *getValueTypeDestructor();
/// Does a conformance for a given suppressible protocol exist for this
/// Does a conformance for a given invertible protocol exist for this
/// type declaration.
CanBeInvertible::Result canConformTo(InvertibleProtocolKind kind) const;

View File

@@ -136,9 +136,9 @@ PROTOCOL(AsyncIteratorProtocol)
PROTOCOL(FloatingPoint)
#define SUPPRESSIBLE_PROTOCOL(Name, Bit) \
#define INVERTIBLE_PROTOCOL(Name, Bit) \
INVERTIBLE_PROTOCOL_WITH_NAME(Name, #Name)
#include "swift/ABI/SuppressibleProtocols.def"
#include "swift/ABI/InvertibleProtocols.def"
PROTOCOL_(BitwiseCopyable)

View File

@@ -13,7 +13,7 @@
#ifndef SWIFT_AST_KNOWNPROTOCOLS_H
#define SWIFT_AST_KNOWNPROTOCOLS_H
#include "swift/ABI/SuppressibleProtocols.h"
#include "swift/ABI/InvertibleProtocols.h"
#include "swift/Config.h"
namespace llvm {
@@ -50,13 +50,13 @@ llvm::StringRef getProtocolName(KnownProtocolKind kind);
enum : uint8_t {
// Use preprocessor trick to count all the invertible protocols.
#define SUPPRESSIBLE_PROTOCOL(Name, Bit) +1
#define INVERTIBLE_PROTOCOL(Name, Bit) +1
/// The number of invertible protocols.
NumInvertibleProtocols =
#include "swift/ABI/SuppressibleProtocols.def"
#include "swift/ABI/InvertibleProtocols.def"
};
using InvertibleProtocolSet = SuppressibleProtocolSet;
using InvertibleProtocolSet = InvertibleProtocolSet;
/// Maps a KnownProtocol to the set of InvertibleProtocols, if a mapping exists.
/// \returns None if the known protocol is not invertible.

View File

@@ -22,7 +22,7 @@
#include "swift/Basic/LLVM.h"
#include "swift/ABI/MetadataValues.h"
#include "swift/ABI/SuppressibleProtocols.h"
#include "swift/ABI/InvertibleProtocols.h"
#include "swift/AST/LayoutConstraintKind.h"
#include "swift/AST/RequirementKind.h"
#include "swift/Basic/OptionSet.h"
@@ -462,7 +462,7 @@ void decodeRequirement(
return;
auto protocolKind =
static_cast<SuppressibleProtocolKind>(child->getChild(1)->getIndex());
static_cast<InvertibleProtocolKind>(child->getChild(1)->getIndex());
inverseRequirements.push_back(
Builder.createInverseRequirement(subjectType, protocolKind));
continue;

View File

@@ -1354,9 +1354,9 @@ public:
case GenericRequirementKind::SameShape:
return TypeLookupError(
"Unexpected same-shape requirement in runtime generic signature");
case GenericRequirementKind::SuppressedProtocols:
case GenericRequirementKind::InvertedProtocols:
return TypeLookupError(
"Unexpected suppressible protocol in runtime generic signature");
"Unexpected invertible protocol in runtime generic signature");
}
}
@@ -2886,7 +2886,7 @@ private:
case GenericRequirementKind::SameShape:
llvm_unreachable("Implement me");
case GenericRequirementKind::SuppressedProtocols:
case GenericRequirementKind::InvertedProtocols:
llvm_unreachable("Implement me");
}
}

View File

@@ -130,11 +130,11 @@ void swift::simple_display(llvm::raw_ostream &out,
out << getProtocolName(getKnownProtocolKind(value));
}
// Metadata stores a 16-bit field for suppressible protocols. Trigger a build
// Metadata stores a 16-bit field for invertible protocols. Trigger a build
// error when we assign the 15th bit so we can think about what to do.
#define SUPPRESSIBLE_PROTOCOL(Name, Bit) \
#define INVERTIBLE_PROTOCOL(Name, Bit) \
static_assert(Bit < 15);
#include "swift/ABI/SuppressibleProtocols.def"
#include "swift/ABI/InvertibleProtocols.def"
namespace {
enum class SearchPathKind : uint8_t {

View File

@@ -2868,9 +2868,9 @@ NodePointer NodePrinter::print(NodePointer Node, unsigned depth,
print(type, depth + 1);
Printer << ": ~";
switch (Node->getChild(1)->getIndex()) {
#define SUPPRESSIBLE_PROTOCOL(Name, Bit) \
#define INVERTIBLE_PROTOCOL(Name, Bit) \
case Bit: Printer << "Swift." << #Name; break;
#include "swift/ABI/SuppressibleProtocols.def"
#include "swift/ABI/InvertibleProtocols.def"
default:
Printer << "Swift.<bit " << Node->getChild(1)->getIndex() << ">";
break;

View File

@@ -425,7 +425,7 @@ namespace {
unsigned NumGenericKeyArguments = 0;
SmallVector<CanType, 2> ShapeClasses;
SmallVector<GenericPackArgument, 2> GenericPackArguments;
SuppressibleProtocolSet ConditionalSuppressedProtocols;
InvertibleProtocolSet ConditionalInvertedProtocols;
GenericSignatureHeaderBuilder(IRGenModule &IGM,
ConstantStructBuilder &builder)
@@ -466,10 +466,10 @@ namespace {
NumGenericKeyArguments + ShapeClasses.size());
bool hasTypePacks = !GenericPackArguments.empty();
bool hasConditionalSuppressedProtocols =
!ConditionalSuppressedProtocols.empty();
bool hasConditionalInvertedProtocols =
!ConditionalInvertedProtocols.empty();
GenericContextDescriptorFlags flags(
hasTypePacks, hasConditionalSuppressedProtocols);
hasTypePacks, hasConditionalInvertedProtocols);
b.fillPlaceholderWithInt(FlagsPP, IGM.Int16Ty,
flags.getIntValue());
}
@@ -502,7 +502,7 @@ namespace {
ContextDescriptorFlags(asImpl().getContextKind(),
!asImpl().getGenericSignature().isNull(),
asImpl().isUniqueDescriptor(),
!asImpl().getSuppressedProtocols().empty(),
!asImpl().getInvertedProtocols().empty(),
asImpl().getKindSpecificFlags())
.getIntValue());
}
@@ -524,7 +524,7 @@ namespace {
asImpl().addGenericParameters();
asImpl().addGenericRequirements();
asImpl().addGenericPackShapeDescriptors();
asImpl().addConditionalSuppressedProtocols();
asImpl().addConditionalInvertedProtocols();
asImpl().finishGenericParameters();
}
@@ -557,20 +557,20 @@ namespace {
/// Adds the set of suppressed protocols, which must be explicitly called
/// by the concrete subclasses.
void addSuppressedProtocols() {
auto protocols = asImpl().getSuppressedProtocols();
void addInvertedProtocols() {
auto protocols = asImpl().getInvertedProtocols();
if (protocols.empty())
return;
B.addInt(IGM.Int16Ty, protocols.rawBits());
}
SuppressibleProtocolSet getConditionalSuppressedProtocols() {
return SuppressibleProtocolSet();
InvertibleProtocolSet getConditionalInvertedProtocols() {
return InvertibleProtocolSet();
}
void addConditionalSuppressedProtocols() {
assert(asImpl().getConditionalSuppressedProtocols().empty() &&
void addConditionalInvertedProtocols() {
assert(asImpl().getConditionalInvertedProtocols().empty() &&
"Subclass must implement this operation");
}
@@ -601,8 +601,8 @@ namespace {
}
/// Retrieve the set of protocols that are suppressed in this context.
SuppressibleProtocolSet getSuppressedProtocols() {
return SuppressibleProtocolSet();
InvertibleProtocolSet getInvertedProtocols() {
return InvertibleProtocolSet();
}
uint16_t getKindSpecificFlags() {
@@ -1261,13 +1261,13 @@ namespace {
}
/// Retrieve the set of protocols that are suppressed by this type.
SuppressibleProtocolSet getSuppressedProtocols() {
SuppressibleProtocolSet result;
InvertibleProtocolSet getInvertedProtocols() {
InvertibleProtocolSet result;
auto nominal = dyn_cast<NominalTypeDecl>(Type);
if (!nominal)
return result;
auto checkProtocol = [&](SuppressibleProtocolKind kind) {
auto checkProtocol = [&](InvertibleProtocolKind kind) {
switch (nominal->canConformTo(kind)) {
case TypeDecl::CanBeInvertible::Never:
case TypeDecl::CanBeInvertible::Conditionally:
@@ -1279,21 +1279,21 @@ namespace {
}
};
for (auto kind : SuppressibleProtocolSet::allKnown())
for (auto kind : InvertibleProtocolSet::allKnown())
checkProtocol(kind);
return result;
}
/// Retrieve the set of suppressible protocols to which this type
/// Retrieve the set of invertible protocols to which this type
/// conditionally conforms.
SuppressibleProtocolSet getConditionalSuppressedProtocols() {
SuppressibleProtocolSet result;
InvertibleProtocolSet getConditionalInvertedProtocols() {
InvertibleProtocolSet result;
auto nominal = dyn_cast<NominalTypeDecl>(Type);
if (!nominal)
return result;
auto checkProtocol = [&](SuppressibleProtocolKind kind) {
auto checkProtocol = [&](InvertibleProtocolKind kind) {
switch (nominal->canConformTo(kind)) {
case TypeDecl::CanBeInvertible::Never:
case TypeDecl::CanBeInvertible::Always:
@@ -1305,19 +1305,19 @@ namespace {
}
};
for (auto kind : SuppressibleProtocolSet::allKnown())
for (auto kind : InvertibleProtocolSet::allKnown())
checkProtocol(kind);
return result;
}
void addConditionalSuppressedProtocols() {
auto protocols = asImpl().getConditionalSuppressedProtocols();
void addConditionalInvertedProtocols() {
auto protocols = asImpl().getConditionalInvertedProtocols();
if (protocols.empty())
return;
// Note the conditional suppressed protocols.
this->SignatureHeader->ConditionalSuppressedProtocols = protocols;
this->SignatureHeader->ConditionalInvertedProtocols = protocols;
// The suppressed protocols with conditional conformances.
B.addInt(IGM.Int16Ty, protocols.rawBits());
@@ -1335,7 +1335,7 @@ namespace {
}
// Emit the generic requirements for the conditional conformance
// to each suppressible protocol.
// to each invertible protocol.
auto nominal = cast<NominalTypeDecl>(Type);
auto genericSig = nominal->getGenericSignatureOfContext();
ASTContext &ctx = nominal->getASTContext();
@@ -1473,7 +1473,7 @@ namespace {
return Type->getGenericSignature();
}
bool hasSuppressibleProtocols() {
bool hasInvertibleProtocols() {
auto genericSig = asImpl().getGenericSignature();
if (!genericSig)
return false;
@@ -1704,7 +1704,7 @@ namespace {
void layout() {
super::layout();
maybeAddCanonicalMetadataPrespecializations();
addSuppressedProtocols();
addInvertedProtocols();
}
ContextDescriptorKind getContextKind() {
@@ -1778,7 +1778,7 @@ namespace {
void layout() {
super::layout();
maybeAddCanonicalMetadataPrespecializations();
addSuppressedProtocols();
addInvertedProtocols();
}
ContextDescriptorKind getContextKind() {
@@ -1911,7 +1911,7 @@ namespace {
addOverrideTable();
addObjCResilientClassStubInfo();
maybeAddCanonicalMetadataPrespecializations();
addSuppressedProtocols();
addInvertedProtocols();
}
void addIncompleteMetadataOrRelocationFunction() {
@@ -7027,7 +7027,7 @@ GenericArgumentMetadata irgen::addGenericRequirements(
return metadata;
// Collect the inverse requirements on each of the generic parameters.
SmallVector<SuppressibleProtocolSet, 2>
SmallVector<InvertibleProtocolSet, 2>
suppressed(sig.getGenericParams().size(), { });
for (const auto &inverse : inverses) {
// Determine which generic parameter this constraint applies to.
@@ -7037,9 +7037,9 @@ GenericArgumentMetadata irgen::addGenericRequirements(
continue;
// Insert this suppression into the set for that generic parameter.
auto suppressibleKind = inverse.getKind();
auto invertibleKind = inverse.getKind();
unsigned index = sig->getGenericParamOrdinal(genericParam);
suppressed[index].insert(suppressibleKind);
suppressed[index].insert(invertibleKind);
}
// Go through the generic parameters, emitting a requirement for each
@@ -7051,7 +7051,7 @@ GenericArgumentMetadata irgen::addGenericRequirements(
// Encode the suppressed protocols constraint.
auto genericParam = sig.getGenericParams()[index];
auto flags = GenericRequirementFlags(
GenericRequirementKind::SuppressedProtocols,
GenericRequirementKind::InvertedProtocols,
/*key argument*/ false,
genericParam->isParameterPack());
addGenericRequirement(IGM, B, metadata, sig, flags,

View File

@@ -1417,21 +1417,21 @@ getFunctionTypeFlags(CanFunctionType type) {
}
// Compute the set of suppressed protocols.
SuppressibleProtocolSet suppressedProtocols;
for (auto suppressibleKind : SuppressibleProtocolSet::allKnown()) {
switch (suppressibleKind) {
case SuppressibleProtocolKind::Copyable: {
InvertibleProtocolSet InvertedProtocols;
for (auto invertibleKind : InvertibleProtocolSet::allKnown()) {
switch (invertibleKind) {
case InvertibleProtocolKind::Copyable: {
// If the function type is noncopyable, note that in the suppressed
// protocols.
auto proto =
type->getASTContext().getProtocol(KnownProtocolKind::Copyable);
if (proto &&
proto->getParentModule()->lookupConformance(type, proto).isInvalid())
suppressedProtocols.insert(suppressibleKind);
InvertedProtocols.insert(invertibleKind);
break;
}
case SuppressibleProtocolKind::Escapable:
case InvertibleProtocolKind::Escapable:
// We intentionally do not record the "escapable" bit here, because it's
// already in the normal function type flags. The runtime will
// introduce it as necessary.
@@ -1444,7 +1444,7 @@ getFunctionTypeFlags(CanFunctionType type) {
auto extFlags = ExtendedFunctionTypeFlags()
.withTypedThrows(!type->getThrownError().isNull())
.withTransferringResult(type->hasTransferringResult())
.withSuppressedProtocols(suppressedProtocols);
.withInvertedProtocols(InvertedProtocols);
if (isolation.isErased())
extFlags = extFlags.withIsolatedAny();

View File

@@ -1355,7 +1355,7 @@ checkGenericRequirement(
llvm::SmallVectorImpl<const void *> &extraArguments,
SubstGenericParameterFn substGenericParam,
SubstDependentWitnessTableFn substWitnessTable,
llvm::SmallVectorImpl<SuppressibleProtocolSet> &suppressed) {
llvm::SmallVectorImpl<InvertibleProtocolSet> &suppressed) {
assert(!req.getFlags().isPackRequirement());
// Make sure we understand the requirement we're dealing with.
@@ -1443,18 +1443,18 @@ checkGenericRequirement(
return TYPE_LOOKUP_ERROR_FMT("can't have same-shape requirement where "
"subject type is not a pack");
}
case GenericRequirementKind::SuppressedProtocols: {
uint16_t index = req.getSuppressedProtocolsGenericParamIndex();
case GenericRequirementKind::InvertedProtocols: {
uint16_t index = req.getInvertedProtocolsGenericParamIndex();
if (index == 0xFFFF)
return TYPE_LOOKUP_ERROR_FMT("unable to suppress protocols");
// Expand the suppression set so we can record these protocols.
if (index >= suppressed.size()) {
suppressed.resize(index + 1, SuppressibleProtocolSet());
suppressed.resize(index + 1, InvertibleProtocolSet());
}
// Record these suppressed protocols for this generic parameter.
suppressed[index] |= req.getSuppressedProtocols();
suppressed[index] |= req.getInvertedProtocols();
return std::nullopt;
}
}
@@ -1470,7 +1470,7 @@ checkGenericPackRequirement(
llvm::SmallVectorImpl<const void *> &extraArguments,
SubstGenericParameterFn substGenericParam,
SubstDependentWitnessTableFn substWitnessTable,
llvm::SmallVectorImpl<SuppressibleProtocolSet> &suppressed) {
llvm::SmallVectorImpl<InvertibleProtocolSet> &suppressed) {
assert(req.getFlags().isPackRequirement());
// Make sure we understand the requirement we're dealing with.
@@ -1611,18 +1611,18 @@ checkGenericPackRequirement(
return std::nullopt;
}
case GenericRequirementKind::SuppressedProtocols: {
uint16_t index = req.getSuppressedProtocolsGenericParamIndex();
case GenericRequirementKind::InvertedProtocols: {
uint16_t index = req.getInvertedProtocolsGenericParamIndex();
if (index == 0xFFFF)
return TYPE_LOOKUP_ERROR_FMT("unable to suppress protocols");
// Expand the suppression set so we can record these protocols.
if (index >= suppressed.size()) {
suppressed.resize(index + 1, SuppressibleProtocolSet());
suppressed.resize(index + 1, InvertibleProtocolSet());
}
// Record these suppressed protocols for this generic parameter.
suppressed[index] |= req.getSuppressedProtocols();
suppressed[index] |= req.getInvertedProtocols();
return std::nullopt;
}
}
@@ -1633,12 +1633,12 @@ checkGenericPackRequirement(
}
static std::optional<TypeLookupError>
checkSuppressibleRequirements(const Metadata *type,
SuppressibleProtocolSet ignored);
checkInvertibleRequirements(const Metadata *type,
InvertibleProtocolSet ignored);
static std::optional<TypeLookupError>
checkSuppressibleRequirementsStructural(const Metadata *type,
SuppressibleProtocolSet ignored) {
checkInvertibleRequirementsStructural(const Metadata *type,
InvertibleProtocolSet ignored) {
switch (type->getKind()) {
case MetadataKind::Class:
case MetadataKind::Struct:
@@ -1657,7 +1657,7 @@ checkSuppressibleRequirementsStructural(const Metadata *type,
case MetadataKind::Task:
case MetadataKind::Job:
// Not part of the user-visible type system; assumed to handle all
// suppressible requirements.
// invertible requirements.
return std::nullopt;
case MetadataKind::Tuple: {
@@ -1665,7 +1665,7 @@ checkSuppressibleRequirementsStructural(const Metadata *type,
auto tupleMetadata = cast<TupleTypeMetadata>(type);
for (unsigned i = 0, n = tupleMetadata->NumElements; i != n; ++i) {
if (auto error =
checkSuppressibleRequirements(&*tupleMetadata->getElement(i).Type,
checkInvertibleRequirements(&*tupleMetadata->getElement(i).Type,
ignored))
return error;
}
@@ -1677,10 +1677,10 @@ checkSuppressibleRequirementsStructural(const Metadata *type,
// Determine the set of protocols that are suppressed by the function
// type.
SuppressibleProtocolSet suppressed;
InvertibleProtocolSet suppressed;
if (functionMetadata->hasExtendedFlags()) {
suppressed = functionMetadata->getExtendedFlags()
.getSuppressedProtocols();
.getInvertedProtocols();
}
// Map the existing "noescape" bit as a suppressed protocol, when
@@ -1689,7 +1689,7 @@ checkSuppressibleRequirementsStructural(const Metadata *type,
case FunctionMetadataConvention::Swift:
// Swift function types can be non-escaping, so honor the bit.
if (!functionMetadata->isEscaping())
suppressed.insert(SuppressibleProtocolKind::Escapable);
suppressed.insert(InvertibleProtocolKind::Escapable);
break;
case FunctionMetadataConvention::Block:
@@ -1707,7 +1707,7 @@ checkSuppressibleRequirementsStructural(const Metadata *type,
auto missing = suppressed - ignored;
if (!missing.empty()) {
return TYPE_LOOKUP_ERROR_FMT(
"function type missing suppressible protocols %x", missing.rawBits());
"function type missing invertible protocols %x", missing.rawBits());
}
return std::nullopt;
@@ -1722,14 +1722,14 @@ checkSuppressibleRequirementsStructural(const Metadata *type,
// has suppressed a protocol that is not ignored, then the existential
// does not meet the specified requirements.
for (const auto& req : reqs) {
if (req.getKind() != GenericRequirementKind::SuppressedProtocols)
if (req.getKind() != GenericRequirementKind::InvertedProtocols)
continue;
auto suppressed = req.getSuppressedProtocols();
auto suppressed = req.getInvertedProtocols();
auto missing = suppressed - ignored;
if (!missing.empty()) {
return TYPE_LOOKUP_ERROR_FMT(
"existential type missing suppressible protocols %x",
"existential type missing invertible protocols %x",
missing.rawBits());
}
}
@@ -1739,7 +1739,7 @@ checkSuppressibleRequirementsStructural(const Metadata *type,
case MetadataKind::Metatype:
case MetadataKind::ExistentialMetatype:
// Metatypes themselves can't have suppressible protocols.
// Metatypes themselves can't have invertible protocols.
return std::nullopt;
case MetadataKind::Existential:
@@ -1755,45 +1755,45 @@ checkSuppressibleRequirementsStructural(const Metadata *type,
return std::nullopt;
}
/// Check that the given `type` meets all suppressible protocol requirements
/// Check that the given `type` meets all invertible protocol requirements
/// that haven't been explicitly suppressed by `ignored`.
std::optional<TypeLookupError>
checkSuppressibleRequirements(const Metadata *type,
SuppressibleProtocolSet ignored) {
checkInvertibleRequirements(const Metadata *type,
InvertibleProtocolSet ignored) {
auto contextDescriptor = type->getTypeContextDescriptor();
if (!contextDescriptor)
return checkSuppressibleRequirementsStructural(type, ignored);
return checkInvertibleRequirementsStructural(type, ignored);
// If no conformances are suppressed, then it conforms to everything.
if (!contextDescriptor->hasSuppressibleProtocols()) {
if (!contextDescriptor->hasInvertibleProtocols()) {
return std::nullopt;
}
// If this type has suppressed conformances, but we can't find them...
// bail out.
auto suppressedProtocols = contextDescriptor->getSuppressedProtocols();
if (!suppressedProtocols) {
auto InvertedProtocols = contextDescriptor->getInvertedProtocols();
if (!InvertedProtocols) {
return TYPE_LOOKUP_ERROR_FMT("unable to find suppressed protocols");
}
// Determine the set of suppressible conformances that the type has
// Determine the set of invertible conformances that the type has
// suppressed but aren't being ignored. These are missing conformances
// based on the primary definition of the type.
SuppressibleProtocolSet missingConformances = *suppressedProtocols - ignored;
InvertibleProtocolSet missingConformances = *InvertedProtocols - ignored;
if (missingConformances.empty())
return std::nullopt;
// If the context descriptor is not generic, there are no conditional
// conformances: fail.
if (!contextDescriptor->isGeneric()) {
return TYPE_LOOKUP_ERROR_FMT("type missing suppressible conformances %x",
return TYPE_LOOKUP_ERROR_FMT("type missing invertible conformances %x",
missingConformances.rawBits());
}
auto genericContext = contextDescriptor->getGenericContext();
if (!genericContext ||
!genericContext->hasConditionalSuppressedProtocols()) {
return TYPE_LOOKUP_ERROR_FMT("type missing suppressible conformances %x",
!genericContext->hasConditionalInvertedProtocols()) {
return TYPE_LOOKUP_ERROR_FMT("type missing invertible conformances %x",
missingConformances.rawBits());
}
@@ -1801,23 +1801,23 @@ checkSuppressibleRequirements(const Metadata *type,
// conditional conformances, then the nominal type does not satisfy these
// suppressed conformances. We're done.
auto conditionalSuppressed =
genericContext->getConditionalSuppressedProtocols();
genericContext->getConditionalInvertedProtocols();
auto alwaysMissingConformances = missingConformances - conditionalSuppressed;
if (!alwaysMissingConformances.empty()) {
return TYPE_LOOKUP_ERROR_FMT("type missing suppressible conformances %x",
return TYPE_LOOKUP_ERROR_FMT("type missing invertible conformances %x",
alwaysMissingConformances.rawBits());
}
// Now we need to check the conditional conformances for each of the
// missing conformances.
for (auto suppressibleKind : missingConformances) {
for (auto invertibleKind : missingConformances) {
// Get the conditional requirements.
// Note: This will end up being quadratic in the number of suppressible
// Note: This will end up being quadratic in the number of invertible
// protocols. That number is small (currently 2) and cannot be more than 16,
// but if it's a problem we can switch to a different strategy.
auto condReqs =
genericContext->getConditionalSuppressibleProtocolRequirementsFor(
suppressibleKind);
genericContext->getConditionalInvertibleProtocolRequirementsFor(
invertibleKind);
// Check the conditional requirements.
llvm::ArrayRef<GenericRequirementDescriptor> requirements(
@@ -1852,7 +1852,7 @@ std::optional<TypeLookupError> swift::_checkGenericRequirements(
SubstGenericParameterOrdinalFn substGenericParamOrdinal,
SubstDependentWitnessTableFn substWitnessTable) {
// The suppressed conformances for each generic parameter.
llvm::SmallVector<SuppressibleProtocolSet, 4> allSuppressed;
llvm::SmallVector<InvertibleProtocolSet, 4> allSuppressed;
for (const auto &req : requirements) {
if (req.getFlags().isPackRequirement()) {
@@ -1872,7 +1872,7 @@ std::optional<TypeLookupError> swift::_checkGenericRequirements(
}
}
// Now, check all of the generic arguments for suppressible protocols.
// Now, check all of the generic arguments for invertible protocols.
unsigned numGenericParams = genericParams.size();
for (unsigned index = 0; index != numGenericParams; ++index) {
// Non-key arguments don't need to be checked, because they are
@@ -1880,7 +1880,7 @@ std::optional<TypeLookupError> swift::_checkGenericRequirements(
if (!genericParams[index].hasKeyArgument())
continue;
SuppressibleProtocolSet suppressed;
InvertibleProtocolSet suppressed;
if (index < allSuppressed.size())
suppressed = allSuppressed[index];
@@ -1893,7 +1893,7 @@ std::optional<TypeLookupError> swift::_checkGenericRequirements(
}
auto metadata = metadataOrPack.getMetadata();
if (auto error = checkSuppressibleRequirements(metadata, suppressed))
if (auto error = checkInvertibleRequirements(metadata, suppressed))
return error;
break;
@@ -1914,7 +1914,7 @@ std::optional<TypeLookupError> swift::_checkGenericRequirements(
llvm::ArrayRef<const Metadata *> elements(
pack.getElements(), pack.getNumElements());
for (auto element : elements) {
if (auto error = checkSuppressibleRequirements(element, suppressed))
if (auto error = checkInvertibleRequirements(element, suppressed))
return error;
}
}

View File

@@ -34,7 +34,7 @@ inline void addModuleContextDescriptor(AnyObjectBuilder &builder,
auto contextFlags = ContextDescriptorFlags(ContextDescriptorKind::Module,
/*generic*/ false,
/*unique*/ true,
/*hasSuppressibleProtocols*/ false,
/*hasInvertibleProtocols*/ false,
/*kindSpecific*/ 0);
builder.add32(contextFlags.getIntValue());
@@ -55,7 +55,7 @@ inline void addProtocolDescriptor(AnyObjectBuilder &builder,
auto contextFlags = ContextDescriptorFlags(ContextDescriptorKind::Protocol,
/*generic*/ false,
/*unique*/ true,
/*hasSuppressibleProtocols*/ false,
/*hasInvertibleProtocols*/ false,
/*kindSpecific*/ 0);
builder.add32(contextFlags.getIntValue());