Skip to content

Equate a parameter with its argument only when the body never assigns it - #335

Open
coord-e wants to merge 2 commits into
mainfrom
claude/gifted-bohr-ls42w4
Open

coord-e wants to merge 2 commits into
mainfrom
claude/gifted-bohr-ls42w4

Conversation

@coord-e

@coord-e coord-e commented Oct 12, 2026

Copy link
Copy Markdown
Owner

Fixes #334.

bind_locals assumes that a non-flow parameter local still holds the function's argument, and adds entry == current at every block that has its own precondition. A parameter that is moved out and then re-initialized (let t = s; s = S { .. };) stays non-flow, because reassign_local_mutabilities marks a local mutable only when it is assigned while initialized. From then on it holds a different value. At the next join point the equation contradicts the incoming state, so the function's postcondition becomes vacuous. Callers then verify panicking programs, even assert!(false), as safe.

This change skips the equation when the parameter local is the destination of any assignment in the body. It uses PlaceContext::is_place_assignment(), as drop_point::def_local does. A parameter that is never assigned always holds its argument, so the invariant-header case the workaround exists for keeps working.

Tests

  • New pair tests/ui/{pass,fail}/fn_param_reinit_after_move.rs. Before this change the fail program was reported as safe.
  • cargo test: all 396 UI tests pass, including the loop_invariant_* ones and the PCSat-backed ones. cargo fmt --check and cargo clippy -D warnings are clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LhtkSy2XUScvjq9LXzmTQS


Generated by Claude Code

`bind_locals` assumes that a non-flow parameter local still holds the
function's argument and equates the two at every block with its own
precondition. A parameter that is moved out and then re-initialized
stays non-flow, because `reassign_local_mutabilities` marks a local
mutable only when it is assigned while initialized, yet it holds a
different value from then on. The equation then contradicts the
incoming state at the next join point, so the function's postcondition
becomes vacuous and callers verify panicking programs as safe.

Skip the equation when the parameter local is the destination of any
assignment in the body.

Fixes #334

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LhtkSy2XUScvjq9LXzmTQS
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T02:22:48.391629Z b896c63 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: af427bdb11

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/analyze/basic_block.rs Outdated
Comment thread src/analyze/basic_block.rs
Skipping the entry-argument equation whenever the body assigns the
parameter anywhere also dropped it at blocks that no assignment can
reach, such as a loop header before the parameter is moved out and
re-initialized, so a loop invariant relating the parameter to its
argument could no longer be established. Compute, once per body, which
parameters may have been assigned on entry to each block by forward
reachability from their assignment sites, and skip the equation only
there. This also avoids rescanning the whole body for every parameter
of every block.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LhtkSy2XUScvjq9LXzmTQS

Copilot AI 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.

🟢 Approval recommended

The dataflow guard addresses the unsound assumption while paired tests cover both the regression and invariant preservation.

0 open findings

What changed in this PR

Fixes unsound parameter-to-argument equality assumptions after parameter reassignment.

Changes:

  • Tracks parameter assignments per basic-block entry.
  • Suppresses invalid argument equality assumptions after reassignment.
  • Adds regression coverage for joins and loop invariants.
File Description
src/​analyze/​basic_block.rs Adds assignment tracking and guards equality assumptions.
src/​analyze/​local_def.rs Supplies assignment state to block analysis.
tests/​ui/​pass/​fn_param_reinit_after_move.rs Verifies correct reinitialization result.
tests/​ui/​fail/​fn_param_reinit_after_move.rs Rejects the previously vacuous assertion.
tests/​ui/​pass/​fn_param_reinit_after_loop.rs Preserves valid loop-invariant reasoning.
tests/​ui/​fail/​fn_param_reinit_after_loop.rs Rejects an invalid postcondition after a loop.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b896c632b2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

location: mir::Location,
) {
let is_param = (1..=self.arg_count).contains(&local.index());
if is_param && ctxt.is_place_assignment() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Track assignments through projected parameter places

When a parameter is assigned through a projection, such as let t = s.field; s.field = replacement;, MIR's visitor changes the base local's context to MutatingUse::Projection, for which is_place_assignment() returns false. If the non-Copy field was moved out first, the parameter can remain classified as non-flow, so this assignment is absent from assigned_params; at a later join block bind_locals therefore reinstates the false entry-argument equality, makes the path inconsistent, and can verify a caller containing a failing assertion. Record the base local from projected assignment destinations as well as direct-local assignments.

Useful? React with 👍 / 👎.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants