Skip to content

Commit ad0ffb2

Browse files
committed
More opened-existential vs. local-archetype fixes in SIL
1 parent 079df64 commit ad0ffb2

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

include/swift/SIL/SILCloner.h

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
4949

5050
SILBuilder Builder;
5151
DominanceInfo *DomTree = nullptr;
52-
TypeSubstitutionMap OpenedExistentialSubs;
52+
TypeSubstitutionMap LocalArchetypeSubs;
5353

5454
// The old-to-new value map.
5555
llvm::DenseMap<SILValue, SILValue> ValueMap;
@@ -164,10 +164,10 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
164164
asImpl().mapValue(origValue, mappedValue);
165165
}
166166

167-
/// Register a re-mapping for opened existentials.
168-
void registerOpenedExistentialRemapping(ArchetypeType *From,
169-
ArchetypeType *To) {
170-
auto result = OpenedExistentialSubs.insert(
167+
/// Register a re-mapping for local archetypes such as opened existentials.
168+
void registerLocalArchetypeRemapping(ArchetypeType *From,
169+
ArchetypeType *To) {
170+
auto result = LocalArchetypeSubs.insert(
171171
std::make_pair(CanArchetypeType(From), CanType(To)));
172172
assert(result.second);
173173
(void)result;
@@ -189,15 +189,15 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
189189
}
190190

191191
SubstitutionMap getOpSubstitutionMap(SubstitutionMap Subs) {
192-
// If we have open existentials to substitute, check whether that's
192+
// If we have local archetypes to substitute, check whether that's
193193
// relevant to this particular substitution.
194-
if (!OpenedExistentialSubs.empty()) {
194+
if (!LocalArchetypeSubs.empty()) {
195195
for (auto ty : Subs.getReplacementTypes()) {
196-
// If we found a type containing an opened existential, substitute
196+
// If we found a type containing a local archetype, substitute
197197
// open existentials throughout the substitution map.
198-
if (ty->hasOpenedExistential()) {
198+
if (ty->hasLocalArchetype()) {
199199
Subs = Subs.subst(QueryTypeSubstitutionMapOrIdentity{
200-
OpenedExistentialSubs},
200+
LocalArchetypeSubs},
201201
MakeAbstractConformanceForGenericType());
202202
break;
203203
}
@@ -209,19 +209,19 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
209209

210210
SILType getTypeInClonedContext(SILType Ty) {
211211
auto objectTy = Ty.getASTType();
212-
// Do not substitute opened existential types, if we do not have any.
213-
if (!objectTy->hasOpenedExistential())
212+
// Do not substitute local archetypes, if we do not have any.
213+
if (!objectTy->hasLocalArchetype())
214214
return Ty;
215-
// Do not substitute opened existential types, if it is not required.
215+
// Do not substitute local archetypes, if it is not required.
216216
// This is often the case when cloning basic blocks inside the same
217217
// function.
218-
if (OpenedExistentialSubs.empty())
218+
if (LocalArchetypeSubs.empty())
219219
return Ty;
220220

221-
// Substitute opened existential types, if we have any.
221+
// Substitute local archetypes, if we have any.
222222
return Ty.subst(
223223
Builder.getModule(),
224-
QueryTypeSubstitutionMapOrIdentity{OpenedExistentialSubs},
224+
QueryTypeSubstitutionMapOrIdentity{LocalArchetypeSubs},
225225
MakeAbstractConformanceForGenericType());
226226
}
227227
SILType getOpType(SILType Ty) {
@@ -230,17 +230,17 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
230230
}
231231

232232
CanType getASTTypeInClonedContext(Type ty) {
233-
// Do not substitute opened existential types, if we do not have any.
234-
if (!ty->hasOpenedExistential())
233+
// Do not substitute local archetypes, if we do not have any.
234+
if (!ty->hasLocalArchetype())
235235
return ty->getCanonicalType();
236-
// Do not substitute opened existential types, if it is not required.
236+
// Do not substitute local archetypes, if it is not required.
237237
// This is often the case when cloning basic blocks inside the same
238238
// function.
239-
if (OpenedExistentialSubs.empty())
239+
if (LocalArchetypeSubs.empty())
240240
return ty->getCanonicalType();
241241

242242
return ty.subst(
243-
QueryTypeSubstitutionMapOrIdentity{OpenedExistentialSubs},
243+
QueryTypeSubstitutionMapOrIdentity{LocalArchetypeSubs},
244244
MakeAbstractConformanceForGenericType()
245245
)->getCanonicalType();
246246
}
@@ -258,7 +258,7 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
258258
->getCanonicalType();
259259
auto substExistentialTy = getOpASTType(origExistentialTy);
260260
auto replacementTy = OpenedArchetypeType::get(substExistentialTy, sig);
261-
registerOpenedExistentialRemapping(archetypeTy, replacementTy);
261+
registerLocalArchetypeRemapping(archetypeTy, replacementTy);
262262
}
263263

264264
// SILCloner will take care of debug scope on the instruction
@@ -273,12 +273,12 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
273273

274274
ProtocolConformanceRef getOpConformance(Type ty,
275275
ProtocolConformanceRef conformance) {
276-
// If we have open existentials to substitute, do so now.
277-
if (ty->hasOpenedExistential() && !OpenedExistentialSubs.empty()) {
276+
// If we have local archetypes to substitute, do so now.
277+
if (ty->hasLocalArchetype() && !LocalArchetypeSubs.empty()) {
278278
conformance =
279279
conformance.subst(ty,
280280
QueryTypeSubstitutionMapOrIdentity{
281-
OpenedExistentialSubs},
281+
LocalArchetypeSubs},
282282
MakeAbstractConformanceForGenericType());
283283
}
284284

lib/SILOptimizer/Transforms/CSE.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ bool CSE::processOpenExistentialRef(OpenExistentialRefInst *Inst,
842842
// Use a cloner. It makes copying the instruction and remapping of
843843
// opened archetypes trivial.
844844
InstructionCloner Cloner(Inst->getFunction());
845-
Cloner.registerOpenedExistentialRemapping(
845+
Cloner.registerLocalArchetypeRemapping(
846846
OldOpenedArchetype->castTo<ArchetypeType>(), NewOpenedArchetype);
847847
auto &Builder = Cloner.getBuilder();
848848

0 commit comments

Comments
 (0)