@@ -3498,6 +3498,58 @@ class DeclDeserializer {
3498
3498
// / offsets in \c customAttrOffsets.
3499
3499
llvm::Error deserializeCustomAttrs ();
3500
3500
3501
+ DeclNameRef deserializeDeclNameRefIfPresent () {
3502
+ using namespace decls_block ;
3503
+
3504
+ SmallVector<uint64_t , 64 > scratch;
3505
+ StringRef blobData;
3506
+
3507
+ BCOffsetRAII restoreOffset (MF.DeclTypeCursor );
3508
+ llvm::BitstreamEntry entry =
3509
+ MF.fatalIfUnexpected (MF.DeclTypeCursor .advance ());
3510
+
3511
+ unsigned recordID = MF.fatalIfUnexpected (
3512
+ MF.DeclTypeCursor .readRecord (entry.ID , scratch, &blobData));
3513
+
3514
+ if (recordID != DECL_NAME_REF)
3515
+ // This is normal--it just means there isn't a DeclNameRef here.
3516
+ return { DeclNameRef () };
3517
+
3518
+ bool isCompoundName;
3519
+ bool hasModuleSelector;
3520
+ ArrayRef<uint64_t > rawPieceIDs;
3521
+
3522
+ DeclNameRefLayout::readRecord (scratch, isCompoundName, hasModuleSelector,
3523
+ rawPieceIDs);
3524
+ restoreOffset.cancel ();
3525
+
3526
+ Identifier moduleSelector;
3527
+ DeclBaseName baseName;
3528
+
3529
+ unsigned restIndex = 0 ;
3530
+
3531
+ ASSERT (rawPieceIDs.size () > 0 );
3532
+ if (hasModuleSelector) {
3533
+ moduleSelector = MF.getIdentifier (rawPieceIDs[restIndex]);
3534
+ restIndex++;
3535
+ }
3536
+
3537
+ ASSERT (rawPieceIDs.size () > restIndex);
3538
+ baseName = MF.getDeclBaseName (rawPieceIDs[restIndex]);
3539
+ restIndex++;
3540
+
3541
+ if (isCompoundName) {
3542
+ SmallVector<Identifier, 8 > argLabels;
3543
+ for (auto rawArgLabel : rawPieceIDs.drop_front (restIndex))
3544
+ argLabels.push_back (MF.getIdentifier (rawArgLabel));
3545
+
3546
+ return DeclNameRef (ctx, moduleSelector, baseName, argLabels);
3547
+ }
3548
+
3549
+ ASSERT (rawPieceIDs.size () == restIndex);
3550
+ return DeclNameRef (ctx, moduleSelector, baseName);
3551
+ }
3552
+
3501
3553
Expected<Decl *> getDeclCheckedImpl (
3502
3554
llvm::function_ref<bool (DeclAttributes)> matchAttributes = nullptr);
3503
3555
@@ -6141,56 +6193,32 @@ llvm::Error DeclDeserializer::deserializeDeclCommon() {
6141
6193
unsigned specializationKindVal;
6142
6194
GenericSignatureID specializedSigID;
6143
6195
6144
- ArrayRef<uint64_t > rawPieceIDs;
6145
- uint64_t numArgs;
6196
+ ArrayRef<uint64_t > rawTrailingIDs;
6146
6197
uint64_t numSPIGroups;
6147
6198
uint64_t numAvailabilityAttrs;
6148
- uint64_t numTypeErasedParams;
6149
6199
DeclID targetFunID;
6150
6200
6151
6201
serialization::decls_block::SpecializeDeclAttrLayout::readRecord (
6152
6202
scratch, exported, specializationKindVal, specializedSigID,
6153
- targetFunID, numArgs, numSPIGroups, numAvailabilityAttrs,
6154
- numTypeErasedParams, rawPieceIDs);
6203
+ targetFunID, numSPIGroups, numAvailabilityAttrs, rawTrailingIDs);
6155
6204
6156
- assert (rawPieceIDs.size () == numArgs + numSPIGroups + numTypeErasedParams ||
6157
- rawPieceIDs.size () == (numArgs - 1 + numSPIGroups + numTypeErasedParams));
6158
6205
specializationKind = specializationKindVal
6159
6206
? SpecializeAttr::SpecializationKind::Partial
6160
6207
: SpecializeAttr::SpecializationKind::Full;
6161
- // The 'target' parameter.
6162
- DeclNameRef replacedFunctionName;
6163
- if (numArgs) {
6164
- bool numArgumentLabels = (numArgs == 1 ) ? 0 : numArgs - 2 ;
6165
- auto baseName = MF.getDeclBaseName (rawPieceIDs[0 ]);
6166
- SmallVector<Identifier, 4 > pieces;
6167
- if (numArgumentLabels) {
6168
- for (auto pieceID : rawPieceIDs.slice (1 , numArgumentLabels))
6169
- pieces.push_back (MF.getIdentifier (pieceID));
6170
- }
6171
- replacedFunctionName = (numArgs == 1 )
6172
- ? DeclNameRef ({baseName}) // simple name
6173
- : DeclNameRef ({ctx, baseName, pieces});
6174
- }
6175
6208
6209
+ auto specializedSig = MF.getGenericSignature (specializedSigID);
6210
+
6211
+ // Take `numSPIGroups` trailing identifiers for the SPI groups.
6176
6212
SmallVector<Identifier, 4 > spis;
6177
- if (numSPIGroups) {
6178
- auto numTargetFunctionPiecesToSkip =
6179
- (rawPieceIDs.size () == numArgs + numSPIGroups + numTypeErasedParams) ? numArgs
6180
- : numArgs - 1 ;
6181
- for (auto id : rawPieceIDs.slice (numTargetFunctionPiecesToSkip))
6213
+ for (auto id : rawTrailingIDs.take_front (numSPIGroups))
6182
6214
spis.push_back (MF.getIdentifier (id));
6183
- }
6184
6215
6216
+ // Take the rest for type-erased parameters.
6185
6217
SmallVector<Type, 4 > typeErasedParams;
6186
- if (numTypeErasedParams) {
6187
- auto numTargetFunctionPiecesToSkip =
6188
- (rawPieceIDs.size () == numArgs + numSPIGroups + numTypeErasedParams) ? numArgs + numSPIGroups
6189
- : numArgs - 1 + numSPIGroups;
6190
- for (auto id : rawPieceIDs.slice (numTargetFunctionPiecesToSkip))
6191
- typeErasedParams.push_back (MF.getType (id));
6192
- }
6218
+ for (auto id : rawTrailingIDs.drop_front (numSPIGroups))
6219
+ typeErasedParams.push_back (MF.getType (id));
6193
6220
6221
+ // Read availability attrs.
6194
6222
SmallVector<AvailableAttr *, 4 > availabilityAttrs;
6195
6223
while (numAvailabilityAttrs) {
6196
6224
// Prepare to read the next record.
@@ -6220,10 +6248,12 @@ llvm::Error DeclDeserializer::deserializeDeclCommon() {
6220
6248
--numAvailabilityAttrs;
6221
6249
}
6222
6250
6223
- auto specializedSig = MF.getGenericSignature (specializedSigID);
6251
+ // Read target function DeclNameRef, if present.
6252
+ DeclNameRef targetFunName = deserializeDeclNameRefIfPresent ();
6253
+
6224
6254
Attr = SpecializeAttr::create (ctx, exported != 0 , specializationKind,
6225
6255
spis, availabilityAttrs, typeErasedParams,
6226
- specializedSig, replacedFunctionName , &MF,
6256
+ specializedSig, targetFunName , &MF,
6227
6257
targetFunID);
6228
6258
break ;
6229
6259
}
@@ -6254,21 +6284,15 @@ llvm::Error DeclDeserializer::deserializeDeclCommon() {
6254
6284
6255
6285
case decls_block::DynamicReplacement_DECL_ATTR: {
6256
6286
bool isImplicit;
6257
- uint64_t numArgs;
6258
- ArrayRef<uint64_t > rawPieceIDs;
6259
6287
DeclID replacedFunID;
6260
6288
serialization::decls_block::DynamicReplacementDeclAttrLayout::
6261
- readRecord (scratch, isImplicit, replacedFunID, numArgs, rawPieceIDs );
6289
+ readRecord (scratch, isImplicit, replacedFunID);
6262
6290
6263
- auto baseName = MF.getDeclBaseName (rawPieceIDs[0 ]);
6264
- SmallVector<Identifier, 4 > pieces;
6265
- for (auto pieceID : rawPieceIDs.slice (1 ))
6266
- pieces.push_back (MF.getIdentifier (pieceID));
6291
+ DeclNameRef replacedFunName = deserializeDeclNameRefIfPresent ();
6267
6292
6268
- assert (numArgs != 0 );
6269
6293
assert (!isImplicit && " Need to update for implicit" );
6270
- Attr = DynamicReplacementAttr::create (
6271
- ctx, DeclNameRef ({ ctx, baseName, pieces }), &MF, replacedFunID);
6294
+ Attr = DynamicReplacementAttr::create (ctx, replacedFunName, &MF,
6295
+ replacedFunID);
6272
6296
break ;
6273
6297
}
6274
6298
@@ -6339,15 +6363,14 @@ llvm::Error DeclDeserializer::deserializeDeclCommon() {
6339
6363
6340
6364
case decls_block::Derivative_DECL_ATTR: {
6341
6365
bool isImplicit;
6342
- uint64_t origNameId;
6343
6366
bool hasAccessorKind;
6344
6367
uint64_t rawAccessorKind;
6345
6368
DeclID origDeclId;
6346
6369
uint64_t rawDerivativeKind;
6347
6370
ArrayRef<uint64_t > parameters;
6348
6371
6349
6372
serialization::decls_block::DerivativeDeclAttrLayout::readRecord (
6350
- scratch, isImplicit, origNameId, hasAccessorKind, rawAccessorKind,
6373
+ scratch, isImplicit, hasAccessorKind, rawAccessorKind,
6351
6374
origDeclId, rawDerivativeKind, parameters);
6352
6375
6353
6376
std::optional<AccessorKind> accessorKind = std::nullopt;
@@ -6358,8 +6381,6 @@ llvm::Error DeclDeserializer::deserializeDeclCommon() {
6358
6381
accessorKind = *maybeAccessorKind;
6359
6382
}
6360
6383
6361
- DeclNameRefWithLoc origName{DeclNameRef (MF.getDeclBaseName (origNameId)),
6362
- DeclNameLoc (), accessorKind};
6363
6384
auto derivativeKind =
6364
6385
getActualAutoDiffDerivativeFunctionKind (rawDerivativeKind);
6365
6386
if (!derivativeKind)
@@ -6369,9 +6390,14 @@ llvm::Error DeclDeserializer::deserializeDeclCommon() {
6369
6390
parametersBitVector[i] = parameters[i];
6370
6391
auto *indices = IndexSubset::get (ctx, parametersBitVector);
6371
6392
6393
+ auto origName = deserializeDeclNameRefIfPresent ();
6394
+ DeclNameRefWithLoc origNameWithLoc{origName, DeclNameLoc (),
6395
+ accessorKind};
6396
+
6372
6397
auto *derivativeAttr =
6373
6398
DerivativeAttr::create (ctx, isImplicit, SourceLoc (), SourceRange (),
6374
- /* baseType*/ nullptr , origName, indices);
6399
+ /* baseType*/ nullptr , origNameWithLoc,
6400
+ indices);
6375
6401
derivativeAttr->setOriginalFunctionResolver (&MF, origDeclId);
6376
6402
derivativeAttr->setDerivativeKind (*derivativeKind);
6377
6403
Attr = derivativeAttr;
@@ -6380,20 +6406,21 @@ llvm::Error DeclDeserializer::deserializeDeclCommon() {
6380
6406
6381
6407
case decls_block::Transpose_DECL_ATTR: {
6382
6408
bool isImplicit;
6383
- uint64_t origNameId;
6384
6409
DeclID origDeclId;
6385
6410
ArrayRef<uint64_t > parameters;
6386
6411
6387
6412
serialization::decls_block::TransposeDeclAttrLayout::readRecord (
6388
- scratch, isImplicit, origNameId, origDeclId, parameters);
6413
+ scratch, isImplicit, origDeclId, parameters);
6389
6414
6390
- DeclNameRefWithLoc origName{DeclNameRef (MF.getDeclBaseName (origNameId)),
6391
- DeclNameLoc (), std::nullopt};
6392
6415
auto *origDecl = cast<AbstractFunctionDecl>(MF.getDecl (origDeclId));
6393
6416
llvm::SmallBitVector parametersBitVector (parameters.size ());
6394
6417
for (unsigned i : indices (parameters))
6395
6418
parametersBitVector[i] = parameters[i];
6396
6419
auto *indices = IndexSubset::get (ctx, parametersBitVector);
6420
+
6421
+ auto origNameRef = deserializeDeclNameRefIfPresent ();
6422
+ DeclNameRefWithLoc origName{origNameRef, DeclNameLoc (), std::nullopt};
6423
+
6397
6424
auto *transposeAttr =
6398
6425
TransposeAttr::create (ctx, isImplicit, SourceLoc (), SourceRange (),
6399
6426
/* baseTypeRepr*/ nullptr , origName, indices);
0 commit comments