@@ -254,7 +254,7 @@ bool RewriteSystem::simplify(MutableTerm &term, RewritePath *path) const {
254
254
// / Simplify terms appearing in the substitutions of the last symbol of \p term,
255
255
// / which must be a superclass or concrete type symbol.
256
256
bool RewriteSystem::simplifySubstitutions (Symbol &symbol,
257
- RewritePath & path) const {
257
+ RewritePath * path) const {
258
258
assert (symbol.hasSubstitutions ());
259
259
260
260
auto substitutions = symbol.getSubstitutions ();
@@ -263,14 +263,16 @@ bool RewriteSystem::simplifySubstitutions(Symbol &symbol,
263
263
264
264
// Save the original rewrite path length so that we can reset if if we don't
265
265
// find anything to simplify.
266
- unsigned oldSize = path. size ();
266
+ unsigned oldSize = ( path ? path-> size () : 0 );
267
267
268
- // The term is on the A stack. Push all substitutions onto the A stack.
269
- path.add (RewriteStep::forDecompose (substitutions.size (), /* inverse=*/ false ));
268
+ if (path) {
269
+ // The term is on the A stack. Push all substitutions onto the A stack.
270
+ path->add (RewriteStep::forDecompose (substitutions.size (), /* inverse=*/ false ));
270
271
271
- // Move all substitutions but the first one to the B stack.
272
- for (unsigned i = 1 ; i < substitutions.size (); ++i)
273
- path.add (RewriteStep::forShift (/* inverse=*/ false ));
272
+ // Move all substitutions but the first one to the B stack.
273
+ for (unsigned i = 1 ; i < substitutions.size (); ++i)
274
+ path->add (RewriteStep::forShift (/* inverse=*/ false ));
275
+ }
274
276
275
277
// Simplify and collect substitutions.
276
278
SmallVector<Term, 2 > newSubstitutions;
@@ -280,34 +282,37 @@ bool RewriteSystem::simplifySubstitutions(Symbol &symbol,
280
282
bool anyChanged = false ;
281
283
for (auto substitution : substitutions) {
282
284
// Move the next substitution from the B stack to the A stack.
283
- if (!first)
284
- path. add (RewriteStep::forShift (/* inverse=*/ true ));
285
+ if (!first && path )
286
+ path-> add (RewriteStep::forShift (/* inverse=*/ true ));
285
287
first = false ;
286
288
287
289
// The current substitution is at the top of the A stack; simplify it.
288
290
MutableTerm mutTerm (substitution);
289
- anyChanged |= simplify (mutTerm, & path);
291
+ anyChanged |= simplify (mutTerm, path);
290
292
291
293
// Record the new substitution.
292
294
newSubstitutions.push_back (Term::get (mutTerm, Context));
293
295
}
294
296
295
297
// All simplified substitutions are now on the A stack. Collect them to
296
298
// produce the new term.
297
- path.add (RewriteStep::forDecompose (substitutions.size (), /* inverse=*/ true ));
299
+ if (path)
300
+ path->add (RewriteStep::forDecompose (substitutions.size (), /* inverse=*/ true ));
298
301
299
302
// If nothing changed, we don't have to rebuild the symbol.
300
303
if (!anyChanged) {
301
- // The rewrite path should consist of a Decompose, followed by a number
302
- // of Shifts, followed by a Compose.
303
- #ifndef NDEBUG
304
- for (auto iter = path.begin () + oldSize; iter < path.end (); ++iter) {
305
- assert (iter->Kind == RewriteStep::Shift ||
306
- iter->Kind == RewriteStep::Decompose);
307
- }
308
- #endif
304
+ if (path) {
305
+ // The rewrite path should consist of a Decompose, followed by a number
306
+ // of Shifts, followed by a Compose.
307
+ #ifndef NDEBUG
308
+ for (auto iter = path->begin () + oldSize; iter < path->end (); ++iter) {
309
+ assert (iter->Kind == RewriteStep::Shift ||
310
+ iter->Kind == RewriteStep::Decompose);
311
+ }
312
+ #endif
309
313
310
- path.resize (oldSize);
314
+ path->resize (oldSize);
315
+ }
311
316
return false ;
312
317
}
313
318
@@ -571,7 +576,7 @@ void RewriteSystem::simplifyRightHandSidesAndSubstitutions() {
571
576
ruleID, /* inverse=*/ true ));
572
577
573
578
// (2) Now, simplify the substitutions to get the new lhs.
574
- if (!simplifySubstitutions (symbol, path))
579
+ if (!simplifySubstitutions (symbol, & path))
575
580
continue ;
576
581
577
582
// We're either going to add a new rule or record an identity, so
0 commit comments