Source:
private List<ConstrainedTerm> computeRewriteStep(ConstrainedTerm subject, int step, boolean computeOne) { RuleAuditing.setAuditingRule(javaOptions, step, subject.termContext().definition()); try { subject.termContext().setTopTerm(subject.term()); Set<Rule> failedRules = new HashSet<>(subject2DisabledRules.getOrDefault(subject, Collections.emptySet())); List<ConstrainedTerm> results = new ArrayList<>(); for (strategy.reset(ruleIndex.getRules(subject.term())); strategy.hasNext(); ) { transition = strategy.nextIsTransition(); Set<Rule> rules = new LinkedHashSet<>(strategy.next()); rules.removeAll(failedRules); Map<Rule, List<ConstrainedTerm>> rule2Results; if (computeOne || !transition) { rule2Results = Collections.emptyMap(); for (Rule rule : rules) { List<ConstrainedTerm> terms; if (!(terms = computeRewriteStepByRule(subject, rule)).isEmpty()) { rule2Results = Collections.singletonMap(rule, terms); results.add(terms.get(0)); break; } else { failedRules.add(rule); } } } else { rule2Results = (RuleAuditing.isAudit() ? rules.stream() : rules.parallelStream()) .collect(Collectors.toMap(r -> r, r -> computeRewriteStepByRule(subject, r), (u, v) -> u, LinkedHashMap::new)); rule2Results.forEach((rule, terms) -> { if (terms.isEmpty()) { failedRules.add(rule); } else { results.addAll(terms); } }); } if (!results.isEmpty()) { subject2DisabledRules.remove(subject); rule2Results.forEach((appliedRule, terms) -> { Set<Rule> rulesWillFail = failedRules.stream() .filter(failedRule -> failedRule.isCompiledForFastRewriting() && appliedRule.isCompiledForFastRewriting() && Collections.disjoint(failedRule.readCells(), appliedRule.writeCells())) .collect(Collectors.toSet()); terms.forEach(t -> subject2DisabledRules.put(t, rulesWillFail)); }); break; } } return results; } finally { RuleAuditing.clearAuditingRule(); } }

Target:
private List<ConstrainedTerm> computeRewriteStep(ConstrainedTerm subject, int step, boolean computeOne) { RuleAuditing.setAuditingRule(javaOptions, step, subject.termContext().definition()); try { subject.termContext().setTopTerm(subject.term()); Set<Rule> failedRules = new HashSet<>(subject2DisabledRules.getOrDefault(subject, Collections.emptySet())); List<ConstrainedTerm> results = new ArrayList<>(); for (strategy.reset(ruleIndex.getRules(subject.term())); strategy.hasNext(); ) { transition = strategy.nextIsTransition(); Set<Rule> rules = new LinkedHashSet<>(strategy.next()); rules.removeAll(failedRules); Map<Rule, List<ConstrainedTerm>> rule2Results; if (computeOne || !transition) { rule2Results = Collections.emptyMap(); for (Rule rule : rules) { List<ConstrainedTerm> terms = computeRewriteStepByRule(subject, rule); if (!terms.isEmpty()) { rule2Results = Collections.singletonMap(rule, terms); results.add(terms.get(0)); break; } else { failedRules.add(rule); } } } else { rule2Results = (RuleAuditing.isAudit() ? rules.stream() : rules.parallelStream()) .collect(Collectors.toMap(r -> r, r -> computeRewriteStepByRule(subject, r), (u, v) -> u, LinkedHashMap::new)); rule2Results.forEach((rule, terms) -> { if (terms.isEmpty()) { failedRules.add(rule); } else { results.addAll(terms); } }); } if (!results.isEmpty()) { subject2DisabledRules.remove(subject); rule2Results.forEach((appliedRule, terms) -> { Set<Rule> rulesWillFail = failedRules.stream() .filter(failedRule -> failedRule.isCompiledForFastRewriting() && appliedRule.isCompiledForFastRewriting() && Collections.disjoint(failedRule.readCells(), appliedRule.writeCells())) .collect(Collectors.toSet()); terms.forEach(t -> subject2DisabledRules.put(t, rulesWillFail)); }); break; } } return results; } finally { RuleAuditing.clearAuditingRule(); } }