@@ -41,70 +41,69 @@ static void *allocateTrailingInst(SILFunction &F, CountTypes... counts) {
4141 alignof (Inst));
4242}
4343
44- // Collect used open archetypes from a given type into the \p openedArchetypes.
45- // \p openedArchetypes is being used as a set. We don't use a real set type here
46- // for performance reasons.
47- static void
48- collectDependentTypeInfo (CanType Ty,
49- SmallVectorImpl<CanArchetypeType> &openedArchetypes,
50- bool &hasDynamicSelf) {
44+ // / Collect root open archetypes from a given type into \p RootOpenedArchetypes.
45+ // / \p RootOpenedArchetypes is being used as a set. We don't use a real set type
46+ // / here for performance reasons.
47+ static void collectDependentTypeInfo (
48+ CanType Ty, SmallVectorImpl<CanOpenedArchetypeType> &RootOpenedArchetypes,
49+ bool &hasDynamicSelf) {
5150 if (!Ty)
5251 return ;
5352 if (Ty->hasDynamicSelfType ())
5453 hasDynamicSelf = true ;
5554 if (!Ty->hasOpenedExistential ())
5655 return ;
5756 Ty.visit ([&](CanType t) {
58- if (t->isOpenedExistential ()) {
59- // Add this opened archetype if it was not seen yet.
57+ if (const auto opened = dyn_cast<OpenedArchetypeType>(t)) {
58+ const auto root = cast<OpenedArchetypeType>(CanType (opened->getRoot ()));
59+
60+ // Add this root opened archetype if it was not seen yet.
6061 // We don't use a set here, because the number of open archetypes
6162 // is usually very small and using a real set may introduce too
6263 // much overhead.
63- auto archetypeTy = cast<ArchetypeType>(t);
64- if (std::find (openedArchetypes.begin (), openedArchetypes.end (),
65- archetypeTy) == openedArchetypes.end ())
66- openedArchetypes.push_back (archetypeTy);
64+ if (std::find (RootOpenedArchetypes.begin (), RootOpenedArchetypes.end (),
65+ root) == RootOpenedArchetypes.end ())
66+ RootOpenedArchetypes.push_back (root);
6767 }
6868 });
6969}
7070
71- // Takes a set of open archetypes as input and produces a set of
72- // references to open archetype definitions.
71+ // / Takes a set of root opened archetypes as input and produces a set of
72+ // / references to their definitions.
7373static void buildTypeDependentOperands (
74- SmallVectorImpl<CanArchetypeType > &OpenedArchetypes ,
75- bool hasDynamicSelf,
76- SmallVectorImpl<SILValue> &TypeDependentOperands, SILFunction &F) {
74+ SmallVectorImpl<CanOpenedArchetypeType > &RootOpenedArchetypes ,
75+ bool hasDynamicSelf, SmallVectorImpl<SILValue> &TypeDependentOperands,
76+ SILFunction &F) {
7777
78- for (auto archetype : OpenedArchetypes ) {
79- SILValue def = F.getModule ().getOpenedArchetypeDef (archetype, &F);
78+ for (const auto archetype : RootOpenedArchetypes ) {
79+ SILValue def = F.getModule ().getRootOpenedArchetypeDef (archetype, &F);
8080 assert (def->getFunction () == &F &&
81- " def of opened archetype is in wrong function" );
81+ " def of root opened archetype is in wrong function" );
8282 TypeDependentOperands.push_back (def);
8383 }
8484 if (hasDynamicSelf)
8585 TypeDependentOperands.push_back (F.getDynamicSelfMetadata ());
8686}
8787
88- // Collects all opened archetypes from a type and a substitutions list and form
89- // a corresponding list of opened archetype operands.
90- // We need to know the number of opened archetypes to estimate
91- // the number of opened archetype operands for the instruction
92- // being formed, because we need to reserve enough memory
93- // for these operands.
88+ // / Collects all root opened archetypes from a type and a substitution list, and
89+ // / forms a corresponding list of operands.
90+ // / We need to know the number of root opened archetypes to estimate the number
91+ // / of corresponding operands for the instruction being formed, because we need
92+ // / to reserve enough memory for these operands.
9493static void collectTypeDependentOperands (
9594 SmallVectorImpl<SILValue> &TypeDependentOperands,
9695 SILFunction &F,
9796 CanType Ty,
9897 SubstitutionMap subs = { }) {
99- SmallVector<CanArchetypeType , 4 > openedArchetypes ;
98+ SmallVector<CanOpenedArchetypeType , 4 > RootOpenedArchetypes ;
10099 bool hasDynamicSelf = false ;
101- collectDependentTypeInfo (Ty, openedArchetypes , hasDynamicSelf);
100+ collectDependentTypeInfo (Ty, RootOpenedArchetypes , hasDynamicSelf);
102101 for (Type replacement : subs.getReplacementTypes ()) {
103102 // Substitutions in SIL should really be canonical.
104103 auto ReplTy = replacement->getCanonicalType ();
105- collectDependentTypeInfo (ReplTy, openedArchetypes , hasDynamicSelf);
104+ collectDependentTypeInfo (ReplTy, RootOpenedArchetypes , hasDynamicSelf);
106105 }
107- buildTypeDependentOperands (openedArchetypes , hasDynamicSelf,
106+ buildTypeDependentOperands (RootOpenedArchetypes , hasDynamicSelf,
108107 TypeDependentOperands, F);
109108}
110109
0 commit comments