Skip to content

fix(hy-check): track call may_share and post-closure const rebinds in scan_block_const_writes (fixes #2059) - #2138

Open
jpereyra243-byte wants to merge 1 commit into
limitlessprojects:mainfrom
jpereyra243-byte:fix/scan-block-const-writes-call-may-share-2059
Open

jpereyra243-byte wants to merge 1 commit into
limitlessprojects:mainfrom
jpereyra243-byte:fix/scan-block-const-writes-call-may-share-2059

Conversation

@jpereyra243-byte

Copy link
Copy Markdown
Contributor

Summary

Fixes two deep const immutability (T22 / HYB-E3006) soundness gaps in Checker::scan_block_const_writes (compiler/crates/hy-check/src/loans.rs) that allowed closures to mutate package-level const maps and slices across concurrent task boundaries with 0 diagnostics, producing immediate concurrent read/write data races (WARNING: DATA RACE) and runtime crashes under go run -race:

  1. Call-mediated may_share tracking: In scan_block_const_writes, record_copy_may_share and record_callee_param_stores are now invoked unconditionally across block walk iterations (even when check_writes == false), ensuring that containers populated with const references via helper calls (store_into) or copy() propagate their may_share edges to closure bodies.
  2. Post-closure rebinds in block scopes: Closure bodies are now evaluated with accumulated post-closure aliases and may_share edges merged via merge_post_closure_const_state, while tracking lexical overwrite depths to avoid leaking shadowed variables.

Fixes #2059.

Changes

  • Updated compiler/crates/hy-check/src/loans.rs:
    • Run record_copy_may_share and record_callee_param_stores unconditionally for all calls.
    • Defer closure body scanning until block-scoped statements populate trailing rebinds, then merge post-closure state.
    • Added unit test closure_const_writes_via_block_scoped_callee_store_copy_and_post_rebind verifying rejection with HYB-E3006 across callee stores, copy(), and post-rebind patterns, as well as zero diagnostics on clean non-const stores.

Settlement / Payout Wallet (Polygon / USDC): 0xC175c34c256598C7e1AD5B15503cFcED7Ed67e10

@github-actions github-actions Bot added the bot:stale-base Shepherd: behind main beyond threshold label Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:stale-base Shepherd: behind main beyond threshold

Projects

None yet

1 participant