Introduce AllFreeLifetimes.

For now, this function is equivalent to iterating over all the non-static
lifetimes in the FunctionLifetimes and storing each visited lifetime in a
DenseSet.  However, this function is meant to behave differently in the
presence of HRTBs.

PiperOrigin-RevId: 440317977
diff --git a/lifetime_annotations/function_lifetimes.cc b/lifetime_annotations/function_lifetimes.cc
index a37b3c4..81afb3f 100644
--- a/lifetime_annotations/function_lifetimes.cc
+++ b/lifetime_annotations/function_lifetimes.cc
@@ -127,6 +127,17 @@
          (this_lifetimes_.has_value() && this_lifetimes_->HasAny(predicate));
 }
 
+llvm::DenseSet<Lifetime> FunctionLifetimes::AllFreeLifetimes() const {
+  // TODO(veluca): this is incorrect in the presence of HRTBs.
+  llvm::DenseSet<Lifetime> all_lifetimes;
+  Traverse([&all_lifetimes](Lifetime l, Variance) {
+    if (l != Lifetime::Static()) {
+      all_lifetimes.insert(l);
+    }
+  });
+  return all_lifetimes;
+}
+
 void FunctionLifetimes::Traverse(
     std::function<void(Lifetime&, Variance)> visitor) {
   for (auto& param : param_lifetimes_) {