Skip to content

Commit dac90fd

Browse files
DougGregorlorentey
authored andcommitted
[Noncopyable generics] Suppress inverse conformance mangling for more symbols
Don't mangle inverse conformances for symbols related to dispatch thunks, protocol members, and other entities that are inexorably tied to the primary definition of the type and must have stable names. Extend the conditional suppression of inverse conformance mangling to property descriptors and more conformance-related symbols. (cherry picked from commit e1ee19a)
1 parent fdfa57c commit dac90fd

File tree

3 files changed

+86
-8
lines changed

3 files changed

+86
-8
lines changed

lib/IRGen/IRGenMangler.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ std::string IRGenMangler::mangleProtocolConformanceDescriptor(
214214

215215
std::string IRGenMangler::mangleProtocolConformanceDescriptorRecord(
216216
const RootProtocolConformance *conformance) {
217+
llvm::SaveAndRestore X(AllowInverses,
218+
inversesAllowedIn(conformance->getDeclContext()));
219+
217220
beginMangling();
218221
appendProtocolConformance(conformance);
219222
appendOperator("Hc");
@@ -222,6 +225,9 @@ std::string IRGenMangler::mangleProtocolConformanceDescriptorRecord(
222225

223226
std::string IRGenMangler::mangleProtocolConformanceInstantiationCache(
224227
const RootProtocolConformance *conformance) {
228+
llvm::SaveAndRestore X(AllowInverses,
229+
inversesAllowedIn(conformance->getDeclContext()));
230+
225231
beginMangling();
226232
if (isa<NormalProtocolConformance>(conformance)) {
227233
appendProtocolConformance(conformance);
@@ -511,3 +517,17 @@ IRGenMangler::appendExtendedExistentialTypeShape(CanGenericSignature genSig,
511517
appendOperator(genSig ? "XG" : "Xg");
512518
}
513519

520+
std::string
521+
IRGenMangler::mangleConformanceSymbol(Type type,
522+
const ProtocolConformance *Conformance,
523+
const char *Op) {
524+
llvm::SaveAndRestore X(AllowInverses,
525+
inversesAllowedIn(Conformance->getDeclContext()));
526+
527+
beginMangling();
528+
if (type)
529+
appendType(type, nullptr);
530+
appendProtocolConformance(Conformance);
531+
appendOperator(Op);
532+
return finalize();
533+
}

lib/IRGen/IRGenMangler.h

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ 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+
4952
beginMangling();
5053
appendEntity(func);
5154
appendOperator("Tj");
@@ -55,6 +58,9 @@ class IRGenMangler : public Mangle::ASTMangler {
5558
std::string mangleDerivativeDispatchThunk(
5659
const AbstractFunctionDecl *func,
5760
AutoDiffDerivativeFunctionIdentifier *derivativeId) {
61+
// Dispatch thunks do not mangle inverse conformances.
62+
llvm::SaveAndRestore X(AllowInverses, false);
63+
5864
beginManglingWithAutoDiffOriginalFunction(func);
5965
auto kind = Demangle::getAutoDiffFunctionKind(derivativeId->getKind());
6066
auto *resultIndices =
@@ -71,13 +77,19 @@ class IRGenMangler : public Mangle::ASTMangler {
7177

7278
std::string mangleConstructorDispatchThunk(const ConstructorDecl *ctor,
7379
bool isAllocating) {
80+
// Dispatch thunks do not mangle inverse conformances.
81+
llvm::SaveAndRestore X(AllowInverses, false);
82+
7483
beginMangling();
7584
appendConstructorEntity(ctor, isAllocating);
7685
appendOperator("Tj");
7786
return finalize();
7887
}
7988

8089
std::string mangleMethodDescriptor(const FuncDecl *func) {
90+
// Method descriptors do not mangle inverse conformances.
91+
llvm::SaveAndRestore X(AllowInverses, false);
92+
8193
beginMangling();
8294
appendEntity(func);
8395
appendOperator("Tq");
@@ -87,6 +99,9 @@ class IRGenMangler : public Mangle::ASTMangler {
8799
std::string mangleDerivativeMethodDescriptor(
88100
const AbstractFunctionDecl *func,
89101
AutoDiffDerivativeFunctionIdentifier *derivativeId) {
102+
// Method descriptors do not mangle inverse conformances.
103+
llvm::SaveAndRestore X(AllowInverses, false);
104+
90105
beginManglingWithAutoDiffOriginalFunction(func);
91106
auto kind = Demangle::getAutoDiffFunctionKind(derivativeId->getKind());
92107
auto *resultIndices =
@@ -103,6 +118,9 @@ class IRGenMangler : public Mangle::ASTMangler {
103118

104119
std::string mangleConstructorMethodDescriptor(const ConstructorDecl *ctor,
105120
bool isAllocating) {
121+
// Method descriptors do not mangle inverse conformances.
122+
llvm::SaveAndRestore X(AllowInverses, false);
123+
106124
beginMangling();
107125
appendConstructorEntity(ctor, isAllocating);
108126
appendOperator("Tq");
@@ -327,6 +345,10 @@ class IRGenMangler : public Mangle::ASTMangler {
327345
// among the type descriptors of different protocols.
328346
llvm::SaveAndRestore<bool> optimizeProtocolNames(OptimizeProtocolNames,
329347
false);
348+
349+
// No mangling of inverse conformances inside protocols.
350+
llvm::SaveAndRestore X(AllowInverses, false);
351+
330352
beginMangling();
331353
bool isAssocTypeAtDepth = false;
332354
(void)appendAssocType(
@@ -341,6 +363,9 @@ class IRGenMangler : public Mangle::ASTMangler {
341363
const ProtocolDecl *proto,
342364
CanType subject,
343365
const ProtocolDecl *requirement) {
366+
// No mangling of inverse conformances inside protocols.
367+
llvm::SaveAndRestore X(AllowInverses, false);
368+
344369
beginMangling();
345370
appendAnyGenericType(proto);
346371
if (isa<GenericTypeParamType>(subject)) {
@@ -357,6 +382,9 @@ class IRGenMangler : public Mangle::ASTMangler {
357382
std::string mangleBaseConformanceDescriptor(
358383
const ProtocolDecl *proto,
359384
const ProtocolDecl *requirement) {
385+
// No mangling of inverse conformances inside protocols.
386+
llvm::SaveAndRestore X(AllowInverses, false);
387+
360388
beginMangling();
361389
appendAnyGenericType(proto);
362390
appendProtocolName(requirement);
@@ -368,6 +396,9 @@ class IRGenMangler : public Mangle::ASTMangler {
368396
const ProtocolDecl *proto,
369397
CanType subject,
370398
const ProtocolDecl *requirement) {
399+
// No mangling of inverse conformances inside protocols.
400+
llvm::SaveAndRestore X(AllowInverses, false);
401+
371402
beginMangling();
372403
appendAnyGenericType(proto);
373404
bool isFirstAssociatedTypeIdentifier = true;
@@ -385,20 +416,27 @@ class IRGenMangler : public Mangle::ASTMangler {
385416
const RootProtocolConformance *conformance);
386417

387418
std::string manglePropertyDescriptor(const AbstractStorageDecl *storage) {
419+
llvm::SaveAndRestore X(AllowInverses, inversesAllowed(storage));
388420
beginMangling();
389421
appendEntity(storage);
390422
appendOperator("MV");
391423
return finalize();
392424
}
393425

394426
std::string mangleFieldOffset(const ValueDecl *Decl) {
427+
// No mangling of inverse conformances.
428+
llvm::SaveAndRestore X(AllowInverses, false);
429+
395430
beginMangling();
396431
appendEntity(Decl);
397432
appendOperator("Wvd");
398433
return finalize();
399434
}
400435

401436
std::string mangleEnumCase(const ValueDecl *Decl) {
437+
// No mangling of inverse conformances.
438+
llvm::SaveAndRestore X(AllowInverses, false);
439+
402440
beginMangling();
403441
appendEntity(Decl);
404442
appendOperator("WC");
@@ -713,14 +751,7 @@ class IRGenMangler : public Mangle::ASTMangler {
713751

714752
std::string mangleConformanceSymbol(Type type,
715753
const ProtocolConformance *Conformance,
716-
const char *Op) {
717-
beginMangling();
718-
if (type)
719-
appendType(type, nullptr);
720-
appendProtocolConformance(Conformance);
721-
appendOperator(Op);
722-
return finalize();
723-
}
754+
const char *Op);
724755
};
725756

726757
/// Determines if the minimum deployment target's runtime demangler will not
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-ir -o - %s -module-name test \
3+
// RUN: -enable-experimental-feature NoncopyableGenerics \
4+
// RUN: -enable-experimental-feature NonescapableTypes \
5+
// RUN: -parse-as-library \
6+
// RUN: -enable-library-evolution \
7+
// RUN: > %t/test.irgen
8+
9+
// RUN: %FileCheck %s < %t/test.irgen
10+
11+
public protocol P: ~Copyable { }
12+
13+
public protocol Hello<Person>: ~Copyable {
14+
// CHECK: @"$s4test5HelloP6PersonAC_AA1PTn"
15+
// CHECK: @"$s6Person4test5HelloPTl" = alias
16+
associatedtype Person: P & ~Copyable
17+
18+
// CHECK: @"$s4test5HelloP14favoritePerson0D0QzvrTq" = alias
19+
var favoritePerson: Person { get }
20+
21+
// CHECK: @"$s4test5HelloP5greetyy6PersonQzFTq"
22+
func greet(_ person: borrowing Person)
23+
}
24+
25+
public struct Wrapper<T: ~Copyable> {
26+
var wrapped: T { fatalError("boom") }
27+
}

0 commit comments

Comments
 (0)