Skip to content

Commit d19b15b

Browse files
committed
RequirementMachine: Introduce Symbol::Kind::ConcreteConformance
1 parent 0398252 commit d19b15b

11 files changed

+199
-36
lines changed

lib/AST/RequirementMachine/GeneratingConformances.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ static const ProtocolDecl *getParentConformanceForTerm(Term lhs) {
596596
case Symbol::Kind::Layout:
597597
case Symbol::Kind::Superclass:
598598
case Symbol::Kind::ConcreteType:
599+
case Symbol::Kind::ConcreteConformance:
599600
break;
600601
}
601602

lib/AST/RequirementMachine/GenericSignatureQueries.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ RequirementMachine::getLongestValidPrefix(const MutableTerm &term) const {
240240
case Symbol::Kind::Layout:
241241
case Symbol::Kind::Superclass:
242242
case Symbol::Kind::ConcreteType:
243+
case Symbol::Kind::ConcreteConformance:
243244
llvm_unreachable("Property symbol cannot appear in a type term");
244245
}
245246

lib/AST/RequirementMachine/KnuthBendix.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ RewriteSystem::computeCriticalPair(ArrayRef<Symbol>::const_iterator from,
451451
// perform the concrete type adjustment:
452452
//
453453
// (σ - T)
454-
if (xv.back().isSuperclassOrConcreteType() &&
454+
if (xv.back().hasSubstitutions() &&
455455
!xv.back().getSubstitutions().empty() &&
456456
t.size() > 0) {
457457
path.add(RewriteStep::forAdjustment(t.size(), /*inverse=*/true));

lib/AST/RequirementMachine/PropertyUnification.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,10 @@ void PropertyBag::addProperty(
350350
return;
351351
}
352352

353+
case Symbol::Kind::ConcreteConformance:
354+
// FIXME
355+
return;
356+
353357
case Symbol::Kind::Name:
354358
case Symbol::Kind::GenericParam:
355359
case Symbol::Kind::AssociatedType:

lib/AST/RequirementMachine/RequirementMachine.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ void RequirementMachine::verify(const MutableTerm &term) const {
5858
case Symbol::Kind::Layout:
5959
case Symbol::Kind::Superclass:
6060
case Symbol::Kind::ConcreteType:
61+
case Symbol::Kind::ConcreteConformance:
6162
llvm::errs() << "Bad initial symbol in " << term << "\n";
6263
abort();
6364
break;
@@ -79,6 +80,7 @@ void RequirementMachine::verify(const MutableTerm &term) const {
7980
case Symbol::Kind::Layout:
8081
case Symbol::Kind::Superclass:
8182
case Symbol::Kind::ConcreteType:
83+
case Symbol::Kind::ConcreteConformance:
8284
llvm::errs() << "Bad interior symbol " << symbol << " in " << term << "\n";
8385
abort();
8486
break;

lib/AST/RequirementMachine/RequirementMachineRequests.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ RequirementMachine::buildRequirementsFromRules(
140140
return;
141141
}
142142

143+
case Symbol::Kind::ConcreteConformance:
144+
// FIXME
145+
llvm::errs() << "Concrete conformance: " << rule << "\n";
146+
break;
147+
143148
case Symbol::Kind::Name:
144149
case Symbol::Kind::AssociatedType:
145150
case Symbol::Kind::GenericParam:

lib/AST/RequirementMachine/RewriteContext.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ Type getTypeForSymbolRange(Iter begin, Iter end, Type root,
349349
case Symbol::Kind::Layout:
350350
case Symbol::Kind::Superclass:
351351
case Symbol::Kind::ConcreteType:
352+
case Symbol::Kind::ConcreteConformance:
352353
llvm_unreachable("Term has invalid root symbol");
353354
}
354355
}

lib/AST/RequirementMachine/RewriteLoop.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ void RewriteStep::applyDecompose(RewritePathEvaluator &evaluator,
170170
// concrete type symbol.
171171
const auto &term = evaluator.getCurrentTerm();
172172
auto symbol = term.back();
173-
if (!symbol.isSuperclassOrConcreteType()) {
173+
if (!symbol.hasSubstitutions()) {
174174
llvm::errs() << "Expected term with superclass or concrete type symbol"
175175
<< " on A stack\n";
176176
evaluator.dump(llvm::errs());
@@ -201,7 +201,7 @@ void RewriteStep::applyDecompose(RewritePathEvaluator &evaluator,
201201
// updating with new substitutions.
202202
auto &term = *(evaluator.A.end() - numSubstitutions - 1);
203203
auto symbol = term.back();
204-
if (!symbol.isSuperclassOrConcreteType()) {
204+
if (!symbol.hasSubstitutions()) {
205205
llvm::errs() << "Expected term with superclass or concrete type symbol"
206206
<< " on A stack\n";
207207
evaluator.dump(llvm::errs());

lib/AST/RequirementMachine/RewriteSystem.cpp

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ bool Rule::isProtocolRefinementRule() const {
9595
unsigned Rule::getDepth() const {
9696
auto result = LHS.size();
9797

98-
if (LHS.back().isSuperclassOrConcreteType()) {
98+
if (LHS.back().hasSubstitutions()) {
9999
for (auto substitution : LHS.back().getSubstitutions()) {
100100
result = std::max(result, substitution.size());
101101
}
@@ -228,7 +228,7 @@ bool RewriteSystem::simplify(MutableTerm &term, RewritePath *path) const {
228228
void RewriteSystem::simplifySubstitutions(MutableTerm &term,
229229
RewritePath &path) const {
230230
auto symbol = term.back();
231-
assert(symbol.isSuperclassOrConcreteType());
231+
assert(symbol.hasSubstitutions());
232232

233233
auto substitutions = symbol.getSubstitutions();
234234
if (substitutions.empty())
@@ -285,13 +285,33 @@ void RewriteSystem::simplifySubstitutions(MutableTerm &term,
285285
}
286286

287287
// Build the new symbol with simplified substitutions.
288-
auto newSymbol = (symbol.getKind() == Symbol::Kind::Superclass
289-
? Symbol::forSuperclass(symbol.getSuperclass(),
290-
newSubstitutions, Context)
291-
: Symbol::forConcreteType(symbol.getConcreteType(),
292-
newSubstitutions, Context));
288+
switch (symbol.getKind()) {
289+
case Symbol::Kind::Superclass:
290+
term.back() = Symbol::forSuperclass(symbol.getSuperclass(),
291+
newSubstitutions, Context);
292+
return;
293+
294+
case Symbol::Kind::ConcreteType:
295+
term.back() = Symbol::forConcreteType(symbol.getConcreteType(),
296+
newSubstitutions, Context);
297+
return;
298+
299+
case Symbol::Kind::ConcreteConformance:
300+
term.back() = Symbol::forConcreteConformance(symbol.getConcreteType(),
301+
newSubstitutions,
302+
symbol.getProtocol(),
303+
Context);
304+
return;
305+
306+
case Symbol::Kind::Protocol:
307+
case Symbol::Kind::Name:
308+
case Symbol::Kind::AssociatedType:
309+
case Symbol::Kind::GenericParam:
310+
case Symbol::Kind::Layout:
311+
break;
312+
}
293313

294-
term.back() = newSymbol;
314+
llvm_unreachable("Bad symbol kind");
295315
}
296316

297317
/// Adds a rewrite rule, returning true if the new rule was non-trivial.
@@ -321,10 +341,10 @@ bool RewriteSystem::addRule(MutableTerm lhs, MutableTerm rhs,
321341
RewritePath lhsPath;
322342
RewritePath rhsPath;
323343

324-
if (lhs.back().isSuperclassOrConcreteType())
344+
if (lhs.back().hasSubstitutions())
325345
simplifySubstitutions(lhs, lhsPath);
326346

327-
if (rhs.back().isSuperclassOrConcreteType())
347+
if (rhs.back().hasSubstitutions())
328348
simplifySubstitutions(rhs, rhsPath);
329349

330350
simplify(lhs, &lhsPath);
@@ -548,7 +568,7 @@ void RewriteSystem::verifyRewriteRules(ValidityPolicy policy) const {
548568

549569
if (index != lhs.size() - 1) {
550570
ASSERT_RULE(symbol.getKind() != Symbol::Kind::Layout);
551-
ASSERT_RULE(!symbol.isSuperclassOrConcreteType());
571+
ASSERT_RULE(!symbol.hasSubstitutions());
552572
}
553573

554574
if (index != 0) {
@@ -571,7 +591,7 @@ void RewriteSystem::verifyRewriteRules(ValidityPolicy policy) const {
571591
}
572592

573593
ASSERT_RULE(symbol.getKind() != Symbol::Kind::Layout);
574-
ASSERT_RULE(!symbol.isSuperclassOrConcreteType());
594+
ASSERT_RULE(!symbol.hasSubstitutions());
575595

576596
if (index != 0) {
577597
ASSERT_RULE(symbol.getKind() != Symbol::Kind::GenericParam);

0 commit comments

Comments
 (0)