@@ -1744,7 +1744,8 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
17441744 " Caller's generic param list." );
17451745 if (auto localA = getLocalArchetypeOf (A)) {
17461746 auto *openingInst =
1747- F->getModule ().getRootLocalArchetypeDefInst (localA.getRoot (), F);
1747+ F->getModule ().getLocalGenericEnvironmentDefInst (
1748+ localA->getGenericEnvironment (), F);
17481749 require (I == nullptr || openingInst == I ||
17491750 properlyDominates (openingInst, I),
17501751 " Use of a local archetype should be dominated by a "
@@ -1893,12 +1894,10 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
18931894 require (isArchetypeValidInFunction (A, AI->getFunction ()),
18941895 " Archetype to be substituted must be valid in function." );
18951896
1896- const auto root = A.getRoot ();
1897-
18981897 // Check that opened archetypes are properly tracked inside
18991898 // the current function.
1900- auto *openingInst = F.getModule ().getRootLocalArchetypeDefInst (
1901- root , AI->getFunction ());
1899+ auto *openingInst = F.getModule ().getLocalGenericEnvironmentDefInst (
1900+ A-> getGenericEnvironment () , AI->getFunction ());
19021901 require (openingInst,
19031902 " Root opened archetype should be registered in SILModule" );
19041903 require (openingInst == AI || properlyDominates (openingInst, AI),
@@ -4853,8 +4852,8 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
48534852 Ty.visit ([&](CanType t) {
48544853 SILValue Def;
48554854 if (const auto archetypeTy = dyn_cast<LocalArchetypeType>(t)) {
4856- Def = I->getModule ().getRootLocalArchetypeDefInst (
4857- archetypeTy. getRoot (), I->getFunction ());
4855+ Def = I->getModule ().getLocalGenericEnvironmentDefInst (
4856+ archetypeTy-> getGenericEnvironment (), I->getFunction ());
48584857 require (Def, " Root opened archetype should be registered in SILModule" );
48594858 } else if (t->hasDynamicSelfType ()) {
48604859 require (I->getFunction ()->hasSelfParam () ||
@@ -6162,28 +6161,29 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
61626161 llvm::DenseMap<CanType, CanPackType>
61636162 collectOpenedElementArchetypeBindings (CanType type,
61646163 AnyPackIndexInst *indexedBy) {
6164+ llvm::DenseSet<GenericEnvironment *> visited;
61656165 llvm::DenseMap<CanType, CanPackType> result;
61666166
61676167 type.visit ([&](CanType type) {
61686168 auto opened = dyn_cast<ElementArchetypeType>(type);
61696169 if (!opened) return ;
6170- opened = opened.getRoot ();
6170+
6171+ auto *genericEnv = opened->getGenericEnvironment ();
61716172
61726173 // Don't repeat this work if the same archetype is named twice.
6173- if (result. count (opened) ) return ;
6174+ if (!visited. insert (genericEnv). second ) return ;
61746175
61756176 // Ignore archetypes defined by open_pack_elements not based on the
61766177 // same pack_index instruction.
61776178 auto openingInst =
6178- F.getModule ().getRootLocalArchetypeDef (opened ,
6179+ F.getModule ().getLocalGenericEnvironmentDef (genericEnv ,
61796180 const_cast <SILFunction*>(&F));
61806181 auto opi = dyn_cast<OpenPackElementInst>(openingInst);
61816182 if (!opi || opi->getIndexOperand () != indexedBy) return ;
61826183
61836184 // Map each root opened element archetype to its pack substitution.
61846185 // FIXME: remember conformances?
6185- auto openedEnv = opi->getOpenedGenericEnvironment ();
6186- openedEnv->forEachPackElementBinding (
6186+ genericEnv->forEachPackElementBinding (
61876187 [&](ElementArchetypeType *elementArchetype, PackType *substitution) {
61886188 auto subPack = cast<PackType>(substitution->getCanonicalType ());
61896189 result.insert ({elementArchetype->getCanonicalType (), subPack});
@@ -6282,7 +6282,11 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
62826282 if (!archetype)
62836283 return type;
62846284
6285- auto root = archetype->getRoot ();
6285+ auto *genericEnv = archetype->getGenericEnvironment ();
6286+ auto interfaceTy = archetype->getInterfaceType ();
6287+
6288+ auto root = genericEnv->mapTypeIntoContext (
6289+ interfaceTy->getRootGenericParam ())->castTo <ElementArchetypeType>();
62866290 auto it = allOpened.find (root->getCanonicalType ());
62876291 assert (it != allOpened.end ());
62886292
@@ -6295,10 +6299,10 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
62956299 assert (!indexedShape && " pack substitution doesn't match in shape" );
62966300 }
62976301
6298- if (archetype-> isRoot ())
6302+ if (interfaceTy-> is <GenericTypeParamType> ())
62996303 return packElementType;
63006304
6301- return archetype-> getInterfaceType () ->castTo <DependentMemberType>()
6305+ return interfaceTy ->castTo <DependentMemberType>()
63026306 ->substRootParam (packElementType, LookUpConformanceInModule (),
63036307 std::nullopt );
63046308 };
0 commit comments