Skip to content

Commit c9d490c

Browse files
committed
Revert "Merge pull request #30612 from aschwaighofer/irgen_also_unique_ext_method_types_list"
This reverts commit f0cdd76, reversing changes made to 703fe0f. Revert "IRGen: Refactor getObjCEncodingForMethod and getObjectEncodingFromClangNode into one" This reverts commit 0082682. Revert "Merge pull request #30438 from aschwaighofer/irgen_prefer_clang_type_encoding" This reverts commit eeb7fa5, reversing changes made to 77af77f. Revert "Merge pull request #30433 from aschwaighofer/irgen_no_duplicate_objc_method_descriptor_entries" This reverts commit 77af77f, reversing changes made to 841eeb0. This reverts the changes for rdar://60461850, rdar://60474785, rdar://60778637 There is still at least an issue that we address with PR#30654. Revert until we have confidence that this is the right fix set.
1 parent 4981da4 commit c9d490c

File tree

6 files changed

+38
-137
lines changed

6 files changed

+38
-137
lines changed

lib/IRGen/GenClass.cpp

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,33 +1521,27 @@ namespace {
15211521
}
15221522

15231523
void buildMethod(ConstantArrayBuilder &descriptors,
1524-
MethodDescriptor descriptor,
1525-
llvm::StringSet<> &uniqueSelectors) {
1524+
MethodDescriptor descriptor) {
15261525
switch (descriptor.getKind()) {
15271526
case MethodDescriptor::Kind::Method:
1528-
return buildMethod(descriptors, descriptor.getMethod(),
1529-
uniqueSelectors);
1527+
return buildMethod(descriptors, descriptor.getMethod());
15301528
case MethodDescriptor::Kind::IVarInitializer:
15311529
emitObjCIVarInitDestroyDescriptor(IGM, descriptors, getClass(),
1532-
descriptor.getImpl(), false,
1533-
uniqueSelectors);
1530+
descriptor.getImpl(), false);
15341531
return;
15351532
case MethodDescriptor::Kind::IVarDestroyer:
15361533
emitObjCIVarInitDestroyDescriptor(IGM, descriptors, getClass(),
1537-
descriptor.getImpl(), true,
1538-
uniqueSelectors);
1534+
descriptor.getImpl(), true);
15391535
return;
15401536
}
15411537
llvm_unreachable("bad method descriptor kind");
15421538
}
15431539

15441540
void buildMethod(ConstantArrayBuilder &descriptors,
1545-
AbstractFunctionDecl *method,
1546-
llvm::StringSet<> &uniqueSelectors) {
1541+
AbstractFunctionDecl *method) {
15471542
auto accessor = dyn_cast<AccessorDecl>(method);
15481543
if (!accessor)
1549-
return emitObjCMethodDescriptor(IGM, descriptors, method,
1550-
uniqueSelectors);
1544+
return emitObjCMethodDescriptor(IGM, descriptors, method);
15511545

15521546
switch (accessor->getAccessorKind()) {
15531547
case AccessorKind::Get:
@@ -1616,9 +1610,7 @@ namespace {
16161610
namePrefix = "_PROTOCOL_INSTANCE_METHODS_OPT_";
16171611
break;
16181612
}
1619-
llvm::StringSet<> uniqueSelectors;
1620-
llvm::Constant *methodListPtr =
1621-
buildMethodList(methods, namePrefix, uniqueSelectors);
1613+
llvm::Constant *methodListPtr = buildMethodList(methods, namePrefix);
16221614
builder.add(methodListPtr);
16231615
}
16241616

@@ -1644,15 +1636,12 @@ namespace {
16441636
void buildExtMethodTypes(ConstantArrayBuilder &array,
16451637
ArrayRef<MethodDescriptor> methods) {
16461638
assert(isBuildingProtocol());
1647-
llvm::StringSet<> uniqueSelectors;
1639+
16481640
for (auto descriptor : methods) {
16491641
assert(descriptor.getKind() == MethodDescriptor::Kind::Method &&
16501642
"cannot emit descriptor for non-method");
16511643
auto method = descriptor.getMethod();
1652-
auto *encodingOrNullIfDuplicate =
1653-
getMethodTypeExtendedEncoding(IGM, method, uniqueSelectors);
1654-
if (encodingOrNullIfDuplicate != nullptr)
1655-
array.add(encodingOrNullIfDuplicate);
1644+
array.add(getMethodTypeExtendedEncoding(IGM, method));
16561645
}
16571646
}
16581647

@@ -1664,12 +1653,11 @@ namespace {
16641653
///
16651654
/// This method does not return a value of a predictable type.
16661655
llvm::Constant *buildMethodList(ArrayRef<MethodDescriptor> methods,
1667-
StringRef name,
1668-
llvm::StringSet<> &uniqueSelectors) {
1656+
StringRef name) {
16691657
return buildOptionalList(methods, 3 * IGM.getPointerSize(), name,
16701658
[&](ConstantArrayBuilder &descriptors,
16711659
MethodDescriptor descriptor) {
1672-
buildMethod(descriptors, descriptor, uniqueSelectors);
1660+
buildMethod(descriptors, descriptor);
16731661
});
16741662
}
16751663

lib/IRGen/GenObjC.cpp

Lines changed: 21 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,41 +1100,9 @@ static llvm::Constant *getObjCEncodingForTypes(IRGenModule &IGM,
11001100
return IGM.getAddrOfGlobalString(encodingString);
11011101
}
11021102

1103-
static llvm::Constant *
1104-
getObjectEncodingFromClangNode(IRGenModule &IGM, Decl *d,
1105-
bool useExtendedEncoding) {
1106-
// Use the clang node's encoding if there is a clang node.
1107-
if (d->getClangNode()) {
1108-
auto clangDecl = d->getClangNode().castAsDecl();
1109-
auto &clangASTContext = IGM.getClangASTContext();
1110-
std::string typeStr;
1111-
if (auto objcMethodDecl = dyn_cast<clang::ObjCMethodDecl>(clangDecl)) {
1112-
typeStr = clangASTContext.getObjCEncodingForMethodDecl(
1113-
objcMethodDecl, useExtendedEncoding /*extended*/);
1114-
}
1115-
if (auto objcPropertyDecl = dyn_cast<clang::ObjCPropertyDecl>(clangDecl)) {
1116-
typeStr = clangASTContext.getObjCEncodingForPropertyDecl(objcPropertyDecl,
1117-
nullptr);
1118-
}
1119-
if (!typeStr.empty()) {
1120-
return IGM.getAddrOfGlobalString(typeStr.c_str());
1121-
}
1122-
}
1123-
return nullptr;
1124-
}
1125-
1126-
static llvm::Constant *getObjCEncodingForMethod(IRGenModule &IGM,
1127-
CanSILFunctionType fnType,
1128-
bool useExtendedEncoding,
1129-
Decl *optionalDecl) {
1130-
// Use the decl's ClangNode to get the encoding if possible.
1131-
if (optionalDecl) {
1132-
if (auto *enc = getObjectEncodingFromClangNode(IGM, optionalDecl,
1133-
useExtendedEncoding)) {
1134-
return enc;
1135-
}
1136-
}
1137-
1103+
static llvm::Constant *getObjCEncodingForMethodType(IRGenModule &IGM,
1104+
CanSILFunctionType fnType,
1105+
bool useExtendedEncoding) {
11381106
// Get the inputs without 'self'.
11391107
auto inputs = fnType->getParameters().drop_back();
11401108

@@ -1160,13 +1128,11 @@ irgen::emitObjCMethodDescriptorParts(IRGenModule &IGM,
11601128
/// The first element is the selector.
11611129
descriptor.selectorRef = IGM.getAddrOfObjCMethodName(selector.str());
11621130

1163-
/// The second element is the method signature. A method signature is made
1164-
/// of the return type @encoding and every parameter type @encoding, glued
1165-
/// with numbers that used to represent stack offsets for each of these
1166-
/// elements.
1131+
/// The second element is the method signature. A method signature is made of
1132+
/// the return type @encoding and every parameter type @encoding, glued with
1133+
/// numbers that used to represent stack offsets for each of these elements.
11671134
CanSILFunctionType methodType = getObjCMethodType(IGM, method);
1168-
descriptor.typeEncoding =
1169-
getObjCEncodingForMethod(IGM, methodType, /*extended*/ false, method);
1135+
descriptor.typeEncoding = getObjCEncodingForMethodType(IGM, methodType, /*extended*/false);
11701136

11711137
/// The third element is the method implementation pointer.
11721138
if (!concrete) {
@@ -1225,13 +1191,10 @@ irgen::emitObjCGetterDescriptorParts(IRGenModule &IGM,
12251191
Selector getterSel(subscript, Selector::ForGetter);
12261192
ObjCMethodDescriptor descriptor{};
12271193
descriptor.selectorRef = IGM.getAddrOfObjCMethodName(getterSel.str());
1228-
1229-
auto methodTy =
1230-
getObjCMethodType(IGM, subscript->getOpaqueAccessor(AccessorKind::Get));
1231-
descriptor.typeEncoding =
1232-
getObjCEncodingForMethod(IGM, methodTy,
1233-
/*extended*/ false, subscript);
1234-
1194+
auto methodTy = getObjCMethodType(IGM,
1195+
subscript->getOpaqueAccessor(AccessorKind::Get));
1196+
descriptor.typeEncoding = getObjCEncodingForMethodType(IGM, methodTy,
1197+
/*extended*/false);
12351198
descriptor.silFunction = nullptr;
12361199
descriptor.impl = getObjCGetterPointer(IGM, subscript,
12371200
descriptor.silFunction);
@@ -1303,9 +1266,8 @@ irgen::emitObjCSetterDescriptorParts(IRGenModule &IGM,
13031266
descriptor.selectorRef = IGM.getAddrOfObjCMethodName(setterSel.str());
13041267
auto methodTy = getObjCMethodType(IGM,
13051268
subscript->getOpaqueAccessor(AccessorKind::Set));
1306-
descriptor.typeEncoding =
1307-
getObjCEncodingForMethod(IGM, methodTy,
1308-
/*extended*/ false, subscript);
1269+
descriptor.typeEncoding = getObjCEncodingForMethodType(IGM, methodTy,
1270+
/*extended*/false);
13091271
descriptor.silFunction = nullptr;
13101272
descriptor.impl = getObjCSetterPointer(IGM, subscript,
13111273
descriptor.silFunction);
@@ -1361,33 +1323,23 @@ static void emitObjCDescriptor(IRGenModule &IGM,
13611323
/// };
13621324
void irgen::emitObjCMethodDescriptor(IRGenModule &IGM,
13631325
ConstantArrayBuilder &descriptors,
1364-
AbstractFunctionDecl *method,
1365-
llvm::StringSet<> &uniqueSelectors) {
1366-
// Don't emit a selector twice.
1367-
Selector selector(method);
1368-
if (!uniqueSelectors.insert(selector.str()).second)
1369-
return;
1370-
1326+
AbstractFunctionDecl *method) {
13711327
ObjCMethodDescriptor descriptor(
13721328
emitObjCMethodDescriptorParts(IGM, method, /*concrete*/ true));
13731329
emitObjCDescriptor(IGM, descriptors, descriptor);
13741330
}
13751331

1376-
void irgen::emitObjCIVarInitDestroyDescriptor(
1377-
IRGenModule &IGM, ConstantArrayBuilder &descriptors, ClassDecl *cd,
1378-
llvm::Function *objcImpl, bool isDestroyer,
1379-
llvm::StringSet<> &uniqueSelectors) {
1332+
void irgen::emitObjCIVarInitDestroyDescriptor(IRGenModule &IGM,
1333+
ConstantArrayBuilder &descriptors,
1334+
ClassDecl *cd,
1335+
llvm::Function *objcImpl,
1336+
bool isDestroyer) {
13801337
/// The first element is the selector.
13811338
SILDeclRef declRef = SILDeclRef(cd,
13821339
isDestroyer? SILDeclRef::Kind::IVarDestroyer
13831340
: SILDeclRef::Kind::IVarInitializer,
13841341
/*foreign*/ true);
13851342
Selector selector(declRef);
1386-
1387-
// Don't emit a selector twice.
1388-
if (!uniqueSelectors.insert(selector.str()).second)
1389-
return;
1390-
13911343
ObjCMethodDescriptor descriptor{};
13921344
descriptor.selectorRef = IGM.getAddrOfObjCMethodName(selector.str());
13931345

@@ -1406,18 +1358,11 @@ void irgen::emitObjCIVarInitDestroyDescriptor(
14061358
buildMethodDescriptor(IGM, descriptors, descriptor);
14071359
}
14081360

1409-
14101361
llvm::Constant *
14111362
irgen::getMethodTypeExtendedEncoding(IRGenModule &IGM,
1412-
AbstractFunctionDecl *method,
1413-
llvm::StringSet<> &uniqueSelectors) {
1414-
// Don't emit a selector twice.
1415-
Selector selector(method);
1416-
if (!uniqueSelectors.insert(selector.str()).second)
1417-
return nullptr;
1418-
1363+
AbstractFunctionDecl *method) {
14191364
CanSILFunctionType methodType = getObjCMethodType(IGM, method);
1420-
return getObjCEncodingForMethod(IGM, methodType, true /*Extended*/, method);
1365+
return getObjCEncodingForMethodType(IGM, methodType, true/*Extended*/);
14211366
}
14221367

14231368
llvm::Constant *

lib/IRGen/GenObjC.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,15 @@ namespace irgen {
155155
/// constructor, or destructor implementation.
156156
void emitObjCMethodDescriptor(IRGenModule &IGM,
157157
ConstantArrayBuilder &descriptors,
158-
AbstractFunctionDecl *method,
159-
llvm::StringSet<> &uniqueSelectors);
158+
AbstractFunctionDecl *method);
160159

161160
/// Build an Objective-C method descriptor for the ivar initializer
162161
/// or destroyer of a class (-.cxx_construct or -.cxx_destruct).
163162
void emitObjCIVarInitDestroyDescriptor(IRGenModule &IGM,
164163
ConstantArrayBuilder &descriptors,
165164
ClassDecl *cd,
166165
llvm::Function *impl,
167-
bool isDestroyer,
168-
llvm::StringSet<> &uniqueSelectors);
166+
bool isDestroyer);
169167

170168
/// Get the type encoding for an ObjC property.
171169
void getObjCEncodingForPropertyType(IRGenModule &IGM, VarDecl *property,
@@ -177,12 +175,10 @@ namespace irgen {
177175
CanSILFunctionType invokeTy);
178176

179177
/// Produces extended encoding of method type.
180-
/// \returns the encoded type or null if it is a duplicate (exists in
181-
/// \p uniqueSelectors).
182-
llvm::Constant *
183-
getMethodTypeExtendedEncoding(IRGenModule &IGM, AbstractFunctionDecl *method,
184-
llvm::StringSet<> &uniqueSelectors);
185-
178+
/// \returns the encoded type.
179+
llvm::Constant *getMethodTypeExtendedEncoding(IRGenModule &IGM,
180+
AbstractFunctionDecl *method);
181+
186182
/// Build an Objective-C method descriptor for the given getter method.
187183
void emitObjCGetterDescriptor(IRGenModule &IGM,
188184
ConstantArrayBuilder &descriptors,

test/IRGen/Inputs/usr/include/Gizmo.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,3 @@ struct StructOfNSStrings useStructOfNSStringsInObjC(struct StructOfNSStrings);
159159
__attribute__((swift_name("OuterType.InnerType")))
160160
@interface OuterTypeInnerType : NSObject<NSRuncing>
161161
@end
162-
163-
@protocol P
164-
- (oneway void)stuff;
165-
@end

test/IRGen/objc_protocol_instance_methods.swift

Lines changed: 0 additions & 16 deletions
This file was deleted.

test/IRGen/objc_type_encoding.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ import gizmo
166166
func subclassComposition(_: MyCustomObject & NSRuncing & NSFunging)
167167
}
168168

169-
170169
// CHECK-macosx: [[ENC1:@.*]] = private unnamed_addr constant [35 x i8] c"v24@0:8@\22<NSFunging><NSRuncing>\2216\00"
171170
// CHECK-macosx: [[ENC2:@.*]] = private unnamed_addr constant [46 x i8] c"v32@0:8@\22Gizmo\2216@?<v@?@\22NSView\22@\22NSSpoon\22>24\00"
172171
// CHECK-macosx: [[ENC3:@.*]] = private unnamed_addr constant [53 x i8] c"v24@0:8@\22_TtC18objc_type_encoding14MyCustomObject\2216\00"
@@ -182,10 +181,3 @@ import gizmo
182181
// CHECK-tvos: [[ENC3:@.*]] = private unnamed_addr constant [53 x i8] c"v24@0:8@\22_TtC18objc_type_encoding14MyCustomObject\2216\00"
183182
// CHECK-tvos: [[ENC4:@.*]] = private unnamed_addr constant [75 x i8] c"v24@0:8@\22_TtC18objc_type_encoding14MyCustomObject<NSFunging><NSRuncing>\2216\00"
184183
// CHECK-tvos: @_PROTOCOL_METHOD_TYPES__TtP18objc_type_encoding10MyProtocol_ = private constant [4 x i8*] [i8* getelementptr inbounds ([35 x i8], [35 x i8]* [[ENC1]], i64 0, i64 0), i8* getelementptr inbounds ([46 x i8], [46 x i8]* [[ENC2]], i64 0, i64 0), i8* getelementptr inbounds ([53 x i8], [53 x i8]* [[ENC3]], i64 0, i64 0), i8* getelementptr inbounds ([75 x i8], [75 x i8]* [[ENC4]], i64 0, i64 0)]
185-
186-
class C: P {
187-
func stuff() {}
188-
}
189-
190-
// CHECK-macosx: [[ENC5:@.*]] = private unnamed_addr constant [9 x i8] c"Vv16@0:8\00"
191-
// CHECK-macosx: @_PROTOCOL_INSTANCE_METHODS_P = {{.*}}@"\01L_selector_data(stuff)"{{.*}}[[ENC5]]{{.*}}, section "__DATA, __objc_const", align 8

0 commit comments

Comments
 (0)