Skip to content

Apply east-const to function parameter definitions#2216

Open
Baltoli wants to merge 1 commit intomainfrom
bruce/const-params-definitions
Open

Apply east-const to function parameter definitions#2216
Baltoli wants to merge 1 commit intomainfrom
bruce/const-params-definitions

Conversation

@Baltoli
Copy link
Copy Markdown
Contributor

@Baltoli Baltoli commented Apr 20, 2026

Summary

Mechanical pass that adds const (east-const) to function parameter definitions across the codebase, covering both value parameters (int xint const x) and the pointer itself for pointer parameters (T *pT *const p, leaving any pointee qualifier alone).

A small number of declarations are also touched (~19, all in headers) — in each case a leftover top-level const on a by-value parameter is removed so the declaration matches the codebase's existing no-top-level-qualifier convention for declarations. The language ignores top-level qualifiers on parameters in declarations, so there's no behavioral or ABI effect; the normalization came out of the AST tooling re-emitting these headers.

References (T&, T&&), typedefs that hide pointers (e.g. va_list), parameters that are mutated in the body or member-initializer list, and move-only parameters consumed via std::move(name) are deliberately left non-const.

Scope

  • category/, cmd/, test/
  • 198 files, +1,231 / -1,084

Tooling

A libclang-based Python tool walked every TU in compile_commands.json, collected the candidate edits from the AST, deduplicated across TUs, and emitted a single JSON patch set that an applier script then rewrote on disk. Compile errors from each subsystem surfaced the cases where a parameter was actually mutated (read-only assignment, discarded qualifier, reference-to-non-const binding, std::move silently falling back to copy); those were reverted by hand so the build stays green.

Notable exceptions

  • category/async/sender_errc.hpp is left unchanged: adding const to make_status_code(sender_errc) causes boost::outcome's quick_status_code_from_enum machinery to recurse into itself as a constexpr expansion.
  • A handful of params that are legitimately mutated (e.g. event_ring_init_file's error_name, stack_top in call_runtime.hpp, several bytes/prefix_index counters in the MPT code, int argc in test mains) stay non-const.

Test plan

  • cmake --build build --parallel — clean
  • ctest --test-dir build --output-on-failure --timeout 500 — 3520 / 3520 pass
  • scripts/apply-clang-format.sh applied

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings April 20, 2026 16:00
@Baltoli Baltoli requested a review from andreaslyn as a code owner April 20, 2026 16:00
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR performs a large mechanical const-correctness pass across the C/C++ codebase, applying east-const to function parameter definitions (and, for pointer parameters, making the pointer itself const where applicable) to better communicate immutability and prevent accidental reassignment.

Changes:

  • Adds east-const qualifiers to many by-value parameters in function definitions (e.g., T xT const x).
  • Adds top-level const to pointer parameters in definitions where the pointer itself is not reassigned (e.g., T* pT* const p).
  • Reformats a number of signatures for readability/clang-format consistency (line wrapping/alignment).

Reviewed changes

Copilot reviewed 198 out of 198 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
category/mpt/nibbles_view.hpp Mechanical parameter const changes; noted that a declaration was also modified.
category/execution/monad/staking/util/val_execution.hpp Mechanical parameter const changes; noted that a constructor declaration was also modified.
category/vm/runtime/types.hpp Applies pointer top-level const to clarify non-reassignment of pointer parameters.
category/vm/interpreter/push.hpp Applies pointer top-level const in interpreter helpers for stack/code pointers.
category/core/event/event_ring.c Applies top-level const on parameters in C APIs for clearer intent.
category/async/io.hpp Applies top-level const on pointer/value parameters in async I/O submission helpers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread category/mpt/nibbles_view.hpp
Comment thread category/execution/monad/staking/util/val_execution.hpp
@Baltoli Baltoli force-pushed the bruce/const-params-definitions branch from 585a3fb to f231cdb Compare April 20, 2026 19:09
@Baltoli Baltoli removed the request for review from andreaslyn April 20, 2026 19:29
@Baltoli
Copy link
Copy Markdown
Contributor Author

Baltoli commented Apr 20, 2026

@claude review

@github-actions

This comment was marked as outdated.

@Baltoli
Copy link
Copy Markdown
Contributor Author

Baltoli commented Apr 21, 2026

@claude re-review

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 21, 2026

Claude finished @Baltoli's task in 4m 58s —— View job


Re-review of PR #2216

Summary: This is a well-scoped mechanical const-correctness pass. The PR description is accurate and thorough, tooling output looks sound, and spot-checks confirm the claimed exceptions are correctly handled.


On the Copilot review's declaration-scope concern

Copilot flagged nibbles_view.hpp:123 (Nibbles::substr) and val_execution.hpp:90 (ValExecution ctor) as declaration-only edits inconsistent with the PR description. This concern is already addressed: the PR description explicitly calls out that ~19 declarations are touched, with justification ("a leftover top-level const on a by-value parameter is removed so the declaration matches the codebase's existing no-top-level-qualifier convention for declarations… no behavioral or ABI effect"). Both flagged changes fit that pattern exactly. I counted ~20 declaration-level normalizations across the diff (in create_contract_address.hpp, db/util.hpp, evmc_host.hpp, state_tracer.hpp, reserve_balance.hpp, staking_contract.hpp, input_generation.hpp, delegator.hpp, val_execution.hpp, compute.hpp, nibbles_view.hpp, etc.), which matches the stated scope.

Spot checks

  • category/async/sender_errc.hpp — Exception is real and well-documented with a NOLINTNEXTLINE(misc-auto-const-correctness) and a clear comment explaining the boost::outcome constexpr recursion. Good.
  • category/core/event/event_ring.c (error_name stays non-const) — Verified: error_name = namebuf; reassignment at lines 120 and 227. Correctly left alone.
  • category/core/path_util.c (pathbuf/pathbuf_size stay non-const in monad_path_open_subdir) — Verified: both are passed by address to monad_path_append(&pathbuf, dir_name, &pathbuf_size) and get mutated through there.
  • category/mpt/trie.cpp (prefix_index stays non-const) — Verified: ++prefix_index at line 761 in add_to_requests.
  • category/vm/interpreter/call_runtime.hpp (stack_top stays non-const) — This file isn't even in the diff; confirmed it's taken by *&stack_top and mutated (stack_top -= stack_adjustment), so correctly excluded.
  • test/unit/common/src/test/main.cppargc stays non-const (passed by address to InitGoogleTest(&argc, argv)), argv becomes char **const. Correct.

Correctness

No functional concerns. Because top-level const on value/pointer parameters is:

  • Ignored in declarations (no ABI/overload effect), and
  • Local to the function body in definitions (a compile check on the param, not part of the function type),

the change is behaviorally inert. Any parameters the compiler would flag as conflict (assignment, address-of to non-const, non-const ref binding, std::move falling back to copy) were correctly excluded, and CI reports 3520/3520 tests passing.

Minor observations (non-blocking)

  1. category/mpt/compute.hpp:61encode_two_pieces declaration has all top-level qualifiers stripped (*const dest, NibblesView const, byte_string_view const, bool const), while the definition in compute.cpp:34 keeps them. This is consistent with the stated convention, just worth noting that the asymmetry is deliberate.
  2. category/execution/ethereum/transaction_gas.hpp:56 — This is an inline-in-header definition (not a declaration), so adding const to max_fee_per_gas is correctly a definition-side change even though it looks like a declaration edit.
  3. Pointer top-level const (T *const p) — Applied uniformly, which is the right call for mechanical consistency. Slight readability cost in trivial forwarders, but the signal value (pointer-not-reassigned inside this function) is worth it.

Verdict

LGTM. The PR does exactly what the description says, the exceptions are justified, and the build is green. No changes requested. The Copilot bot's objections are a misread of the PR description.

  • Gather PR context and diff
  • Sample changes across subsystems (async, core, execution, mpt, vm)
  • Spot-check the noted exceptions
  • Verify declaration-change claim matches reality
  • Check for any obvious correctness issues
  • Post review
    · bruce/const-params-definitions

@Baltoli Baltoli requested a review from jhunsaker April 21, 2026 08:32
@Baltoli Baltoli force-pushed the bruce/const-params-definitions branch 2 times, most recently from 591bd7f to c38ef60 Compare April 21, 2026 16:14
For every C/C++ function parameter definition (not declaration), add
`const` where applicable:
- value parameters get top-level `const` in east-const style
  (`int const x`)
- pointer parameters get `const` on the pointer itself
  (`T *const p`, leaving the pointee qualifier untouched)

Unnamed parameters are left unchanged — top-level `const` on a parameter
with no name has nothing to constrain. This includes parameters whose
name has been replaced by a `/*comment*/` marker: syntactically they are
still unnamed, so they get no `const`.

References (`T &`, `T &&`), typedefs that hide pointers (e.g.,
`va_list`), and parameters that are mutated in the body or member
initializer list are left alone. Move-only parameters consumed via
`std::move(name)` are also left non-const so the move isn't silently
downgraded to a copy.

One file, `category/async/sender_errc.hpp`, is intentionally left
unchanged: adding `const` to the `make_status_code(sender_errc)`
overload perturbs the boost::outcome `quick_status_code_from_enum`
machinery into a self-recursive constexpr expansion.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Baltoli Baltoli force-pushed the bruce/const-params-definitions branch from c38ef60 to 4a7c1d5 Compare April 21, 2026 16:35
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