Skip to content

Commit fca3cbf

Browse files
Merge pull request #4672 from swiftwasm/release/5.7
[pull] swiftwasm-release/5.7 from release/5.7
2 parents d26aa55 + 970457b commit fca3cbf

Some content is hidden

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

56 files changed

+1293
-520
lines changed

docs/ABI/Mangling.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ The following symbolic reference kinds are currently implemented:
102102
metadata-access-function ::= '\x09' .{4} // Reference points directly to metadata access function that can be invoked to produce referenced object
103103
#endif
104104

105+
#if SWIFT_RUNTIME_VERISON >= 5.7
106+
symbolic-extended-existential-type-shape ::= '\x0A' .{4} // Reference points directly to an ExtendedExistentialTypeShape
107+
symbolic-extended-existential-type-shape ::= '\x0B' .{4} // Reference points directly to a NonUniqueExtendedExistentialTypeShape
108+
#endif
109+
105110
A mangled name may also include ``\xFF`` bytes, which are only used for
106111
alignment padding. They do not affect what the mangled name references and can
107112
be skipped over and ignored.
@@ -637,7 +642,7 @@ Types
637642
type ::= protocol-list 'p' // existential type
638643
type ::= protocol-list superclass 'Xc' // existential type with superclass
639644
type ::= protocol-list 'Xl' // existential type with AnyObject
640-
type ::= protocol-list 'y' (type* '_')* type* retroactive-conformance* 'XP' // parameterized protocol type
645+
type ::= protocol-list requirement* '_' 'XP' // constrained existential type
641646
type ::= type-list 't' // tuple
642647
type ::= type generic-signature 'u' // generic type
643648
type ::= 'x' // generic param, depth=0, idx=0
@@ -653,6 +658,10 @@ Types
653658
type ::= type assoc-type-list 'QX' // associated type relative to base `type`
654659
#endif
655660

661+
#if SWIFT_RUNTIME_VERSION >= 5.7
662+
type ::= symbolic-extended-existential-type-shape type* retroactive-conformance* 'Xj'
663+
#endif
664+
656665
protocol-list ::= protocol '_' protocol*
657666
protocol-list ::= empty-list
658667

@@ -878,6 +887,7 @@ now codified into the ABI; the index 0 is therefore reserved.
878887
GENERIC-PARAM-INDEX ::= 'z' // depth = 0, idx = 0
879888
GENERIC-PARAM-INDEX ::= INDEX // depth = 0, idx = N+1
880889
GENERIC-PARAM-INDEX ::= 'd' INDEX INDEX // depth = M+1, idx = N
890+
GENERIC-PARAM-INDEX ::= 's' // depth = 0, idx = 0; Constrained existential 'Self' type
881891

882892
LAYOUT-CONSTRAINT ::= 'N' // NativeRefCountedObject
883893
LAYOUT-CONSTRAINT ::= 'R' // RefCountedObject

include/swift/AST/ASTDemangler.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,11 @@ class ASTBuilder {
119119

120120
Type createProtocolTypeFromDecl(ProtocolDecl *protocol);
121121

122-
Type createParameterizedProtocolType(Type base, ArrayRef<Type> args);
122+
Type createConstrainedExistentialType(Type base,
123+
ArrayRef<BuiltRequirement> constraints);
124+
125+
Type createSymbolicExtendedExistentialType(NodePointer shapeNode,
126+
ArrayRef<Type> genArgs);
123127

124128
Type createExistentialMetatypeType(Type instance,
125129
Optional<Demangle::ImplMetatypeRepresentation> repr=None);

include/swift/AST/ASTMangler.h

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "swift/Basic/Mangler.h"
1717
#include "swift/AST/Types.h"
1818
#include "swift/AST/Decl.h"
19+
#include "swift/Basic/TaggedUnion.h"
1920

2021
namespace clang {
2122
class NamedDecl;
@@ -79,8 +80,50 @@ class ASTMangler : public Mangler {
7980
bool RespectOriginallyDefinedIn = true;
8081

8182
public:
82-
using SymbolicReferent = llvm::PointerUnion<const NominalTypeDecl *,
83-
const OpaqueTypeDecl *>;
83+
class SymbolicReferent {
84+
public:
85+
enum Kind {
86+
NominalType,
87+
OpaqueType,
88+
ExtendedExistentialTypeShape,
89+
};
90+
private:
91+
// TODO: make a TaggedUnion variant that works with an explicit
92+
// kind instead of requiring this redundant kind storage.
93+
TaggedUnion<const NominalTypeDecl *,
94+
const OpaqueTypeDecl *,
95+
Type>
96+
storage;
97+
Kind kind;
98+
99+
SymbolicReferent(Kind kind, Type type) : storage(type), kind(kind) {}
100+
public:
101+
SymbolicReferent(const NominalTypeDecl *decl)
102+
: storage(decl), kind(NominalType) {}
103+
SymbolicReferent(const OpaqueTypeDecl *decl)
104+
: storage(decl), kind(OpaqueType) {}
105+
static SymbolicReferent forExtendedExistentialTypeShape(Type type) {
106+
return SymbolicReferent(ExtendedExistentialTypeShape, type);
107+
}
108+
109+
Kind getKind() const { return kind; }
110+
111+
bool isNominalType() const { return kind == NominalType; }
112+
const NominalTypeDecl *getNominalType() const {
113+
assert(kind == NominalType);
114+
return storage.get<const NominalTypeDecl *>();
115+
}
116+
117+
const OpaqueTypeDecl *getOpaqueType() const {
118+
assert(kind == OpaqueType);
119+
return storage.get<const OpaqueTypeDecl *>();
120+
}
121+
122+
Type getType() const {
123+
assert(kind == ExtendedExistentialTypeShape);
124+
return storage.get<Type>();
125+
}
126+
};
84127
protected:
85128

86129
/// If set, the mangler calls this function to determine whether to symbolic
@@ -90,8 +133,8 @@ class ASTMangler : public Mangler {
90133

91134
bool canSymbolicReference(SymbolicReferent referent) {
92135
// Marker protocols cannot ever be symbolically referenced.
93-
if (auto nominal = referent.dyn_cast<const NominalTypeDecl *>()) {
94-
if (auto proto = dyn_cast<ProtocolDecl>(nominal)) {
136+
if (referent.isNominalType()) {
137+
if (auto proto = dyn_cast<ProtocolDecl>(referent.getNominalType())) {
95138
if (proto->isMarkerProtocol())
96139
return false;
97140
}
@@ -343,7 +386,8 @@ class ASTMangler : public Mangler {
343386
bool &isAssocTypeAtDepth);
344387

345388
void appendOpWithGenericParamIndex(StringRef,
346-
const GenericTypeParamType *paramTy);
389+
const GenericTypeParamType *paramTy,
390+
bool baseIsProtocolSelf = false);
347391

348392
/// Mangles a sugared type iff we are mangling for the debugger.
349393
template <class T> void appendSugaredType(Type type,
@@ -444,8 +488,17 @@ class ASTMangler : public Mangler {
444488
bool appendGenericSignature(GenericSignature sig,
445489
GenericSignature contextSig = nullptr);
446490

447-
void appendRequirement(const Requirement &reqt,
448-
GenericSignature sig);
491+
/// Append a requirement to the mangling.
492+
///
493+
/// \param reqt The requirement to mangle
494+
/// \param sig The generic signature.
495+
/// \param lhsBaseIsProtocolSelf If \c true, mangle the base of the left-hand
496+
/// side of the constraint with a special protocol 'Self' sentinel node. This
497+
/// supports distinguishing requirements rooted at 'Self' in constrained
498+
/// existentials from ambient generic parameters that would otherwise be
499+
/// at e.g. (0, 0) as well.
500+
void appendRequirement(const Requirement &reqt, GenericSignature sig,
501+
bool lhsBaseIsProtocolSelf = false);
449502

450503
void appendGenericSignatureParts(GenericSignature sig,
451504
ArrayRef<CanTypeWrapper<GenericTypeParamType>> params,
@@ -511,6 +564,10 @@ class ASTMangler : public Mangler {
511564
GenericSignature sig);
512565
void appendOpParamForLayoutConstraint(LayoutConstraint Layout);
513566

567+
void appendSymbolicExtendedExistentialType(SymbolicReferent shapeReferent,
568+
Type type,
569+
GenericSignature sig,
570+
const ValueDecl *forDecl);
514571
void appendSymbolicReference(SymbolicReferent referent);
515572

516573
void appendOpaqueDeclName(const OpaqueTypeDecl *opaqueDecl);
@@ -521,6 +578,9 @@ class ASTMangler : public Mangler {
521578
Demangle::AutoDiffFunctionKind kind,
522579
const AutoDiffConfig &config);
523580
void appendIndexSubset(IndexSubset *indexSubset);
581+
582+
void appendConstrainedExistential(Type base, GenericSignature sig,
583+
const ValueDecl *forDecl);
524584
};
525585

526586
} // end namespace Mangle

include/swift/AST/DiagnosticsSema.def

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,12 @@ FIXIT(insert_closure_return_type_placeholder,
288288
NOTE(use_of_anon_closure_param,none,
289289
"anonymous closure parameter %0 is used here", (Identifier))
290290

291-
ERROR(incorrect_explicit_closure_result,none,
291+
ERROR(incorrect_explicit_closure_result_vs_contextual_type,none,
292292
"declared closure result %0 is incompatible with contextual type %1",
293293
(Type, Type))
294+
ERROR(incorrect_explicit_closure_result_vs_return_type,none,
295+
"declared closure result %0 is incompatible with return type %1",
296+
(Type, Type))
294297

295298
ERROR(unsupported_closure_attr,none,
296299
"%select{attribute |}0 '%1' is not supported on a closure",

include/swift/AST/Types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6529,6 +6529,8 @@ inline bool TypeBase::isClassExistentialType() {
65296529
return pt->requiresClass();
65306530
if (auto pct = dyn_cast<ProtocolCompositionType>(T))
65316531
return pct->requiresClass();
6532+
if (auto ppt = dyn_cast<ParameterizedProtocolType>(T))
6533+
return ppt->requiresClass();
65326534
if (auto existential = dyn_cast<ExistentialType>(T))
65336535
return existential->requiresClass();
65346536
return false;

include/swift/Demangling/DemangleNodes.def

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ NODE(FunctionSignatureSpecializationReturn)
9898
NODE(FunctionSignatureSpecializationParamKind)
9999
NODE(FunctionSignatureSpecializationParamPayload)
100100
NODE(FunctionType)
101+
NODE(ConstrainedExistential)
102+
NODE(ConstrainedExistentialRequirementList)
103+
NODE(ConstrainedExistentialSelf)
101104
NODE(GenericPartialSpecialization)
102105
NODE(GenericPartialSpecializationNotReAbstracted)
103106
NODE(GenericProtocolWitnessTable)
@@ -170,7 +173,6 @@ NODE(EscapingObjCBlock)
170173
CONTEXT_NODE(OtherNominalType)
171174
CONTEXT_NODE(OwningAddressor)
172175
CONTEXT_NODE(OwningMutableAddressor)
173-
NODE(ParameterizedProtocol)
174176
NODE(PartialApplyForwarder)
175177
NODE(PartialApplyObjCForwarder)
176178
NODE(PostfixOperator)
@@ -337,6 +339,9 @@ NODE(BackDeploymentThunk)
337339
NODE(BackDeploymentFallback)
338340
NODE(ExtendedExistentialTypeShape)
339341
NODE(Uniquable)
342+
NODE(UniqueExtendedExistentialTypeShapeSymbolicReference)
343+
NODE(NonUniqueExtendedExistentialTypeShapeSymbolicReference)
344+
NODE(SymbolicExtendedExistentialType)
340345

341346
#undef CONTEXT_NODE
342347
#undef NODE

include/swift/Demangling/Demangler.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,10 @@ enum class SymbolicReferenceKind : uint8_t {
343343
/// A symbolic reference to an accessor function, which can be executed in
344344
/// the process to get a pointer to the referenced entity.
345345
AccessorFunctionReference,
346+
/// A symbolic reference to a unique extended existential type shape.
347+
UniqueExtendedExistentialTypeShape,
348+
/// A symbolic reference to a non-unique extended existential type shape.
349+
NonUniqueExtendedExistentialTypeShape,
346350
};
347351

348352
using SymbolicReferenceResolver_t = NodePointer (SymbolicReferenceKind,
@@ -516,6 +520,7 @@ class Demangler : public NodeFactory {
516520
const Vector<NodePointer> &TypeLists,
517521
size_t TypeListIdx);
518522
NodePointer popAnyProtocolConformanceList();
523+
NodePointer popRetroactiveConformances();
519524
NodePointer demangleRetroactiveConformance();
520525
NodePointer demangleInitializer();
521526
NodePointer demangleImplParamConvention(Node::Kind ConvKind);
@@ -530,6 +535,7 @@ class Demangler : public NodeFactory {
530535
NodePointer demangleAssociatedTypeSimple(NodePointer GenericParamIdx);
531536
NodePointer demangleAssociatedTypeCompound(NodePointer GenericParamIdx);
532537
NodePointer demangleExtendedExistentialShape(char kind);
538+
NodePointer demangleSymbolicExtendedExistentialType();
533539

534540
NodePointer popAssocTypeName();
535541
NodePointer popAssocTypePath();
@@ -580,6 +586,8 @@ class Demangler : public NodeFactory {
580586
NodePointer demangleIndexSubset();
581587
NodePointer demangleDifferentiableFunctionType();
582588

589+
NodePointer demangleConstrainedExistentialRequirementList();
590+
583591
bool demangleBoundGenerics(Vector<NodePointer> &TypeListList,
584592
NodePointer &RetroactiveConformances);
585593

include/swift/Demangling/TypeDecoder.h

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -547,18 +547,8 @@ class TypeDecoder {
547547
Node->getNumChildren());
548548

549549
llvm::SmallVector<BuiltType, 8> args;
550-
551-
const auto &genericArgs = Node->getChild(1);
552-
if (genericArgs->getKind() != NodeKind::TypeList)
553-
return MAKE_NODE_TYPE_ERROR0(genericArgs, "is not TypeList");
554-
555-
for (auto genericArg : *genericArgs) {
556-
auto paramType = decodeMangledType(genericArg, depth + 1,
557-
/*forRequirement=*/false);
558-
if (paramType.isError())
559-
return paramType;
560-
args.push_back(paramType.getType());
561-
}
550+
if (auto error = decodeGenericArgs(Node->getChild(1), depth+1, args))
551+
return *error;
562552

563553
auto ChildNode = Node->getChild(0);
564554
if (ChildNode->getKind() == NodeKind::Type &&
@@ -665,6 +655,18 @@ class TypeDecoder {
665655
"had a different kind when re-checked");
666656
}
667657
}
658+
case NodeKind::SymbolicExtendedExistentialType: {
659+
if (Node->getNumChildren() < 2)
660+
return MAKE_NODE_TYPE_ERROR0(Node, "not enough children");
661+
662+
auto shapeNode = Node->getChild(0);
663+
llvm::SmallVector<BuiltType, 8> args;
664+
if (auto error = decodeGenericArgs(Node->getChild(1), depth + 1, args))
665+
return *error;
666+
667+
return Builder.createSymbolicExtendedExistentialType(shapeNode, args);
668+
}
669+
668670
case NodeKind::ProtocolList:
669671
case NodeKind::ProtocolListWithAnyObject:
670672
case NodeKind::ProtocolListWithClass: {
@@ -713,7 +715,7 @@ class TypeDecoder {
713715
forRequirement);
714716
}
715717

716-
case NodeKind::ParameterizedProtocol: {
718+
case NodeKind::ConstrainedExistential: {
717719
if (Node->getNumChildren() < 2)
718720
return MAKE_NODE_TYPE_ERROR(Node,
719721
"fewer children (%zu) than required (2)",
@@ -723,23 +725,20 @@ class TypeDecoder {
723725
if (protocolType.isError())
724726
return protocolType;
725727

726-
llvm::SmallVector<BuiltType, 8> args;
728+
llvm::SmallVector<BuiltRequirement, 8> requirements;
727729

728-
const auto &genericArgs = Node->getChild(1);
729-
if (genericArgs->getKind() != NodeKind::TypeList)
730-
return MAKE_NODE_TYPE_ERROR0(genericArgs, "is not TypeList");
730+
auto *reqts = Node->getChild(1);
731+
if (reqts->getKind() != NodeKind::ConstrainedExistentialRequirementList)
732+
return MAKE_NODE_TYPE_ERROR0(reqts, "is not requirement list");
731733

732-
for (auto genericArg : *genericArgs) {
733-
auto paramType = decodeMangledType(genericArg, depth + 1,
734-
/*forRequirement=*/false);
735-
if (paramType.isError())
736-
return paramType;
737-
args.push_back(paramType.getType());
738-
}
734+
decodeRequirement<BuiltType, BuiltRequirement, BuiltLayoutConstraint,
735+
BuilderType>(reqts, requirements, Builder);
739736

740-
return Builder.createParameterizedProtocolType(protocolType.getType(),
741-
args);
737+
return Builder.createConstrainedExistentialType(protocolType.getType(),
738+
requirements);
742739
}
740+
case NodeKind::ConstrainedExistentialSelf:
741+
return Builder.createGenericTypeParameterType(/*depth*/ 0, /*index*/ 0);
743742

744743
case NodeKind::Protocol:
745744
case NodeKind::ProtocolSymbolicReference: {
@@ -1383,6 +1382,22 @@ return {}; // Not Implemented!
13831382
return false;
13841383
}
13851384

1385+
llvm::Optional<TypeLookupError>
1386+
decodeGenericArgs(Demangle::NodePointer node, unsigned depth,
1387+
llvm::SmallVectorImpl<BuiltType> &args) {
1388+
if (node->getKind() != NodeKind::TypeList)
1389+
return MAKE_NODE_TYPE_ERROR0(node, "is not TypeList");
1390+
1391+
for (auto genericArg : *node) {
1392+
auto paramType = decodeMangledType(genericArg, depth,
1393+
/*forRequirement=*/false);
1394+
if (paramType.isError())
1395+
return *paramType.getError();
1396+
args.push_back(paramType.getType());
1397+
}
1398+
return llvm::None;
1399+
}
1400+
13861401
llvm::Optional<TypeLookupError>
13871402
decodeMangledTypeDecl(Demangle::NodePointer node, unsigned depth,
13881403
BuiltTypeDecl &typeDecl, BuiltType &parent,

0 commit comments

Comments
 (0)