Skip to content

Commit c564ece

Browse files
authored
Merge pull request #41256 from slavapestov/rqm-remove-merged-assoc-types
RequirementMachine: Remove merged associated types
2 parents de8a724 + 0cf2881 commit c564ece

28 files changed

+134
-661
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -498,9 +498,6 @@ namespace swift {
498498
ASTVerifierOverrideKind ASTVerifierOverride =
499499
ASTVerifierOverrideKind::NoOverride;
500500

501-
/// Enables merged associated type support, which might go away.
502-
bool RequirementMachineMergedAssociatedTypes = false;
503-
504501
/// Enables dumping rewrite systems from the requirement machine.
505502
bool DumpRequirementMachine = false;
506503

include/swift/Option/FrontendOptions.td

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -355,14 +355,6 @@ def requirement_machine_max_concrete_nesting : Joined<["-"], "requirement-machin
355355
Flags<[FrontendOption, HelpHidden, DoesNotAffectIncrementalBuild]>,
356356
HelpText<"Set the maximum concrete type nesting depth before giving up">;
357357

358-
def disable_requirement_machine_merged_associated_types : Flag<["-"], "disable-requirement-machine-merged-associated-types">,
359-
Flags<[FrontendOption, HelpHidden, DoesNotAffectIncrementalBuild]>,
360-
HelpText<"Disable merged associated types">;
361-
362-
def enable_requirement_machine_merged_associated_types : Flag<["-"], "enable-requirement-machine-merged-associated-types">,
363-
Flags<[FrontendOption, HelpHidden, DoesNotAffectIncrementalBuild]>,
364-
HelpText<"Enable merged associated types">;
365-
366358
def debug_generic_signatures : Flag<["-"], "debug-generic-signatures">,
367359
HelpText<"Debug generic signatures">;
368360

lib/AST/RequirementMachine/ConcreteTypeWitness.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ void PropertyMap::concretizeNestedTypesFromConcreteParent(
200200

201201
// We only infer conditional requirements in top-level generic signatures,
202202
// not in protocol requirement signatures.
203-
if (key.getRootProtocols().empty())
203+
if (key.getRootProtocol() == nullptr)
204204
inferConditionalRequirements(concrete, substitutions);
205205
}
206206
}

lib/AST/RequirementMachine/GenericSignatureQueries.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,10 @@ RequirementMachine::getLongestValidPrefix(const MutableTerm &term) const {
227227

228228
auto conformsTo = props->getConformsTo();
229229

230-
for (const auto *proto : symbol.getProtocols()) {
231-
// T.[P:A] is valid iff T conforms to P.
232-
if (std::find(conformsTo.begin(), conformsTo.end(), proto)
233-
== conformsTo.end())
234-
return prefix;
235-
}
230+
// T.[P:A] is valid iff T conforms to P.
231+
if (std::find(conformsTo.begin(), conformsTo.end(), symbol.getProtocol())
232+
== conformsTo.end())
233+
return prefix;
236234

237235
break;
238236
}
@@ -720,7 +718,7 @@ void RequirementMachine::verify(const MutableTerm &term) const {
720718
continue;
721719

722720
case Symbol::Kind::AssociatedType:
723-
erased.add(Symbol::forProtocol(symbol.getProtocols()[0], Context));
721+
erased.add(Symbol::forProtocol(symbol.getProtocol(), Context));
724722
break;
725723

726724
case Symbol::Kind::Name:

lib/AST/RequirementMachine/HomotopyReduction.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -651,10 +651,7 @@ RewriteSystem::getMinimizedProtocolRules() const {
651651
continue;
652652
}
653653

654-
auto domain = rule.getLHS()[0].getProtocols();
655-
assert(domain.size() == 1);
656-
657-
const auto *proto = domain[0];
654+
const auto *proto = rule.getLHS().begin()->getProtocol();
658655
if (std::find(Protos.begin(), Protos.end(), proto) != Protos.end())
659656
rules[proto].push_back(ruleID);
660657
}
@@ -734,7 +731,7 @@ void RewriteSystem::verifyMinimizedRules(
734731
const auto &rule = getRule(ruleID);
735732

736733
// Ignore the rewrite rule if it is not part of our minimization domain.
737-
if (!isInMinimizationDomain(rule.getLHS().getRootProtocols()))
734+
if (!isInMinimizationDomain(rule.getLHS().getRootProtocol()))
738735
continue;
739736

740737
// Note that sometimes permanent rules can be simplified, but they can never

lib/AST/RequirementMachine/InterfaceType.cpp

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -177,26 +177,26 @@ AssociatedTypeDecl *RewriteContext::getAssociatedTypeForSymbol(Symbol symbol) {
177177
// The associated type An' is then the canonical associated type
178178
// representative of the associated type symbol [P0&...&Pn:A].
179179
//
180-
for (auto *proto : symbol.getProtocols()) {
181-
auto checkOtherAssocType = [&](AssociatedTypeDecl *otherAssocType) {
182-
otherAssocType = otherAssocType->getAssociatedTypeAnchor();
180+
auto *proto = symbol.getProtocol();
183181

184-
if (otherAssocType->getName() == name &&
185-
(assocType == nullptr ||
186-
TypeDecl::compare(otherAssocType->getProtocol(),
187-
assocType->getProtocol()) < 0)) {
188-
assocType = otherAssocType;
189-
}
190-
};
182+
auto checkOtherAssocType = [&](AssociatedTypeDecl *otherAssocType) {
183+
otherAssocType = otherAssocType->getAssociatedTypeAnchor();
191184

192-
for (auto *otherAssocType : proto->getAssociatedTypeMembers()) {
193-
checkOtherAssocType(otherAssocType);
185+
if (otherAssocType->getName() == name &&
186+
(assocType == nullptr ||
187+
TypeDecl::compare(otherAssocType->getProtocol(),
188+
assocType->getProtocol()) < 0)) {
189+
assocType = otherAssocType;
194190
}
191+
};
195192

196-
for (auto *inheritedProto : getInheritedProtocols(proto)) {
197-
for (auto *otherAssocType : inheritedProto->getAssociatedTypeMembers()) {
198-
checkOtherAssocType(otherAssocType);
199-
}
193+
for (auto *otherAssocType : proto->getAssociatedTypeMembers()) {
194+
checkOtherAssocType(otherAssocType);
195+
}
196+
197+
for (auto *inheritedProto : getInheritedProtocols(proto)) {
198+
for (auto *otherAssocType : inheritedProto->getAssociatedTypeMembers()) {
199+
checkOtherAssocType(otherAssocType);
200200
}
201201
}
202202

@@ -318,8 +318,8 @@ getTypeForSymbolRange(const Symbol *begin, const Symbol *end, Type root,
318318
#ifndef NDEBUG
319319
// Ensure that the domain of the suffix contains P.
320320
if (iter + 1 < end) {
321-
auto protos = (iter + 1)->getProtocols();
322-
assert(std::find(protos.begin(), protos.end(), symbol.getProtocol()));
321+
auto proto = (iter + 1)->getProtocol();
322+
assert(proto == symbol.getProtocol());
323323
}
324324
#endif
325325
continue;
@@ -350,10 +350,9 @@ getTypeForSymbolRange(const Symbol *begin, const Symbol *end, Type root,
350350
// of protocols that the prefix conforms to.
351351
#ifndef NDEBUG
352352
auto conformsTo = props->getConformsTo();
353-
for (auto *otherProto : symbol.getProtocols()) {
354-
assert(std::find(conformsTo.begin(), conformsTo.end(), otherProto)
355-
!= conformsTo.end());
356-
}
353+
assert(std::find(conformsTo.begin(), conformsTo.end(),
354+
symbol.getProtocol())
355+
!= conformsTo.end());
357356
#endif
358357

359358
assocType = props->getAssociatedType(symbol.getName());

0 commit comments

Comments
 (0)