Skip to content

fix(hy-check): close place-call, paren-callee, and A3/const bypasses (fixes #500) - #511

Closed
gelismarvel wants to merge 1 commit into
limitlessprojects:mainfrom
gelismarvel:fix/issue-500-real-patch
Closed

gelismarvel wants to merge 1 commit into
limitlessprojects:mainfrom
gelismarvel:fix/issue-500-real-patch

Conversation

@gelismarvel

Copy link
Copy Markdown
Contributor

Summary

Fixes #500

Closes five soundness gaps in hy-check where calls and closures inside Stmt::Assign target places, parenthesized callees, A3 closure/method/inline-FnLit callees, and shadowed builtins (delete, copy, len, cap, print, println, make, new, append, close) bypassed HYB-E3003, HYB-E3006, HYB-E3102, and HYB-E2005:

  1. walk::own_calls, walk::own_fnlits, and process_assign target-place traversal (walk.rs, loans.rs, closures.rs, builtins.rs):
    • Extend walk::own_calls to recurse into Stmt::Assign target places (PlaceKind::Index, PlaceKind::Field, PlaceKind::AddrOf) via expr_calls_in_place so calls nested inside LHS index expressions (e.g. arr[copy(dst, src)] = 1, arr[delete_helper(m)] = 1) are visited by process_call, check_builtin_call, A3 interprocedural mutation scans, and T22 const-mutation scans.
    • Add walk::own_fnlits / walk::expr_fnlits and invoke check_closure_captures on PlaceKind::Index index expressions inside process_assign so inline closures inside LHS index expressions are checked for capture/sendability/const-write rules.
  2. Parenthesized callee unwrapping (loans.rs, builtins.rs, closures.rs):
    • Use unwrap_parens(cr.callee) across resolve_call, call_mutates_param, collect_mutation_roots, call_mutates_const_param, check_builtin_call, and expr_contains_spawn_or_send so (copy)(dst, src), (delete)(m, k), and (mutator)(m) are not misclassified as Resolved::None or non-builtin calls.
  3. A3 interprocedural & closure/method/inline-FnLit callee soundness (loans.rs, model.rs):
    • Track per-parameter mutation indices for local closures in FnState::closure_param_mutates (with scope stack closure_param_scopes in FnState::scope_push / scope_pop) and check them via check_a3_closure_param_conflict.
    • Check method calls (Resolved::Method -> check_a3_method_conflict) and inline FnLit / computed expression callees (Resolved::None -> check_a3_inline_or_expr_call) against live A3 map-slot loans, using LexicalStructMap to disambiguate receiver struct types while failing closed when a receiver or callee cannot be statically narrowed.
  4. Shadowed builtin & package-name disambiguation (builtins.rs, loans.rs):
    • Guard builtin checks (delete, copy, A3_PURE_FNS, A3_PURE_PKGS, and check_builtin_call arity/type checks) with self.lookup_binding(st, name).is_none() and lexical shadow tracking so local variables or parameters named delete, copy, len, fmt, etc. neither trigger false-positive builtin diagnostics nor grant A3_PURE_FNS / A3_PURE_PKGS exemptions to mutating closures.
  5. T22 const deep-immutability (HYB-E3006) across Match, Select, and non-Ident callees (loans.rs):
    • Extend stmt_mutates_const_param and call_mutates_const_param to traverse Stmt::Match and Stmt::Select arms, method calls, inline FnLit calls, and unknown/closure callees (failing closed when a const-aliased reference is passed).

Verification

  • Added 14 regression and positive-control tests in compiler/crates/hy-check/tests/place_call_and_a3_callee_soundness.rs.
  • cargo test --manifest-path compiler/Cargo.toml -p hy-check passes completely (137/137 unit tests + 14/14 place_call_and_a3_callee_soundness + all integration test suites, 0 warnings).

@gelismarvel

Copy link
Copy Markdown
Contributor Author

Closing this PR. On review, its changes substantially duplicate the earlier PR #501 by @o2splatform-cmyk, so it should not have been submitted as separate work. Withdrawing it (and any bounty claim attached to it) in favor of the original. Apologies for the noise.

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

Labels

None yet

Projects

None yet

1 participant