Skip to content

Commit da50193

Browse files
committed
Update ABI test
2 parents b788e55 + e7dd1c1 commit da50193

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1042
-610
lines changed

docs/ABI/Mangling.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ Globals
113113
global ::= context 'MXE' // extension descriptor
114114
global ::= context 'MXX' // anonymous context descriptor
115115
global ::= context identifier 'MXY' // anonymous context descriptor
116-
global ::= type assoc-type-list 'MXA' // generic parameter ref
116+
global ::= type assoc-type-list 'MXA' // generic parameter ref (HISTORICAL)
117117
global ::= protocol 'Mp' // protocol descriptor
118118

119119
global ::= nominal-type 'Mo' // class metadata immediate member base offset

include/swift/ABI/Metadata.h

Lines changed: 7 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -2502,137 +2502,13 @@ struct TargetGenericContextDescriptorHeader {
25022502
using GenericContextDescriptorHeader =
25032503
TargetGenericContextDescriptorHeader<InProcess>;
25042504

2505-
/// A reference to a generic parameter that is the subject of a requirement.
2506-
/// This can refer either directly to a generic parameter or to a path to an
2507-
/// associated type.
2508-
template<typename Runtime>
2509-
class TargetGenericParamRef {
2510-
union {
2511-
/// The word of storage, whose low bit indicates whether there is an
2512-
/// associated type path stored out-of-line and whose upper bits describe
2513-
/// the generic parameter at root of the path.
2514-
uint32_t Word;
2515-
2516-
/// This is the associated type path stored out-of-line. The \c bool
2517-
/// is used for masking purposes and is otherwise unused; instead, check
2518-
/// the low bit of \c Word.
2519-
RelativeDirectPointerIntPair<const void, bool> AssociatedTypePath;
2520-
};
2521-
2522-
public:
2523-
/// Index of the parameter being referenced. 0 is the first generic parameter
2524-
/// of the root of the context hierarchy, and subsequent parameters are
2525-
/// numbered breadth-first from there.
2526-
unsigned getRootParamIndex() const {
2527-
// If there is no path, retrieve the index directly.
2528-
if ((Word & 0x01) == 0) return Word >> 1;
2529-
2530-
// Otherwise, the index is at the start of the associated type path.
2531-
return *reinterpret_cast<const unsigned *>(AssociatedTypePath.getPointer());
2532-
}
2533-
2534-
/// A reference to an associated type along the reference path.
2535-
struct AssociatedTypeRef {
2536-
/// The protocol the associated type belongs to.
2537-
RelativeIndirectablePointer<TargetProtocolDescriptor<Runtime>,
2538-
/*nullable*/ false> Protocol;
2539-
/// A reference to the associated type descriptor within the protocol.
2540-
RelativeIndirectablePointer<TargetProtocolRequirement<Runtime>,
2541-
/*nullable*/ false> Requirement;
2542-
};
2543-
2544-
/// A forward iterator that walks through the associated type path, which is
2545-
/// a zero-terminated array of AssociatedTypeRefs.
2546-
class AssociatedTypeIterator {
2547-
const void *addr;
2548-
2549-
explicit AssociatedTypeIterator(const void *startAddr) : addr(startAddr) {}
2550-
2551-
bool isEnd() const {
2552-
if (addr == nullptr)
2553-
return true;
2554-
unsigned word;
2555-
memcpy(&word, addr, sizeof(unsigned));
2556-
if (word == 0)
2557-
return true;
2558-
return false;
2559-
}
2560-
2561-
template <class> friend class TargetGenericParamRef;
2562-
2563-
public:
2564-
AssociatedTypeIterator() : addr(nullptr) {}
2565-
2566-
using iterator_category = std::forward_iterator_tag;
2567-
using value_type = AssociatedTypeRef;
2568-
using difference_type = std::ptrdiff_t;
2569-
using pointer = const AssociatedTypeRef *;
2570-
using reference = const AssociatedTypeRef &;
2571-
2572-
bool operator==(AssociatedTypeIterator i) const {
2573-
// Iterators are same if they both point at the same place, or are both
2574-
// at the end (either by being initialized as an end iterator with a
2575-
// null address, or by being advanced to the null terminator of an
2576-
// associated type list).
2577-
if (addr == i.addr)
2578-
return true;
2579-
2580-
if (isEnd() && i.isEnd())
2581-
return true;
2582-
2583-
return false;
2584-
}
2585-
2586-
bool operator!=(AssociatedTypeIterator i) const {
2587-
return !(*this == i);
2588-
}
2589-
2590-
reference operator*() const {
2591-
return *reinterpret_cast<pointer>(addr);
2592-
}
2593-
pointer operator->() const {
2594-
return reinterpret_cast<pointer>(addr);
2595-
}
2596-
2597-
AssociatedTypeIterator &operator++() {
2598-
addr = reinterpret_cast<const char*>(addr) + sizeof(AssociatedTypeRef);
2599-
return *this;
2600-
}
2601-
2602-
AssociatedTypeIterator operator++(int) {
2603-
auto copy = *this;
2604-
++*this;
2605-
return copy;
2606-
}
2607-
};
2608-
2609-
/// Iterators for going through the associated type path from the root param.
2610-
AssociatedTypeIterator begin() const {
2611-
if (Word & 0x01) {
2612-
// The associated types start after the first word, which holds the
2613-
// root param index.
2614-
return AssociatedTypeIterator(
2615-
reinterpret_cast<const char*>(AssociatedTypePath.getPointer()) +
2616-
sizeof(unsigned));
2617-
} else {
2618-
// This is a direct param reference, so there are no associated types.
2619-
return end();
2620-
}
2621-
}
2622-
2623-
AssociatedTypeIterator end() const {
2624-
return AssociatedTypeIterator{};
2625-
}
2626-
};
2627-
2628-
using GenericParamRef = TargetGenericParamRef<InProcess>;
2629-
26302505
template<typename Runtime>
26312506
class TargetGenericRequirementDescriptor {
26322507
public:
26332508
GenericRequirementFlags Flags;
2634-
/// The generic parameter or associated type that's constrained.
2635-
TargetGenericParamRef<Runtime> Param;
2509+
2510+
/// The type that's constrained, described as a mangled name.
2511+
RelativeDirectPointer<const char, /*nullable*/ false> Param;
26362512

26372513
private:
26382514
union {
@@ -2668,9 +2544,10 @@ class TargetGenericRequirementDescriptor {
26682544
return getFlags().getKind();
26692545
}
26702546

2671-
/// Retrieve the generic parameter that is the subject of this requirement.
2672-
const TargetGenericParamRef<Runtime> &getParam() const {
2673-
return Param;
2547+
/// Retrieve the generic parameter that is the subject of this requirement,
2548+
/// as a mangled type name.
2549+
StringRef getParam() const {
2550+
return swift::Demangle::makeSymbolicMangledNameStringRef(Param.get());
26742551
}
26752552

26762553
/// Retrieve the protocol for a Protocol requirement.

include/swift/AST/DiagnosticsSema.def

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,6 +1691,14 @@ ERROR(type_witness_not_accessible_type,none,
16911691
"%0 %1 must be as accessible as its enclosing type because it "
16921692
"matches a requirement in protocol %3",
16931693
(DescriptiveDeclKind, DeclName, AccessLevel, DeclName))
1694+
ERROR(witness_not_usable_from_inline,none,
1695+
"%0 %1 must be declared '@usableFromInline' because "
1696+
"because it matches a requirement in protocol %2",
1697+
(DescriptiveDeclKind, DeclName, DeclName))
1698+
WARNING(witness_not_usable_from_inline_warn,none,
1699+
"%0 %1 should be declared '@usableFromInline' because "
1700+
"because it matches a requirement in protocol %2",
1701+
(DescriptiveDeclKind, DeclName, DeclName))
16941702
ERROR(type_witness_objc_generic_parameter,none,
16951703
"type %0 involving Objective-C type parameter%select{| %1}2 cannot be "
16961704
"used for associated type %3 of protocol %4",

include/swift/AST/ProtocolConformance.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,10 @@ class NormalProtocolConformance : public ProtocolConformance,
549549
/// modules, but in a manner that ensures that all copies are equivalent.
550550
bool isSynthesizedNonUnique() const;
551551

552+
/// Whether clients from outside the module can rely on the value witnesses
553+
/// being consistent across versions of the framework.
554+
bool isResilient() const;
555+
552556
/// Retrieve the type witness and type decl (if one exists)
553557
/// for the given associated type.
554558
std::pair<Type, TypeDecl *>

include/swift/SIL/SILWitnessTable.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ class SILWitnessTable : public llvm::ilist_node<SILWitnessTable>,
285285
IsSerialized_t isSerialized);
286286

287287
// Whether a conformance should be serialized.
288-
static bool conformanceIsSerialized(ProtocolConformance *conformance);
288+
static bool
289+
conformanceIsSerialized(const NormalProtocolConformance *conformance);
289290

290291
/// Call \c fn on each (split apart) conditional requirement of \c conformance
291292
/// that should appear in a witness table, i.e., conformance requirements that

lib/AST/ASTPrinter.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4445,12 +4445,18 @@ swift::getInheritedForPrinting(const Decl *decl,
44454445
inherited = ed->getInherited();
44464446
}
44474447

4448-
// Collect explicit inheritted types.
4448+
// Collect explicit inherited types.
44494449
for (auto TL: inherited) {
4450-
if (auto Ty = TL.getType()) {
4451-
if (auto NTD = Ty->getAnyNominal())
4452-
if (!shouldPrint(NTD))
4453-
continue;
4450+
if (auto ty = TL.getType()) {
4451+
bool foundUnprintable = ty.findIf([shouldPrint](Type subTy) {
4452+
if (auto aliasTy = dyn_cast<NameAliasType>(subTy.getPointer()))
4453+
return !shouldPrint(aliasTy->getDecl());
4454+
if (auto NTD = subTy->getAnyNominal())
4455+
return !shouldPrint(NTD);
4456+
return false;
4457+
});
4458+
if (foundUnprintable)
4459+
continue;
44544460
}
44554461
Results.push_back(TL);
44564462
}

lib/AST/ASTVerifier.cpp

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2738,37 +2738,6 @@ class Verifier : public ASTWalker {
27382738
verifyCheckedBase(nominal);
27392739
}
27402740

2741-
void verifyCheckedAlways(GenericTypeParamDecl *GTPD) {
2742-
PrettyStackTraceDecl debugStack("verifying GenericTypeParamDecl", GTPD);
2743-
2744-
const DeclContext *DC = GTPD->getDeclContext();
2745-
if (!GTPD->getDeclContext()->isInnermostContextGeneric()) {
2746-
Out << "DeclContext of GenericTypeParamDecl does not have "
2747-
"generic params";
2748-
abort();
2749-
}
2750-
2751-
GenericParamList *paramList =
2752-
static_cast<const GenericContext *>(DC)->getGenericParams();
2753-
if (!paramList) {
2754-
Out << "DeclContext of GenericTypeParamDecl does not have "
2755-
"generic params";
2756-
abort();
2757-
}
2758-
2759-
if (paramList->size() <= GTPD->getIndex() ||
2760-
paramList->getParams()[GTPD->getIndex()] != GTPD) {
2761-
Out << "GenericTypeParamDecl has incorrect index";
2762-
abort();
2763-
}
2764-
if (paramList->getDepth() != GTPD->getDepth()) {
2765-
Out << "GenericTypeParamDecl has incorrect depth";
2766-
abort();
2767-
}
2768-
2769-
verifyCheckedBase(GTPD);
2770-
}
2771-
27722741
void verifyChecked(ExtensionDecl *ext) {
27732742
// Make sure that the protocol conformances are complete.
27742743
for (auto conformance : ext->getLocalConformances()) {

lib/AST/ProtocolConformance.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,23 @@ bool NormalProtocolConformance::isSynthesizedNonUnique() const {
387387
return isa<ClangModuleUnit>(getDeclContext()->getModuleScopeContext());
388388
}
389389

390+
bool NormalProtocolConformance::isResilient() const {
391+
// If the type is non-resilient or the module we're in is non-resilient, the
392+
// conformance is non-resilient.
393+
// FIXME: Looking at the type is not the right long-term solution. We need an
394+
// explicit mechanism for declaring conformances as 'fragile', or even
395+
// individual witnesses.
396+
if (!getType()->getAnyNominal()->isResilient())
397+
return false;
398+
399+
switch (getDeclContext()->getParentModule()->getResilienceStrategy()) {
400+
case ResilienceStrategy::Resilient:
401+
return true;
402+
case ResilienceStrategy::Default:
403+
return false;
404+
}
405+
}
406+
390407
Optional<ArrayRef<Requirement>>
391408
ProtocolConformance::getConditionalRequirementsIfAvailable() const {
392409
CONFORMANCE_SUBCLASS_DISPATCH(getConditionalRequirementsIfAvailable, ());

0 commit comments

Comments
 (0)