@@ -508,9 +508,10 @@ using OriginLoanMap = llvm::ImmutableMap<OriginID, LoanSet>;
508
508
// / An object to hold the factories for immutable collections, ensuring
509
509
// / that all created states share the same underlying memory management.
510
510
struct LifetimeFactory {
511
- OriginLoanMap::Factory OriginMapFact ;
511
+ OriginLoanMap::Factory OriginMapFactory ;
512
512
LoanSet::Factory LoanSetFact;
513
513
514
+ // / Creates a singleton set containing only the given loan ID.
514
515
LoanSet createLoanSet (LoanID LID) {
515
516
return LoanSetFact.add (LoanSetFact.getEmptySet (), LID);
516
517
}
@@ -521,6 +522,8 @@ struct LifetimeFactory {
521
522
// / instance rather than modifying the existing one.
522
523
struct LifetimeLattice {
523
524
// / The map from an origin to the set of loans it contains.
525
+ // / The lattice has a finite height: An origin's loan set is bounded by the
526
+ // / total number of loans in the function.
524
527
// / TODO(opt): To reduce the lattice size, propagate origins of declarations,
525
528
// / not expressions, because expressions are not visible across blocks.
526
529
OriginLoanMap Origins = OriginLoanMap(nullptr );
@@ -535,10 +538,10 @@ struct LifetimeLattice {
535
538
return !(*this == Other);
536
539
}
537
540
538
- LoanSet getLoans (OriginID OID, LifetimeFactory &Factory ) const {
541
+ LoanSet getLoans (OriginID OID) const {
539
542
if (auto *Loans = Origins.lookup (OID))
540
543
return *Loans;
541
- return Factory. LoanSetFact . getEmptySet ( );
544
+ return LoanSet ( nullptr );
542
545
}
543
546
544
547
// / Computes the union of two lattices by performing a key-wise join of
@@ -559,9 +562,8 @@ struct LifetimeLattice {
559
562
for (const auto &Entry : Other.Origins ) {
560
563
OriginID OID = Entry.first ;
561
564
LoanSet OtherLoanSet = Entry.second ;
562
- JoinedState = Factory.OriginMapFact .add (
563
- JoinedState, OID,
564
- join (getLoans (OID, Factory), OtherLoanSet, Factory));
565
+ JoinedState = Factory.OriginMapFactory .add (
566
+ JoinedState, OID, join (getLoans (OID), OtherLoanSet, Factory));
565
567
}
566
568
return LifetimeLattice (JoinedState);
567
569
}
@@ -639,18 +641,18 @@ class Transferer {
639
641
LifetimeLattice transfer (LifetimeLattice In, const IssueFact &F) {
640
642
OriginID OID = F.getOriginID ();
641
643
LoanID LID = F.getLoanID ();
642
- return LifetimeLattice (
643
- Factory. OriginMapFact . add ( In.Origins , OID, Factory.createLoanSet (LID)));
644
+ return LifetimeLattice (Factory. OriginMapFactory . add (
645
+ In.Origins , OID, Factory.createLoanSet (LID)));
644
646
}
645
647
646
648
// / The destination origin's loan set is replaced by the source's.
647
649
// / This implicitly "resets" the old loans of the destination.
648
650
LifetimeLattice transfer (LifetimeLattice InState, const AssignOriginFact &F) {
649
651
OriginID DestOID = F.getDestOriginID ();
650
652
OriginID SrcOID = F.getSrcOriginID ();
651
- LoanSet SrcLoans = InState.getLoans (SrcOID, Factory );
653
+ LoanSet SrcLoans = InState.getLoans (SrcOID);
652
654
return LifetimeLattice (
653
- Factory.OriginMapFact .add (InState.Origins , DestOID, SrcLoans));
655
+ Factory.OriginMapFactory .add (InState.Origins , DestOID, SrcLoans));
654
656
}
655
657
};
656
658
0 commit comments