Skip to content

Commit e35e30a

Browse files
committed
SILGen: Orient witness and vtable thunk emission toward interface types, NFC
1 parent 0188258 commit e35e30a

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

lib/SILGen/SILGenPoly.cpp

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,6 +1669,13 @@ SILGenFunction::emitVTableThunk(SILDeclRef derived,
16691669
F.setContextGenericParams(context);
16701670
subs = getForwardingSubstitutions();
16711671
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());
16721679
}
16731680

16741681
// Emit the indirect return and arguments.
@@ -1839,10 +1846,10 @@ void SILGenFunction::emitProtocolWitness(ProtocolConformance *conformance,
18391846

18401847
// Get the type of the witness.
18411848
auto witnessInfo = getConstantInfo(witness);
1842-
CanAnyFunctionType witnessSubstTy = witnessInfo.LoweredType;
1849+
CanAnyFunctionType witnessSubstTy = witnessInfo.LoweredInterfaceType;
18431850
if (!witnessSubs.empty()) {
18441851
witnessSubstTy = cast<FunctionType>(
1845-
cast<PolymorphicFunctionType>(witnessSubstTy)
1852+
cast<GenericFunctionType>(witnessSubstTy)
18461853
->substGenericArgs(SGM.M.getSwiftModule(), witnessSubs)
18471854
->getCanonicalType());
18481855
}
@@ -1852,17 +1859,19 @@ void SILGenFunction::emitProtocolWitness(ProtocolConformance *conformance,
18521859
// abstraction pattern.
18531860
auto reqtInfo = getConstantInfo(requirement);
18541861

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;
18571866
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())
18611870
->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();
18661875

18671876
AbstractionPattern reqtOrigTy(reqtInfo.LoweredInterfaceType);
18681877
AbstractionPattern reqtOrigInputTy = reqtOrigTy.getFunctionInputType();
@@ -1981,7 +1990,7 @@ void SILGenFunction::emitProtocolWitness(ProtocolConformance *conformance,
19811990
AbstractionPattern(witnessSubstTy.getResult()), // XXX ugly
19821991
witnessSubstTy.getResult(),
19831992
reqtOrigTy.getFunctionResultType(),
1984-
reqtSubstTy.getResult(),
1993+
reqtSubstResultTy,
19851994
witnessResultValue,
19861995
witnessSubstResultAddr,
19871996
reqtResultAddr);

lib/SILGen/SILGenType.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ SILGenModule::emitVTableMethod(SILDeclRef derived, SILDeclRef base) {
9494

9595
SILGenFunction(*this, *thunk)
9696
.emitVTableThunk(derived, basePattern,
97-
overrideInfo.LoweredType, derivedInfo.LoweredType);
97+
overrideInfo.LoweredInterfaceType,
98+
derivedInfo.LoweredInterfaceType);
9899

99100
return thunk;
100101
}

0 commit comments

Comments
 (0)