Repository navigation
check: implement HYB-E2001 (reject non-call defer operand); hoist ? in deferred call args - #288
Conversation
3569a99 to
a53087a
Compare
|
Wave-2 triage: queued — port assessment. The E2001 half is same-fix with landed #191, but the '?-hoist in deferred call args' half may be new — will assess that part on a fresh base and land only what main lacks. |
|
Wave-2 follow-up (validation pass, local main c53978b): NEEDS-INTEGRATION — E2001 half subsumed by landed #191; two of the remaining halves are real and unique. Subsumption evidence: main already rejects |
…peel paren operands v2 per the wave-2 integration bar: E2001 has ONE owner (builtins.rs check_stmt_defer_call, now pub(crate)) — the second emitter is gone, so the merged-tree double diagnostic cannot occur; the Try-operand policy is reconciled to landed code (Try-wrapping a call stays legal; the registry and AST edits are dropped); and the three unique halves are kept on current main: closure-body wiring, deferred-call argument ? hoist, and paren-peeled emission. Part of limitlessprojects#288; closes the R4 check->emit gap of limitlessprojects#155.
|
v2 pushed addressing the integration bar — rebased on v2 — the wave-2 integration bar, addressedRebased on current main @ 1. E2001 dedupe — one owner. The headline E2001 emission in this PR's 2. Try-operand policy reconciled to landed code. The v1 headline reject of 3. The three unique halves — kept, now on current main:
Scope now: Verification: Fixes #155 (R4 + the arg- AI-assisted: yes — operator applied the integration bar hunk-by-hunk and re-ran the full suite. |
a53087a to
d4a29ab
Compare
|
Status update while this awaits the landing call — the defer/ #469 (@exantiv, /claim #155, head What remains unique to this branch — verified against #469's head, none of it is covered there:
The collision to rule on: this branch's pins |
|
Alignment update, now that #469 ( What remains here is two hardening items, both now raised on #469: the emit-side Proposal, to keep this branch useful rather than redundant: if #469 lands first, we rebase onto it and reduce this PR to exactly those two hardening items — a small follow-up instead of an overlapping one. If #469 needs rework, this branch stands as the independent implementation of the same fixes. Ruling welcome either way — happy to be subsumed if that is the cleaner merge. |
# Conflicts: # compiler/crates/hy-check/src/closures.rs
5317e70
into
limitlessprojects:main
Integrate limitlessprojects#288 (HYB-E2001 defer-operand, single owner in builtins.rs): take main's defer emission in hy-emit/stmt.rs; ignore the new SelectArmKind::Send is_move field in try_check.rs; remove try_check's own defer-E2001 arm and the duplicate check_stmt_defer_call in the closure walk, since defer f()? is now the documented legal shape; drop the three limitlessprojects#155 tests that asserted the superseded behaviour (defer_operand.rs covers it).
…projects#449): unify lexical nested-closure capture/header scope collection in hy-check Author: exantiv (head 0a8eeb8, branch fix/issue-445-449-real-patch). What it fixes: closures inside else-if chain conditions / if-init headers / match guards / loop headers inside a closure body never reached the nested boundary pass (collect_stmt_direct_fnlits ran only over direct block stmts and the If arm explicitly skipped Stmt::If else-links), so a task spawn sharing the outer closure's map through an else-if condition closure passed hyb check with 0 diagnostics and raced at runtime (issue limitlessprojects#445, GUARANTEES row 5 / O4.10). Direct FnLits are now collected at their exact lexical evaluation point (if/else-if conditions while the init scope is live, match guards with the arm pattern bound, for/range/while headers, local/assign RHS before LHS defines overwrite the env); NestedClosure snapshots gain an overwritten set so a later same-scope shadow no longer leaks post-shadow moves into the lexical capture (deepens landed limitlessprojects#483/limitlessprojects#449); self-alias entries (name->name) are no longer inserted on may-share rebinds. The PR's model.rs -11 (dead duplicate FnLit arm in collect_ref_roots) was already removed on main during the limitlessprojects#288 landing — merge keeps main's side; no landed content discarded. Residual limitlessprojects#449 sub-block move propagation is already covered by main (limitlessprojects#483): repros r449_shadow/r449_subblock reject identically on both trees. Verification (merged tree on origin/main 1e1a665): cargo test --workspace 971/0 (+13, includes the PR's 11-test nested_closure_and_a3_scope_445_449 suite), corpus_harness 61/61 tripwire not fired, differential FULL 17+44. Repros: r445_elseif.hy -> main OK (0 diagnostics, live data race per issue limitlessprojects#445's go-race demo) vs merged tree HYB-E3001; positive control (closures in if/else-if conds, loop headers, match-free reads) OK on both — no false positives. Credit: exantiv. Triage: task 20-d verified.
…ion scope (fixes limitlessprojects#155) - hy-check: validate every Expr::Try site against E4/T20/E3b: * Reject '?' on option[T] (HYB-E2003, T20) * Reject '?' on non-error returning calls (HYB-E2003, E4) * Reject '?' in functions/closures without error return (HYB-E2004, E3b) * Defer operand checking preserved per landed limitlessprojects#288 policy - hy-diag: register and sort HYB-E2003 and HYB-E2004 in data/diagnostics.json - hy-emit: isolate closure error returns so closure '?' does not bind to main exit contract - tests: add 13 unit tests in try_legality.rs covering valid & invalid usages
What
SPEC-LANGUAGE.md§7 P1:defer f.close()is "the only legal defer operandshape in MVP", and "
deferof a non-call expression is a compile error(
HYB-E2001)". The registry definesHYB-E2001, but no pass enforced it —the parser accepted any expression after
deferand the checker never looked.Why it matters (check→emit gap)
defer cleanup()?has aTryoperand, not aCall. Today:The front-end calls the program clean; the emitter refuses it late with a
message that names neither
defernor the real rule. Reported as R4 in thetry-legality report (#155).
A second instance of the same gap:
defer f(g?)— the operand is a call, buta
?in its arguments hoisted nowhere, so the emitter refused that too, eventhough P1 evaluates a deferred call's arguments at defer time.
Fix
hy-check— implementHYB-E2001in one shared helper(
check_defer_operand). Adeferwhose operand (parens unwrapped) is not aCallis rejected at check time, at the operand's span, with a note showingthe bind-then-defer rewrite.
defer f.close()anddefer (f.close())pass.hy-check/ closures — the helper is wired into both walks. Closurebodies sit outside Tier-0's flat walk (walk.rs skips
FnLitbodies; the A5perimeter), so the per-function Pass B loop alone leaves the same gap one
scope in:
defer cleanup()?inside a closure still passed the checker andfailed late in the emitter. The closure pass (
closures.rs) now enforces ittoo, so the message is identical wherever the statement appears.
hy-emit— hoist?inside a deferred call's arguments (gated on aCalloperand, which the checker now guarantees), sodefer f(g?)lowers toGo's "arguments evaluated at defer time".
user-visible once E2001 fires: the HYB-E2001 fix-it suggested
defer f.close()?(the very shape the rule rejects), and theDeferAST doccomment showed the same illegal form. Both now read
defer f.close().Tests
hy-check:defer cleanup()?anddefer x + 1→HYB-E2001;defer (zap())anddefer zap()→ accept; plus a closure-body case(
defer cleanup()?insidefn() { … }→HYB-E2001;defer zap()→ accept).hy-emit:defer sink(probe()?)→ the argument?hoists before thedefer; the existingexample02_try_desugar_and_deferstill passes.Verification
cargo test --workspace(rustc 1.99.0, x86_64-pc-windows-gnu): hy-check106/106, hy-emit 111/111, every other suite green. The only failures are the
hyb generatetests, and only because this sandbox has no Go toolchain(
gofmt: program not found) — unrelated to this change.Because the rule must hold wherever a
defercan appear, I also swept everysyntactic position and confirmed
defer cleanup()?reportsHYB-E2001in allof them: function body, nested
if,else,forbody,range-for,matcharm,
selectarm,selectarm block,managedblock, closure body, closureinside a closure, closure as a call argument, closure inside an
if, andmanagedinside a closure.Refs #155.