@@ -1445,15 +1445,11 @@ class UsableFromInlineChecker : public AccessControlCheckerBase,
1445
1445
};
1446
1446
1447
1447
class ExportabilityChecker : public DeclVisitor <ExportabilityChecker> {
1448
- using CheckExportabilityTypeCallback =
1449
- llvm::function_ref<void (const TypeDecl *, const TypeRepr *)>;
1450
- using CheckExportabilityConformanceCallback =
1451
- llvm::function_ref<void (const ProtocolConformance *)>;
1448
+ class Diagnoser ;
1452
1449
1453
1450
void checkTypeImpl (
1454
1451
Type type, const TypeRepr *typeRepr, const SourceFile &SF,
1455
- CheckExportabilityTypeCallback diagnoseType,
1456
- CheckExportabilityConformanceCallback diagnoseConformance) {
1452
+ const Diagnoser &diagnoser) {
1457
1453
// Don't bother checking errors.
1458
1454
if (type && type->hasError ())
1459
1455
return ;
@@ -1469,7 +1465,7 @@ class ExportabilityChecker : public DeclVisitor<ExportabilityChecker> {
1469
1465
if (!SF.isImportedImplementationOnly (M))
1470
1466
return true ;
1471
1467
1472
- diagnoseType (component->getBoundDecl (), component);
1468
+ diagnoser. diagnoseType (component->getBoundDecl (), component);
1473
1469
foundAnyIssues = true ;
1474
1470
// We still continue even in the diagnostic case to report multiple
1475
1471
// violations.
@@ -1488,22 +1484,17 @@ class ExportabilityChecker : public DeclVisitor<ExportabilityChecker> {
1488
1484
1489
1485
class ProblematicTypeFinder : public TypeDeclFinder {
1490
1486
const SourceFile &SF;
1491
- CheckExportabilityTypeCallback diagnoseType;
1492
- CheckExportabilityConformanceCallback diagnoseConformance;
1487
+ const Diagnoser &diagnoser;
1493
1488
public:
1494
- ProblematicTypeFinder (
1495
- const SourceFile &SF,
1496
- CheckExportabilityTypeCallback diagnoseType,
1497
- CheckExportabilityConformanceCallback diagnoseConformance)
1498
- : SF(SF), diagnoseType(diagnoseType),
1499
- diagnoseConformance (diagnoseConformance) {}
1489
+ ProblematicTypeFinder (const SourceFile &SF, const Diagnoser &diagnoser)
1490
+ : SF(SF), diagnoser(diagnoser) {}
1500
1491
1501
1492
void visitTypeDecl (const TypeDecl *typeDecl) {
1502
1493
ModuleDecl *M = typeDecl->getModuleContext ();
1503
1494
if (!SF.isImportedImplementationOnly (M))
1504
1495
return ;
1505
1496
1506
- diagnoseType (typeDecl, /* typeRepr*/ nullptr );
1497
+ diagnoser. diagnoseType (typeDecl, /* typeRepr*/ nullptr );
1507
1498
}
1508
1499
1509
1500
void visitSubstitutionMap (SubstitutionMap subs) {
@@ -1521,7 +1512,7 @@ class ExportabilityChecker : public DeclVisitor<ExportabilityChecker> {
1521
1512
ModuleDecl *M = rootConf->getDeclContext ()->getParentModule ();
1522
1513
if (!SF.isImportedImplementationOnly (M))
1523
1514
continue ;
1524
- diagnoseConformance (rootConf);
1515
+ diagnoser. diagnoseConformance (rootConf);
1525
1516
}
1526
1517
}
1527
1518
@@ -1545,25 +1536,20 @@ class ExportabilityChecker : public DeclVisitor<ExportabilityChecker> {
1545
1536
}
1546
1537
};
1547
1538
1548
- type.walk(ProblematicTypeFinder(SF, diagnoseType, diagnoseConformance ));
1539
+ type.walk (ProblematicTypeFinder (SF, diagnoser ));
1549
1540
}
1550
1541
1551
1542
void checkType (
1552
1543
Type type, const TypeRepr *typeRepr, const Decl *context,
1553
- CheckExportabilityTypeCallback diagnoseType,
1554
- CheckExportabilityConformanceCallback diagnoseConformance) {
1544
+ const Diagnoser &diagnoser) {
1555
1545
auto *SF = context->getDeclContext ()->getParentSourceFile ();
1556
1546
assert (SF && " checking a non-source declaration?" );
1557
- return checkTypeImpl (type, typeRepr, *SF, diagnoseType,
1558
- diagnoseConformance);
1547
+ return checkTypeImpl (type, typeRepr, *SF, diagnoser);
1559
1548
}
1560
1549
1561
1550
void checkType (
1562
- const TypeLoc &TL, const Decl *context,
1563
- CheckExportabilityTypeCallback diagnoseType,
1564
- CheckExportabilityConformanceCallback diagnoseConformance) {
1565
- checkType (TL.getType (), TL.getTypeRepr (), context, diagnoseType,
1566
- diagnoseConformance);
1551
+ const TypeLoc &TL, const Decl *context, const Diagnoser &diagnoser) {
1552
+ checkType (TL.getType (), TL.getTypeRepr (), context, diagnoser);
1567
1553
}
1568
1554
1569
1555
void checkGenericParams (const GenericContext *ownerCtx,
@@ -1577,15 +1563,13 @@ class ExportabilityChecker : public DeclVisitor<ExportabilityChecker> {
1577
1563
continue ;
1578
1564
assert (param->getInherited ().size () == 1 );
1579
1565
checkType (param->getInherited ().front (), ownerDecl,
1580
- getDiagnoseCallback (ownerDecl),
1581
- getDiagnoseCallback (ownerDecl));
1566
+ getDiagnoser (ownerDecl));
1582
1567
}
1583
1568
1584
1569
forAllRequirementTypes (WhereClauseOwner (
1585
1570
const_cast <GenericContext *>(ownerCtx)),
1586
1571
[&](Type type, TypeRepr *typeRepr) {
1587
- checkType (type, typeRepr, ownerDecl, getDiagnoseCallback (ownerDecl),
1588
- getDiagnoseCallback (ownerDecl));
1572
+ checkType (type, typeRepr, ownerDecl, getDiagnoser (ownerDecl));
1589
1573
});
1590
1574
}
1591
1575
@@ -1598,14 +1582,14 @@ class ExportabilityChecker : public DeclVisitor<ExportabilityChecker> {
1598
1582
ExtensionWithConditionalConformances
1599
1583
};
1600
1584
1601
- class DiagnoseGenerically {
1585
+ class Diagnoser {
1602
1586
const Decl *D;
1603
1587
Reason reason;
1604
1588
public:
1605
- DiagnoseGenerically (const Decl *D, Reason reason) : D(D), reason(reason) {}
1589
+ Diagnoser (const Decl *D, Reason reason) : D(D), reason(reason) {}
1606
1590
1607
- void operator () (const TypeDecl *offendingType,
1608
- const TypeRepr *complainRepr) {
1591
+ void diagnoseType (const TypeDecl *offendingType,
1592
+ const TypeRepr *complainRepr) const {
1609
1593
ModuleDecl *M = offendingType->getModuleContext ();
1610
1594
auto diag = D->diagnose (diag::decl_from_implementation_only_module,
1611
1595
offendingType->getDescriptiveKind (),
@@ -1614,7 +1598,7 @@ class ExportabilityChecker : public DeclVisitor<ExportabilityChecker> {
1614
1598
highlightOffendingType (diag, complainRepr);
1615
1599
}
1616
1600
1617
- void operator ()( const ProtocolConformance *offendingConformance) {
1601
+ void diagnoseConformance ( const ProtocolConformance *offendingConformance) const {
1618
1602
ModuleDecl *M = offendingConformance->getDeclContext ()->getParentModule ();
1619
1603
D->diagnose (diag::conformance_from_implementation_only_module,
1620
1604
offendingConformance->getType (),
@@ -1623,18 +1607,8 @@ class ExportabilityChecker : public DeclVisitor<ExportabilityChecker> {
1623
1607
}
1624
1608
};
1625
1609
1626
- static_assert (
1627
- std::is_convertible<DiagnoseGenerically,
1628
- CheckExportabilityTypeCallback>::value,
1629
- " DiagnoseGenerically has wrong call signature" );
1630
- static_assert (
1631
- std::is_convertible<DiagnoseGenerically,
1632
- CheckExportabilityConformanceCallback>::value,
1633
- " DiagnoseGenerically has wrong call signature for conformance diags" );
1634
-
1635
- DiagnoseGenerically getDiagnoseCallback (const Decl *D,
1636
- Reason reason = Reason::General) {
1637
- return DiagnoseGenerically (D, reason);
1610
+ Diagnoser getDiagnoser (const Decl *D, Reason reason = Reason::General) {
1611
+ return Diagnoser (D, reason);
1638
1612
}
1639
1613
1640
1614
public:
@@ -1768,7 +1742,7 @@ class ExportabilityChecker : public DeclVisitor<ExportabilityChecker> {
1768
1742
return ;
1769
1743
1770
1744
checkType (theVar->getInterfaceType (), /* typeRepr*/ nullptr , theVar,
1771
- getDiagnoseCallback (theVar), getDiagnoseCallback (theVar));
1745
+ getDiagnoser (theVar));
1772
1746
}
1773
1747
1774
1748
// / \see visitPatternBindingDecl
@@ -1787,8 +1761,7 @@ class ExportabilityChecker : public DeclVisitor<ExportabilityChecker> {
1787
1761
if (shouldSkipChecking (anyVar))
1788
1762
return ;
1789
1763
1790
- checkType (TP->getTypeLoc (), anyVar, getDiagnoseCallback (anyVar),
1791
- getDiagnoseCallback (anyVar));
1764
+ checkType (TP->getTypeLoc (), anyVar, getDiagnoser (anyVar));
1792
1765
}
1793
1766
1794
1767
void visitPatternBindingDecl (PatternBindingDecl *PBD) {
@@ -1812,25 +1785,22 @@ class ExportabilityChecker : public DeclVisitor<ExportabilityChecker> {
1812
1785
void visitTypeAliasDecl (TypeAliasDecl *TAD) {
1813
1786
checkGenericParams (TAD, TAD);
1814
1787
checkType (TAD->getUnderlyingType (),
1815
- TAD->getUnderlyingTypeRepr (), TAD, getDiagnoseCallback (TAD),
1816
- getDiagnoseCallback (TAD));
1788
+ TAD->getUnderlyingTypeRepr (), TAD, getDiagnoser (TAD));
1817
1789
}
1818
1790
1819
1791
void visitAssociatedTypeDecl (AssociatedTypeDecl *assocType) {
1820
1792
llvm::for_each (assocType->getInherited (),
1821
1793
[&](TypeLoc requirement) {
1822
- checkType (requirement, assocType, getDiagnoseCallback (assocType),
1823
- getDiagnoseCallback (assocType));
1794
+ checkType (requirement, assocType, getDiagnoser (assocType));
1824
1795
});
1825
1796
checkType (assocType->getDefaultDefinitionType (),
1826
1797
assocType->getDefaultDefinitionTypeRepr (), assocType,
1827
- getDiagnoseCallback (assocType), getDiagnoseCallback (assocType));
1798
+ getDiagnoser (assocType));
1828
1799
1829
1800
if (assocType->getTrailingWhereClause ()) {
1830
1801
forAllRequirementTypes (assocType,
1831
1802
[&](Type type, TypeRepr *typeRepr) {
1832
- checkType (type, typeRepr, assocType, getDiagnoseCallback (assocType),
1833
- getDiagnoseCallback (assocType));
1803
+ checkType (type, typeRepr, assocType, getDiagnoser (assocType));
1834
1804
});
1835
1805
}
1836
1806
}
@@ -1840,22 +1810,19 @@ class ExportabilityChecker : public DeclVisitor<ExportabilityChecker> {
1840
1810
1841
1811
llvm::for_each (nominal->getInherited (),
1842
1812
[&](TypeLoc nextInherited) {
1843
- checkType (nextInherited, nominal, getDiagnoseCallback (nominal),
1844
- getDiagnoseCallback (nominal));
1813
+ checkType (nextInherited, nominal, getDiagnoser (nominal));
1845
1814
});
1846
1815
}
1847
1816
1848
1817
void visitProtocolDecl (ProtocolDecl *proto) {
1849
1818
llvm::for_each (proto->getInherited (),
1850
1819
[&](TypeLoc requirement) {
1851
- checkType (requirement, proto, getDiagnoseCallback (proto),
1852
- getDiagnoseCallback (proto));
1820
+ checkType (requirement, proto, getDiagnoser (proto));
1853
1821
});
1854
1822
1855
1823
if (proto->getTrailingWhereClause ()) {
1856
1824
forAllRequirementTypes (proto, [&](Type type, TypeRepr *typeRepr) {
1857
- checkType (type, typeRepr, proto, getDiagnoseCallback (proto),
1858
- getDiagnoseCallback (proto));
1825
+ checkType (type, typeRepr, proto, getDiagnoser (proto));
1859
1826
});
1860
1827
}
1861
1828
}
@@ -1865,41 +1832,38 @@ class ExportabilityChecker : public DeclVisitor<ExportabilityChecker> {
1865
1832
1866
1833
for (auto &P : *SD->getIndices ()) {
1867
1834
checkType (P->getInterfaceType (), P->getTypeRepr (), SD,
1868
- getDiagnoseCallback (SD), getDiagnoseCallback (SD));
1835
+ getDiagnoser (SD));
1869
1836
}
1870
- checkType (SD->getElementTypeLoc (), SD, getDiagnoseCallback (SD),
1871
- getDiagnoseCallback (SD));
1837
+ checkType (SD->getElementTypeLoc (), SD, getDiagnoser (SD));
1872
1838
}
1873
1839
1874
1840
void visitAbstractFunctionDecl (AbstractFunctionDecl *fn) {
1875
1841
checkGenericParams (fn, fn);
1876
1842
1877
1843
for (auto *P : *fn->getParameters ())
1878
1844
checkType (P->getInterfaceType (), P->getTypeRepr (), fn,
1879
- getDiagnoseCallback (fn), getDiagnoseCallback (fn));
1845
+ getDiagnoser (fn));
1880
1846
}
1881
1847
1882
1848
void visitFuncDecl (FuncDecl *FD) {
1883
1849
visitAbstractFunctionDecl (FD);
1884
- checkType (FD->getBodyResultTypeLoc (), FD, getDiagnoseCallback (FD),
1885
- getDiagnoseCallback (FD));
1850
+ checkType (FD->getBodyResultTypeLoc (), FD, getDiagnoser (FD));
1886
1851
}
1887
1852
1888
1853
void visitEnumElementDecl (EnumElementDecl *EED) {
1889
1854
if (!EED->hasAssociatedValues ())
1890
1855
return ;
1891
1856
for (auto &P : *EED->getParameterList ())
1892
1857
checkType (P->getInterfaceType (), P->getTypeRepr (), EED,
1893
- getDiagnoseCallback (EED), getDiagnoseCallback (EED));
1858
+ getDiagnoser (EED));
1894
1859
}
1895
1860
1896
1861
void checkConstrainedExtensionRequirements (ExtensionDecl *ED,
1897
1862
Reason reason) {
1898
1863
if (!ED->getTrailingWhereClause ())
1899
1864
return ;
1900
1865
forAllRequirementTypes (ED, [&](Type type, TypeRepr *typeRepr) {
1901
- checkType (type, typeRepr, ED, getDiagnoseCallback (ED, reason),
1902
- getDiagnoseCallback (ED, reason));
1866
+ checkType (type, typeRepr, ED, getDiagnoser (ED, reason));
1903
1867
});
1904
1868
}
1905
1869
@@ -1913,8 +1877,7 @@ class ExportabilityChecker : public DeclVisitor<ExportabilityChecker> {
1913
1877
// but just hide that from interfaces.
1914
1878
llvm::for_each (ED->getInherited (),
1915
1879
[&](TypeLoc nextInherited) {
1916
- checkType (nextInherited, ED, getDiagnoseCallback (ED),
1917
- getDiagnoseCallback (ED));
1880
+ checkType (nextInherited, ED, getDiagnoser (ED));
1918
1881
});
1919
1882
1920
1883
bool hasPublicMembers = llvm::any_of (ED->getMembers (),
@@ -1927,8 +1890,7 @@ class ExportabilityChecker : public DeclVisitor<ExportabilityChecker> {
1927
1890
1928
1891
if (hasPublicMembers) {
1929
1892
checkType (ED->getExtendedType (), ED->getExtendedTypeRepr (), ED,
1930
- getDiagnoseCallback (ED, Reason::ExtensionWithPublicMembers),
1931
- getDiagnoseCallback (ED, Reason::ExtensionWithPublicMembers));
1893
+ getDiagnoser (ED, Reason::ExtensionWithPublicMembers));
1932
1894
}
1933
1895
1934
1896
if (hasPublicMembers || !ED->getInherited ().empty ()) {
0 commit comments