@@ -3498,6 +3498,58 @@ class DeclDeserializer {
34983498 // / offsets in \c customAttrOffsets.
34993499 llvm::Error deserializeCustomAttrs ();
35003500
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+
35013553 Expected<Decl *> getDeclCheckedImpl (
35023554 llvm::function_ref<bool (DeclAttributes)> matchAttributes = nullptr);
35033555
@@ -6141,56 +6193,32 @@ llvm::Error DeclDeserializer::deserializeDeclCommon() {
61416193 unsigned specializationKindVal;
61426194 GenericSignatureID specializedSigID;
61436195
6144- ArrayRef<uint64_t > rawPieceIDs;
6145- uint64_t numArgs;
6196+ ArrayRef<uint64_t > rawTrailingIDs;
61466197 uint64_t numSPIGroups;
61476198 uint64_t numAvailabilityAttrs;
6148- uint64_t numTypeErasedParams;
61496199 DeclID targetFunID;
61506200
61516201 serialization::decls_block::SpecializeDeclAttrLayout::readRecord (
61526202 scratch, exported, specializationKindVal, specializedSigID,
6153- targetFunID, numArgs, numSPIGroups, numAvailabilityAttrs,
6154- numTypeErasedParams, rawPieceIDs);
6203+ targetFunID, numSPIGroups, numAvailabilityAttrs, rawTrailingIDs);
61556204
6156- assert (rawPieceIDs.size () == numArgs + numSPIGroups + numTypeErasedParams ||
6157- rawPieceIDs.size () == (numArgs - 1 + numSPIGroups + numTypeErasedParams));
61586205 specializationKind = specializationKindVal
61596206 ? SpecializeAttr::SpecializationKind::Partial
61606207 : 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- }
61756208
6209+ auto specializedSig = MF.getGenericSignature (specializedSigID);
6210+
6211+ // Take `numSPIGroups` trailing identifiers for the SPI groups.
61766212 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))
61826214 spis.push_back (MF.getIdentifier (id));
6183- }
61846215
6216+ // Take the rest for type-erased parameters.
61856217 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));
61936220
6221+ // Read availability attrs.
61946222 SmallVector<AvailableAttr *, 4 > availabilityAttrs;
61956223 while (numAvailabilityAttrs) {
61966224 // Prepare to read the next record.
@@ -6220,10 +6248,12 @@ llvm::Error DeclDeserializer::deserializeDeclCommon() {
62206248 --numAvailabilityAttrs;
62216249 }
62226250
6223- auto specializedSig = MF.getGenericSignature (specializedSigID);
6251+ // Read target function DeclNameRef, if present.
6252+ DeclNameRef targetFunName = deserializeDeclNameRefIfPresent ();
6253+
62246254 Attr = SpecializeAttr::create (ctx, exported != 0 , specializationKind,
62256255 spis, availabilityAttrs, typeErasedParams,
6226- specializedSig, replacedFunctionName , &MF,
6256+ specializedSig, targetFunName , &MF,
62276257 targetFunID);
62286258 break ;
62296259 }
@@ -6254,21 +6284,15 @@ llvm::Error DeclDeserializer::deserializeDeclCommon() {
62546284
62556285 case decls_block::DynamicReplacement_DECL_ATTR: {
62566286 bool isImplicit;
6257- uint64_t numArgs;
6258- ArrayRef<uint64_t > rawPieceIDs;
62596287 DeclID replacedFunID;
62606288 serialization::decls_block::DynamicReplacementDeclAttrLayout::
6261- readRecord (scratch, isImplicit, replacedFunID, numArgs, rawPieceIDs );
6289+ readRecord (scratch, isImplicit, replacedFunID);
62626290
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 ();
62676292
6268- assert (numArgs != 0 );
62696293 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);
62726296 break ;
62736297 }
62746298
@@ -6339,15 +6363,14 @@ llvm::Error DeclDeserializer::deserializeDeclCommon() {
63396363
63406364 case decls_block::Derivative_DECL_ATTR: {
63416365 bool isImplicit;
6342- uint64_t origNameId;
63436366 bool hasAccessorKind;
63446367 uint64_t rawAccessorKind;
63456368 DeclID origDeclId;
63466369 uint64_t rawDerivativeKind;
63476370 ArrayRef<uint64_t > parameters;
63486371
63496372 serialization::decls_block::DerivativeDeclAttrLayout::readRecord (
6350- scratch, isImplicit, origNameId, hasAccessorKind, rawAccessorKind,
6373+ scratch, isImplicit, hasAccessorKind, rawAccessorKind,
63516374 origDeclId, rawDerivativeKind, parameters);
63526375
63536376 std::optional<AccessorKind> accessorKind = std::nullopt ;
@@ -6358,8 +6381,6 @@ llvm::Error DeclDeserializer::deserializeDeclCommon() {
63586381 accessorKind = *maybeAccessorKind;
63596382 }
63606383
6361- DeclNameRefWithLoc origName{DeclNameRef (MF.getDeclBaseName (origNameId)),
6362- DeclNameLoc (), accessorKind};
63636384 auto derivativeKind =
63646385 getActualAutoDiffDerivativeFunctionKind (rawDerivativeKind);
63656386 if (!derivativeKind)
@@ -6369,9 +6390,14 @@ llvm::Error DeclDeserializer::deserializeDeclCommon() {
63696390 parametersBitVector[i] = parameters[i];
63706391 auto *indices = IndexSubset::get (ctx, parametersBitVector);
63716392
6393+ auto origName = deserializeDeclNameRefIfPresent ();
6394+ DeclNameRefWithLoc origNameWithLoc{origName, DeclNameLoc (),
6395+ accessorKind};
6396+
63726397 auto *derivativeAttr =
63736398 DerivativeAttr::create (ctx, isImplicit, SourceLoc (), SourceRange (),
6374- /* baseType*/ nullptr , origName, indices);
6399+ /* baseType*/ nullptr , origNameWithLoc,
6400+ indices);
63756401 derivativeAttr->setOriginalFunctionResolver (&MF, origDeclId);
63766402 derivativeAttr->setDerivativeKind (*derivativeKind);
63776403 Attr = derivativeAttr;
@@ -6380,20 +6406,21 @@ llvm::Error DeclDeserializer::deserializeDeclCommon() {
63806406
63816407 case decls_block::Transpose_DECL_ATTR: {
63826408 bool isImplicit;
6383- uint64_t origNameId;
63846409 DeclID origDeclId;
63856410 ArrayRef<uint64_t > parameters;
63866411
63876412 serialization::decls_block::TransposeDeclAttrLayout::readRecord (
6388- scratch, isImplicit, origNameId, origDeclId, parameters);
6413+ scratch, isImplicit, origDeclId, parameters);
63896414
6390- DeclNameRefWithLoc origName{DeclNameRef (MF.getDeclBaseName (origNameId)),
6391- DeclNameLoc (), std::nullopt };
63926415 auto *origDecl = cast<AbstractFunctionDecl>(MF.getDecl (origDeclId));
63936416 llvm::SmallBitVector parametersBitVector (parameters.size ());
63946417 for (unsigned i : indices (parameters))
63956418 parametersBitVector[i] = parameters[i];
63966419 auto *indices = IndexSubset::get (ctx, parametersBitVector);
6420+
6421+ auto origNameRef = deserializeDeclNameRefIfPresent ();
6422+ DeclNameRefWithLoc origName{origNameRef, DeclNameLoc (), std::nullopt };
6423+
63976424 auto *transposeAttr =
63986425 TransposeAttr::create (ctx, isImplicit, SourceLoc (), SourceRange (),
63996426 /* baseTypeRepr*/ nullptr , origName, indices);
0 commit comments