File tree Expand file tree Collapse file tree 3 files changed +45
-9
lines changed Expand file tree Collapse file tree 3 files changed +45
-9
lines changed Original file line number Diff line number Diff line change @@ -192,6 +192,10 @@ class Rule final {
192
192
deleted = true ;
193
193
}
194
194
195
+ unsigned getDepth () const {
196
+ return LHS.size ();
197
+ }
198
+
195
199
void dump (llvm::raw_ostream &out) const ;
196
200
};
197
201
@@ -212,7 +216,15 @@ class RewriteSystem final {
212
216
213
217
bool simplify (Term &term) const ;
214
218
215
- void computeConfluentCompletion (unsigned maxIterations);
219
+ enum class CompletionResult {
220
+ Success,
221
+ MaxIterations,
222
+ MaxDepth
223
+ };
224
+
225
+ CompletionResult computeConfluentCompletion (
226
+ unsigned maxIterations,
227
+ unsigned maxDepth);
216
228
217
229
void dump (llvm::raw_ostream &out) const ;
218
230
};
Original file line number Diff line number Diff line change @@ -338,6 +338,10 @@ RequirementMachine::~RequirementMachine() {
338
338
void RequirementMachine::addGenericSignature (CanGenericSignature sig) {
339
339
PrettyStackTraceGenericSignature debugStack (" building rewrite system for" , sig);
340
340
341
+ auto *Stats = Context.Stats ;
342
+
343
+ FrontendStatsTracer (Stats, " build-rewrite-system" );
344
+
341
345
if (Context.LangOpts .DebugRequirementMachine ) {
342
346
llvm::dbgs () << " Adding generic signature " << sig << " {\n " ;
343
347
}
@@ -351,7 +355,24 @@ void RequirementMachine::addGenericSignature(CanGenericSignature sig) {
351
355
Impl->System .addRule (rule.first , rule.second );
352
356
353
357
// FIXME: Add command line flag
354
- Impl->System .computeConfluentCompletion (10000 );
358
+ auto result = Impl->System .computeConfluentCompletion (5000 , 10 );
359
+
360
+ switch (result) {
361
+ case RewriteSystem::CompletionResult::Success:
362
+ break ;
363
+
364
+ case RewriteSystem::CompletionResult::MaxIterations:
365
+ llvm::errs () << " Generic signature " << sig
366
+ << " exceeds maximum completion step count\n " ;
367
+ break ;
368
+ // abort();
369
+
370
+ case RewriteSystem::CompletionResult::MaxDepth:
371
+ llvm::errs () << " Generic signature " << sig
372
+ << " exceeds maximum completion depth\n " ;
373
+ break ;
374
+ // abort();
375
+ }
355
376
356
377
markComplete ();
357
378
Original file line number Diff line number Diff line change @@ -246,8 +246,10 @@ bool RewriteSystem::simplify(Term &term) const {
246
246
return changed;
247
247
}
248
248
249
- void RewriteSystem::computeConfluentCompletion (
250
- unsigned maxIterations) {
249
+ RewriteSystem::CompletionResult
250
+ RewriteSystem::computeConfluentCompletion (
251
+ unsigned maxIterations,
252
+ unsigned maxDepth) {
251
253
SmallVector<std::pair<unsigned , unsigned >, 16 > worklist;
252
254
253
255
for (unsigned i : indices (Rules)) {
@@ -286,15 +288,14 @@ void RewriteSystem::computeConfluentCompletion(
286
288
if (!addRule (first, second))
287
289
continue ;
288
290
289
- if (maxIterations == 0 ) {
290
- dump (llvm::errs ());
291
- llvm::errs () << " Completion procedure exceeded max iteration count\n " ;
292
- abort ();
293
- }
291
+ if (maxIterations == 0 )
292
+ return CompletionResult::MaxIterations;
294
293
295
294
maxIterations--;
296
295
297
296
const auto &newRule = Rules[i];
297
+ if (newRule.getDepth () > maxDepth)
298
+ return CompletionResult::MaxDepth;
298
299
299
300
for (unsigned j : indices (Rules)) {
300
301
if (i == j)
@@ -317,6 +318,8 @@ void RewriteSystem::computeConfluentCompletion(
317
318
rule.markDeleted ();
318
319
}
319
320
}
321
+
322
+ return CompletionResult::Success;
320
323
}
321
324
322
325
void RewriteSystem::dump (llvm::raw_ostream &out) const {
You can’t perform that action at this time.
0 commit comments