Code Conventions AnalysisCode Quality Analysis - February 2026 - Modern C++ Adoption Progress #8493
Closed
Replies: 1 comment
-
|
This discussion was automatically closed because it expired on 2026-02-11T00:30:24.357Z.
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Code Conventions Analysis Report
Analysis Date: February 4, 2026
Run Number: 4
Files Examined: 2,009 files across key directories
Executive Summary
This run successfully implemented a major refactoring to modernize
mk_concatcall sites, eliminating 21 lines of boilerplate code and improving readability across 6 files. The analysis continues to track progress on modern C++ adoption and identifies remaining opportunities for code quality improvements.Progress Tracking Summary
✅ RESOLVED Issues (This Run)
std::initializer_list for mk_concat - IMPLEMENTED 🎉
std::initializer_list(expr*)overloadsrc/ast/rewriter/bv_rewriter.cpp(6 refactorings)src/ast/rewriter/fpa_rewriter.cpp(1 refactoring)src/ast/fpa/fpa2bv_converter.cpp(1 refactoring)src/smt/theory_fpa.cpp(1 refactoring)src/qe/mbp/mbp_solve_plugin.cpp(3 refactorings)src/sat/smt/fpa_solver.cpp(1 refactoring)mk_concat(2, args)→mk_concat({arg1, arg2})✅ RESOLVED Issues (Previous Runs)
std::span migration for mk_or and mk_xor - IMPLEMENTED (Run 3)
std::spanoverloads formk_orandmk_xorAPIsmk_and❌ UNRESOLVED Issues (Still Present)
The following issues from previous analysis runs remain unresolved:
std::span migration to arithmetic utilities (Priority: Medium)
mk_add,mk_mul,mk_subinarith_decl_plugin.hstd::span migration to bitvector utilities (Priority: Medium)
mk_bv_or,mk_bv_and,mk_bv_xor(unsigned + pointer versions)std::initializer_listoverloadsstd::clamp opportunities (Priority: Low)
std::max(min, std::min(max, val))patternstd::clamp(val, min, max)for clarityNULL to nullptr (Priority: Low)
Plain enum to enum class (Priority: Medium)
enumthat could beenum classarith_sort_kind,arith_op_kind,array_sort_kindStream output optimization (Priority: Low)
buffer << ")"→buffer << ')'1. Coding Convention Consistency Findings
1.1 Modern C++ API Consistency
Current State: The codebase has excellent modern API coverage with
std::spanandstd::initializer_listoverloadsThis Run's Achievement:
mk_concatcall sites to use the existingstd::initializer_listoverloadRecommendation: Continue systematic review and refactoring of call sites to use modern overloads where they exist
1.2 Array Parameter Patterns
Observation: Z3 has transitioned well from old-style
(unsigned n, T* args)to modern patternsEvolution:
func(unsigned sz, expr* const* args)- requires temporary arraysfunc(std::span(expr*))- for runtime-sized arraysfunc(std::initializer_list(expr*))- for compile-time small arraysStatus: The infrastructure is in place; remaining work is to refactor call sites
2. Modern C++ Feature Opportunities
2.1 std::initializer_list - COMPLETED ✅
Feature:
std::initializer_list(T)for small, compile-time known arraysImplementation: Successfully refactored
mk_concatcall sitesExample:
Impact: 21 lines removed, improved readability, type safety
Next Candidates: Similar opportunities may exist for
mk_bv_or,mk_bv_and,mk_bv_xorif call sites create temporary arrays2.2 std::span - IN PROGRESS 🔄
Feature:
std::span(T)for array views (C++20)Progress:
mk_and,mk_or,mk_xorhavestd::spanoverloads ✅mk_add,mk_mul,mk_sub) - pendingBenefit: Type-safe array passing without size/pointer mismatch
2.3 std::clamp - LOW HANGING FRUIT 🍎
Feature:
std::clamp(val, min, max)for value clamping (C++17)Current Pattern:
std::max(min, std::min(max, val))Opportunity: 5 verified instances
Example Location:
src/ast/simplifiers/bound_propagator.cpp:394Effort: Low - simple find and replace
Benefit: More readable and intention-revealing code
2.4 Character Literals - OPTIMIZATION 📉
Pattern: Using string literals for single characters
Impact: Binary size and runtime performance
Examples:
src/api/api_ast_vector.cpp:133:buffer << ")"→buffer << ')'src/api/api_params.cpp:203:buffer << "("→buffer << '('Count: 30+ instances
Effort: Low
Benefit: Reduced code size, avoid unnecessary string overhead
2.5 Enum Class - LARGER REFACTORING 🏗️
Current: Plain
enumdeclarations for sort kinds and operation kindsModern:
enum classfor type safety and scopingExamples:
arith_sort_kind,arith_op_kindinsrc/ast/arith_decl_plugin.harray_sort_kind,array_op_kindinsrc/ast/array_decl_plugin.hbv_sort_kindinsrc/ast/bv_decl_plugin.hCount: 15+ enums
Challenge: Would require significant refactoring across 50+ files
Benefit: Type safety, prevents accidental conversions, clearer scoping
Recommendation: Plan as a larger, coordinated effort
3. Z3-Specific Code Quality Opportunities
3.1 Consistent Use of Existing Modern APIs
Discovery: Modern API overloads exist but aren't always used consistently
Example: Before this run,
mk_concathad aninitializer_listoverload since the API was modernized, but 13 call sites still created temporary arraysLesson: API modernization requires two phases:
Recommendation:
3.2 Additional initializer_list Candidates
Potential Targets: Functions with existing
std::initializer_listoverloads that might have old-style call sites:mk_bv_or(std::initializer_list(expr*))- line 509 inbv_decl_plugin.hmk_bv_and(std::initializer_list(expr*))- line 511mk_bv_xor(std::initializer_list(expr*))- line 513Action: Search for call sites that create temporary arrays for these functions
Expected: Likely 0 or very few, but worth checking
3.3 Memory and Performance Patterns
Observation: The refactoring from temporary arrays to
initializer_listis zero-overheadVerification: Compiler will generate identical code for both patterns
Benefit: Pure improvement in readability and maintainability with no runtime cost
4. Priority Recommendations
Ranked by impact and effort:
Continue std::span migration - High Impact, Medium Effort
mk_add,mk_mul,mk_sub)Apply std::clamp refactoring - Low Impact, Low Effort 🍎
Fix remaining NULL usage - Low Impact, Low Effort 🍎
Stream output character literals - Low Impact, Low Effort 🍎
Search for additional initializer_list call sites - Unknown Impact, Low Effort
mk_bv_or,mk_bv_and,mk_bv_xorfor temporary array usagePlan enum class migration - Medium Impact, High Effort
5. Sample Refactoring Examples
Example 1: mk_concat with initializer_list (COMPLETED)
Location:
src/ast/rewriter/bv_rewriter.cpp:927Before:
After:
Benefits:
Example 2: std::clamp opportunity (PENDING)
Location:
src/ast/simplifiers/bound_propagator.cpp:394Current:
std::max(std::min(interval_size, abs_k), 1.0)Recommended:
Benefits:
Example 3: Character literal (PENDING)
Location:
src/api/api_ast_vector.cpp:133Current:
buffer << ")";Recommended:
buffer << ')';Benefits:
6. Next Steps
Refactor mk_concat call sites to use std::initializer_listCOMPLETED ✅7. Metrics and Statistics
This Run (Run 4)
Cumulative Progress
Code Quality Indicators
std::span,std::initializer_listoverloads exist)Appendix: Areas Analyzed
Analyzed This Run
src/ast/rewriter/bv_rewriter.cpp- Bitvector rewriting (modified)src/ast/rewriter/fpa_rewriter.cpp- Floating-point rewriting (modified)src/ast/fpa/fpa2bv_converter.cpp- FP to BV conversion (modified)src/smt/theory_fpa.cpp- FP theory solver (modified)src/qe/mbp/mbp_solve_plugin.cpp- Quantifier elimination (modified)src/sat/smt/fpa_solver.cpp- SAT FP solver (modified)src/ast/bv_decl_plugin.h- Verified initializer_list overloadsPreviously Analyzed
src/ast/*.h- AST headers and utilitiessrc/ast/*.cpp- AST implementationssrc/util/*.hand*.cpp- Utility librariessrc/api/*.cpp- Public API surfacesrc/smt/*.cpp- SMT solver components (partial)src/ast/arith_decl_plugin.h- Arithmetic pluginsrc/ast/array_decl_plugin.h- Array pluginNot Yet Deeply Analyzed
src/solver/- Solver implementationssrc/parsers/- Input parserssrc/model/- Model generationsrc/nlsat/- Nonlinear arithmeticsrc/muz/- Most files (except spacer_context)src/tactic/- Most tactical componentsConclusion
This analysis run successfully implemented a significant code modernization by refactoring 13 call sites to use
std::initializer_list, demonstrating the value of systematic code quality improvements. The Z3 codebase continues to evolve toward modern C++ idioms while maintaining its robust functionality.Key Takeaway: Modern APIs exist in Z3, but consistent adoption requires ongoing refactoring efforts. This run proved that such refactoring is safe, beneficial, and achievable in manageable increments.
Next Focus: Low-effort, high-readability improvements like
std::clamp, nullptr fixes, and character literal optimizations offer quick wins for the next analysis run.Beta Was this translation helpful? Give feedback.
All reactions