-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Open
Labels
Description
This PR refactors factor_rewriter.cpp to use C++17 structured bindings instead of accessing .first and .second members of std::pair(expr*, bool).
Changes
File: src/ast/rewriter/factor_rewriter.cpp
Type: std::pair(expr*, bool) representing expression and sign indicator
Naming: [e, sign] - descriptive names for expression and sign
Modified Functions
1. factor_rewriter::mk_adds() - 3 refactoring sites
-
Line 163: Main loop processing additions
- Before:
bool sign = m_adds[i].second; expr* _e = m_adds[i].first; - After:
auto& [e, sign] = m_adds[i]; - Eliminates 2 intermediate variables, uses
edirectly - Updates all references within loop body (lines 167-188)
- Before:
-
Lines 198-202: TRACE output loop
- Before:
m_adds[i].secondandm_adds[i].first - After:
auto& [e, sign] = m_adds[i]; - Cleaner trace output code
- Before:
2. factor_rewriter::mk_muls() - 1 refactoring site
- Line 210: Loop building multiplication terms
- Before:
m_adds[i].first - After:
auto& [e, sign] = m_adds[i]; - More readable access pattern
- Before:
Benefits
- Readability:
eandsignare semantically meaningful vs generic.first/.second - Code Simplification: Eliminates intermediate variable assignments
- Error Reduction: Reduces chance of confusing
.firstand.second - Modernization: Adopts C++17 idiom (Z3 uses C++20)
- Consistency: Similar refactoring pattern used in 12 previous PRs
Code Statistics
- Lines changed: 17 (+10 added, -10 deleted, net +0)
- Intermediate variables eliminated: 2 (
sign,_e) - Sites refactored: 4 total (3 in mk_adds, 1 in mk_muls)
- Functions modified: 2
Testing
- No functional changes to arithmetic rewriter logic
- All existing behavior preserved
- Original semantics maintained for polynomial factorization
Context
This is part of an ongoing effort to modernize the Z3 codebase with C++17/C++20 features. Previous structured bindings refactorings:
- PR Specify python version required in readme #1-9: SAT/SMT subsystems (103 sites)
- PR fp.isSubnormal is buggy #10: sat_th.cpp enode_pair patterns (4 sites)
- PR Corrected typo: interger -> integer #11: smt_context.cpp clause/assumption pairs (4 sites)
- PR Cleanup: avoid defining reserved identifiers #12: theory_bv.cpp variable pairs (3 sites)
Total Progress: 114+ sites refactored across 16 files
AI generated by Code Conventions Analyzer
Copilot