@@ -4476,41 +4476,54 @@ llvm::Error DeclDeserializer::deserializeDeclCommon() {
4476
4476
GenericSignatureID specializedSigID;
4477
4477
4478
4478
ArrayRef<uint64_t > rawPieceIDs;
4479
- uint64_t numArgs ;
4479
+ uint8_t targetKind ;
4480
4480
uint64_t numSPIGroups;
4481
4481
DeclID targetFunID;
4482
4482
4483
4483
serialization::decls_block::SpecializeDeclAttrLayout::readRecord (
4484
4484
scratch, exported, specializationKindVal, specializedSigID,
4485
- targetFunID, numArgs , numSPIGroups, rawPieceIDs);
4485
+ targetFunID, targetKind , numSPIGroups, rawPieceIDs);
4486
4486
4487
- assert (rawPieceIDs.size () == numArgs + numSPIGroups ||
4488
- rawPieceIDs.size () == (numArgs - 1 + numSPIGroups));
4489
4487
specializationKind = specializationKindVal
4490
4488
? SpecializeAttr::SpecializationKind::Partial
4491
4489
: SpecializeAttr::SpecializationKind::Full;
4490
+
4491
+ SmallVector<Identifier, 4 > identPieces;
4492
+ // if targetKind == 1 or 2, the first piece is a DeclBaseName and
4493
+ // getIdentifier() might crash.
4494
+ for (auto id : rawPieceIDs.slice (targetKind == 0 ? 0 : 1 ))
4495
+ identPieces.push_back (MF.getIdentifier (id));
4496
+
4497
+ assert (identPieces.size () >= numSPIGroups
4498
+ && " has enough identPieces for SPI groups" );
4499
+ auto spis = makeArrayRef (identPieces).take_back (numSPIGroups);
4500
+ auto nameIdents = makeArrayRef (identPieces).drop_back (numSPIGroups);
4501
+
4492
4502
// The 'target' parameter.
4493
4503
DeclNameRef replacedFunctionName;
4494
- if (numArgs) {
4495
- bool numArgumentLabels = (numArgs == 1 ) ? 0 : numArgs - 2 ;
4504
+ // 0 = no target; 1 = target has simple name; 2 = target has compound
4505
+ // name.
4506
+ if (targetKind == 0 ) {
4507
+ assert (rawPieceIDs.size () == identPieces.size ()
4508
+ && " no base names when no target" );
4509
+ assert (nameIdents.empty () && " no extra identifiers when no target" );
4510
+ } else {
4511
+ assert (rawPieceIDs.size () == 1 + identPieces.size ()
4512
+ && " one base name when there's a target" );
4496
4513
auto baseName = MF.getDeclBaseName (rawPieceIDs[0 ]);
4497
- SmallVector<Identifier, 4 > pieces;
4498
- if (numArgumentLabels) {
4499
- for (auto pieceID : rawPieceIDs.slice (1 , numArgumentLabels))
4500
- pieces.push_back (MF.getIdentifier (pieceID));
4501
- }
4502
- replacedFunctionName = (numArgs == 1 )
4503
- ? DeclNameRef ({baseName}) // simple name
4504
- : DeclNameRef ({ctx, baseName, pieces});
4505
- }
4506
4514
4507
- SmallVector<Identifier, 4 > spis;
4508
- if (numSPIGroups) {
4509
- auto numTargetFunctionPiecesToSkip =
4510
- (rawPieceIDs.size () == numArgs + numSPIGroups) ? numArgs
4511
- : numArgs - 1 ;
4512
- for (auto id : rawPieceIDs.slice (numTargetFunctionPiecesToSkip))
4513
- spis.push_back (MF.getIdentifier (id));
4515
+ assert (!nameIdents.empty () && " has module selector for target" );
4516
+ auto modSelector = nameIdents[0 ];
4517
+ auto argLabels = nameIdents.drop_front (1 );
4518
+
4519
+ if (targetKind == 1 ) {
4520
+ assert (argLabels.empty () && " no arg labels with simple DeclName" );
4521
+ replacedFunctionName = DeclNameRef (ctx, modSelector, baseName);
4522
+ } else {
4523
+ assert (targetKind == 2 && " targetKind is a known value" );
4524
+ replacedFunctionName = DeclNameRef (ctx, modSelector, baseName,
4525
+ argLabels);
4526
+ }
4514
4527
}
4515
4528
4516
4529
auto specializedSig = MF.getGenericSignature (specializedSigID);
@@ -4681,19 +4694,21 @@ llvm::Error DeclDeserializer::deserializeDeclCommon() {
4681
4694
4682
4695
case decls_block::Transpose_DECL_ATTR: {
4683
4696
bool isImplicit;
4697
+ uint64_t origModSelId;
4684
4698
uint64_t origNameId;
4685
4699
DeclID origDeclId;
4686
- ArrayRef<uint64_t > parameters ;
4700
+ ArrayRef<uint64_t > params ;
4687
4701
4688
4702
serialization::decls_block::TransposeDeclAttrLayout::readRecord (
4689
- scratch, isImplicit, origNameId, origDeclId, parameters );
4703
+ scratch, isImplicit, origModSelId, origNameId, origDeclId, params );
4690
4704
4691
- DeclNameRefWithLoc origName{
4692
- DeclNameRef (MF.getDeclBaseName (origNameId)), DeclNameLoc (), None};
4705
+ DeclNameRef origNameRef (ctx, MF.getIdentifier (origModSelId),
4706
+ MF.getDeclBaseName (origNameId));
4707
+ DeclNameRefWithLoc origName{origNameRef, DeclNameLoc (), None};
4693
4708
auto *origDecl = cast<AbstractFunctionDecl>(MF.getDecl (origDeclId));
4694
- llvm::SmallBitVector parametersBitVector (parameters .size ());
4695
- for (unsigned i : indices (parameters ))
4696
- parametersBitVector[i] = parameters [i];
4709
+ llvm::SmallBitVector parametersBitVector (params .size ());
4710
+ for (unsigned i : indices (params ))
4711
+ parametersBitVector[i] = params [i];
4697
4712
auto *indices = IndexSubset::get (ctx, parametersBitVector);
4698
4713
auto *transposeAttr =
4699
4714
TransposeAttr::create (ctx, isImplicit, SourceLoc (), SourceRange (),
0 commit comments