Skip to content

Commit b3053cf

Browse files
authored
Merge pull request swiftlang#9035 from swiftix/partial-specialization-fixes
[sil-generic-specializer] Fix bugs in the implementation of partial specialization for partial_apply
2 parents 422ab07 + c897316 commit b3053cf

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

lib/SILOptimizer/Utils/Generics.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,6 +1889,11 @@ SILFunction *ReabstractionThunkGenerator::createThunk() {
18891889

18901890
Thunk->setGenericEnvironment(ReInfo.getSpecializedGenericEnvironment());
18911891

1892+
// Set proper generic context scope for the type lowering.
1893+
CanSILFunctionType SpecType = SpecializedFunc->getLoweredFunctionType();
1894+
Lowering::GenericContextScope GenericScope(M.Types,
1895+
SpecType->getGenericSignature());
1896+
18921897
SILBasicBlock *EntryBB = Thunk->createBasicBlock();
18931898
SILBuilder Builder(EntryBB);
18941899

@@ -1953,12 +1958,14 @@ SILValue ReabstractionThunkGenerator::createReabstractionThunkApply(
19531958
SILBasicBlock *ErrorBB = Thunk->createBasicBlock();
19541959
Builder.createTryApply(Loc, FRI, CalleeSILSubstFnTy, Subs,
19551960
Arguments, NormalBB, ErrorBB);
1956-
auto *ErrorVal = ErrorBB->createPHIArgument(specConv.getSILErrorType(),
1957-
ValueOwnershipKind::Owned);
1961+
auto *ErrorVal = ErrorBB->createPHIArgument(
1962+
SpecializedFunc->mapTypeIntoContext(specConv.getSILErrorType()),
1963+
ValueOwnershipKind::Owned);
19581964
Builder.setInsertionPoint(ErrorBB);
19591965
Builder.createThrow(Loc, ErrorVal);
19601966
SILValue ReturnValue = NormalBB->createPHIArgument(
1961-
specConv.getSILResultType(), ValueOwnershipKind::Owned);
1967+
SpecializedFunc->mapTypeIntoContext(specConv.getSILResultType()),
1968+
ValueOwnershipKind::Owned);
19621969
Builder.setInsertionPoint(NormalBB);
19631970
return ReturnValue;
19641971
}
@@ -1980,9 +1987,6 @@ SILArgument *ReabstractionThunkGenerator::convertReabstractionThunkArguments(
19801987

19811988
assert(specConv.useLoweredAddresses());
19821989

1983-
Lowering::GenericContextScope GenericScope(M.Types,
1984-
SpecType->getGenericSignature());
1985-
19861990
// ReInfo.NumIndirectResults corresponds to SubstTy's formal indirect
19871991
// results. SpecTy may have fewer formal indirect results.
19881992
assert(SubstType->getNumIndirectFormalResults()

0 commit comments

Comments
 (0)