@@ -1728,8 +1728,7 @@ static CanAnyFunctionType getGlobalGetterType(CanType varType) {
1728
1728
static CanAnyFunctionType getDefaultArgGeneratorInterfaceType (
1729
1729
TypeConverter &TC,
1730
1730
AbstractFunctionDecl *AFD,
1731
- unsigned DefaultArgIndex,
1732
- ASTContext &context) {
1731
+ unsigned DefaultArgIndex) {
1733
1732
auto resultTy = AFD->getDefaultArg (DefaultArgIndex).second ;
1734
1733
assert (resultTy && " Didn't find default argument?" );
1735
1734
@@ -1742,52 +1741,50 @@ static CanAnyFunctionType getDefaultArgGeneratorInterfaceType(
1742
1741
// Get the generic signature from the surrounding context.
1743
1742
auto funcInfo = TC.getConstantInfo (SILDeclRef (AFD));
1744
1743
CanGenericSignature sig;
1745
- if (auto genTy = funcInfo. FormalInterfaceType -> getAs <GenericFunctionType>())
1746
- sig = genTy-> getGenericSignature ()-> getCanonicalSignature ();
1744
+ if (auto genTy = dyn_cast <GenericFunctionType>(funcInfo. FormalInterfaceType ))
1745
+ sig = genTy. getGenericSignature ();
1747
1746
1748
1747
if (sig) {
1749
- return cast<GenericFunctionType>(
1750
- GenericFunctionType::get (sig,
1751
- TupleType::getEmpty (context),
1752
- canResultTy,
1753
- AnyFunctionType::ExtInfo ())
1754
- ->getCanonicalType ());
1748
+ return CanGenericFunctionType::get (sig,
1749
+ TupleType::getEmpty (TC.Context ),
1750
+ canResultTy,
1751
+ AnyFunctionType::ExtInfo ());
1755
1752
}
1756
1753
1757
- return CanFunctionType::get (TupleType::getEmpty (context ), canResultTy);
1754
+ return CanFunctionType::get (TupleType::getEmpty (TC. Context ), canResultTy);
1758
1755
}
1759
1756
1760
1757
// / Get the type of a stored property initializer, () -> T.
1761
1758
static CanAnyFunctionType getStoredPropertyInitializerInterfaceType (
1762
1759
TypeConverter &TC,
1763
- VarDecl *VD,
1764
- ASTContext &context) {
1760
+ VarDecl *VD) {
1765
1761
auto *DC = VD->getDeclContext ();
1766
1762
CanType resultTy =
1767
1763
DC->mapTypeOutOfContext (VD->getParentPattern ()->getType ())
1768
1764
->getCanonicalType ();
1769
- GenericSignature * sig = DC-> getGenericSignatureOfContext ( );
1765
+ auto sig = TC. getEffectiveGenericSignature (DC );
1770
1766
1771
1767
if (sig)
1772
- return CanGenericFunctionType::get (sig-> getCanonicalSignature () ,
1773
- TupleType::getEmpty (context ),
1768
+ return CanGenericFunctionType::get (sig,
1769
+ TupleType::getEmpty (TC. Context ),
1774
1770
resultTy,
1775
1771
GenericFunctionType::ExtInfo ());
1776
1772
1777
- return CanFunctionType::get (TupleType::getEmpty (context ), resultTy);
1773
+ return CanFunctionType::get (TupleType::getEmpty (TC. Context ), resultTy);
1778
1774
}
1779
1775
1780
1776
// / Get the type of a destructor function.
1781
- static CanAnyFunctionType getDestructorInterfaceType (DestructorDecl *dd,
1777
+ static CanAnyFunctionType getDestructorInterfaceType (TypeConverter &TC,
1778
+ DestructorDecl *dd,
1782
1779
bool isDeallocating,
1783
- ASTContext &C,
1784
1780
bool isForeign) {
1785
1781
auto classType = dd->getDeclContext ()->getDeclaredInterfaceType ()
1786
- ->getCanonicalType ();
1782
+ ->getCanonicalType (dd->getGenericSignatureOfContext (),
1783
+ *TC.M .getSwiftModule ());
1787
1784
1788
1785
assert ((!isForeign || isDeallocating)
1789
1786
&& " There are no foreign destroying destructors" );
1790
- AnyFunctionType::ExtInfo extInfo =
1787
+ auto extInfo =
1791
1788
AnyFunctionType::ExtInfo (FunctionType::Representation::Thin,
1792
1789
/* throws*/ false );
1793
1790
if (isForeign)
@@ -1797,37 +1794,39 @@ static CanAnyFunctionType getDestructorInterfaceType(DestructorDecl *dd,
1797
1794
extInfo = extInfo
1798
1795
.withSILRepresentation (SILFunctionTypeRepresentation::Method);
1799
1796
1800
- CanType resultTy = isDeallocating? TupleType::getEmpty (C)->getCanonicalType ()
1801
- : C.TheNativeObjectType ;
1797
+ auto &C = TC.Context ;
1798
+ CanType resultTy = (isDeallocating
1799
+ ? TupleType::getEmpty (C)
1800
+ : C.TheNativeObjectType );
1802
1801
1803
- auto sig = dd-> getDeclContext ()-> getGenericSignatureOfContext ( );
1802
+ auto sig = TC. getEffectiveGenericSignature (dd );
1804
1803
if (sig)
1805
- return cast<GenericFunctionType>(
1806
- GenericFunctionType::get (sig, classType, resultTy, extInfo)
1807
- ->getCanonicalType ());
1804
+ return CanGenericFunctionType::get (sig, classType, resultTy, extInfo);
1808
1805
return CanFunctionType::get (classType, resultTy, extInfo);
1809
1806
}
1810
1807
1811
1808
// / Retrieve the type of the ivar initializer or destroyer method for
1812
1809
// / a class.
1813
- static CanAnyFunctionType getIVarInitDestroyerInterfaceType (ClassDecl *cd,
1810
+ static CanAnyFunctionType getIVarInitDestroyerInterfaceType (TypeConverter &TC,
1811
+ ClassDecl *cd,
1814
1812
bool isObjC,
1815
- ASTContext &ctx,
1816
1813
bool isDestroyer) {
1817
- auto classType = cd->getDeclaredInterfaceType ()->getCanonicalType ();
1814
+ auto classType = cd->getDeclaredInterfaceType ()
1815
+ ->getCanonicalType (cd->getGenericSignatureOfContext (),
1816
+ *TC.M .getSwiftModule ());
1818
1817
1819
- auto emptyTupleTy = TupleType::getEmpty (ctx)-> getCanonicalType ( );
1820
- CanType resultType = isDestroyer? emptyTupleTy : classType;
1818
+ CanType emptyTupleTy = TupleType::getEmpty (TC. Context );
1819
+ auto resultType = ( isDestroyer ? emptyTupleTy : classType) ;
1821
1820
auto extInfo = AnyFunctionType::ExtInfo (FunctionType::Representation::Thin,
1822
1821
/* throws*/ false );
1823
1822
extInfo = extInfo
1824
1823
.withSILRepresentation (isObjC? SILFunctionTypeRepresentation::ObjCMethod
1825
1824
: SILFunctionTypeRepresentation::Method);
1826
1825
1827
1826
resultType = CanFunctionType::get (emptyTupleTy, resultType, extInfo);
1828
- auto sig = cd-> getGenericSignatureOfContext ( );
1827
+ auto sig = TC. getEffectiveGenericSignature (cd );
1829
1828
if (sig)
1830
- return CanGenericFunctionType::get (sig-> getCanonicalSignature () ,
1829
+ return CanGenericFunctionType::get (sig,
1831
1830
classType, resultType,
1832
1831
extInfo);
1833
1832
return CanFunctionType::get (classType, resultType, extInfo);
@@ -1844,6 +1843,17 @@ TypeConverter::getEffectiveGenericEnvironment(AnyFunctionRef fn,
1844
1843
return nullptr ;
1845
1844
}
1846
1845
1846
+ CanGenericSignature
1847
+ TypeConverter::getEffectiveGenericSignature (DeclContext *dc) {
1848
+ if (auto sig = dc->getGenericSignatureOfContext ()) {
1849
+ if (sig->areAllParamsConcrete ())
1850
+ return nullptr ;
1851
+ return sig->getCanonicalSignature ();
1852
+ }
1853
+
1854
+ return nullptr ;
1855
+ }
1856
+
1847
1857
CanGenericSignature
1848
1858
TypeConverter::getEffectiveGenericSignature (AnyFunctionRef fn,
1849
1859
CaptureInfo captureInfo) {
@@ -1853,13 +1863,7 @@ TypeConverter::getEffectiveGenericSignature(AnyFunctionRef fn,
1853
1863
!captureInfo.hasGenericParamCaptures ())
1854
1864
return nullptr ;
1855
1865
1856
- if (auto sig = dc->getGenericSignatureOfContext ()) {
1857
- if (sig->areAllParamsConcrete ())
1858
- return nullptr ;
1859
- return sig->getCanonicalSignature ();
1860
- }
1861
-
1862
- return nullptr ;
1866
+ return getEffectiveGenericSignature (dc);
1863
1867
}
1864
1868
1865
1869
CanAnyFunctionType
@@ -1926,10 +1930,10 @@ CanAnyFunctionType TypeConverter::makeConstantInterfaceType(SILDeclRef c) {
1926
1930
1927
1931
case SILDeclRef::Kind::Destroyer:
1928
1932
case SILDeclRef::Kind::Deallocator:
1929
- return getDestructorInterfaceType (cast<DestructorDecl>(vd) ,
1930
- c. kind == SILDeclRef::Kind::Deallocator ,
1931
- Context ,
1932
- c.isForeign );
1933
+ return getDestructorInterfaceType (* this ,
1934
+ cast<DestructorDecl>(vd) ,
1935
+ c. kind == SILDeclRef::Kind::Deallocator ,
1936
+ c.isForeign );
1933
1937
1934
1938
case SILDeclRef::Kind::GlobalAccessor: {
1935
1939
VarDecl *var = cast<VarDecl>(vd);
@@ -1946,17 +1950,18 @@ CanAnyFunctionType TypeConverter::makeConstantInterfaceType(SILDeclRef c) {
1946
1950
case SILDeclRef::Kind::DefaultArgGenerator:
1947
1951
return getDefaultArgGeneratorInterfaceType (*this ,
1948
1952
cast<AbstractFunctionDecl>(vd),
1949
- c.defaultArgIndex , Context );
1953
+ c.defaultArgIndex );
1950
1954
case SILDeclRef::Kind::StoredPropertyInitializer:
1951
1955
return getStoredPropertyInitializerInterfaceType (*this ,
1952
- cast<VarDecl>(vd),
1953
- Context);
1956
+ cast<VarDecl>(vd));
1954
1957
case SILDeclRef::Kind::IVarInitializer:
1955
- return getIVarInitDestroyerInterfaceType (cast<ClassDecl>(vd),
1956
- c.isForeign , Context, false );
1958
+ return getIVarInitDestroyerInterfaceType (*this ,
1959
+ cast<ClassDecl>(vd),
1960
+ c.isForeign , false );
1957
1961
case SILDeclRef::Kind::IVarDestroyer:
1958
- return getIVarInitDestroyerInterfaceType (cast<ClassDecl>(vd),
1959
- c.isForeign , Context, true );
1962
+ return getIVarInitDestroyerInterfaceType (*this ,
1963
+ cast<ClassDecl>(vd),
1964
+ c.isForeign , true );
1960
1965
}
1961
1966
1962
1967
llvm_unreachable (" Unhandled SILDeclRefKind in switch." );
@@ -2466,9 +2471,7 @@ TypeConverter::getInterfaceBoxTypeForCapture(ValueDecl *captured,
2466
2471
CanType loweredInterfaceType,
2467
2472
bool isMutable) {
2468
2473
auto &C = M.getASTContext ();
2469
- CanGenericSignature signature;
2470
- if (auto sig = captured->getDeclContext ()->getGenericSignatureOfContext ())
2471
- signature = sig->getCanonicalSignature ();
2474
+ auto signature = getEffectiveGenericSignature (captured->getDeclContext ());
2472
2475
2473
2476
// If the type is not dependent at all, we can form a concrete box layout.
2474
2477
// We don't need to capture the generic environment.
0 commit comments