@@ -839,8 +839,7 @@ bool CSE::processLazyPropertyGetters(SILFunction &F) {
839839// / archetypes. Replace such types by performing type substitutions
840840// / according to the provided type substitution map.
841841static void updateBasicBlockArgTypes (SILBasicBlock *BB,
842- ArchetypeType *OldOpenedArchetype,
843- ArchetypeType *NewOpenedArchetype,
842+ InstructionCloner &Cloner,
844843 InstructionWorklist &usersToHandle) {
845844 // Check types of all BB arguments.
846845 for (auto *Arg : BB->getSILPhiArguments ()) {
@@ -850,15 +849,8 @@ static void updateBasicBlockArgTypes(SILBasicBlock *BB,
850849 // Try to apply substitutions to it and if it produces a different type,
851850 // use this type as new type of the BB argument.
852851 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);
862854 if (NewArgType == Arg->getType ())
863855 continue ;
864856 // Replace the type of this BB argument. The type of a BBArg
@@ -910,13 +902,14 @@ bool CSE::processOpenExistentialRef(OpenExistentialRefInst *Inst,
910902 usersToHandle.pushIfNotVisited (User);
911903 }
912904
905+ auto *OldEnv = OldOpenedArchetype->getGenericEnvironment ();
906+ auto *NewEnv = NewOpenedArchetype->getGenericEnvironment ();
907+
913908 // Now process candidates.
914909 // Use a cloner. It makes copying the instruction and remapping of
915910 // opened archetypes trivial.
916911 InstructionCloner Cloner (Inst->getFunction ());
917- Cloner.registerLocalArchetypeRemapping (
918- OldOpenedArchetype->getGenericEnvironment (),
919- NewOpenedArchetype->getGenericEnvironment ());
912+ Cloner.registerLocalArchetypeRemapping (OldEnv, NewEnv);
920913 auto &Builder = Cloner.getBuilder ();
921914
922915 // Now clone each candidate and replace the opened archetype
@@ -931,8 +924,7 @@ bool CSE::processOpenExistentialRef(OpenExistentialRefInst *Inst,
931924 if (Successor->args_empty ())
932925 continue ;
933926 // If a BB has any arguments, update their types if necessary.
934- updateBasicBlockArgTypes (Successor, OldOpenedArchetype,
935- NewOpenedArchetype, usersToHandle);
927+ updateBasicBlockArgTypes (Successor, Cloner, usersToHandle);
936928 }
937929 }
938930
@@ -948,10 +940,7 @@ bool CSE::processOpenExistentialRef(OpenExistentialRefInst *Inst,
948940
949941 // Check if the result type depends on this specific opened existential.
950942 auto ResultDependsOnOldOpenedArchetype =
951- result->getType ().getASTType ().findIf (
952- [&OldOpenedArchetype](Type t) -> bool {
953- return (CanType (t) == OldOpenedArchetype);
954- });
943+ result->getType ().getASTType ()->hasLocalArchetypeFromEnvironment (OldEnv);
955944
956945 // If it does, the candidate depends on the opened existential.
957946 if (ResultDependsOnOldOpenedArchetype) {
0 commit comments