@@ -839,8 +839,7 @@ bool CSE::processLazyPropertyGetters(SILFunction &F) {
839
839
// / archetypes. Replace such types by performing type substitutions
840
840
// / according to the provided type substitution map.
841
841
static void updateBasicBlockArgTypes (SILBasicBlock *BB,
842
- ArchetypeType *OldOpenedArchetype,
843
- ArchetypeType *NewOpenedArchetype,
842
+ InstructionCloner &Cloner,
844
843
InstructionWorklist &usersToHandle) {
845
844
// Check types of all BB arguments.
846
845
for (auto *Arg : BB->getSILPhiArguments ()) {
@@ -850,15 +849,8 @@ static void updateBasicBlockArgTypes(SILBasicBlock *BB,
850
849
// Try to apply substitutions to it and if it produces a different type,
851
850
// use this type as new type of the BB argument.
852
851
auto OldArgType = Arg->getType ();
853
- auto NewArgType = OldArgType.subst (BB->getModule (),
854
- [&](SubstitutableType *type) -> Type {
855
- if (type == OldOpenedArchetype)
856
- return NewOpenedArchetype;
857
- return type;
858
- },
859
- MakeAbstractConformanceForGenericType (),
860
- CanGenericSignature (),
861
- SubstFlags::SubstituteLocalArchetypes);
852
+
853
+ auto NewArgType = Cloner.getOpType (OldArgType);
862
854
if (NewArgType == Arg->getType ())
863
855
continue ;
864
856
// Replace the type of this BB argument. The type of a BBArg
@@ -910,13 +902,14 @@ bool CSE::processOpenExistentialRef(OpenExistentialRefInst *Inst,
910
902
usersToHandle.pushIfNotVisited (User);
911
903
}
912
904
905
+ auto *OldEnv = OldOpenedArchetype->getGenericEnvironment ();
906
+ auto *NewEnv = NewOpenedArchetype->getGenericEnvironment ();
907
+
913
908
// Now process candidates.
914
909
// Use a cloner. It makes copying the instruction and remapping of
915
910
// opened archetypes trivial.
916
911
InstructionCloner Cloner (Inst->getFunction ());
917
- Cloner.registerLocalArchetypeRemapping (
918
- OldOpenedArchetype->getGenericEnvironment (),
919
- NewOpenedArchetype->getGenericEnvironment ());
912
+ Cloner.registerLocalArchetypeRemapping (OldEnv, NewEnv);
920
913
auto &Builder = Cloner.getBuilder ();
921
914
922
915
// Now clone each candidate and replace the opened archetype
@@ -931,8 +924,7 @@ bool CSE::processOpenExistentialRef(OpenExistentialRefInst *Inst,
931
924
if (Successor->args_empty ())
932
925
continue ;
933
926
// If a BB has any arguments, update their types if necessary.
934
- updateBasicBlockArgTypes (Successor, OldOpenedArchetype,
935
- NewOpenedArchetype, usersToHandle);
927
+ updateBasicBlockArgTypes (Successor, Cloner, usersToHandle);
936
928
}
937
929
}
938
930
@@ -948,10 +940,7 @@ bool CSE::processOpenExistentialRef(OpenExistentialRefInst *Inst,
948
940
949
941
// Check if the result type depends on this specific opened existential.
950
942
auto ResultDependsOnOldOpenedArchetype =
951
- result->getType ().getASTType ().findIf (
952
- [&OldOpenedArchetype](Type t) -> bool {
953
- return (CanType (t) == OldOpenedArchetype);
954
- });
943
+ result->getType ().getASTType ()->hasLocalArchetypeFromEnvironment (OldEnv);
955
944
956
945
// If it does, the candidate depends on the opened existential.
957
946
if (ResultDependsOnOldOpenedArchetype) {
0 commit comments