@@ -3324,17 +3324,33 @@ class DiagnosisEmitter : public SDKNodeVisitor {
3324
3324
struct MetaInfo {
3325
3325
StringRef ModuleName;
3326
3326
StringRef HeaderName;
3327
+ DeclKind Kind;
3328
+ StringRef Name;
3327
3329
bool IsABISpecific;
3328
- MetaInfo (const SDKNodeDecl *Node, bool IsABISpecific = false ):
3330
+ MetaInfo (const SDKNodeDecl *Node, bool IsABISpecific):
3329
3331
ModuleName (Node->getModuleName ()), HeaderName(Node->getHeaderName ()),
3332
+ Kind(Node->getDeclKind ()), Name(Node->getFullyQualifiedName ()),
3330
3333
IsABISpecific(IsABISpecific) {}
3334
+ int compare (MetaInfo &Other) const {
3335
+ if (ModuleName != Other.ModuleName )
3336
+ return ModuleName.compare (Other.ModuleName );
3337
+ if (HeaderName != Other.HeaderName )
3338
+ return HeaderName.compare (Other.HeaderName );
3339
+ if (Kind != Other.Kind )
3340
+ return (uint8_t )Kind - (uint8_t )Other.Kind ;
3341
+ return Name.compare (Other.Name );
3342
+ }
3331
3343
};
3332
3344
3333
3345
class DiagBase {
3346
+ protected:
3334
3347
MetaInfo Info;
3335
- public:
3336
3348
DiagBase (MetaInfo Info): Info(Info) {}
3337
3349
virtual ~DiagBase () = default ;
3350
+ raw_ostream &outputName () const {
3351
+ return llvm::outs () << Info.Kind << " " << printName (Info.Name );
3352
+ }
3353
+ public:
3338
3354
void outputModule () const {
3339
3355
if (options::PrintModule) {
3340
3356
llvm::outs () << Info.ModuleName ;
@@ -3351,115 +3367,94 @@ class DiagnosisEmitter : public SDKNodeVisitor {
3351
3367
DeclKind Kind;
3352
3368
StringRef Name;
3353
3369
bool IsDeprecated;
3354
- RemovedDeclDiag (MetaInfo Info, DeclKind Kind, StringRef Name,
3355
- bool IsDeprecated): DiagBase(Info), Kind(Kind),
3356
- Name (Name), IsDeprecated(IsDeprecated) {}
3357
- bool operator <(RemovedDeclDiag Other) const ;
3370
+ RemovedDeclDiag (MetaInfo Info, bool IsDeprecated): DiagBase(Info),
3371
+ IsDeprecated (IsDeprecated) {}
3372
+ bool operator <(RemovedDeclDiag Other) const {
3373
+ return Info.compare (Other.Info ) < 0 ;
3374
+ }
3358
3375
void output () const override ;
3359
3376
static void theme (raw_ostream &OS) { OS << " Removed Decls" ; };
3360
3377
};
3361
3378
3362
3379
struct MovedDeclDiag : public DiagBase {
3363
- DeclKind RemovedKind;
3364
3380
DeclKind AddedKind;
3365
- StringRef RemovedName;
3366
3381
StringRef AddedName;
3367
- MovedDeclDiag (MetaInfo Info, DeclKind RemovedKind, DeclKind AddedKind,
3368
- StringRef RemovedName, StringRef AddedName):
3369
- DiagBase (Info), RemovedKind(RemovedKind), AddedKind(AddedKind),
3370
- RemovedName (RemovedName), AddedName(AddedName) {}
3371
- bool operator <(MovedDeclDiag other) const ;
3382
+ MovedDeclDiag (MetaInfo Info, DeclKind AddedKind, StringRef AddedName):
3383
+ DiagBase (Info), AddedKind(AddedKind), AddedName(AddedName) {}
3384
+ bool operator <(MovedDeclDiag Other) const {
3385
+ return Info. compare (Other. Info ) < 0 ;
3386
+ }
3372
3387
void output () const override ;
3373
3388
static void theme (raw_ostream &OS) { OS << " Moved Decls" ; };
3374
3389
};
3375
3390
3376
3391
struct RenamedDeclDiag : public DiagBase {
3377
- DeclKind KindBefore;
3378
3392
DeclKind KindAfter;
3379
- StringRef NameBefore;
3380
3393
StringRef NameAfter;
3381
- RenamedDeclDiag (MetaInfo Info, DeclKind KindBefore, DeclKind KindAfter,
3382
- StringRef NameBefore, StringRef NameAfter):
3383
- DiagBase (Info),
3384
- KindBefore (KindBefore), KindAfter(KindAfter),
3385
- NameBefore (NameBefore), NameAfter(NameAfter) {}
3386
- bool operator <(RenamedDeclDiag Other) const ;
3394
+ RenamedDeclDiag (MetaInfo Info, DeclKind KindAfter, StringRef NameAfter):
3395
+ DiagBase (Info), KindAfter(KindAfter), NameAfter(NameAfter) {}
3396
+ bool operator <(RenamedDeclDiag Other) const {
3397
+ return Info.compare (Other.Info ) < 0 ;
3398
+ };
3387
3399
void output () const override ;
3388
3400
static void theme (raw_ostream &OS) { OS << " Renamed Decls" ; };
3389
3401
};
3390
3402
3391
3403
struct DeclAttrDiag : public DiagBase {
3392
- DeclKind Kind;
3393
- StringRef DeclName;
3394
3404
StringRef AttrBefore;
3395
3405
StringRef AttrAfter;
3396
- DeclAttrDiag (MetaInfo Info, DeclKind Kind, StringRef DeclName,
3397
- StringRef AttrBefore, StringRef AttrAfter):
3398
- DiagBase (Info), Kind(Kind), DeclName(DeclName),
3399
- AttrBefore (AttrBefore), AttrAfter(AttrAfter) {}
3400
- DeclAttrDiag (MetaInfo Info, DeclKind Kind, StringRef DeclName,
3401
- StringRef AttrAfter): DeclAttrDiag(Info, Kind, DeclName,
3402
- StringRef (), AttrAfter) {}
3403
-
3406
+ DeclAttrDiag (MetaInfo Info, StringRef AttrBefore, StringRef AttrAfter):
3407
+ DiagBase (Info), AttrBefore(AttrBefore), AttrAfter(AttrAfter) {}
3408
+ DeclAttrDiag (MetaInfo Info, StringRef AttrAfter): DeclAttrDiag(Info,
3409
+ StringRef (), AttrAfter) {}
3404
3410
bool operator <(DeclAttrDiag Other) const ;
3405
3411
void output () const override ;
3406
3412
static void theme (raw_ostream &OS) { OS << " Decl Attribute changes" ; };
3407
3413
};
3408
3414
3409
3415
struct DeclTypeChangeDiag : public DiagBase {
3410
- DeclKind Kind;
3411
- StringRef DeclName;
3412
3416
StringRef TypeNameBefore;
3413
3417
StringRef TypeNameAfter;
3414
3418
StringRef Description;
3415
- DeclTypeChangeDiag (MetaInfo Info, DeclKind Kind, StringRef DeclName ,
3416
- StringRef TypeNameBefore, StringRef TypeNameAfter,
3419
+ DeclTypeChangeDiag (MetaInfo Info, StringRef TypeNameBefore ,
3420
+ StringRef TypeNameAfter,
3417
3421
StringRef Description): DiagBase(Info),
3418
- Kind (Kind), DeclName(DeclName), TypeNameBefore(TypeNameBefore),
3419
- TypeNameAfter(TypeNameAfter), Description(Description) {}
3420
- bool operator <(DeclTypeChangeDiag Other) const ;
3422
+ TypeNameBefore (TypeNameBefore), TypeNameAfter(TypeNameAfter),
3423
+ Description(Description) {}
3424
+ bool operator <(DeclTypeChangeDiag Other) const {
3425
+ return Info.compare (Other.Info ) < 0 ;
3426
+ };
3421
3427
void output () const override ;
3422
3428
static void theme (raw_ostream &OS) { OS << " Type Changes" ; };
3423
3429
};
3424
3430
3425
3431
struct RawRepresentableChangeDiag : public DiagBase {
3426
- DeclKind Kind;
3427
- StringRef DeclName;
3428
3432
StringRef UnderlyingType;
3429
3433
StringRef RawTypeName;
3430
- RawRepresentableChangeDiag (MetaInfo Info, DeclKind Kind, StringRef DeclName,
3431
- StringRef UnderlyingType, StringRef RawTypeName): DiagBase(Info),
3432
- Kind (Kind), DeclName(DeclName), UnderlyingType(UnderlyingType),
3433
- RawTypeName(RawTypeName) {}
3434
+ RawRepresentableChangeDiag (MetaInfo Info, StringRef UnderlyingType,
3435
+ StringRef RawTypeName): DiagBase(Info), UnderlyingType(UnderlyingType),
3436
+ RawTypeName (RawTypeName) {}
3434
3437
bool operator <(RawRepresentableChangeDiag Other) const {
3435
- if (Kind != Other.Kind )
3436
- return Kind < Other.Kind ;
3437
- return DeclName.compare (Other.DeclName ) < 0 ;
3438
+ return Info.compare (Other.Info ) < 0 ;
3438
3439
}
3439
3440
void output () const override {
3440
- llvm::outs () << Kind << " " << printName (DeclName)
3441
- << " (" << UnderlyingType << " )"
3441
+ outputName () << " (" << UnderlyingType << " )"
3442
3442
<< " is now " << RawTypeName << " representable\n " ;
3443
3443
}
3444
3444
static void theme (raw_ostream &OS) { OS << " RawRepresentable Changes" ; };
3445
3445
};
3446
3446
3447
3447
struct GenericSignatureChangeDiag : public DiagBase {
3448
- DeclKind Kind;
3449
- StringRef DeclName;
3450
3448
StringRef GSBefore;
3451
3449
StringRef GSAfter;
3452
- GenericSignatureChangeDiag (MetaInfo Info, DeclKind Kind, StringRef DeclName ,
3453
- StringRef GSBefore, StringRef GSAfter): DiagBase(Info), Kind(Kind ),
3454
- DeclName (DeclName), GSBefore(GSBefore), GSAfter(GSAfter) {}
3450
+ GenericSignatureChangeDiag (MetaInfo Info, StringRef GSBefore ,
3451
+ StringRef GSAfter): DiagBase(Info),
3452
+ GSBefore (GSBefore), GSAfter(GSAfter) {}
3455
3453
bool operator <(GenericSignatureChangeDiag Other) const {
3456
- if (Kind != Other.Kind )
3457
- return Kind < Other.Kind ;
3458
- return DeclName.compare (Other.DeclName ) < 0 ;
3454
+ return Info.compare (Other.Info ) < 0 ;
3459
3455
}
3460
3456
void output () const override {
3461
- llvm::outs () << Kind << " " << printName (DeclName)
3462
- << " has generic signature change from " << GSBefore << " to "
3457
+ outputName () << " has generic signature change from " << GSBefore << " to "
3463
3458
<< GSAfter << " \n " ;
3464
3459
}
3465
3460
static void theme (raw_ostream &OS) { OS << " Generic Signature Changes" ; };
@@ -3529,77 +3524,44 @@ StringRef DiagnosisEmitter::printDiagKeyword(StringRef Name) {
3529
3524
return StringRef ();
3530
3525
}
3531
3526
3532
- bool DiagnosisEmitter::RemovedDeclDiag::
3533
- operator <(RemovedDeclDiag Other) const {
3534
- if (Kind != Other.Kind )
3535
- return Kind < Other.Kind ;
3536
- return Name.compare (Other.Name ) < 0 ;
3537
- }
3538
-
3539
3527
void DiagnosisEmitter::RemovedDeclDiag::output () const {
3540
- llvm::outs () << Kind << " " << printName (Name) << " has been "
3541
- << printDiagKeyword (" removed" );
3528
+ outputName () << " has been " << printDiagKeyword (" removed" );
3542
3529
if (IsDeprecated)
3543
3530
llvm::outs () << " (deprecated)" ;
3544
3531
llvm::outs () << " \n " ;
3545
3532
}
3546
3533
3547
- bool DiagnosisEmitter::MovedDeclDiag::
3548
- operator <(MovedDeclDiag Other) const {
3549
- if (RemovedKind != Other.RemovedKind )
3550
- return RemovedKind < Other.RemovedKind ;
3551
- return RemovedName.compare (Other.RemovedName ) < 0 ;
3552
- }
3553
-
3554
3534
void DiagnosisEmitter::MovedDeclDiag::output () const {
3555
- llvm::outs () << RemovedKind << " " << printName (RemovedName) << " has been "
3556
- << printDiagKeyword (" moved" ) << " to " << AddedKind << " "
3557
- << printName (AddedName) << " \n " ;
3558
- }
3559
-
3560
- bool DiagnosisEmitter::RenamedDeclDiag::
3561
- operator <(RenamedDeclDiag Other) const {
3562
- if (KindBefore != Other.KindBefore )
3563
- return KindBefore < Other.KindBefore ;
3564
- return NameBefore.compare (Other.NameBefore ) < 0 ;
3535
+ outputName () << " has been " << printDiagKeyword (" moved" ) << " to "
3536
+ << AddedKind << " " << printName (AddedName) << " \n " ;
3565
3537
}
3566
3538
3567
3539
void DiagnosisEmitter::RenamedDeclDiag::output () const {
3568
- llvm::outs () << KindBefore << " " << printName (NameBefore)
3569
- << " has been " << printDiagKeyword (" renamed" ) << " to "
3570
- << KindAfter << " " << printName (NameAfter) << " \n " ;
3571
- }
3572
-
3573
- bool DiagnosisEmitter::DeclTypeChangeDiag::
3574
- operator <(DeclTypeChangeDiag Other) const {
3575
- if (Kind != Other.Kind )
3576
- return Kind < Other.Kind ;
3577
- return DeclName.compare (Other.DeclName ) < 0 ;
3540
+ outputName () << " has been " << printDiagKeyword (" renamed" ) << " to "
3541
+ << KindAfter << " " << printName (NameAfter) << " \n " ;
3578
3542
}
3579
3543
3580
3544
void DiagnosisEmitter::DeclTypeChangeDiag::output () const {
3581
- llvm::outs () << Kind << " " << printName (DeclName ) << " has "
3545
+ outputName ( ) << " has "
3582
3546
<< Description << " type change from "
3583
3547
<< printName (TypeNameBefore) << " to "
3584
3548
<< printName (TypeNameAfter) << " \n " ;
3585
3549
}
3586
3550
3587
3551
3588
3552
bool DiagnosisEmitter::DeclAttrDiag::operator <(DeclAttrDiag Other) const {
3589
- if (Kind != Other.Kind )
3590
- return Kind < Other.Kind ;
3591
- if (DeclName != Other.DeclName )
3592
- return DeclName.compare (Other.DeclName ) < 0 ;
3553
+ auto result = Info.compare (Other.Info );
3554
+ if (result)
3555
+ return result < 0 ;
3593
3556
return AttrAfter.compare (Other.AttrAfter ) < 0 ;
3594
3557
}
3595
3558
3596
3559
void DiagnosisEmitter::DeclAttrDiag::output () const {
3597
3560
if (AttrBefore.empty ())
3598
- llvm::outs () << Kind << " " << printName (DeclName) << " is now " <<
3599
- printDiagKeyword (AttrAfter)<< " \n " ;
3561
+ outputName () << " is now " << printDiagKeyword (AttrAfter)<< " \n " ;
3600
3562
else
3601
- llvm::outs () << Kind << " " << printName (DeclName) << " changes from " <<
3602
- printDiagKeyword (AttrBefore) << " to " << printDiagKeyword (AttrAfter)<< " \n " ;
3563
+ outputName () << " changes from " << printDiagKeyword (AttrBefore)
3564
+ << " to " << printDiagKeyword (AttrAfter)<< " \n " ;
3603
3565
}
3604
3566
3605
3567
void DiagnosisEmitter::diagnosis (NodePtr LeftRoot, NodePtr RightRoot,
@@ -3622,9 +3584,7 @@ void DiagnosisEmitter::handle(const SDKNodeDecl *Node, NodeAnnotation Anno) {
3622
3584
if (auto *Added = findAddedDecl (Node)) {
3623
3585
if (Node->getDeclKind () != DeclKind::Constructor) {
3624
3586
MovedDecls.Diags .emplace_back (ScreenInfo,
3625
- Node->getDeclKind (),
3626
3587
Added->getDeclKind (),
3627
- Node->getFullyQualifiedName (),
3628
3588
Added->getFullyQualifiedName ());
3629
3589
return ;
3630
3590
}
@@ -3636,7 +3596,6 @@ void DiagnosisEmitter::handle(const SDKNodeDecl *Node, NodeAnnotation Anno) {
3636
3596
[&](TypeMemberDiffItem &Item) { return Item.usr == Node->getUsr (); });
3637
3597
if (It != MemberChanges.end ()) {
3638
3598
RenamedDecls.Diags .emplace_back (ScreenInfo, Node->getDeclKind (),
3639
- Node->getDeclKind (), Node->getFullyQualifiedName (),
3640
3599
Ctx.buffer ((Twine (It->newTypeName ) + " ." + It->newPrintedName ).str ()));
3641
3600
return ;
3642
3601
}
@@ -3646,8 +3605,7 @@ void DiagnosisEmitter::handle(const SDKNodeDecl *Node, NodeAnnotation Anno) {
3646
3605
// refine diagnostics message instead of showing the type alias has been
3647
3606
// removed.
3648
3607
if (TypeAliasUpdateMap.find ((SDKNode*)Node) != TypeAliasUpdateMap.end ()) {
3649
- RawRepresentableDecls.Diags .emplace_back (ScreenInfo, Node->getDeclKind (),
3650
- Node->getFullyQualifiedName (),
3608
+ RawRepresentableDecls.Diags .emplace_back (ScreenInfo,
3651
3609
Node->getAs <SDKNodeDeclTypeAlias>()->getUnderlyingType ()->getPrintedName (),
3652
3610
TypeAliasUpdateMap[(SDKNode*)Node]->getAs <SDKNodeDeclType>()->
3653
3611
getRawValueType ()->getPrintedName ());
@@ -3670,41 +3628,30 @@ void DiagnosisEmitter::handle(const SDKNodeDecl *Node, NodeAnnotation Anno) {
3670
3628
if (FoundInSuperclass)
3671
3629
return ;
3672
3630
RemovedDecls.Diags .emplace_back (ScreenInfo,
3673
- Node->getDeclKind (),
3674
- Node->getFullyQualifiedName (),
3675
3631
Node->isDeprecated ());
3676
3632
return ;
3677
3633
}
3678
3634
case NodeAnnotation::Rename: {
3679
3635
MetaInfo ScreenInfo (Node, false );
3680
3636
auto *Count = UpdateMap.findUpdateCounterpart (Node)->getAs <SDKNodeDecl>();
3681
3637
RenamedDecls.Diags .emplace_back (ScreenInfo,
3682
- Node->getDeclKind (), Count->getDeclKind (),
3683
- Node->getFullyQualifiedName (),
3638
+ Count->getDeclKind (),
3684
3639
Count->getFullyQualifiedName ());
3685
3640
return ;
3686
3641
}
3687
3642
case NodeAnnotation::NowMutating: {
3688
3643
MetaInfo ScreenInfo (Node, false );
3689
- AttrChangedDecls.Diags .emplace_back (ScreenInfo,
3690
- Node->getDeclKind (),
3691
- Node->getFullyQualifiedName (),
3692
- Ctx.buffer (" mutating" ));
3644
+ AttrChangedDecls.Diags .emplace_back (ScreenInfo, Ctx.buffer (" mutating" ));
3693
3645
return ;
3694
3646
}
3695
3647
case NodeAnnotation::NowThrowing: {
3696
3648
MetaInfo ScreenInfo (Node, false );
3697
- AttrChangedDecls.Diags .emplace_back (ScreenInfo,
3698
- Node->getDeclKind (),
3699
- Node->getFullyQualifiedName (),
3700
- Ctx.buffer (" throwing" ));
3649
+ AttrChangedDecls.Diags .emplace_back (ScreenInfo, Ctx.buffer (" throwing" ));
3701
3650
return ;
3702
3651
}
3703
3652
case NodeAnnotation::StaticChange: {
3704
3653
MetaInfo ScreenInfo (Node, false );
3705
3654
AttrChangedDecls.Diags .emplace_back (ScreenInfo,
3706
- Node->getDeclKind (),
3707
- Node->getFullyQualifiedName (),
3708
3655
Ctx.buffer (Node->isStatic () ? " not static" : " static" ));
3709
3656
return ;
3710
3657
}
@@ -3717,15 +3664,14 @@ void DiagnosisEmitter::handle(const SDKNodeDecl *Node, NodeAnnotation Anno) {
3717
3664
};
3718
3665
auto *Count = UpdateMap.findUpdateCounterpart (Node)->getAs <SDKNodeDecl>();
3719
3666
AttrChangedDecls.Diags .emplace_back (
3720
- ScreenInfo, Node-> getDeclKind (), Node-> getFullyQualifiedName (),
3667
+ ScreenInfo,
3721
3668
getOwnershipDescription (Node->getReferenceOwnership ()),
3722
3669
getOwnershipDescription (Count->getReferenceOwnership ()));
3723
3670
return ;
3724
3671
}
3725
3672
case NodeAnnotation::ChangeGenericSignature: {
3726
3673
MetaInfo ScreenInfo (Node, false );
3727
- GSChangeDecls.Diags .emplace_back (ScreenInfo, Node->getDeclKind (),
3728
- Node->getFullyQualifiedName (), Node->getGenericSignature (),
3674
+ GSChangeDecls.Diags .emplace_back (ScreenInfo, Node->getGenericSignature (),
3729
3675
UpdateMap.findUpdateCounterpart (Node)->getAs <SDKNodeDecl>()->
3730
3676
getGenericSignature ());
3731
3677
return ;
@@ -3742,8 +3688,7 @@ void DiagnosisEmitter::handle(const SDKNodeDecl *Node, NodeAnnotation Anno) {
3742
3688
auto Desc = Node->hasDeclAttribute (It->Kind ) ?
3743
3689
Ctx.buffer ((llvm::Twine (" without " ) + It->Content ).str ()):
3744
3690
Ctx.buffer ((llvm::Twine (" with " ) + It->Content ).str ());
3745
- AttrChangedDecls.Diags .emplace_back (ScreenInfo, Node->getDeclKind (),
3746
- Node->getFullyQualifiedName (), Desc);
3691
+ AttrChangedDecls.Diags .emplace_back (ScreenInfo, Desc);
3747
3692
return ;
3748
3693
}
3749
3694
}
@@ -3761,7 +3706,7 @@ void DiagnosisEmitter::visitType(SDKNodeType *Node) {
3761
3706
auto *Parent = dyn_cast<SDKNodeDecl>(Node->getParent ());
3762
3707
if (!Parent || Parent->isSDKPrivate ())
3763
3708
return ;
3764
- MetaInfo ScreenInfo (Parent);
3709
+ MetaInfo ScreenInfo (Parent, false );
3765
3710
SDKContext &Ctx = Node->getSDKContext ();
3766
3711
if (Node->isAnnotatedAs (NodeAnnotation::Updated)) {
3767
3712
auto *Count = UpdateMap.findUpdateCounterpart (Node)->getAs <SDKNodeType>();
@@ -3775,8 +3720,6 @@ void DiagnosisEmitter::visitType(SDKNodeType *Node) {
3775
3720
Ctx.buffer (" declared" );
3776
3721
if (Node->getPrintedName () != Count->getPrintedName ())
3777
3722
TypeChangedDecls.Diags .emplace_back (ScreenInfo,
3778
- Parent->getDeclKind (),
3779
- Parent->getFullyQualifiedName (),
3780
3723
Node->getPrintedName (),
3781
3724
Count->getPrintedName (),
3782
3725
Descriptor);
0 commit comments