@@ -1669,6 +1669,13 @@ SILGenFunction::emitVTableThunk(SILDeclRef derived,
1669
1669
F.setContextGenericParams (context);
1670
1670
subs = getForwardingSubstitutions ();
1671
1671
fTy = fTy ->substGenericArgs (SGM.M , SGM.SwiftModule , subs);
1672
+
1673
+ inputSubstType = cast<FunctionType>(
1674
+ cast<GenericFunctionType>(inputSubstType)
1675
+ ->substGenericArgs (SGM.SwiftModule , subs)->getCanonicalType ());
1676
+ outputSubstType = cast<FunctionType>(
1677
+ cast<GenericFunctionType>(outputSubstType)
1678
+ ->substGenericArgs (SGM.SwiftModule , subs)->getCanonicalType ());
1672
1679
}
1673
1680
1674
1681
// Emit the indirect return and arguments.
@@ -1839,10 +1846,10 @@ void SILGenFunction::emitProtocolWitness(ProtocolConformance *conformance,
1839
1846
1840
1847
// Get the type of the witness.
1841
1848
auto witnessInfo = getConstantInfo (witness);
1842
- CanAnyFunctionType witnessSubstTy = witnessInfo.LoweredType ;
1849
+ CanAnyFunctionType witnessSubstTy = witnessInfo.LoweredInterfaceType ;
1843
1850
if (!witnessSubs.empty ()) {
1844
1851
witnessSubstTy = cast<FunctionType>(
1845
- cast<PolymorphicFunctionType >(witnessSubstTy)
1852
+ cast<GenericFunctionType >(witnessSubstTy)
1846
1853
->substGenericArgs (SGM.M .getSwiftModule (), witnessSubs)
1847
1854
->getCanonicalType ());
1848
1855
}
@@ -1852,17 +1859,19 @@ void SILGenFunction::emitProtocolWitness(ProtocolConformance *conformance,
1852
1859
// abstraction pattern.
1853
1860
auto reqtInfo = getConstantInfo (requirement);
1854
1861
1855
- // Ugh...
1856
- CanAnyFunctionType reqtSubstTy = reqtInfo.FormalType ;
1862
+ // FIXME: reqtSubstTy is already computed in SGM::emitProtocolWitness(),
1863
+ // but its called witnessSubstIfaceTy there; the mapTypeIntoContext()
1864
+ // calls should be pushed down into thunk emission.
1865
+ CanAnyFunctionType reqtSubstTy = reqtInfo.LoweredInterfaceType ;
1857
1866
reqtSubstTy = cast<AnyFunctionType>(
1858
- cast<PolymorphicFunctionType >(reqtSubstTy)
1859
- ->substGenericArgs (conformance->getDeclContext ()->getParentModule (),
1860
- conformance->getType ())
1867
+ cast<GenericFunctionType >(reqtSubstTy)
1868
+ ->partialSubstGenericArgs (conformance->getDeclContext ()->getParentModule (),
1869
+ conformance->getInterfaceType ())
1861
1870
->getCanonicalType ());
1862
- reqtSubstTy = SGM. Types . getLoweredASTFunctionType (reqtSubstTy,
1863
- requirement. uncurryLevel ,
1864
- requirement);
1865
- CanType reqtSubstInputTy = reqtSubstTy. getInput ();
1871
+ CanType reqtSubstInputTy = F. mapTypeIntoContext (reqtSubstTy. getInput ())
1872
+ -> getCanonicalType ();
1873
+ CanType reqtSubstResultTy = F. mapTypeIntoContext (reqtSubstTy. getResult ())
1874
+ -> getCanonicalType ();
1866
1875
1867
1876
AbstractionPattern reqtOrigTy (reqtInfo.LoweredInterfaceType );
1868
1877
AbstractionPattern reqtOrigInputTy = reqtOrigTy.getFunctionInputType ();
@@ -1981,7 +1990,7 @@ void SILGenFunction::emitProtocolWitness(ProtocolConformance *conformance,
1981
1990
AbstractionPattern (witnessSubstTy.getResult ()), // XXX ugly
1982
1991
witnessSubstTy.getResult (),
1983
1992
reqtOrigTy.getFunctionResultType (),
1984
- reqtSubstTy. getResult () ,
1993
+ reqtSubstResultTy ,
1985
1994
witnessResultValue,
1986
1995
witnessSubstResultAddr,
1987
1996
reqtResultAddr);
0 commit comments