Skip to content

Commit f0cdd76

Browse files
Merge pull request swiftlang#30612 from aschwaighofer/irgen_also_unique_ext_method_types_list
IRGen: Also unique selectors in extended method types list
2 parents 703fe0f + e344971 commit f0cdd76

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

lib/IRGen/GenClass.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,12 +1644,15 @@ namespace {
16441644
void buildExtMethodTypes(ConstantArrayBuilder &array,
16451645
ArrayRef<MethodDescriptor> methods) {
16461646
assert(isBuildingProtocol());
1647-
1647+
llvm::StringSet<> uniqueSelectors;
16481648
for (auto descriptor : methods) {
16491649
assert(descriptor.getKind() == MethodDescriptor::Kind::Method &&
16501650
"cannot emit descriptor for non-method");
16511651
auto method = descriptor.getMethod();
1652-
array.add(getMethodTypeExtendedEncoding(IGM, method));
1652+
auto *encodingOrNullIfDuplicate =
1653+
getMethodTypeExtendedEncoding(IGM, method, uniqueSelectors);
1654+
if (encodingOrNullIfDuplicate != nullptr)
1655+
array.add(encodingOrNullIfDuplicate);
16531656
}
16541657
}
16551658

lib/IRGen/GenObjC.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,13 @@ void irgen::emitObjCIVarInitDestroyDescriptor(
14091409

14101410
llvm::Constant *
14111411
irgen::getMethodTypeExtendedEncoding(IRGenModule &IGM,
1412-
AbstractFunctionDecl *method) {
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+
14131419
CanSILFunctionType methodType = getObjCMethodType(IGM, method);
14141420
return getObjCEncodingForMethod(IGM, methodType, true /*Extended*/, method);
14151421
}

lib/IRGen/GenObjC.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,12 @@ namespace irgen {
177177
CanSILFunctionType invokeTy);
178178

179179
/// Produces extended encoding of method type.
180-
/// \returns the encoded type.
181-
llvm::Constant *getMethodTypeExtendedEncoding(IRGenModule &IGM,
182-
AbstractFunctionDecl *method);
183-
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+
184186
/// Build an Objective-C method descriptor for the given getter method.
185187
void emitObjCGetterDescriptor(IRGenModule &IGM,
186188
ConstantArrayBuilder &descriptors,

test/IRGen/objc_protocol_instance_methods.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
// CHECK-NOT: _PROTOCOL_INSTANCE_METHODS_NSObject{{.*}}"\01L_selector_data(conformsToProtocol:)"{{.*}}"\01L_selector_data(conformsToProtocol:)"
99

10+
// Make sure that extended method types are in sync with entries in method list.
11+
// CHECK: @_PROTOCOL_INSTANCE_METHODS_NSObject = private constant { i32, i32, [5 x
12+
// CHECK: @_PROTOCOL_METHOD_TYPES_NSObject = private constant [5
1013
import Foundation
1114

1215
@objc protocol P: NSObjectProtocol {}

0 commit comments

Comments
 (0)