@@ -366,12 +366,11 @@ void PropertyMap::addSuperclassProperty(
366
366
367
367
// / Given a rule (V.[LHS] => V) and a rewrite path (T.[RHS] => T) where
368
368
// / T == U.V, build a rewrite path from T.[RHS] to T.[LHS].
369
- static void buildRewritePathForUnifier (Term key,
370
- unsigned lhsRuleID,
371
- const RewritePath &rhsPath,
372
- const RewriteSystem &system,
373
- RewritePath *path) {
374
- unsigned lhsLength = system.getRule (lhsRuleID).getRHS ().size ();
369
+ void RewriteSystem::buildRewritePathForUnifier (Term key,
370
+ unsigned lhsRuleID,
371
+ const RewritePath &rhsPath,
372
+ RewritePath *path) const {
373
+ unsigned lhsLength = getRule (lhsRuleID).getRHS ().size ();
375
374
unsigned lhsPrefix = key.size () - lhsLength;
376
375
377
376
path->append (rhsPath);
@@ -452,7 +451,7 @@ static void buildRewritePathForInducedRule(Term key,
452
451
path->add (RewriteStep::forRightConcreteProjection (
453
452
differenceID, substitutionIndex, /* inverse=*/ false ));
454
453
455
- buildRewritePathForUnifier (key, lhsRuleID, rhsPath, system , path);
454
+ system. buildRewritePathForUnifier (key, lhsRuleID, rhsPath, path);
456
455
457
456
// Pop T.[LHS] from the stack, leaving behind Xn.
458
457
path->add (RewriteStep::forLeftConcreteProjection (
@@ -461,14 +460,13 @@ static void buildRewritePathForInducedRule(Term key,
461
460
462
461
// / Given that LHS and RHS are known to simplify to the same term, build a
463
462
// / rewrite path from RHS to LHS.
464
- static void buildPathJoiningTerms (MutableTerm lhsTerm,
465
- MutableTerm rhsTerm,
466
- RewriteSystem &system,
467
- RewritePath *path) {
468
- (void ) system.simplify (rhsTerm, path);
463
+ void RewriteSystem::buildRewritePathForJoiningTerms (MutableTerm lhsTerm,
464
+ MutableTerm rhsTerm,
465
+ RewritePath *path) const {
466
+ (void ) simplify (rhsTerm, path);
469
467
470
468
RewritePath lhsPath;
471
- (void ) system. simplify (lhsTerm, &lhsPath);
469
+ (void ) simplify (lhsTerm, &lhsPath);
472
470
lhsPath.invert ();
473
471
474
472
path->append (lhsPath);
@@ -487,10 +485,10 @@ static void buildPathJoiningTerms(MutableTerm lhsTerm,
487
485
// /
488
486
// / Finally, builds a rewrite loop relating the two concrete type rules
489
487
// / via the induced rules.
490
- void PropertyMap ::processTypeDifference (const TypeDifference &difference,
491
- unsigned differenceID,
492
- unsigned lhsRuleID,
493
- const RewritePath &rhsPath) {
488
+ void RewriteSystem ::processTypeDifference (const TypeDifference &difference,
489
+ unsigned differenceID,
490
+ unsigned lhsRuleID,
491
+ const RewritePath &rhsPath) {
494
492
bool debug = Debug.contains (DebugFlags::ConcreteUnification);
495
493
496
494
if (debug) {
@@ -521,17 +519,17 @@ void PropertyMap::processTypeDifference(const TypeDifference &difference,
521
519
RewritePath inducedRulePath;
522
520
buildRewritePathForInducedRule (difference.BaseTerm , differenceID,
523
521
lhsRuleID, rhsPath, index,
524
- System , &inducedRulePath);
522
+ * this , &inducedRulePath);
525
523
526
524
if (debug) {
527
525
llvm::dbgs () << " %% Induced rule " << lhsTerm
528
526
<< " => " << rhsTerm << " with path " ;
529
- inducedRulePath.dump (llvm::dbgs (), lhsTerm, System );
527
+ inducedRulePath.dump (llvm::dbgs (), lhsTerm, * this );
530
528
llvm::dbgs () << " \n " ;
531
529
}
532
530
533
- System. addRule (lhsTerm, rhsTerm, &inducedRulePath);
534
- buildPathJoiningTerms (lhsTerm, rhsTerm, System , &unificationPath);
531
+ addRule (lhsTerm, rhsTerm, &inducedRulePath);
532
+ buildRewritePathForJoiningTerms (lhsTerm, rhsTerm, &unificationPath);
535
533
}
536
534
537
535
// All simplified substitutions are now on the primary stack. Collect them to
@@ -543,17 +541,17 @@ void PropertyMap::processTypeDifference(const TypeDifference &difference,
543
541
// newly-recorded induced rules. Close the loop with a path from
544
542
// T.[RHS] to R.[LHS] via the concrete type rules being unified.
545
543
buildRewritePathForUnifier (difference.BaseTerm , lhsRuleID, rhsPath,
546
- System, &unificationPath);
544
+ &unificationPath);
547
545
548
546
// Record a rewrite loop at T.[LHS].
549
547
MutableTerm basepoint (difference.BaseTerm );
550
548
basepoint.add (difference.LHS );
551
- System. recordRewriteLoop (basepoint, unificationPath);
549
+ recordRewriteLoop (basepoint, unificationPath);
552
550
553
551
// Optimization: If the LHS rule applies to the entire base term and not
554
552
// a suffix, mark it substitution-simplified so that we can skip recording
555
553
// the same rewrite loop in concretelySimplifyLeftHandSideSubstitutions().
556
- auto &lhsRule = System. getRule (lhsRuleID);
554
+ auto &lhsRule = getRule (lhsRuleID);
557
555
if (lhsRule.getRHS () == difference.BaseTerm )
558
556
lhsRule.markSubstitutionSimplified ();
559
557
}
@@ -629,15 +627,15 @@ void PropertyMap::unifyConcreteTypes(
629
627
630
628
// Recover a rewrite path from T to T.[LHS ∧ RHS].
631
629
RewritePath path;
632
- buildPathJoiningTerms (rhsTerm, lhsTerm, System , &path);
630
+ System. buildRewritePathForJoiningTerms (rhsTerm, lhsTerm, &path);
633
631
634
632
// Process LHS -> (LHS ∧ RHS).
635
- processTypeDifference (lhsDifference, *lhsDifferenceID,
636
- *existingRuleID, path);
633
+ System. processTypeDifference (lhsDifference, *lhsDifferenceID,
634
+ *existingRuleID, path);
637
635
638
636
// Process RHS -> (LHS ∧ RHS).
639
- processTypeDifference (rhsDifference, *rhsDifferenceID,
640
- ruleID, path);
637
+ System. processTypeDifference (rhsDifference, *rhsDifferenceID,
638
+ ruleID, path);
641
639
}
642
640
643
641
// The new property is more specific, so update ConcreteType and
@@ -663,8 +661,8 @@ void PropertyMap::unifyConcreteTypes(
663
661
/* startOffset=*/ 0 , /* endOffset=*/ 0 ,
664
662
/* ruleID=*/ ruleID, /* inverse=*/ false ));
665
663
666
- processTypeDifference (lhsDifference, *lhsDifferenceID,
667
- *existingRuleID, path);
664
+ System. processTypeDifference (lhsDifference, *lhsDifferenceID,
665
+ *existingRuleID, path);
668
666
}
669
667
670
668
// The new property is more specific, so update existingProperty and
@@ -698,8 +696,8 @@ void PropertyMap::unifyConcreteTypes(
698
696
/* startOffset=*/ prefix, /* endOffset=*/ 0 ,
699
697
/* ruleID=*/ *existingRuleID, /* inverse=*/ false ));
700
698
701
- processTypeDifference (rhsDifference, *rhsDifferenceID,
702
- ruleID, path);
699
+ System. processTypeDifference (rhsDifference, *rhsDifferenceID,
700
+ ruleID, path);
703
701
}
704
702
705
703
// The new property is less specific, so existingProperty and existingRuleID
@@ -730,7 +728,7 @@ void PropertyMap::unifyConcreteTypes(
730
728
/* ruleID=*/ ruleID, /* inverse=*/ false ));
731
729
732
730
RewritePath path;
733
- buildRewritePathForUnifier (key, *existingRuleID, rhsPath, System , &path);
731
+ System. buildRewritePathForUnifier (key, *existingRuleID, rhsPath, &path);
734
732
System.recordRewriteLoop (MutableTerm (rule.getLHS ()), path);
735
733
736
734
rule.markSubstitutionSimplified ();
0 commit comments