[Mlir-commits] [mlir] [MLIR] Support interrupting AffineExpr walks (PR #74792)

Oleksandr Alex Zinenko llvmlistbot at llvm.org
Fri Dec 8 01:27:38 PST 2023


================
@@ -123,8 +124,19 @@ class AffineExpr {
   /// Return true if the affine expression involves AffineSymbolExpr `position`.
   bool isFunctionOfSymbol(unsigned position) const;
 
-  /// Walk all of the AffineExpr's in this expression in postorder.
-  void walk(std::function<void(AffineExpr)> callback) const;
+  /// Walk all of the AffineExpr's in this expression in postorder. This allows
+  /// a lambda walk function that can either return `void` or a WalkResult. With
+  /// a WalkResult, interrupting is supported.
+  template <typename FnT, typename RetT = detail::walkResultType<FnT>>
+  std::enable_if_t<std::is_same<RetT, void>::value, RetT>
+  walk(FnT &&callback) const {
+    return walk<void>(*this, callback);
+  }
+  template <typename FnT, typename RetT = detail::walkResultType<FnT>>
+  std::enable_if_t<std::is_same<RetT, WalkResult>::value, RetT>
+  walk(FnT &&callback) const {
+    return walk<WalkResult>(*this, callback);
+  }
----------------
ftynse wrote:

Wouldn't this work as just this:

```cpp
  template <typename FnT, typename RetT = detail::walkResultType<FnT>>
  RetT walk(FnT &&callback) const {
    return walk<RetT>(*this, callback);
  }
```

without the `enable_if` fluff?

https://github.com/llvm/llvm-project/pull/74792


More information about the Mlir-commits mailing list