[Arith] Add Analyzer::Clone for deep-copying analyzer state#19836
Conversation
Copying an Analyzer handle shares the same mutable AnalyzerObj, so a pass had no way to snapshot accumulated facts (variable bounds, modular sets, rewrite/canonical bindings, integer-set domains, literal constraints, transitive comparisons) and keep exploring without mutating the original. Add AnalyzerObj::Clone(), which allocates a fresh AnalyzerObj and copies each sub-analyzer's persistent state through a new per-sub-analyzer CopyFrom. Parent back-pointers are re-established by the fresh constructor rather than copied, and per-query/recursion scratch state is left default. Exposed to Python as Analyzer.clone(). This follows the per-sub-analyzer CopyFrom design from tile-ai/tvm, adapted to the upstream FFI-object Analyzer: Clone returns an Analyzer handle to a new object rather than a unique_ptr.
|
cc @LeiWang1999 |
There was a problem hiding this comment.
Code Review
This pull request introduces a Clone method to the Analyzer class (and its Python bindings), enabling a deep copy of an analyzer with independent state. To support this, CopyFrom methods have been implemented across various sub-analyzers, including ConstIntBoundAnalyzer, ModularSetAnalyzer, RewriteSimplifier, CanonicalSimplifier, TransitiveComparisonAnalyzer, and IntSetAnalyzer. Additionally, new C++ and Python unit tests have been added to verify the independence of the cloned analyzer and its sub-analyzers. There are no review comments, and we have no feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Copying an Analyzer handle shares the same mutable AnalyzerObj, so a pass had no way to snapshot accumulated facts (variable bounds, modular sets, rewrite/canonical bindings, integer-set domains, literal constraints, transitive comparisons) and keep exploring without mutating the original.
This pr adds AnalyzerObj::Clone(), which allocates a fresh AnalyzerObj and copies each sub-analyzer's persistent state through a new per-sub-analyzer CopyFrom. Parent back-pointers are re-established by the fresh constructor rather than copied, and per-query/recursion scratch state is left default. Exposed to Python as Analyzer.clone().