Skip to content

Commit c37ce27

Browse files
committed
Merge rewrite SILCombiner::propagateConcreteTypeOfInitExistential onto 4.2.
1 parent aa492e2 commit c37ce27

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

include/swift/SILOptimizer/Utils/Existential.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef SWIFT_SILOPTIMIZER_UTILS_EXISTENTIAL_H
1414
#define SWIFT_SILOPTIMIZER_UTILS_EXISTENTIAL_H
1515

16+
#include "swift/AST/SubstitutionMap.h"
1617
#include "swift/SIL/SILInstruction.h"
1718

1819
namespace swift {

lib/SILOptimizer/SILCombiner/SILCombinerApplyVisitors.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -725,34 +725,40 @@ SILCombiner::createApplyWithConcreteType(FullApplySite Apply,
725725

726726
// Form a new set of substitutions where Self is
727727
// replaced by a concrete type.
728-
SubstitutionMap OrigCallSubs = Apply.getSubstitutionMap();
728+
auto OrigCallSubs =
729+
Apply.getOrigCalleeType()->getGenericSignature()->getSubstitutionMap(
730+
Apply.getSubstitutions());
729731
SubstitutionMap NewCallSubs = OrigCallSubs.subst(
730732
[&](SubstitutableType *type) -> Type {
731733
if (type == CEI.OpenedArchetype)
732734
return CEI.ConcreteType;
733735
return type;
734736
},
735737
[&](CanType origTy, Type substTy,
736-
ProtocolDecl *proto) -> Optional<ProtocolConformanceRef> {
738+
ProtocolType *proto) -> Optional<ProtocolConformanceRef> {
737739
if (origTy->isEqual(CEI.OpenedArchetype)) {
738740
assert(substTy->isEqual(CEI.ConcreteType));
739741
// Do a conformance lookup on this witness requirement using the
740742
// existential's conformances. The witness requirement may be a base
741743
// type of the existential's requirements.
742-
return CEI.lookupExistentialConformance(proto).getValue();
744+
return CEI.lookupExistentialConformance(proto->getDecl()).getValue();
743745
}
744-
return ProtocolConformanceRef(proto);
746+
return ProtocolConformanceRef(proto->getDecl());
745747
});
746748

749+
SmallVector<Substitution, 8> Substitutions;
750+
Apply.getOrigCalleeType()->getGenericSignature()->getSubstitutions(
751+
NewCallSubs, Substitutions);
752+
747753
SILBuilderWithScope ApplyBuilder(Apply.getInstruction(), BuilderCtx);
748754
FullApplySite NewApply;
749755
if (auto *TAI = dyn_cast<TryApplyInst>(Apply))
750756
NewApply = ApplyBuilder.createTryApply(
751-
Apply.getLoc(), Apply.getCallee(), NewCallSubs, NewArgs,
757+
Apply.getLoc(), Apply.getCallee(), Substitutions, NewArgs,
752758
TAI->getNormalBB(), TAI->getErrorBB());
753759
else
754760
NewApply = ApplyBuilder.createApply(
755-
Apply.getLoc(), Apply.getCallee(), NewCallSubs, NewArgs,
761+
Apply.getLoc(), Apply.getCallee(), Substitutions, NewArgs,
756762
cast<ApplyInst>(Apply)->isNonThrowing());
757763

758764
if (auto NewAI = dyn_cast<ApplyInst>(NewApply))
@@ -825,7 +831,7 @@ SILCombiner::propagateConcreteTypeOfInitExistential(FullApplySite Apply,
825831
auto *NewWMI = WMIBuilder.createWitnessMethod(
826832
WMI->getLoc(), CEI.ConcreteType, SelfConformance, WMI->getMember(),
827833
WMI->getType());
828-
NewWMI->dump();
834+
829835
// Replace only uses of the witness_method in the apply that was analyzed by
830836
// ConcreteExistentialInfo.
831837
MutableArrayRef<Operand> Operands =

lib/SILOptimizer/Utils/Existential.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,9 @@ ConcreteExistentialInfo::ConcreteExistentialInfo(Operand &openedUse) {
240240
CanGenericSignature ExistentialSig =
241241
M.getASTContext().getExistentialSignature(ExistentialType,
242242
M.getSwiftModule());
243-
ExistentialSubs = SubstitutionMap::get(ExistentialSig, {ConcreteType},
244-
ExistentialConformances);
243+
ExistentialSubs = ExistentialSig->getSubstitutionMap(
244+
{Substitution(ConcreteType, ExistentialConformances)});
245+
245246
// If the concrete type is another existential, we're "forwarding" an
246247
// opened existential type, so we must keep track of the original
247248
// defining instruction.

test/SILOptimizer/sil_combine_concrete_existential.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-sil-opt -enable-objc-interop -assume-parsing-unqualified-ownership-sil -enable-sil-verify-all %s -sil-combine | %FileCheck %s
1+
// RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -enable-sil-verify-all %s -sil-combine | %FileCheck %s
22

33
// These tests exercise the same SILCombine optimization as
44
// existential_type_propagation.sil, but cover additional corner

0 commit comments

Comments
 (0)