[clang] [clang] Specialize invocation path visitation to the cow (PR #205686)
Ben Langmuir via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 26 08:16:43 PDT 2026
================
@@ -445,13 +424,30 @@ class CowCompilerInvocation : public CompilerInvocationBase {
ssaf::SSAFOptions &getMutSSAFOpts();
/// @}
+ /// The result of mutable visitation.
+ struct VisitMutResult {
+ /// Whether to replace the given StringRef with the modified std::string &.
+ bool Replace = false;
+ /// Whether to short-circuit the visitation.
+ bool Terminate = false;
+ };
+
/// Visits paths stored in the invocation, allowing the callback to mutate
- /// them. To preserve the copy-on-write invariant for groups whose paths the
- /// caller might modify, this ensures unique ownership of every option group
- /// up front; if the callback only inspects (and does not mutate) the paths,
- /// the const \c visitPaths overload should be used instead to avoid those
- /// per-group copies.
- void visitMutPaths(llvm::function_ref<bool(std::string &)> Callback);
+ /// them via the out-param. This upholds the same copy-on-write semantics as
+ /// the mutable getters.
+ void visitMutPaths(
+ llvm::function_ref<VisitMutResult(StringRef, std::string &)> Cb);
----------------
benlangmuir wrote:
Since you're providing a separate `std::string` out parameter, I wonder if it would be simpler to just infer `Replace` from the string being non-empty after the callback. Normally I would err on the side of explicitness, but the extra complexity of having `visitMutPaths and `visitPaths` with two similar but different return types makes me think something like
```c++
enum class VisitResult {
Continue,
Terminate,
};
void visitPaths(llvm::function_ref<VisitResult(StringRef)> Cb) const;
void visitMutPaths(llvm::function_ref<VisitResult(StringRef, std::string &)> Cb);
```
https://github.com/llvm/llvm-project/pull/205686
More information about the cfe-commits
mailing list