Skip to content

[Arith] Add Analyzer::Clone for deep-copying analyzer state#19836

Merged
tqchen merged 1 commit into
apache:mainfrom
tlopex:arith-analyzer-clone
Jun 19, 2026
Merged

[Arith] Add Analyzer::Clone for deep-copying analyzer state#19836
tqchen merged 1 commit into
apache:mainfrom
tlopex:arith-analyzer-clone

Conversation

@tlopex

@tlopex tlopex commented Jun 19, 2026

Copy link
Copy Markdown
Member

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().

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.
@tlopex

tlopex commented Jun 19, 2026

Copy link
Copy Markdown
Member Author

cc @LeiWang1999

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@tqchen tqchen merged commit 9f907f5 into apache:main Jun 19, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants