@@ -391,6 +391,48 @@ void PropertyMap::addSuperclassProperty(
391391 }
392392}
393393
394+ // / Record induced rules from the given type difference.
395+ void PropertyMap::processTypeDifference (const TypeDifference &difference,
396+ unsigned differenceID,
397+ unsigned lhsRuleID,
398+ unsigned rhsRuleID) {
399+ bool debug = Debug.contains (DebugFlags::ConcreteUnification);
400+
401+ if (debug) {
402+ difference.dump (llvm::dbgs ());
403+ }
404+
405+ for (const auto &pair : difference.SameTypes ) {
406+ // Both sides are type parameters; add a same-type requirement.
407+ MutableTerm lhsTerm (difference.LHS .getSubstitutions ()[pair.first ]);
408+ MutableTerm rhsTerm (pair.second );
409+
410+ if (debug) {
411+ llvm::dbgs () << " %% Induced rule " << lhsTerm
412+ << " == " << rhsTerm << " \n " ;
413+ }
414+
415+ // FIXME: Need a rewrite path here.
416+ System.addRule (lhsTerm, rhsTerm);
417+ }
418+
419+ for (const auto &pair : difference.ConcreteTypes ) {
420+ // A type parameter is equated with a concrete type; add a concrete
421+ // type requirement.
422+ MutableTerm rhsTerm (difference.LHS .getSubstitutions ()[pair.first ]);
423+ MutableTerm lhsTerm (rhsTerm);
424+ lhsTerm.add (pair.second );
425+
426+ if (debug) {
427+ llvm::dbgs () << " %% Induced rule " << lhsTerm
428+ << " == " << rhsTerm << " \n " ;
429+ }
430+
431+ // FIXME: Need a rewrite path here.
432+ System.addRule (lhsTerm, rhsTerm);
433+ }
434+ }
435+
394436// / When a type parameter has two concrete types, we have to unify the
395437// / type constructor arguments.
396438// /
@@ -450,43 +492,6 @@ void PropertyMap::addConcreteTypeProperty(
450492 return ;
451493 }
452494
453- // Record induced rules from the given type difference.
454- auto processTypeDifference = [&](const TypeDifference &difference) {
455- if (debug) {
456- difference.dump (llvm::dbgs ());
457- }
458-
459- for (const auto &pair : difference.SameTypes ) {
460- // Both sides are type parameters; add a same-type requirement.
461- MutableTerm lhsTerm (difference.LHS .getSubstitutions ()[pair.first ]);
462- MutableTerm rhsTerm (pair.second );
463-
464- if (debug) {
465- llvm::dbgs () << " %% Induced rule " << lhsTerm
466- << " == " << rhsTerm << " \n " ;
467- }
468-
469- // FIXME: Need a rewrite path here.
470- System.addRule (lhsTerm, rhsTerm);
471- }
472-
473- for (const auto &pair : difference.ConcreteTypes ) {
474- // A type parameter is equated with a concrete type; add a concrete
475- // type requirement.
476- MutableTerm rhsTerm (difference.LHS .getSubstitutions ()[pair.first ]);
477- MutableTerm lhsTerm (rhsTerm);
478- lhsTerm.add (pair.second );
479-
480- if (debug) {
481- llvm::dbgs () << " %% Induced rule " << lhsTerm
482- << " == " << rhsTerm << " \n " ;
483- }
484-
485- // FIXME: Need a rewrite path here.
486- System.addRule (lhsTerm, rhsTerm);
487- }
488- };
489-
490495 // Handle the case where (LHS ∧ RHS) is distinct from both LHS and RHS:
491496 // - First, record a new rule.
492497 // - Next, process the LHS -> (LHS ∧ RHS) difference.
@@ -510,6 +515,8 @@ void PropertyMap::addConcreteTypeProperty(
510515 << " == " << rhsTerm << " \n " ;
511516 }
512517
518+ // This rule does not need a rewrite path because it will be related
519+ // to the existing rule in concretelySimplifyLeftHandSideSubstitutions().
513520 System.addRule (lhsTerm, rhsTerm);
514521 }
515522
@@ -529,11 +536,13 @@ void PropertyMap::addConcreteTypeProperty(
529536
530537 // Process LHS -> (LHS ∧ RHS).
531538 if (checkRulePairOnce (*props->ConcreteTypeRule , newRuleID))
532- processTypeDifference (lhsDifference);
539+ processTypeDifference (lhsDifference, *lhsDifferenceID,
540+ *props->ConcreteTypeRule , newRuleID);
533541
534542 // Process RHS -> (LHS ∧ RHS).
535543 if (checkRulePairOnce (ruleID, newRuleID))
536- processTypeDifference (rhsDifference);
544+ processTypeDifference (rhsDifference, *rhsDifferenceID,
545+ ruleID, newRuleID);
537546
538547 // The new property is more specific, so update ConcreteType and
539548 // ConcreteTypeRule.
@@ -552,7 +561,8 @@ void PropertyMap::addConcreteTypeProperty(
552561 assert (property == lhsDifference.RHS );
553562
554563 if (checkRulePairOnce (*props->ConcreteTypeRule , ruleID))
555- processTypeDifference (lhsDifference);
564+ processTypeDifference (lhsDifference, *lhsDifferenceID,
565+ *props->ConcreteTypeRule , ruleID);
556566
557567 // The new property is more specific, so update ConcreteType and
558568 // ConcreteTypeRule.
@@ -571,7 +581,8 @@ void PropertyMap::addConcreteTypeProperty(
571581 assert (*props->ConcreteType == rhsDifference.RHS );
572582
573583 if (checkRulePairOnce (*props->ConcreteTypeRule , ruleID))
574- processTypeDifference (rhsDifference);
584+ processTypeDifference (rhsDifference, *rhsDifferenceID,
585+ ruleID, *props->ConcreteTypeRule );
575586
576587 // The new property is less specific, so ConcreteType and ConcreteTypeRule
577588 // remain unchanged.
0 commit comments