@@ -1100,22 +1100,6 @@ static llvm::Constant *getObjCEncodingForTypes(IRGenModule &IGM,
1100
1100
return IGM.getAddrOfGlobalString (encodingString);
1101
1101
}
1102
1102
1103
- static llvm::Constant *getObjCEncodingForMethodType (IRGenModule &IGM,
1104
- CanSILFunctionType fnType,
1105
- bool useExtendedEncoding) {
1106
- // Get the inputs without 'self'.
1107
- auto inputs = fnType->getParameters ().drop_back ();
1108
-
1109
- // Include the encoding for 'self' and '_cmd'.
1110
- llvm::SmallString<8 > specialParams;
1111
- specialParams += " @0:" ;
1112
- auto ptrSize = IGM.getPointerSize ().getValue ();
1113
- specialParams += llvm::itostr (ptrSize);
1114
- GenericContextScope scope (IGM, fnType->getInvocationGenericSignature ());
1115
- return getObjCEncodingForTypes (IGM, fnType, inputs, specialParams,
1116
- ptrSize * 2 , useExtendedEncoding);
1117
- }
1118
-
1119
1103
static llvm::Constant *
1120
1104
getObjectEncodingFromClangNode (IRGenModule &IGM, Decl *d,
1121
1105
bool useExtendedEncoding) {
@@ -1139,6 +1123,31 @@ getObjectEncodingFromClangNode(IRGenModule &IGM, Decl *d,
1139
1123
return nullptr ;
1140
1124
}
1141
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
+
1138
+ // Get the inputs without 'self'.
1139
+ auto inputs = fnType->getParameters ().drop_back ();
1140
+
1141
+ // Include the encoding for 'self' and '_cmd'.
1142
+ llvm::SmallString<8 > specialParams;
1143
+ specialParams += " @0:" ;
1144
+ auto ptrSize = IGM.getPointerSize ().getValue ();
1145
+ specialParams += llvm::itostr (ptrSize);
1146
+ GenericContextScope scope (IGM, fnType->getInvocationGenericSignature ());
1147
+ return getObjCEncodingForTypes (IGM, fnType, inputs, specialParams,
1148
+ ptrSize * 2 , useExtendedEncoding);
1149
+ }
1150
+
1142
1151
// / Emit the components of an Objective-C method descriptor: its selector,
1143
1152
// / type encoding, and IMP pointer.
1144
1153
ObjCMethodDescriptor
@@ -1151,18 +1160,13 @@ irgen::emitObjCMethodDescriptorParts(IRGenModule &IGM,
1151
1160
// / The first element is the selector.
1152
1161
descriptor.selectorRef = IGM.getAddrOfObjCMethodName (selector.str ());
1153
1162
1154
- if (auto e =
1155
- getObjectEncodingFromClangNode (IGM, method, false /* extended*/ )) {
1156
- descriptor.typeEncoding = e;
1157
- } else {
1158
- // / The second element is the method signature. A method signature is made
1159
- // / of the return type @encoding and every parameter type @encoding, glued
1160
- // / with numbers that used to represent stack offsets for each of these
1161
- // / elements.
1162
- CanSILFunctionType methodType = getObjCMethodType (IGM, method);
1163
- descriptor.typeEncoding =
1164
- getObjCEncodingForMethodType (IGM, methodType, /* extended*/ false );
1165
- }
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.
1167
+ CanSILFunctionType methodType = getObjCMethodType (IGM, method);
1168
+ descriptor.typeEncoding =
1169
+ getObjCEncodingForMethod (IGM, methodType, /* extended*/ false , method);
1166
1170
1167
1171
// / The third element is the method implementation pointer.
1168
1172
if (!concrete) {
@@ -1222,15 +1226,11 @@ irgen::emitObjCGetterDescriptorParts(IRGenModule &IGM,
1222
1226
ObjCMethodDescriptor descriptor{};
1223
1227
descriptor.selectorRef = IGM.getAddrOfObjCMethodName (getterSel.str ());
1224
1228
1225
- if (auto e =
1226
- getObjectEncodingFromClangNode (IGM, subscript, false /* extended*/ )) {
1227
- descriptor.typeEncoding = e;
1228
- } else {
1229
- auto methodTy =
1230
- getObjCMethodType (IGM, subscript->getOpaqueAccessor (AccessorKind::Get));
1231
- descriptor.typeEncoding = getObjCEncodingForMethodType (IGM, methodTy,
1232
- /* extended*/ false );
1233
- }
1229
+ auto methodTy =
1230
+ getObjCMethodType (IGM, subscript->getOpaqueAccessor (AccessorKind::Get));
1231
+ descriptor.typeEncoding =
1232
+ getObjCEncodingForMethod (IGM, methodTy,
1233
+ /* extended*/ false , subscript);
1234
1234
1235
1235
descriptor.silFunction = nullptr ;
1236
1236
descriptor.impl = getObjCGetterPointer (IGM, subscript,
@@ -1303,13 +1303,9 @@ irgen::emitObjCSetterDescriptorParts(IRGenModule &IGM,
1303
1303
descriptor.selectorRef = IGM.getAddrOfObjCMethodName (setterSel.str ());
1304
1304
auto methodTy = getObjCMethodType (IGM,
1305
1305
subscript->getOpaqueAccessor (AccessorKind::Set));
1306
- if (auto e =
1307
- getObjectEncodingFromClangNode (IGM, subscript, false /* extended*/ )) {
1308
- descriptor.typeEncoding = e;
1309
- } else {
1310
- descriptor.typeEncoding = getObjCEncodingForMethodType (IGM, methodTy,
1311
- /* extended*/ false );
1312
- }
1306
+ descriptor.typeEncoding =
1307
+ getObjCEncodingForMethod (IGM, methodTy,
1308
+ /* extended*/ false , subscript);
1313
1309
descriptor.silFunction = nullptr ;
1314
1310
descriptor.impl = getObjCSetterPointer (IGM, subscript,
1315
1311
descriptor.silFunction );
@@ -1415,13 +1411,8 @@ void irgen::emitObjCIVarInitDestroyDescriptor(
1415
1411
llvm::Constant *
1416
1412
irgen::getMethodTypeExtendedEncoding (IRGenModule &IGM,
1417
1413
AbstractFunctionDecl *method) {
1418
- // Use the clang node's encoding if there is a clang node.
1419
- if (auto e = getObjectEncodingFromClangNode (IGM, method, true /* extended*/ )) {
1420
- return e;
1421
- }
1422
-
1423
1414
CanSILFunctionType methodType = getObjCMethodType (IGM, method);
1424
- return getObjCEncodingForMethodType (IGM, methodType, true /* Extended*/ );
1415
+ return getObjCEncodingForMethod (IGM, methodType, true /* Extended*/ , method );
1425
1416
}
1426
1417
1427
1418
llvm::Constant *
0 commit comments