Skip to content

Commit c044889

Browse files
committed
SILGen: Remove redundant mapType{Into,OutOf}Context() calls
1 parent 68dc945 commit c044889

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

lib/SIL/SILVerifier.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,12 +1720,19 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
17201720
// Get the expected type of a dynamic method reference.
17211721
SILType getDynamicMethodType(SILType selfType, SILDeclRef method) {
17221722
auto &C = F.getASTContext();
1723-
1723+
17241724
// The type of the dynamic method must match the usual type of the method,
17251725
// but with the more opaque Self type.
1726-
auto methodTy = F.getModule().Types.getConstantType(method)
1727-
.castTo<SILFunctionType>();
1728-
1726+
auto constantInfo = F.getModule().Types.getConstantInfo(method);
1727+
auto methodTy = constantInfo.SILFnType;
1728+
1729+
// Map interface types to archetypes.
1730+
if (auto *params = constantInfo.ContextGenericParams)
1731+
methodTy = methodTy->substGenericArgs(F.getModule(), M,
1732+
params->getForwardingSubstitutions(C));
1733+
assert(!methodTy->isPolymorphic());
1734+
1735+
// Replace Self parameter with type of 'self' at the call site.
17291736
auto params = methodTy->getParameters();
17301737
SmallVector<SILParameterInfo, 4>
17311738
dynParams(params.begin(), params.end() - 1);
@@ -1756,10 +1763,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
17561763
dynResults,
17571764
methodTy->getOptionalErrorResult(),
17581765
F.getASTContext());
1759-
auto boundFnTy = ArchetypeBuilder::mapTypeIntoContext(
1760-
method.getDecl()->getDeclContext(), fnTy)
1761-
->getCanonicalType();
1762-
return SILType::getPrimitiveObjectType(boundFnTy);
1766+
return SILType::getPrimitiveObjectType(fnTy);
17631767
}
17641768

17651769
void checkDynamicMethodInst(DynamicMethodInst *EMI) {

lib/SILGen/SILGenBridging.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,8 @@ ManagedValue SILGenFunction::emitFuncToBlock(SILLocation loc,
353353
// thunks, which is what we are in spirit.
354354
auto thunk = SGM.getOrCreateReabstractionThunk(F.getContextGenericParams(),
355355
invokeTy,
356-
fnInterfaceTy,
357-
blockInterfaceTy,
356+
fnTy,
357+
blockTy,
358358
F.isFragile());
359359

360360
// Build it if necessary.
@@ -772,7 +772,7 @@ static SILFunctionType *emitObjCThunkArguments(SILGenFunction &gen,
772772
// Emit the indirect result arguments, if any.
773773
// FIXME: we're just assuming that these match up exactly?
774774
for (auto indirectResult : objcFnTy->getIndirectResults()) {
775-
SILType argTy = gen.F.mapTypeIntoContext(indirectResult.getSILType());
775+
SILType argTy = indirectResult.getSILType();
776776
auto arg = new (gen.F.getModule()) SILArgument(gen.F.begin(), argTy);
777777
args.push_back(arg);
778778
}
@@ -783,7 +783,7 @@ static SILFunctionType *emitObjCThunkArguments(SILGenFunction &gen,
783783
assert(inputs.size() ==
784784
nativeInputs.size() + unsigned(foreignError.hasValue()));
785785
for (unsigned i = 0, e = inputs.size(); i < e; ++i) {
786-
SILType argTy = gen.F.mapTypeIntoContext(inputs[i].getSILType());
786+
SILType argTy = inputs[i].getSILType();
787787
SILValue arg = new(gen.F.getModule()) SILArgument(gen.F.begin(), argTy);
788788

789789
// If this parameter is the foreign error slot, pull it out.
@@ -832,8 +832,7 @@ static SILFunctionType *emitObjCThunkArguments(SILGenFunction &gen,
832832
Scope scope(gen.Cleanups, CleanupLocation::get(loc));
833833
assert(bridgedArgs.size() == nativeInputs.size());
834834
for (unsigned i = 0, size = bridgedArgs.size(); i < size; ++i) {
835-
SILType argTy = gen.F.mapTypeIntoContext(
836-
swiftFnTy->getParameters()[i].getSILType());
835+
SILType argTy = swiftFnTy->getParameters()[i].getSILType();
837836
ManagedValue native =
838837
gen.emitBridgedToNativeValue(loc,
839838
bridgedArgs[i],
@@ -869,8 +868,7 @@ void SILGenFunction::emitNativeToForeignThunk(SILDeclRef thunk) {
869868
auto nativeInfo = getConstantInfo(native);
870869
auto swiftResultTy =
871870
F.mapTypeIntoContext(nativeInfo.SILFnType->getSILResult());
872-
auto objcResultTy =
873-
F.mapTypeIntoContext(objcFnTy->getSILResult());
871+
auto objcResultTy = objcFnTy->getSILResult();
874872

875873
// Call the native entry point.
876874
SILValue nativeFn = emitGlobalFunctionRef(loc, native, nativeInfo);

0 commit comments

Comments
 (0)