Skip to content

Commit 1be8e86

Browse files
authored
Merge pull request swiftlang#72348 from DougGregor/more-preinversegenerics
Enable `@_preInverseGenerics` to suppress mangled names in more places
2 parents 4c5558d + 854d087 commit 1be8e86

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

lib/IRGen/IRGenMangler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,8 +521,8 @@ std::string
521521
IRGenMangler::mangleConformanceSymbol(Type type,
522522
const ProtocolConformance *Conformance,
523523
const char *Op) {
524-
llvm::SaveAndRestore X(AllowInverses,
525-
inversesAllowedIn(Conformance->getDeclContext()));
524+
llvm::SaveAndRestore X(AllowInverses,
525+
inversesAllowedIn(Conformance->getDeclContext()));
526526

527527
beginMangling();
528528
if (type)

lib/IRGen/IRGenMangler.h

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

4848
std::string mangleDispatchThunk(const FuncDecl *func) {
49+
llvm::SaveAndRestore X(AllowInverses, inversesAllowed(func));
4950
beginMangling();
5051
appendEntity(func);
5152
appendOperator("Tj");
@@ -55,6 +56,7 @@ class IRGenMangler : public Mangle::ASTMangler {
5556
std::string mangleDerivativeDispatchThunk(
5657
const AbstractFunctionDecl *func,
5758
AutoDiffDerivativeFunctionIdentifier *derivativeId) {
59+
llvm::SaveAndRestore X(AllowInverses, inversesAllowed(func));
5860
beginManglingWithAutoDiffOriginalFunction(func);
5961
auto kind = Demangle::getAutoDiffFunctionKind(derivativeId->getKind());
6062
auto *resultIndices =
@@ -71,13 +73,15 @@ class IRGenMangler : public Mangle::ASTMangler {
7173

7274
std::string mangleConstructorDispatchThunk(const ConstructorDecl *ctor,
7375
bool isAllocating) {
76+
llvm::SaveAndRestore X(AllowInverses, inversesAllowed(ctor));
7477
beginMangling();
7578
appendConstructorEntity(ctor, isAllocating);
7679
appendOperator("Tj");
7780
return finalize();
7881
}
7982

8083
std::string mangleMethodDescriptor(const FuncDecl *func) {
84+
llvm::SaveAndRestore X(AllowInverses, inversesAllowed(func));
8185
beginMangling();
8286
appendEntity(func);
8387
appendOperator("Tq");
@@ -87,6 +91,7 @@ class IRGenMangler : public Mangle::ASTMangler {
8791
std::string mangleDerivativeMethodDescriptor(
8892
const AbstractFunctionDecl *func,
8993
AutoDiffDerivativeFunctionIdentifier *derivativeId) {
94+
llvm::SaveAndRestore X(AllowInverses, inversesAllowed(func));
9095
beginManglingWithAutoDiffOriginalFunction(func);
9196
auto kind = Demangle::getAutoDiffFunctionKind(derivativeId->getKind());
9297
auto *resultIndices =
@@ -103,6 +108,7 @@ class IRGenMangler : public Mangle::ASTMangler {
103108

104109
std::string mangleConstructorMethodDescriptor(const ConstructorDecl *ctor,
105110
bool isAllocating) {
111+
llvm::SaveAndRestore X(AllowInverses, inversesAllowed(ctor));
106112
beginMangling();
107113
appendConstructorEntity(ctor, isAllocating);
108114
appendOperator("Tq");
@@ -394,6 +400,7 @@ class IRGenMangler : public Mangle::ASTMangler {
394400
}
395401

396402
std::string mangleFieldOffset(const ValueDecl *Decl) {
403+
llvm::SaveAndRestore X(AllowInverses, inversesAllowed(Decl));
397404
beginMangling();
398405
appendEntity(Decl);
399406
appendOperator("Wvd");

test/IRGen/mangling_inverse_generics_evolution.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ extension CallMe {
2929
}
3030
}
3131

32+
// CHECK: @"$s4test13ManagedBufferC12_doNotCallMeACyxq_Gyt_tcfCTq"
33+
34+
3235
public protocol Hello<Person>: ~Copyable {
3336
// CHECK: @"$s4test5HelloP6PersonAC_AA1PTn"
3437
// CHECK: @"$s6Person4test5HelloPTl" =
@@ -58,3 +61,18 @@ struct XQ<T: ~Copyable>: ~Copyable {
5861
extension XQ: Q where T: ~Copyable {
5962
struct A { }
6063
}
64+
65+
// Class metadata
66+
67+
@_fixed_layout
68+
open class ManagedBuffer<Header, Element: ~Copyable> {
69+
@_preInverseGenerics
70+
public final var header: Header
71+
72+
// CHECK: @"$s4test13ManagedBufferC12_doNotCallMeACyxq_Gyt_tcfCTj"
73+
@_preInverseGenerics
74+
@usableFromInline
75+
internal init(_doNotCallMe: ()) {
76+
fatalError("boom")
77+
}
78+
}

0 commit comments

Comments
 (0)