Skip to content

Commit eab371d

Browse files
committed
RequirementMachine: Simplify RewriteStep::Decompose
The inverted form no longer has to replace substitutions; we use the inverted form of DecomposeConcrete for that. So just assert that the substitutions are equal.
1 parent 41a6f9e commit eab371d

File tree

2 files changed

+12
-27
lines changed

2 files changed

+12
-27
lines changed

lib/AST/RequirementMachine/RewriteLoop.cpp

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,6 @@ void RewritePathEvaluator::applyDecompose(const RewriteStep &step,
367367
const RewriteSystem &system) {
368368
assert(step.Kind == RewriteStep::Decompose);
369369

370-
auto &ctx = system.getRewriteContext();
371370
unsigned numSubstitutions = step.Arg;
372371

373372
if (!step.Inverse) {
@@ -405,15 +404,8 @@ void RewritePathEvaluator::applyDecompose(const RewriteStep &step,
405404

406405
// The term immediately underneath the substitutions is the one we're
407406
// updating with new substitutions.
408-
auto &term = *(Primary.end() - numSubstitutions - 1);
409-
410-
auto &symbol = *(term.end() - step.EndOffset - 1);
411-
if (!symbol.hasSubstitutions()) {
412-
llvm::errs() << "Expected term with superclass or concrete type symbol"
413-
<< " on primary stack\n";
414-
dump(llvm::errs());
415-
abort();
416-
}
407+
const auto &term = *(Primary.end() - numSubstitutions - 1);
408+
auto symbol = *(term.end() - step.EndOffset - 1);
417409

418410
// The symbol at the end of this term must have the expected number of
419411
// substitutions.
@@ -423,17 +415,16 @@ void RewritePathEvaluator::applyDecompose(const RewriteStep &step,
423415
abort();
424416
}
425417

426-
// Collect the substitutions from the primary stack.
427-
SmallVector<Term, 2> substitutions;
428-
substitutions.reserve(numSubstitutions);
429418
for (unsigned i = 0; i < numSubstitutions; ++i) {
430419
const auto &substitution = *(Primary.end() - numSubstitutions + i);
431-
substitutions.push_back(Term::get(substitution, ctx));
420+
if (MutableTerm(symbol.getSubstitutions()[i]) != substitution) {
421+
llvm::errs() << "Expected " << symbol.getSubstitutions()[i] << "\n";
422+
llvm::errs() << "Got " << substitution << "\n";
423+
dump(llvm::errs());
424+
abort();
425+
}
432426
}
433427

434-
// Build the new symbol with the new substitutions.
435-
symbol = symbol.withConcreteSubstitutions(substitutions, ctx);
436-
437428
// Pop the substitutions from the primary stack.
438429
Primary.resize(Primary.size() - numSubstitutions);
439430
}

lib/AST/RequirementMachine/RewriteLoop.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,15 @@ struct RewriteStep {
8282
///
8383
/// T.[concrete: C<...> with <X1, X2...>] X1 X2...
8484
///
85-
/// If inverted: pop concrete substitutions Xn' from the primary stack,
85+
/// If inverted: pop concrete substitutions Xn from the primary stack,
8686
/// which must follow a term ending with a superclass or concrete type
8787
/// symbol:
8888
///
89-
/// T.[concrete: C<...> with <X1, X2...>] X1' X2'...
90-
///
91-
/// The new substitutions replace the substitutions in that symbol:
92-
///
93-
/// T.[concrete: C<...> with <X1', X2'...>]
89+
/// T.[concrete: C<...> with <X1, X2...>] X1 X2...
9490
///
9591
/// The Arg field encodes the number of substitutions.
9692
///
97-
/// Used by RewriteSystem::simplifyLeftHandSideSubstitutions() and
98-
/// PropertyMap::concretelySimplifyLeftHandSideSubstitutions().
93+
/// Used by RewriteSystem::simplifyLeftHandSideSubstitutions().
9994
Decompose,
10095

10196
///
@@ -155,8 +150,7 @@ struct RewriteStep {
155150
///
156151
/// T.[concrete: C'<...> with <X1', X2'...>]
157152
///
158-
/// Used by PropertyMap::concretelySimplifyLeftHandSideSubstitutions() and
159-
/// PropertyMap::processTypeDifference().
153+
/// Used by RewriteSystem::simplifyLeftHandSideSubstitutions().
160154
DecomposeConcrete,
161155

162156
/// For decomposing the left hand side of an induced rule in concrete type

0 commit comments

Comments
 (0)