Skip to content

[Conventions] Refactor factor_rewriter to use structured bindings for expr/sign pairs #8370

@github-actions

Description

@github-actions

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 e directly
    • Updates all references within loop body (lines 167-188)
  • Lines 198-202: TRACE output loop

    • Before: m_adds[i].second and m_adds[i].first
    • After: auto& [e, sign] = m_adds[i];
    • Cleaner trace output code

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

Benefits

  1. Readability: e and sign are semantically meaningful vs generic .first/.second
  2. Code Simplification: Eliminates intermediate variable assignments
  3. Error Reduction: Reduces chance of confusing .first and .second
  4. Modernization: Adopts C++17 idiom (Z3 uses C++20)
  5. 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:

Total Progress: 114+ sites refactored across 16 files

AI generated by Code Conventions Analyzer

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions