Skip to content

Commit 94e9aeb

Browse files
Merge pull request #30667 from aschwaighofer/revert_objc_protocol_method_uniquing
Revert "Merge pull request #30612 from aschwaighofer/irgen_also_uniqu…
2 parents 2831548 + c9d490c commit 94e9aeb

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
@@ -1520,33 +1520,27 @@ namespace {
15201520
}
15211521

15221522
void buildMethod(ConstantArrayBuilder &descriptors,
1523-
MethodDescriptor descriptor,
1524-
llvm::StringSet<> &uniqueSelectors) {
1523+
MethodDescriptor descriptor) {
15251524
switch (descriptor.getKind()) {
15261525
case MethodDescriptor::Kind::Method:
1527-
return buildMethod(descriptors, descriptor.getMethod(),
1528-
uniqueSelectors);
1526+
return buildMethod(descriptors, descriptor.getMethod());
15291527
case MethodDescriptor::Kind::IVarInitializer:
15301528
emitObjCIVarInitDestroyDescriptor(IGM, descriptors, getClass(),
1531-
descriptor.getImpl(), false,
1532-
uniqueSelectors);
1529+
descriptor.getImpl(), false);
15331530
return;
15341531
case MethodDescriptor::Kind::IVarDestroyer:
15351532
emitObjCIVarInitDestroyDescriptor(IGM, descriptors, getClass(),
1536-
descriptor.getImpl(), true,
1537-
uniqueSelectors);
1533+
descriptor.getImpl(), true);
15381534
return;
15391535
}
15401536
llvm_unreachable("bad method descriptor kind");
15411537
}
15421538

15431539
void buildMethod(ConstantArrayBuilder &descriptors,
1544-
AbstractFunctionDecl *method,
1545-
llvm::StringSet<> &uniqueSelectors) {
1540+
AbstractFunctionDecl *method) {
15461541
auto accessor = dyn_cast<AccessorDecl>(method);
15471542
if (!accessor)
1548-
return emitObjCMethodDescriptor(IGM, descriptors, method,
1549-
uniqueSelectors);
1543+
return emitObjCMethodDescriptor(IGM, descriptors, method);
15501544

15511545
switch (accessor->getAccessorKind()) {
15521546
case AccessorKind::Get:
@@ -1615,9 +1609,7 @@ namespace {
16151609
namePrefix = "_PROTOCOL_INSTANCE_METHODS_OPT_";
16161610
break;
16171611
}
1618-
llvm::StringSet<> uniqueSelectors;
1619-
llvm::Constant *methodListPtr =
1620-
buildMethodList(methods, namePrefix, uniqueSelectors);
1612+
llvm::Constant *methodListPtr = buildMethodList(methods, namePrefix);
16211613
builder.add(methodListPtr);
16221614
}
16231615

@@ -1643,15 +1635,12 @@ namespace {
16431635
void buildExtMethodTypes(ConstantArrayBuilder &array,
16441636
ArrayRef<MethodDescriptor> methods) {
16451637
assert(isBuildingProtocol());
1646-
llvm::StringSet<> uniqueSelectors;
1638+
16471639
for (auto descriptor : methods) {
16481640
assert(descriptor.getKind() == MethodDescriptor::Kind::Method &&
16491641
"cannot emit descriptor for non-method");
16501642
auto method = descriptor.getMethod();
1651-
auto *encodingOrNullIfDuplicate =
1652-
getMethodTypeExtendedEncoding(IGM, method, uniqueSelectors);
1653-
if (encodingOrNullIfDuplicate != nullptr)
1654-
array.add(encodingOrNullIfDuplicate);
1643+
array.add(getMethodTypeExtendedEncoding(IGM, method));
16551644
}
16561645
}
16571646

@@ -1663,12 +1652,11 @@ namespace {
16631652
///
16641653
/// This method does not return a value of a predictable type.
16651654
llvm::Constant *buildMethodList(ArrayRef<MethodDescriptor> methods,
1666-
StringRef name,
1667-
llvm::StringSet<> &uniqueSelectors) {
1655+
StringRef name) {
16681656
return buildOptionalList(methods, 3 * IGM.getPointerSize(), name,
16691657
[&](ConstantArrayBuilder &descriptors,
16701658
MethodDescriptor descriptor) {
1671-
buildMethod(descriptors, descriptor, uniqueSelectors);
1659+
buildMethod(descriptors, descriptor);
16721660
});
16731661
}
16741662

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)