Skip to content

Commit 663865c

Browse files
authored
Merge pull request swiftlang#72279 from DougGregor/noncopyable-protocol-mangle
[Noncopyable] Mangle protocol members without the inverse requirements of the protocol itself
2 parents 2d27ec5 + 1cd7a56 commit 663865c

File tree

4 files changed

+29
-37
lines changed

4 files changed

+29
-37
lines changed

lib/AST/ASTMangler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4669,6 +4669,11 @@ ASTMangler::BaseEntitySignature::BaseEntitySignature(const Decl *decl)
46694669
case DeclKind::Struct:
46704670
case DeclKind::Class:
46714671
sig = decl->getInnermostDeclContext()->getGenericSignatureOfContext();
4672+
4673+
// Protocol members never mangle inverse constraints on `Self`.
4674+
if (isa<ProtocolDecl>(decl->getDeclContext()))
4675+
setDepth(0);
4676+
46724677
break;
46734678

46744679
case DeclKind::TypeAlias: // FIXME: is this right? typealiases have a generic signature!

lib/IRGen/IRGenMangler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ IRGenMangler::appendExtendedExistentialTypeShape(CanGenericSignature genSig,
505505
CanType shapeType) {
506506
// Append the generalization signature.
507507
if (genSig) {
508-
// Generalization signature never reference inverses.
508+
// Generalization signature never mangles inverses.
509509
llvm::SaveAndRestore X(AllowInverses, false);
510510
appendGenericSignature(genSig);
511511
}

lib/IRGen/IRGenMangler.h

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ class IRGenMangler : public Mangle::ASTMangler {
4646
IRGenMangler() { }
4747

4848
std::string mangleDispatchThunk(const FuncDecl *func) {
49-
// Dispatch thunks do not mangle inverse conformances.
50-
llvm::SaveAndRestore X(AllowInverses, false);
51-
5249
beginMangling();
5350
appendEntity(func);
5451
appendOperator("Tj");
@@ -58,9 +55,6 @@ class IRGenMangler : public Mangle::ASTMangler {
5855
std::string mangleDerivativeDispatchThunk(
5956
const AbstractFunctionDecl *func,
6057
AutoDiffDerivativeFunctionIdentifier *derivativeId) {
61-
// Dispatch thunks do not mangle inverse conformances.
62-
llvm::SaveAndRestore X(AllowInverses, false);
63-
6458
beginManglingWithAutoDiffOriginalFunction(func);
6559
auto kind = Demangle::getAutoDiffFunctionKind(derivativeId->getKind());
6660
auto *resultIndices =
@@ -77,19 +71,13 @@ class IRGenMangler : public Mangle::ASTMangler {
7771

7872
std::string mangleConstructorDispatchThunk(const ConstructorDecl *ctor,
7973
bool isAllocating) {
80-
// Dispatch thunks do not mangle inverse conformances.
81-
llvm::SaveAndRestore X(AllowInverses, false);
82-
8374
beginMangling();
8475
appendConstructorEntity(ctor, isAllocating);
8576
appendOperator("Tj");
8677
return finalize();
8778
}
8879

8980
std::string mangleMethodDescriptor(const FuncDecl *func) {
90-
// Method descriptors do not mangle inverse conformances.
91-
llvm::SaveAndRestore X(AllowInverses, false);
92-
9381
beginMangling();
9482
appendEntity(func);
9583
appendOperator("Tq");
@@ -99,9 +87,6 @@ class IRGenMangler : public Mangle::ASTMangler {
9987
std::string mangleDerivativeMethodDescriptor(
10088
const AbstractFunctionDecl *func,
10189
AutoDiffDerivativeFunctionIdentifier *derivativeId) {
102-
// Method descriptors do not mangle inverse conformances.
103-
llvm::SaveAndRestore X(AllowInverses, false);
104-
10590
beginManglingWithAutoDiffOriginalFunction(func);
10691
auto kind = Demangle::getAutoDiffFunctionKind(derivativeId->getKind());
10792
auto *resultIndices =
@@ -118,9 +103,6 @@ class IRGenMangler : public Mangle::ASTMangler {
118103

119104
std::string mangleConstructorMethodDescriptor(const ConstructorDecl *ctor,
120105
bool isAllocating) {
121-
// Method descriptors do not mangle inverse conformances.
122-
llvm::SaveAndRestore X(AllowInverses, false);
123-
124106
beginMangling();
125107
appendConstructorEntity(ctor, isAllocating);
126108
appendOperator("Tq");
@@ -346,9 +328,6 @@ class IRGenMangler : public Mangle::ASTMangler {
346328
llvm::SaveAndRestore<bool> optimizeProtocolNames(OptimizeProtocolNames,
347329
false);
348330

349-
// No mangling of inverse conformances inside protocols.
350-
llvm::SaveAndRestore X(AllowInverses, false);
351-
352331
beginMangling();
353332
bool isAssocTypeAtDepth = false;
354333
(void)appendAssocType(
@@ -363,9 +342,6 @@ class IRGenMangler : public Mangle::ASTMangler {
363342
const ProtocolDecl *proto,
364343
CanType subject,
365344
const ProtocolDecl *requirement) {
366-
// No mangling of inverse conformances inside protocols.
367-
llvm::SaveAndRestore X(AllowInverses, false);
368-
369345
beginMangling();
370346
appendAnyGenericType(proto);
371347
if (isa<GenericTypeParamType>(subject)) {
@@ -382,9 +358,6 @@ class IRGenMangler : public Mangle::ASTMangler {
382358
std::string mangleBaseConformanceDescriptor(
383359
const ProtocolDecl *proto,
384360
const ProtocolDecl *requirement) {
385-
// No mangling of inverse conformances inside protocols.
386-
llvm::SaveAndRestore X(AllowInverses, false);
387-
388361
beginMangling();
389362
appendAnyGenericType(proto);
390363
appendProtocolName(requirement);
@@ -396,9 +369,6 @@ class IRGenMangler : public Mangle::ASTMangler {
396369
const ProtocolDecl *proto,
397370
CanType subject,
398371
const ProtocolDecl *requirement) {
399-
// No mangling of inverse conformances inside protocols.
400-
llvm::SaveAndRestore X(AllowInverses, false);
401-
402372
beginMangling();
403373
appendAnyGenericType(proto);
404374
bool isFirstAssociatedTypeIdentifier = true;
@@ -424,9 +394,6 @@ class IRGenMangler : public Mangle::ASTMangler {
424394
}
425395

426396
std::string mangleFieldOffset(const ValueDecl *Decl) {
427-
// No mangling of inverse conformances.
428-
llvm::SaveAndRestore X(AllowInverses, false);
429-
430397
beginMangling();
431398
appendEntity(Decl);
432399
appendOperator("Wvd");

test/IRGen/mangling_inverse_generics_evolution.swift

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,24 @@
1010

1111
public protocol P: ~Copyable { }
1212

13+
public struct CallMe<U: ~Copyable> {
14+
public enum Maybe<T: ~Copyable>: ~Copyable {
15+
// CHECK-LABEL: @"$s4test6CallMeV5MaybeO4someyAEyx_qd__Gqd__cAGmr__lFWC"
16+
// CHECK: @"$s4test6CallMeV5MaybeO4noneyAEyx_qd__GAGmr__lFWC"
17+
case none
18+
case some(T)
19+
}
20+
}
21+
22+
extension CallMe {
23+
public enum Box<T: ~Copyable>: ~Copyable {
24+
// CHECK-LABEL: @"$s4test6CallMeV3BoxO4someyAEyx_qd__Gqd__cAGmr__lFWC"
25+
// CHECK: @"$s4test6CallMeV3BoxO4noneyAEyx_qd__GAGmr__lFWC"
26+
case none
27+
case some(T)
28+
}
29+
}
30+
1331
public protocol Hello<Person>: ~Copyable {
1432
// CHECK: @"$s4test5HelloP6PersonAC_AA1PTn"
1533
// CHECK: @"$s6Person4test5HelloPTl" =
@@ -20,8 +38,10 @@ public protocol Hello<Person>: ~Copyable {
2038

2139
// CHECK: @"$s4test5HelloP5greetyy6PersonQzFTq"
2240
func greet(_ person: borrowing Person)
23-
}
2441

25-
public struct Wrapper<T: ~Copyable> {
26-
var wrapped: T { fatalError("boom") }
42+
// CHECK: @"$s4test5HelloP10overloadedyyqd__lFTj"
43+
func overloaded<T>(_: borrowing T)
44+
45+
// CHECK: @"$s4test5HelloP10overloadedyyqd__Ricd__lFTj"
46+
func overloaded<T: ~Copyable>(_: borrowing T)
2747
}

0 commit comments

Comments
 (0)