Skip to content

Commit 278ca42

Browse files
authored
Merge pull request #3774 from swiftwasm/release/5.5
2 parents 1e9a74c + 6a355ae commit 278ca42

File tree

15 files changed

+137
-24
lines changed

15 files changed

+137
-24
lines changed

include/swift/AST/ASTMangler.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ class ASTMangler : public Mangler {
6161
/// concurrency library.
6262
bool AllowConcurrencyStandardSubstitutions = true;
6363

64+
/// If enabled, marker protocols can be encoded in the mangled name.
65+
bool AllowMarkerProtocols = true;
66+
6467
public:
6568
using SymbolicReferent = llvm::PointerUnion<const NominalTypeDecl *,
6669
const OpaqueTypeDecl *>;
@@ -294,6 +297,9 @@ class ASTMangler : public Mangler {
294297
static const clang::NamedDecl *
295298
getClangDeclForMangling(const ValueDecl *decl);
296299

300+
void appendExistentialLayout(
301+
const ExistentialLayout &layout, const ValueDecl *forDecl);
302+
297303
protected:
298304

299305
void appendSymbolKind(SymbolKind SKind);

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5827,6 +5827,9 @@ ERROR(marker_protocol_requirement, none,
58275827
ERROR(marker_protocol_inherit_nonmarker, none,
58285828
"marker protocol %0 cannot inherit non-marker protocol %1",
58295829
(DeclName, DeclName))
5830+
ERROR(marker_protocol_inherit_class, none,
5831+
"marker protocol %0 cannot inherit class %1",
5832+
(DeclName, Type))
58305833
ERROR(marker_protocol_cast,none,
58315834
"marker protocol %0 cannot be used in a conditional cast", (DeclName))
58325835
ERROR(marker_protocol_conditional_conformance,none,

include/swift/AST/IRGenOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ class IRGenOptions {
405405
DisableAutolinkStdlib(false),
406406
PrintInlineTree(false), EmbedMode(IRGenEmbedMode::None),
407407
LLVMLTOKind(IRGenLLVMLTOKind::None),
408-
SwiftAsyncFramePointer(SwiftAsyncFramePointerKind::Always),
408+
SwiftAsyncFramePointer(SwiftAsyncFramePointerKind::Auto),
409409
HasValueNamesSetting(false),
410410
ValueNames(false), EnableReflectionMetadata(true),
411411
EnableReflectionNames(true), EnableAnonymousContextMangledNames(false),

lib/AST/ASTMangler.cpp

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,40 @@ void ASTMangler::appendOpaqueDeclName(const OpaqueTypeDecl *opaqueDecl) {
10201020
}
10211021
}
10221022

1023+
void ASTMangler::appendExistentialLayout(
1024+
const ExistentialLayout &layout, const ValueDecl *forDecl) {
1025+
bool First = true;
1026+
bool DroppedRequiresClass = false;
1027+
bool SawRequiresClass = false;
1028+
for (Type protoTy : layout.getProtocols()) {
1029+
auto proto = protoTy->castTo<ProtocolType>()->getDecl();
1030+
// If we aren't allowed to emit marker protocols, suppress them here.
1031+
if (!AllowMarkerProtocols && proto->isMarkerProtocol()) {
1032+
if (proto->requiresClass())
1033+
DroppedRequiresClass = true;
1034+
1035+
continue;
1036+
}
1037+
1038+
if (proto->requiresClass())
1039+
SawRequiresClass = true;
1040+
1041+
appendProtocolName(protoTy->castTo<ProtocolType>()->getDecl());
1042+
appendListSeparator(First);
1043+
}
1044+
if (First)
1045+
appendOperator("y");
1046+
1047+
if (auto superclass = layout.explicitSuperclass) {
1048+
appendType(superclass, forDecl);
1049+
return appendOperator("Xc");
1050+
} else if (layout.hasExplicitAnyObject ||
1051+
(DroppedRequiresClass && !SawRequiresClass)) {
1052+
return appendOperator("Xl");
1053+
}
1054+
return appendOperator("p");
1055+
}
1056+
10231057
/// Mangle a type into the buffer.
10241058
///
10251059
void ASTMangler::appendType(Type type, const ValueDecl *forDecl) {
@@ -1189,31 +1223,15 @@ void ASTMangler::appendType(Type type, const ValueDecl *forDecl) {
11891223
return appendOperator("t");
11901224

11911225
case TypeKind::Protocol: {
1192-
bool First = true;
1193-
appendProtocolName(cast<ProtocolType>(tybase)->getDecl());
1194-
appendListSeparator(First);
1195-
return appendOperator("p");
1226+
return appendExistentialLayout(
1227+
ExistentialLayout(cast<ProtocolType>(tybase)), forDecl);
11961228
}
11971229

11981230
case TypeKind::ProtocolComposition: {
11991231
// We mangle ProtocolType and ProtocolCompositionType using the
12001232
// same production:
1201-
bool First = true;
12021233
auto layout = type->getExistentialLayout();
1203-
for (Type protoTy : layout.getProtocols()) {
1204-
appendProtocolName(protoTy->castTo<ProtocolType>()->getDecl());
1205-
appendListSeparator(First);
1206-
}
1207-
if (First)
1208-
appendOperator("y");
1209-
1210-
if (auto superclass = layout.explicitSuperclass) {
1211-
appendType(superclass, forDecl);
1212-
return appendOperator("Xc");
1213-
} else if (layout.hasExplicitAnyObject) {
1214-
return appendOperator("Xl");
1215-
}
1216-
return appendOperator("p");
1234+
return appendExistentialLayout(layout, forDecl);
12171235
}
12181236

12191237
case TypeKind::UnboundGeneric:
@@ -2196,6 +2214,8 @@ void ASTMangler::appendModule(const ModuleDecl *module,
21962214
/// Mangle the name of a protocol as a substitution candidate.
21972215
void ASTMangler::appendProtocolName(const ProtocolDecl *protocol,
21982216
bool allowStandardSubstitution) {
2217+
assert(AllowMarkerProtocols || !protocol->isMarkerProtocol());
2218+
21992219
if (allowStandardSubstitution && tryAppendStandardSubstitution(protocol))
22002220
return;
22012221

@@ -2344,6 +2364,8 @@ void ASTMangler::appendAnyGenericType(const GenericTypeDecl *decl) {
23442364
appendOperator("a");
23452365
break;
23462366
case DeclKind::Protocol:
2367+
assert(AllowMarkerProtocols ||
2368+
!cast<ProtocolDecl>(decl)->isMarkerProtocol());
23472369
appendOperator("P");
23482370
break;
23492371
case DeclKind::Class:
@@ -2657,6 +2679,11 @@ void ASTMangler::appendRequirement(const Requirement &reqt) {
26572679
case RequirementKind::Layout: {
26582680
} break;
26592681
case RequirementKind::Conformance: {
2682+
// If we don't allow marker protocols but we have one here, skip it.
2683+
if (!AllowMarkerProtocols &&
2684+
reqt.getProtocolDecl()->isMarkerProtocol())
2685+
return;
2686+
26602687
appendProtocolName(reqt.getProtocolDecl());
26612688
} break;
26622689
case RequirementKind::Superclass:
@@ -3187,6 +3214,12 @@ void ASTMangler::appendAnyProtocolConformance(
31873214
CanGenericSignature genericSig,
31883215
CanType conformingType,
31893216
ProtocolConformanceRef conformance) {
3217+
// If we have a conformance to a marker protocol but we aren't allowed to
3218+
// emit marker protocols, skip it.
3219+
if (!AllowMarkerProtocols &&
3220+
conformance.getRequirement()->isMarkerProtocol())
3221+
return;
3222+
31903223
if (conformingType->isTypeParameter()) {
31913224
assert(genericSig && "Need a generic signature to resolve conformance");
31923225
auto path = genericSig->getConformanceAccessPath(conformingType,

lib/IRGen/IRGenMangler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ IRGenMangler::mangleTypeForReflection(IRGenModule &IGM,
159159
AllowConcurrencyStandardSubstitutions = false;
160160
}
161161

162+
llvm::SaveAndRestore<bool> savedAllowMarkerProtocols(
163+
AllowMarkerProtocols, false);
162164
return withSymbolicReferences(IGM, [&]{
163165
bindGenericParameters(Sig);
164166
appendType(Ty);

lib/Sema/TypeCheckAttr.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5588,6 +5588,12 @@ void AttributeChecker::visitMarkerAttr(MarkerAttr *attr) {
55885588
}
55895589
}
55905590

5591+
if (Type superclass = proto->getSuperclass()) {
5592+
proto->diagnose(
5593+
diag::marker_protocol_inherit_class,
5594+
proto->getName(), superclass);
5595+
}
5596+
55915597
// A marker protocol cannot have any requirements.
55925598
for (auto member : proto->getAllMembers()) {
55935599
auto value = dyn_cast<ValueDecl>(member);

lib/Serialization/Deserialization.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3080,12 +3080,14 @@ class DeclDeserializer {
30803080
bool isIUO;
30813081
bool isVariadic;
30823082
bool isAutoClosure;
3083+
bool isIsolated;
30833084
uint8_t rawDefaultArg;
30843085

30853086
decls_block::ParamLayout::readRecord(scratch, argNameID, paramNameID,
30863087
contextID, rawSpecifier,
30873088
interfaceTypeID, isIUO, isVariadic,
3088-
isAutoClosure, rawDefaultArg);
3089+
isAutoClosure, isIsolated,
3090+
rawDefaultArg);
30893091

30903092
auto argName = MF.getIdentifier(argNameID);
30913093
auto paramName = MF.getIdentifier(paramNameID);
@@ -3119,6 +3121,7 @@ class DeclDeserializer {
31193121
param->setImplicitlyUnwrappedOptional(isIUO);
31203122
param->setVariadic(isVariadic);
31213123
param->setAutoClosure(isAutoClosure);
3124+
param->setIsolated(isIsolated);
31223125

31233126
// Decode the default argument kind.
31243127
// FIXME: Default argument expression, if available.

lib/Serialization/ModuleFormat.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5656
/// describe what change you made. The content of this comment isn't important;
5757
/// it just ensures a conflict if two people change the module format.
5858
/// Don't worry about adhering to the 80-column limit for this line.
59-
const uint16_t SWIFTMODULE_VERSION_MINOR = 621; // builtin protocol conformances
59+
const uint16_t SWIFTMODULE_VERSION_MINOR = 622; // 'isolated' in param decls
6060

6161
/// A standard hash seed used for all string hashes in a serialized module.
6262
///
@@ -1322,6 +1322,7 @@ namespace decls_block {
13221322
BCFixed<1>, // isIUO?
13231323
BCFixed<1>, // isVariadic?
13241324
BCFixed<1>, // isAutoClosure?
1325+
BCFixed<1>, // isIsolated?
13251326
DefaultArgumentField, // default argument kind
13261327
BCBlob // default argument text
13271328
>;

lib/Serialization/Serialization.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3614,6 +3614,7 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
36143614
param->isImplicitlyUnwrappedOptional(),
36153615
param->isVariadic(),
36163616
param->isAutoClosure(),
3617+
param->isIsolated(),
36173618
getRawStableDefaultArgumentKind(argKind),
36183619
defaultArgumentText);
36193620

test/Concurrency/Backdeploy/linking.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
// REQUIRES: OS=macosx
1717
// REQUIRES: CPU=x86_64
18+
// REQUIRES: maccatalyst_support
1819

1920
// CHECK-DIRECT: /usr/lib/swift/libswift_Concurrency.dylib
2021
// CHECK-RPATH: @rpath/libswift_Concurrency.dylib

0 commit comments

Comments
 (0)