Skip to content

Revert "[Mangling] Uniformly use "So" for imported decls." #9233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions include/swift/Strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ namespace swift {
static const char LLDB_EXPRESSIONS_MODULE_NAME_PREFIX[] = "__lldb_expr_";

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

#endif // SWIFT_STRINGS_H
29 changes: 18 additions & 11 deletions lib/AST/ASTMangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1073,21 +1073,28 @@ void ASTMangler::appendImplFunctionType(SILFunctionType *fn) {
/// Mangle the context of the given declaration as a <context.
/// This is the top-level entrypoint for mangling <context>.
void ASTMangler::appendContextOf(const ValueDecl *decl) {
// Declarations provided by a C module have a special context
auto clangDecl = decl->getClangDecl();

// Classes and protocols implemented in Objective-C have a special context
// mangling.
// known-context ::= 'So'
//
// Also handle top-level imported declarations that don't have corresponding
// Clang decls. Check getKind() directly to avoid a layering dependency.
if (isa<ClassDecl>(decl) && clangDecl) {
assert(isa<clang::ObjCInterfaceDecl>(clangDecl) ||
isa<clang::TypedefDecl>(clangDecl));
return appendOperator("So");
}

if (isa<ProtocolDecl>(decl) && clangDecl) {
assert(isa<clang::ObjCProtocolDecl>(clangDecl));
return appendOperator("So");
}

// Declarations provided by a C module have a special context mangling.
// known-context ::= 'SC'
// Do a dance to avoid a layering dependency.
if (auto file = dyn_cast<FileUnit>(decl->getDeclContext())) {
if (file->getKind() == FileUnitKind::ClangModule) {
// FIXME: Import-as-member Clang decls should appear under 'So' as well,
// rather than under their current parent.
if (decl->getClangDecl())
return appendOperator("So");
if (file->getKind() == FileUnitKind::ClangModule)
return appendOperator("SC");
}
}

// Just mangle the decl's DC.
Expand Down Expand Up @@ -1285,7 +1292,7 @@ void ASTMangler::appendModule(const ModuleDecl *module) {
StringRef ModName = module->getName().str();
if (ModName == MANGLING_MODULE_OBJC)
return appendOperator("So");
if (ModName == MANGLING_MODULE_CLANG_IMPORTER)
if (ModName == MANGLING_MODULE_C)
return appendOperator("SC");

appendIdentifier(ModName);
Expand Down
2 changes: 1 addition & 1 deletion lib/Demangling/Demangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ NodePointer Demangler::demangleStandardSubstitution() {
case 'o':
return createNode(Node::Kind::Module, MANGLING_MODULE_OBJC);
case 'C':
return createNode(Node::Kind::Module, MANGLING_MODULE_CLANG_IMPORTER);
return createNode(Node::Kind::Module, MANGLING_MODULE_C);
case 'g': {
NodePointer OptionalTy =
createType(createWithChildren(Node::Kind::BoundGenericEnum,
Expand Down
3 changes: 1 addition & 2 deletions lib/Demangling/OldDemangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -863,8 +863,7 @@ class OldDemangler {
if (Mangled.nextIf('o'))
return Factory.createNode(Node::Kind::Module, MANGLING_MODULE_OBJC);
if (Mangled.nextIf('C'))
return Factory.createNode(Node::Kind::Module,
MANGLING_MODULE_CLANG_IMPORTER);
return Factory.createNode(Node::Kind::Module, MANGLING_MODULE_C);
if (Mangled.nextIf('a'))
return createSwiftType(Node::Kind::Structure, "Array");
if (Mangled.nextIf('b'))
Expand Down
2 changes: 1 addition & 1 deletion lib/Demangling/OldRemangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ bool Remangler::mangleStandardSubstitution(Node *node) {
case Node::Kind::Module:
SUCCESS_IF_TEXT_IS(STDLIB_NAME, "s");
SUCCESS_IF_TEXT_IS(MANGLING_MODULE_OBJC, "So");
SUCCESS_IF_TEXT_IS(MANGLING_MODULE_CLANG_IMPORTER, "SC");
SUCCESS_IF_TEXT_IS(MANGLING_MODULE_C, "SC");
break;
case Node::Kind::Structure:
if (isInSwiftModule(node)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Demangling/Remangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1292,7 +1292,7 @@ void Remangler::mangleModule(Node *node) {
Buffer << 's';
} else if (node->getText() == MANGLING_MODULE_OBJC) {
Buffer << "So";
} else if (node->getText() == MANGLING_MODULE_CLANG_IMPORTER) {
} else if (node->getText() == MANGLING_MODULE_C) {
Buffer << "SC";
} else {
mangleIdentifier(node);
Expand Down
2 changes: 1 addition & 1 deletion lib/IDE/TypeReconstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class DeclsLookupSource {
assert(!module_name.empty());
static ConstString g_ObjectiveCModule(MANGLING_MODULE_OBJC);
static ConstString g_BuiltinModule("Builtin");
static ConstString g_CModule(MANGLING_MODULE_CLANG_IMPORTER);
static ConstString g_CModule(MANGLING_MODULE_C);
if (allow_crawler) {
if (module_name == g_ObjectiveCModule || module_name == g_CModule)
return DeclsLookupSource(&ast, module_name);
Expand Down
4 changes: 1 addition & 3 deletions lib/RemoteAST/RemoteAST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#include "swift/RemoteAST/RemoteAST.h"
#include "swift/Remote/MetadataReader.h"
#include "swift/Strings.h"
#include "swift/Subsystems.h"
#include "swift/AST/ASTContext.h"
#include "swift/AST/Decl.h"
Expand Down Expand Up @@ -523,8 +522,7 @@ bool RemoteASTTypeBuilder::isForeignModule(const Demangle::NodePointer &node) {
if (node->getKind() != Demangle::Node::Kind::Module)
return false;

return (node->getText() == MANGLING_MODULE_OBJC ||
node->getText() == MANGLING_MODULE_CLANG_IMPORTER);
return (node->getText() == "__ObjC");
}

DeclContext *
Expand Down
4 changes: 3 additions & 1 deletion stdlib/public/runtime/Demangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ swift::_swift_buildDemanglingForMetadata(const Metadata *type,
auto objcWrapper = static_cast<const ObjCClassWrapperMetadata *>(type);
const char *className = class_getName((Class)objcWrapper->Class);

auto module = Dem.createNode(Node::Kind::Module, MANGLING_MODULE_OBJC);
// ObjC classes mangle as being in the magic "__ObjC" module.
auto module = Dem.createNode(Node::Kind::Module, "__ObjC");

auto node = Dem.createNode(Node::Kind::Class);
node->addChild(module, Dem);
node->addChild(Dem.createNode(Node::Kind::Identifier,
Expand Down
6 changes: 3 additions & 3 deletions test/APINotes/versioned.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ func testAKA(structValue: ImportantCStruct, aliasValue: ImportantCAlias) {

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

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

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

2 changes: 1 addition & 1 deletion test/ClangImporter/ctypes_ir.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func testStructWithFlexibleArray(_ s : StructWithFlexibleArray) {
}

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

typealias EightUp = (Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8)

Expand Down
16 changes: 8 additions & 8 deletions test/Demangle/Inputs/manglings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ _TtGSqSS_ ---> Swift.String?
_TtGSQSS_ ---> Swift.String!
_TtGVs10DictionarySSSi_ ---> [Swift.String : Swift.Int]
_TtVs7CString ---> Swift.CString
_TtCSo8NSObject ---> __C.NSObject
_TtCSo8NSObject ---> __ObjC.NSObject
_TtO6Monads6Either ---> Monads.Either
_TtbSiSu ---> @convention(block) (Swift.Int) -> Swift.UInt
_TtcSiSu ---> @convention(c) (Swift.Int) -> Swift.UInt
Expand Down Expand Up @@ -78,11 +78,11 @@ _TF3foog3barSi ---> foo.bar.getter : Swift.Int
_TF3foos3barSi ---> foo.bar.setter : Swift.Int
_TFC3foo3bar3basfT3zimCS_3zim_T_ ---> foo.bar.bas(zim: foo.zim) -> ()
_TToFC3foo3bar3basfT3zimCS_3zim_T_ ---> {T:_TFC3foo3bar3basfT3zimCS_3zim_T_,C} @objc foo.bar.bas(zim: foo.zim) -> ()
_TTOFSC3fooFTSdSd_Sd ---> {T:_TFSC3fooFTSdSd_Sd} @nonobjc __C_Synthesized.foo(Swift.Double, Swift.Double) -> Swift.Double
_TTOFSC3fooFTSdSd_Sd ---> {T:_TFSC3fooFTSdSd_Sd} @nonobjc __C.foo(Swift.Double, Swift.Double) -> Swift.Double
_T03foo3barC3basyAA3zimCAE_tFTo ---> {T:_T03foo3barC3basyAA3zimCAE_tF,C} @objc foo.bar.bas(zim: foo.zim) -> ()
_T0SC3fooS2d_SdtFTO ---> {T:_T0SC3fooS2d_SdtF} @nonobjc __C_Synthesized.foo(Swift.Double, Swift.Double) -> Swift.Double
_T0SC3fooS2d_SdtFTO ---> {T:_T0SC3fooS2d_SdtF} @nonobjc __C.foo(Swift.Double, Swift.Double) -> Swift.Double
_S3foo3barC3basyAA3zimCAE_tFTo ---> {T:_S3foo3barC3basyAA3zimCAE_tF,C} @objc foo.bar.bas(zim: foo.zim) -> ()
_SSC3fooS2d_SdtFTO ---> {T:_SSC3fooS2d_SdtF} @nonobjc __C_Synthesized.foo(Swift.Double, Swift.Double) -> Swift.Double
_SSC3fooS2d_SdtFTO ---> {T:_SSC3fooS2d_SdtF} @nonobjc __C.foo(Swift.Double, Swift.Double) -> Swift.Double
_TTDFC3foo3bar3basfT3zimCS_3zim_T_ ---> dynamic foo.bar.bas(zim: foo.zim) -> ()
_TFC3foo3bar3basfT3zimCS_3zim_T_ ---> foo.bar.bas(zim: foo.zim) -> ()
_TF3foooi1pFTCS_3barVS_3bas_OS_3zim ---> foo.+ infix(foo.bar, foo.bas) -> foo.zim
Expand Down Expand Up @@ -120,7 +120,7 @@ _TWGC3foo3barS_8barrableS_ ---> generic protocol witness table for foo.bar : foo
_TWIC3foo3barS_8barrableS_ ---> {C} instantiation function for generic protocol witness table for foo.bar : foo.barrable in foo
_TWtC3foo3barS_8barrableS_4fred ---> {C} associated type metadata accessor for fred in foo.bar : foo.barrable in foo
_TWTC3foo3barS_8barrableS_4fredS_6thomas ---> {C} associated type witness table accessor for fred : foo.thomas in foo.bar : foo.barrable in foo
_TFSCg5greenVSC5Color ---> __C_Synthesized.green.getter : __C_Synthesized.Color
_TFSCg5greenVSC5Color ---> __C.green.getter : __C.Color
_TIF1t1fFT1iSi1sSS_T_A_ ---> default argument 0 of t.f(i: Swift.Int, s: Swift.String) -> ()
_TIF1t1fFT1iSi1sSS_T_A0_ ---> default argument 1 of t.f(i: Swift.Int, s: Swift.String) -> ()
_TFSqcfT_GSqx_ ---> Swift.Optional.init() -> A?
Expand Down Expand Up @@ -169,8 +169,8 @@ _TFCF5types1gFT1bSb_T_L0_10Collection3zimfT_T_ ---> zim() -> () in Collection #2
_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"
_TFIVs8_Processi10_argumentsGSaSS_U_FT_GSaSS_ ---> _arguments : [Swift.String] in variable initialization expression of Swift._Process with unmangled suffix "U_FT_GSaSS_"
_TFIvVs8_Process10_argumentsGSaSS_iU_FT_GSaSS_ ---> closure #1 () -> [Swift.String] in variable initialization expression of Swift._Process._arguments : [Swift.String]
_TFCSo1AE ---> __C.A.__ivar_destroyer
_TFCSo1Ae ---> __C.A.__ivar_initializer
_TFCSo1AE ---> __ObjC.A.__ivar_destroyer
_TFCSo1Ae ---> __ObjC.A.__ivar_initializer
_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
_T013call_protocol1CCAA1PA2aDP3fooSiyFTW ---> {T:} protocol witness for call_protocol.P.foo() -> Swift.Int in conformance call_protocol.C : call_protocol.P in call_protocol
_TFC12dynamic_self1X1ffT_DS0_ ---> dynamic_self.X.f() -> Self
Expand Down Expand Up @@ -249,7 +249,7 @@ _T0s10DictionaryV3t17E6Index2V1loiSbAEyxq__G_AGtFZ ---> static (extension in t17
_T08mangling14varargsVsArrayySaySiG3arrd_SS1ntF ---> mangling.varargsVsArray(arr: Swift.Int..., n: Swift.String) -> ()
_T08mangling14varargsVsArrayySaySiG3arrd_tF ---> mangling.varargsVsArray(arr: Swift.Int...) -> ()
_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
_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
_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
_T04main1_yyF ---> main._() -> ()
_T04test6testitSiyt_tF ---> test.testit(()) -> Swift.Int

Loading