@@ -508,9 +508,10 @@ using OriginLoanMap = llvm::ImmutableMap<OriginID, LoanSet>;
508508// / An object to hold the factories for immutable collections, ensuring
509509// / that all created states share the same underlying memory management.
510510struct LifetimeFactory {
511- OriginLoanMap::Factory OriginMapFact ;
511+ OriginLoanMap::Factory OriginMapFactory ;
512512 LoanSet::Factory LoanSetFact;
513513
514+ // / Creates a singleton set containing only the given loan ID.
514515 LoanSet createLoanSet (LoanID LID) {
515516 return LoanSetFact.add (LoanSetFact.getEmptySet (), LID);
516517 }
@@ -521,6 +522,8 @@ struct LifetimeFactory {
521522// / instance rather than modifying the existing one.
522523struct LifetimeLattice {
523524 // / 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.
524527 // / TODO(opt): To reduce the lattice size, propagate origins of declarations,
525528 // / not expressions, because expressions are not visible across blocks.
526529 OriginLoanMap Origins = OriginLoanMap(nullptr );
@@ -535,10 +538,10 @@ struct LifetimeLattice {
535538 return !(*this == Other);
536539 }
537540
538- LoanSet getLoans (OriginID OID, LifetimeFactory &Factory ) const {
541+ LoanSet getLoans (OriginID OID) const {
539542 if (auto *Loans = Origins.lookup (OID))
540543 return *Loans;
541- return Factory. LoanSetFact . getEmptySet ( );
544+ return LoanSet ( nullptr );
542545 }
543546
544547 // / Computes the union of two lattices by performing a key-wise join of
@@ -559,9 +562,8 @@ struct LifetimeLattice {
559562 for (const auto &Entry : Other.Origins ) {
560563 OriginID OID = Entry.first ;
561564 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));
565567 }
566568 return LifetimeLattice (JoinedState);
567569 }
@@ -639,18 +641,18 @@ class Transferer {
639641 LifetimeLattice transfer (LifetimeLattice In, const IssueFact &F) {
640642 OriginID OID = F.getOriginID ();
641643 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)));
644646 }
645647
646648 // / The destination origin's loan set is replaced by the source's.
647649 // / This implicitly "resets" the old loans of the destination.
648650 LifetimeLattice transfer (LifetimeLattice InState, const AssignOriginFact &F) {
649651 OriginID DestOID = F.getDestOriginID ();
650652 OriginID SrcOID = F.getSrcOriginID ();
651- LoanSet SrcLoans = InState.getLoans (SrcOID, Factory );
653+ LoanSet SrcLoans = InState.getLoans (SrcOID);
652654 return LifetimeLattice (
653- Factory.OriginMapFact .add (InState.Origins , DestOID, SrcLoans));
655+ Factory.OriginMapFactory .add (InState.Origins , DestOID, SrcLoans));
654656 }
655657};
656658
0 commit comments