Skip to content

Commit ff42942

Browse files
authored
Merge pull request swiftlang#36156 from xedin/rdar-74723323
[CSBindings] Copy-initialize transitive protocols for equivalence class
2 parents 3dec40c + 67d8cb8 commit ff42942

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,11 @@ void BindingSet::inferTransitiveProtocolRequirements(
252252
const SmallPtrSetImpl<Constraint *> &transitive) {
253253
auto &destination = protocols[dstVar];
254254

255-
for (auto *protocol : direct)
256-
destination.insert(protocol);
255+
if (direct.size() > 0)
256+
destination.insert(direct.begin(), direct.end());
257257

258-
for (auto *protocol : transitive)
259-
destination.insert(protocol);
258+
if (transitive.size() > 0)
259+
destination.insert(transitive.begin(), transitive.end());
260260
};
261261

262262
addToWorkList(nullptr, TypeVar);
@@ -288,7 +288,7 @@ void BindingSet::inferTransitiveProtocolRequirements(
288288
addToWorkList(currentVar, entry.first);
289289

290290
// If current type variable is part of an equivalence
291-
// class, make it a "representative" and let's it infer
291+
// class, make it a "representative" and let it infer
292292
// supertypes and direct protocol requirements from
293293
// other members.
294294
for (const auto &entry : bindings.Info.EquivalentTo) {
@@ -326,7 +326,7 @@ void BindingSet::inferTransitiveProtocolRequirements(
326326
protocols[currentVar]);
327327
}
328328

329-
auto inferredProtocols = std::move(protocols[currentVar]);
329+
auto &inferredProtocols = protocols[currentVar];
330330

331331
llvm::SmallPtrSet<Constraint *, 4> protocolsForEquivalence;
332332

@@ -350,13 +350,15 @@ void BindingSet::inferTransitiveProtocolRequirements(
350350
auto eqBindings = inferredBindings.find(equivalence.first);
351351
if (eqBindings != inferredBindings.end()) {
352352
auto &bindings = eqBindings->getSecond();
353-
bindings.TransitiveProtocols.emplace(protocolsForEquivalence);
353+
bindings.TransitiveProtocols.emplace(protocolsForEquivalence.begin(),
354+
protocolsForEquivalence.end());
354355
}
355356
}
356357

357358
// Update the bindings associated with current type variable,
358359
// to avoid repeating this inference process.
359-
bindings.TransitiveProtocols.emplace(std::move(inferredProtocols));
360+
bindings.TransitiveProtocols.emplace(inferredProtocols.begin(),
361+
inferredProtocols.end());
360362
} while (!workList.empty());
361363
}
362364

0 commit comments

Comments
 (0)