Skip to content

Commit c8d3506

Browse files
authored
Revert "[Mangling] Uniformly use "So" for imported decls." (#9233)
This reverts commit 25985cb. For now, we're trying to avoid spurious non-structural changes to the mangling, so that the /old/ mangling doesn't appear to change. That doesn't mean no changes at all, but we can save this one for later.
1 parent 7fa0aec commit c8d3506

Some content is hidden

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

41 files changed

+237
-229
lines changed

include/swift/Strings.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ namespace swift {
3939
static const char LLDB_EXPRESSIONS_MODULE_NAME_PREFIX[] = "__lldb_expr_";
4040

4141
/// The name of the fake module used to hold imported Objective-C things.
42-
static const char MANGLING_MODULE_OBJC[] = "__C";
43-
/// The name of the fake module used to hold synthesized ClangImporter things.
44-
static const char MANGLING_MODULE_CLANG_IMPORTER[] = "__C_Synthesized";
42+
static const char MANGLING_MODULE_OBJC[] = "__ObjC";
43+
/// The name of the fake module used to hold imported C things.
44+
static const char MANGLING_MODULE_C[] = "__C";
4545
} // end namespace swift
4646

4747
#endif // SWIFT_STRINGS_H

lib/AST/ASTMangler.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,21 +1073,28 @@ void ASTMangler::appendImplFunctionType(SILFunctionType *fn) {
10731073
/// Mangle the context of the given declaration as a <context.
10741074
/// This is the top-level entrypoint for mangling <context>.
10751075
void ASTMangler::appendContextOf(const ValueDecl *decl) {
1076-
// Declarations provided by a C module have a special context
1076+
auto clangDecl = decl->getClangDecl();
1077+
1078+
// Classes and protocols implemented in Objective-C have a special context
10771079
// mangling.
10781080
// known-context ::= 'So'
1079-
//
1080-
// Also handle top-level imported declarations that don't have corresponding
1081-
// Clang decls. Check getKind() directly to avoid a layering dependency.
1081+
if (isa<ClassDecl>(decl) && clangDecl) {
1082+
assert(isa<clang::ObjCInterfaceDecl>(clangDecl) ||
1083+
isa<clang::TypedefDecl>(clangDecl));
1084+
return appendOperator("So");
1085+
}
1086+
1087+
if (isa<ProtocolDecl>(decl) && clangDecl) {
1088+
assert(isa<clang::ObjCProtocolDecl>(clangDecl));
1089+
return appendOperator("So");
1090+
}
1091+
1092+
// Declarations provided by a C module have a special context mangling.
10821093
// known-context ::= 'SC'
1094+
// Do a dance to avoid a layering dependency.
10831095
if (auto file = dyn_cast<FileUnit>(decl->getDeclContext())) {
1084-
if (file->getKind() == FileUnitKind::ClangModule) {
1085-
// FIXME: Import-as-member Clang decls should appear under 'So' as well,
1086-
// rather than under their current parent.
1087-
if (decl->getClangDecl())
1088-
return appendOperator("So");
1096+
if (file->getKind() == FileUnitKind::ClangModule)
10891097
return appendOperator("SC");
1090-
}
10911098
}
10921099

10931100
// Just mangle the decl's DC.
@@ -1285,7 +1292,7 @@ void ASTMangler::appendModule(const ModuleDecl *module) {
12851292
StringRef ModName = module->getName().str();
12861293
if (ModName == MANGLING_MODULE_OBJC)
12871294
return appendOperator("So");
1288-
if (ModName == MANGLING_MODULE_CLANG_IMPORTER)
1295+
if (ModName == MANGLING_MODULE_C)
12891296
return appendOperator("SC");
12901297

12911298
appendIdentifier(ModName);

lib/Demangling/Demangler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ NodePointer Demangler::demangleStandardSubstitution() {
505505
case 'o':
506506
return createNode(Node::Kind::Module, MANGLING_MODULE_OBJC);
507507
case 'C':
508-
return createNode(Node::Kind::Module, MANGLING_MODULE_CLANG_IMPORTER);
508+
return createNode(Node::Kind::Module, MANGLING_MODULE_C);
509509
case 'g': {
510510
NodePointer OptionalTy =
511511
createType(createWithChildren(Node::Kind::BoundGenericEnum,

lib/Demangling/OldDemangler.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -863,8 +863,7 @@ class OldDemangler {
863863
if (Mangled.nextIf('o'))
864864
return Factory.createNode(Node::Kind::Module, MANGLING_MODULE_OBJC);
865865
if (Mangled.nextIf('C'))
866-
return Factory.createNode(Node::Kind::Module,
867-
MANGLING_MODULE_CLANG_IMPORTER);
866+
return Factory.createNode(Node::Kind::Module, MANGLING_MODULE_C);
868867
if (Mangled.nextIf('a'))
869868
return createSwiftType(Node::Kind::Structure, "Array");
870869
if (Mangled.nextIf('b'))

lib/Demangling/OldRemangler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ bool Remangler::mangleStandardSubstitution(Node *node) {
357357
case Node::Kind::Module:
358358
SUCCESS_IF_TEXT_IS(STDLIB_NAME, "s");
359359
SUCCESS_IF_TEXT_IS(MANGLING_MODULE_OBJC, "So");
360-
SUCCESS_IF_TEXT_IS(MANGLING_MODULE_CLANG_IMPORTER, "SC");
360+
SUCCESS_IF_TEXT_IS(MANGLING_MODULE_C, "SC");
361361
break;
362362
case Node::Kind::Structure:
363363
if (isInSwiftModule(node)) {

lib/Demangling/Remangler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1292,7 +1292,7 @@ void Remangler::mangleModule(Node *node) {
12921292
Buffer << 's';
12931293
} else if (node->getText() == MANGLING_MODULE_OBJC) {
12941294
Buffer << "So";
1295-
} else if (node->getText() == MANGLING_MODULE_CLANG_IMPORTER) {
1295+
} else if (node->getText() == MANGLING_MODULE_C) {
12961296
Buffer << "SC";
12971297
} else {
12981298
mangleIdentifier(node);

lib/IDE/TypeReconstruction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class DeclsLookupSource {
101101
assert(!module_name.empty());
102102
static ConstString g_ObjectiveCModule(MANGLING_MODULE_OBJC);
103103
static ConstString g_BuiltinModule("Builtin");
104-
static ConstString g_CModule(MANGLING_MODULE_CLANG_IMPORTER);
104+
static ConstString g_CModule(MANGLING_MODULE_C);
105105
if (allow_crawler) {
106106
if (module_name == g_ObjectiveCModule || module_name == g_CModule)
107107
return DeclsLookupSource(&ast, module_name);

lib/RemoteAST/RemoteAST.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
#include "swift/RemoteAST/RemoteAST.h"
1818
#include "swift/Remote/MetadataReader.h"
19-
#include "swift/Strings.h"
2019
#include "swift/Subsystems.h"
2120
#include "swift/AST/ASTContext.h"
2221
#include "swift/AST/Decl.h"
@@ -523,8 +522,7 @@ bool RemoteASTTypeBuilder::isForeignModule(const Demangle::NodePointer &node) {
523522
if (node->getKind() != Demangle::Node::Kind::Module)
524523
return false;
525524

526-
return (node->getText() == MANGLING_MODULE_OBJC ||
527-
node->getText() == MANGLING_MODULE_CLANG_IMPORTER);
525+
return (node->getText() == "__ObjC");
528526
}
529527

530528
DeclContext *

stdlib/public/runtime/Demangle.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ swift::_swift_buildDemanglingForMetadata(const Metadata *type,
131131
auto objcWrapper = static_cast<const ObjCClassWrapperMetadata *>(type);
132132
const char *className = class_getName((Class)objcWrapper->Class);
133133

134-
auto module = Dem.createNode(Node::Kind::Module, MANGLING_MODULE_OBJC);
134+
// ObjC classes mangle as being in the magic "__ObjC" module.
135+
auto module = Dem.createNode(Node::Kind::Module, "__ObjC");
136+
135137
auto node = Dem.createNode(Node::Kind::Class);
136138
node->addChild(module, Dem);
137139
node->addChild(Dem.createNode(Node::Kind::Identifier,

test/APINotes/versioned.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ func testAKA(structValue: ImportantCStruct, aliasValue: ImportantCAlias) {
8888

8989
#if !swift(>=4)
9090
func useSwift3Name(_: ImportantCStruct) {}
91-
// CHECK-SILGEN-3: sil hidden @_T09versioned13useSwift3NameySo20VeryImportantCStructVF
91+
// CHECK-SILGEN-3: sil hidden @_T09versioned13useSwift3NameySC20VeryImportantCStructVF
9292

9393
func useNewlyNested(_: InnerInSwift4) {}
94-
// CHECK-SILGEN-3: sil hidden @_T09versioned14useNewlyNestedySo5OuterV5InnerVF
94+
// CHECK-SILGEN-3: sil hidden @_T09versioned14useNewlyNestedySC5OuterV5InnerVF
9595
#endif
9696

9797
func useSwift4Name(_: VeryImportantCStruct) {}
98-
// CHECK-SILGEN: sil hidden @_T09versioned13useSwift4NameySo20VeryImportantCStructVF
98+
// CHECK-SILGEN: sil hidden @_T09versioned13useSwift4NameySC20VeryImportantCStructVF
9999

test/ClangImporter/ctypes_ir.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func testStructWithFlexibleArray(_ s : StructWithFlexibleArray) {
2727
}
2828

2929
// Make sure flexible array struct member isn't represented in IR function signature as i0 (or at all). rdar://problem/18510461
30-
// CHECK-LABEL: define hidden swiftcc void @_T09ctypes_ir27testStructWithFlexibleArrayySo0defG0VF(i32)
30+
// CHECK-LABEL: define hidden swiftcc void @_T09ctypes_ir27testStructWithFlexibleArrayySC0defG0VF(i32)
3131

3232
typealias EightUp = (Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8)
3333

test/Demangle/Inputs/manglings.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ _TtGSqSS_ ---> Swift.String?
2525
_TtGSQSS_ ---> Swift.String!
2626
_TtGVs10DictionarySSSi_ ---> [Swift.String : Swift.Int]
2727
_TtVs7CString ---> Swift.CString
28-
_TtCSo8NSObject ---> __C.NSObject
28+
_TtCSo8NSObject ---> __ObjC.NSObject
2929
_TtO6Monads6Either ---> Monads.Either
3030
_TtbSiSu ---> @convention(block) (Swift.Int) -> Swift.UInt
3131
_TtcSiSu ---> @convention(c) (Swift.Int) -> Swift.UInt
@@ -78,11 +78,11 @@ _TF3foog3barSi ---> foo.bar.getter : Swift.Int
7878
_TF3foos3barSi ---> foo.bar.setter : Swift.Int
7979
_TFC3foo3bar3basfT3zimCS_3zim_T_ ---> foo.bar.bas(zim: foo.zim) -> ()
8080
_TToFC3foo3bar3basfT3zimCS_3zim_T_ ---> {T:_TFC3foo3bar3basfT3zimCS_3zim_T_,C} @objc foo.bar.bas(zim: foo.zim) -> ()
81-
_TTOFSC3fooFTSdSd_Sd ---> {T:_TFSC3fooFTSdSd_Sd} @nonobjc __C_Synthesized.foo(Swift.Double, Swift.Double) -> Swift.Double
81+
_TTOFSC3fooFTSdSd_Sd ---> {T:_TFSC3fooFTSdSd_Sd} @nonobjc __C.foo(Swift.Double, Swift.Double) -> Swift.Double
8282
_T03foo3barC3basyAA3zimCAE_tFTo ---> {T:_T03foo3barC3basyAA3zimCAE_tF,C} @objc foo.bar.bas(zim: foo.zim) -> ()
83-
_T0SC3fooS2d_SdtFTO ---> {T:_T0SC3fooS2d_SdtF} @nonobjc __C_Synthesized.foo(Swift.Double, Swift.Double) -> Swift.Double
83+
_T0SC3fooS2d_SdtFTO ---> {T:_T0SC3fooS2d_SdtF} @nonobjc __C.foo(Swift.Double, Swift.Double) -> Swift.Double
8484
_S3foo3barC3basyAA3zimCAE_tFTo ---> {T:_S3foo3barC3basyAA3zimCAE_tF,C} @objc foo.bar.bas(zim: foo.zim) -> ()
85-
_SSC3fooS2d_SdtFTO ---> {T:_SSC3fooS2d_SdtF} @nonobjc __C_Synthesized.foo(Swift.Double, Swift.Double) -> Swift.Double
85+
_SSC3fooS2d_SdtFTO ---> {T:_SSC3fooS2d_SdtF} @nonobjc __C.foo(Swift.Double, Swift.Double) -> Swift.Double
8686
_TTDFC3foo3bar3basfT3zimCS_3zim_T_ ---> dynamic foo.bar.bas(zim: foo.zim) -> ()
8787
_TFC3foo3bar3basfT3zimCS_3zim_T_ ---> foo.bar.bas(zim: foo.zim) -> ()
8888
_TF3foooi1pFTCS_3barVS_3bas_OS_3zim ---> foo.+ infix(foo.bar, foo.bas) -> foo.zim
@@ -120,7 +120,7 @@ _TWGC3foo3barS_8barrableS_ ---> generic protocol witness table for foo.bar : foo
120120
_TWIC3foo3barS_8barrableS_ ---> {C} instantiation function for generic protocol witness table for foo.bar : foo.barrable in foo
121121
_TWtC3foo3barS_8barrableS_4fred ---> {C} associated type metadata accessor for fred in foo.bar : foo.barrable in foo
122122
_TWTC3foo3barS_8barrableS_4fredS_6thomas ---> {C} associated type witness table accessor for fred : foo.thomas in foo.bar : foo.barrable in foo
123-
_TFSCg5greenVSC5Color ---> __C_Synthesized.green.getter : __C_Synthesized.Color
123+
_TFSCg5greenVSC5Color ---> __C.green.getter : __C.Color
124124
_TIF1t1fFT1iSi1sSS_T_A_ ---> default argument 0 of t.f(i: Swift.Int, s: Swift.String) -> ()
125125
_TIF1t1fFT1iSi1sSS_T_A0_ ---> default argument 1 of t.f(i: Swift.Int, s: Swift.String) -> ()
126126
_TFSqcfT_GSqx_ ---> Swift.Optional.init() -> A?
@@ -169,8 +169,8 @@ _TFCF5types1gFT1bSb_T_L0_10Collection3zimfT_T_ ---> zim() -> () in Collection #2
169169
_TFF17capture_promotion22test_capture_promotionFT_FT_SiU_FT_Si_promote0 ---> closure #1 () -> Swift.Int in capture_promotion.test_capture_promotion() -> () -> Swift.Int with unmangled suffix "_promote0"
170170
_TFIVs8_Processi10_argumentsGSaSS_U_FT_GSaSS_ ---> _arguments : [Swift.String] in variable initialization expression of Swift._Process with unmangled suffix "U_FT_GSaSS_"
171171
_TFIvVs8_Process10_argumentsGSaSS_iU_FT_GSaSS_ ---> closure #1 () -> [Swift.String] in variable initialization expression of Swift._Process._arguments : [Swift.String]
172-
_TFCSo1AE ---> __C.A.__ivar_destroyer
173-
_TFCSo1Ae ---> __C.A.__ivar_initializer
172+
_TFCSo1AE ---> __ObjC.A.__ivar_destroyer
173+
_TFCSo1Ae ---> __ObjC.A.__ivar_initializer
174174
_TTWC13call_protocol1CS_1PS_FS1_3foofT_Si ---> protocol witness for call_protocol.P.foo() -> Swift.Int in conformance call_protocol.C : call_protocol.P in call_protocol
175175
_T013call_protocol1CCAA1PA2aDP3fooSiyFTW ---> {T:} protocol witness for call_protocol.P.foo() -> Swift.Int in conformance call_protocol.C : call_protocol.P in call_protocol
176176
_TFC12dynamic_self1X1ffT_DS0_ ---> dynamic_self.X.f() -> Self
@@ -249,7 +249,7 @@ _T0s10DictionaryV3t17E6Index2V1loiSbAEyxq__G_AGtFZ ---> static (extension in t17
249249
_T08mangling14varargsVsArrayySaySiG3arrd_SS1ntF ---> mangling.varargsVsArray(arr: Swift.Int..., n: Swift.String) -> ()
250250
_T08mangling14varargsVsArrayySaySiG3arrd_tF ---> mangling.varargsVsArray(arr: Swift.Int...) -> ()
251251
_T0s13_UnicodeViewsVss22RandomAccessCollectionRzs0A8EncodingR_11SubSequence_5IndexQZAFRtzsAcERpzAE_AEQZAIRSs15UnsignedInteger8Iterator_7ElementRPzAE_AlMQZANRS13EncodedScalar_AlMQY_AORSr0_lE13CharacterViewVyxq__G ---> (extension in Swift):Swift._UnicodeViews<A, B><A, B where A: Swift.RandomAccessCollection, B: Swift.UnicodeEncoding, A.Index == A.SubSequence.Index, A.SubSequence: Swift.RandomAccessCollection, A.SubSequence == A.SubSequence.SubSequence, A.Iterator.Element: Swift.UnsignedInteger, A.Iterator.Element == A.SubSequence.Iterator.Element, A.SubSequence.Iterator.Element == B.EncodedScalar.Iterator.Element>.CharacterView
252-
_T010Foundation11MeasurementV12SimulatorKitSo9UnitAngleCRszlE11OrientationO2eeoiSbAcDEAGOyAF_G_AKtFZ ---> static (extension in SimulatorKit):Foundation.Measurement<A where A == __C.UnitAngle>.Orientation.== infix((extension in SimulatorKit):Foundation.Measurement<__C.UnitAngle>.Orientation, (extension in SimulatorKit):Foundation.Measurement<__C.UnitAngle>.Orientation) -> Swift.Bool
252+
_T010Foundation11MeasurementV12SimulatorKitSo9UnitAngleCRszlE11OrientationO2eeoiSbAcDEAGOyAF_G_AKtFZ ---> static (extension in SimulatorKit):Foundation.Measurement<A where A == __ObjC.UnitAngle>.Orientation.== infix((extension in SimulatorKit):Foundation.Measurement<__ObjC.UnitAngle>.Orientation, (extension in SimulatorKit):Foundation.Measurement<__ObjC.UnitAngle>.Orientation) -> Swift.Bool
253253
_T04main1_yyF ---> main._() -> ()
254254
_T04test6testitSiyt_tF ---> test.testit(()) -> Swift.Int
255255

0 commit comments

Comments
 (0)