Skip to content

Commit 84e93a2

Browse files
authored
Merge pull request #76477 from slavapestov/tiny-rqm-cleanup
RequirementMachine: Small cleanup
2 parents a4bd03c + d57b6d7 commit 84e93a2

File tree

11 files changed

+23
-43
lines changed

11 files changed

+23
-43
lines changed

lib/AST/RequirementMachine/HomotopyReduction.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ void RewriteSystem::minimizeRewriteSystem(const PropertyMap &map) {
501501
performHomotopyReduction([&](unsigned loopID, unsigned ruleID) -> bool {
502502
const auto &rule = getRule(ruleID);
503503

504-
if (rule.containsUnresolvedSymbols())
504+
if (rule.containsNameSymbols())
505505
return true;
506506

507507
return false;
@@ -613,7 +613,7 @@ GenericSignatureErrors RewriteSystem::getErrors() const {
613613

614614
if (!rule.isRedundant() &&
615615
!rule.isProtocolTypeAliasRule() &&
616-
rule.containsUnresolvedSymbols())
616+
rule.containsNameSymbols())
617617
result |= GenericSignatureErrorFlags::HasInvalidRequirements;
618618

619619
if (rule.isRecursive())
@@ -626,7 +626,7 @@ GenericSignatureErrors RewriteSystem::getErrors() const {
626626

627627
if (property->hasSubstitutions()) {
628628
for (auto t : property->getSubstitutions()) {
629-
if (t.containsUnresolvedSymbols())
629+
if (t.containsNameSymbols())
630630
result |= GenericSignatureErrorFlags::HasInvalidRequirements;
631631
}
632632
}
@@ -663,7 +663,7 @@ RewriteSystem::getMinimizedProtocolRules() const {
663663

664664
if (rule.isProtocolTypeAliasRule())
665665
rules[proto].TypeAliases.push_back(ruleID);
666-
else if (!rule.containsUnresolvedSymbols())
666+
else if (!rule.containsNameSymbols())
667667
rules[proto].Requirements.push_back(ruleID);
668668
}
669669

@@ -687,7 +687,7 @@ RewriteSystem::getMinimizedGenericSignatureRules() const {
687687
if (rule.isPermanent() ||
688688
rule.isRedundant() ||
689689
rule.isConflicting() ||
690-
rule.containsUnresolvedSymbols()) {
690+
rule.containsNameSymbols()) {
691691
continue;
692692
}
693693

@@ -793,7 +793,7 @@ void RewriteSystem::verifyMinimizedRules(
793793
rule.isAnyConformanceRule() &&
794794
!rule.isRHSSimplified() &&
795795
!rule.isSubstitutionSimplified() &&
796-
!rule.containsUnresolvedSymbols() &&
796+
!rule.containsNameSymbols() &&
797797
!redundantConformances.count(ruleID)) {
798798
llvm::errs() << "Minimal conformance is redundant: " << rule << "\n\n";
799799
dump(llvm::errs());

lib/AST/RequirementMachine/InterfaceType.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,6 @@
107107
using namespace swift;
108108
using namespace rewriting;
109109

110-
Term RewriteContext::getTermForType(CanType paramType,
111-
const ProtocolDecl *proto) {
112-
return Term::get(getMutableTermForType(paramType, proto), *this);
113-
}
114-
115110
/// Map an interface type to a term.
116111
///
117112
/// If \p proto is null, this is a term relative to a generic

lib/AST/RequirementMachine/MinimalConformances.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ void MinimalConformances::collectConformanceRules() {
311311
rule.isSubstitutionSimplified())
312312
continue;
313313

314-
if (rule.containsUnresolvedSymbols())
314+
if (rule.containsNameSymbols())
315315
continue;
316316

317317
if (!rule.isAnyConformanceRule())
@@ -426,7 +426,7 @@ void RewriteSystem::computeCandidateConformancePaths(
426426
if (lhs.isRHSSimplified() ||
427427
lhs.isSubstitutionSimplified() ||
428428
lhs.isIdentityConformanceRule() ||
429-
lhs.containsUnresolvedSymbols())
429+
lhs.containsNameSymbols())
430430
continue;
431431

432432
if (!lhs.isAnyConformanceRule() &&
@@ -505,7 +505,7 @@ void RewriteSystem::computeCandidateConformancePaths(
505505
if (rhs.isRHSSimplified() ||
506506
rhs.isSubstitutionSimplified() ||
507507
rhs.isIdentityConformanceRule() ||
508-
rhs.containsUnresolvedSymbols())
508+
rhs.containsNameSymbols())
509509
return;
510510

511511
if (!rhs.isAnyConformanceRule() &&
@@ -951,7 +951,7 @@ void MinimalConformances::verifyMinimalConformances() const {
951951
continue;
952952
}
953953

954-
if (rule.containsUnresolvedSymbols()) {
954+
if (rule.containsNameSymbols()) {
955955
llvm::errs() << "Minimal conformance contains unresolved symbols: ";
956956
llvm::errs() << rule << "\n\n";
957957
dumpMinimalConformanceEquations(llvm::errs());

lib/AST/RequirementMachine/RequirementBuilder.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,16 +194,16 @@ void RequirementBuilder::addRequirementRules(ArrayRef<unsigned> rules) {
194194

195195
case Symbol::Kind::Superclass:
196196
case Symbol::Kind::ConcreteType: {
197-
bool containsUnresolvedSymbols = false;
197+
bool containsNameSymbols = false;
198198
for (auto term : prop->getSubstitutions()) {
199-
containsUnresolvedSymbols |= term.containsUnresolvedSymbols();
199+
containsNameSymbols |= term.containsNameSymbols();
200200
}
201201

202202
Type concreteType = Map.getTypeFromSubstitutionSchema(
203203
prop->getConcreteType(),
204204
prop->getSubstitutions(),
205205
GenericParams, MutableTerm());
206-
if (containsUnresolvedSymbols || rule.isRecursive())
206+
if (containsNameSymbols || rule.isRecursive())
207207
concreteType = replaceTypeParametersWithErrorTypes(concreteType);
208208

209209
if (ReconstituteSugar)
@@ -302,7 +302,7 @@ void RequirementBuilder::addTypeAliasRules(ArrayRef<unsigned> rules) {
302302
// Requirements containing unresolved name symbols originate from
303303
// invalid code and should not appear in the generic signature.
304304
for (auto term : prop->getSubstitutions()) {
305-
if (term.containsUnresolvedSymbols())
305+
if (term.containsNameSymbols())
306306
continue;
307307
}
308308

lib/AST/RequirementMachine/RewriteContext.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,6 @@ class RewriteContext final {
174174

175175
static unsigned getGenericParamIndex(Type type);
176176

177-
Term getTermForType(CanType paramType, const ProtocolDecl *proto);
178-
179177
MutableTerm getMutableTermForType(CanType paramType,
180178
const ProtocolDecl *proto);
181179

lib/AST/RequirementMachine/RewriteSystem.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ class RewriteSystem final {
6565
/// top-level generic signature and this array is empty.
6666
ArrayRef<const ProtocolDecl *> Protos;
6767

68-
/// The requirements written in source code.
69-
std::vector<StructuralRequirement> WrittenRequirements;
70-
7168
/// The rules added so far, including rules from our client, as well
7269
/// as rules introduced by the completion procedure.
7370
std::vector<Rule> Rules;

lib/AST/RequirementMachine/Rule.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ std::optional<Identifier> Rule::isProtocolTypeAliasRule() const {
177177
if (LHS.size() == 2) {
178178
// This is the case where the underlying type is a type parameter.
179179
//
180-
// We shouldn't have unresolved symbols on the right hand side;
181-
// they should have been simplified away.
182-
if (RHS.containsUnresolvedSymbols()) {
180+
// We shouldn't have name symbols on the right hand side; they
181+
// should have been simplified away.
182+
if (RHS.containsNameSymbols()) {
183183
if (RHS.size() != 2 ||
184184
RHS[0] != LHS[0] ||
185185
RHS[1].getKind() != Symbol::Kind::Name) {

lib/AST/RequirementMachine/Rule.h

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,6 @@ class Rule final {
3838
Term LHS;
3939
Term RHS;
4040

41-
/// The written requirement ID, which can be used to index into the
42-
/// \c WrittenRequirements array in the rewrite system to retrieve
43-
/// the structural requirement.
44-
///
45-
/// This uses a biased representation where an ID of 0 means 'no ID',
46-
/// otherwise the value is the actual ID plus one.
47-
unsigned RequirementID : 16;
48-
4941
/// A 'permanent' rule cannot be deleted by homotopy reduction. These
5042
/// do not correspond to generic requirements and are re-added when the
5143
/// rewrite system is built.
@@ -96,7 +88,6 @@ class Rule final {
9688
public:
9789
Rule(Term lhs, Term rhs)
9890
: LHS(lhs), RHS(rhs) {
99-
RequirementID = 0;
10091
Permanent = false;
10192
Explicit = false;
10293
LHSSimplified = false;
@@ -162,9 +153,9 @@ class Rule final {
162153
return Frozen;
163154
}
164155

165-
bool containsUnresolvedSymbols() const {
166-
return (LHS.containsUnresolvedSymbols() ||
167-
RHS.containsUnresolvedSymbols());
156+
bool containsNameSymbols() const {
157+
return (LHS.containsNameSymbols() ||
158+
RHS.containsNameSymbols());
168159
}
169160

170161
std::optional<Identifier> isProtocolTypeAliasRule() const;
@@ -228,7 +219,6 @@ class Rule final {
228219

229220
void freeze() {
230221
Redundant = false;
231-
RequirementID = 0;
232222
Frozen = true;
233223
}
234224

lib/AST/RequirementMachine/Symbol.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ struct Symbol::Storage final
113113
}
114114

115115
Storage(CanType type, ArrayRef<Term> substitutions, const ProtocolDecl *proto) {
116-
DEBUG_ASSERT(!type->hasTypeVariable());
116+
ASSERT(!type->hasTypeVariable());
117117
ASSERT(type->hasTypeParameter() != substitutions.empty());
118118

119119
Kind = Symbol::Kind::ConcreteConformance;

lib/AST/RequirementMachine/Term.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ void Term::Storage::Profile(llvm::FoldingSetNodeID &id) const {
113113
id.AddPointer(symbol.getOpaquePointer());
114114
}
115115

116-
bool Term::containsUnresolvedSymbols() const {
116+
bool Term::containsNameSymbols() const {
117117
for (auto symbol : *this) {
118118
if (symbol.getKind() == Symbol::Kind::Name)
119119
return true;

lib/AST/RequirementMachine/Term.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class Term final {
7676
return begin()->getRootProtocol();
7777
}
7878

79-
bool containsUnresolvedSymbols() const;
79+
bool containsNameSymbols() const;
8080

8181
void dump(llvm::raw_ostream &out) const;
8282

0 commit comments

Comments
 (0)