Skip to content

fix: add SAFETY comments to all unsafe blocks in vm/mod.rs#1

Merged
danieljohnmorris merged 1 commit into
mainfrom
fix/safety-comments
Feb 26, 2026
Merged

fix: add SAFETY comments to all unsafe blocks in vm/mod.rs#1
danieljohnmorris merged 1 commit into
mainfrom
fix/safety-comments

Conversation

@danieljohnmorris
Copy link
Copy Markdown
Collaborator

Summary

  • Adds // SAFETY: comments to all 35+ unsafe sites in vm/mod.rs
  • Adds /// # Safety doc section to NanVal::as_heap_ref explaining caller requirements
  • Documents invariants for: heap pointer dereferences, manual RC management, get_unchecked bounds, unwrap_unchecked frame liveness, and raw stack writes

Motivation

The file had ~35 unsafe blocks with only 1 SAFETY comment. This makes it impossible to audit soundness — a reviewer cannot tell whether an unsafe operation is intentional or accidental.

Test plan

  • cargo build passes with no new warnings
  • cargo test passes
  • No behavioral change — comments only

Documents the invariants required at every unsafe site:
- as_heap_ref: lifetime and RC liveness requirements
- clone_rc/drop_rc: Rc::into_raw pairing contract
- get_unchecked calls: bounds guaranteed by compiler-emitted indices
- unwrap_unchecked calls: frames non-empty while execute() runs
- raw stack pointer writes: register slots pre-allocated by setup_call
@danieljohnmorris danieljohnmorris merged commit bf75631 into main Feb 26, 2026
@danieljohnmorris danieljohnmorris deleted the fix/safety-comments branch February 26, 2026 19:09
danieljohnmorris pushed a commit that referenced this pull request Mar 1, 2026
Phase I — what AI agents actually need daily:
- I1: JSON parsing (jp, jparse, jdump — the #1 gap)
- I2: Shell/command execution (sh builtin + backtick syntax option)
- I3: Environment variables (env/env!)
- I4: String interpolation (fmt with %s placeholders)
- I5: Logging/debug output (log, dbg)
- I6: Time and timestamps (now, sleep)
- I7: Encoding (urlencode, b64enc/dec, htmlesc)
- I8: Regex (match, matchall, sub, suball)
- I9: Hashing (hash, hmac for API auth)
- I10: Standard output (print, input)
- I11: Sleep/delay/retry helpers

Non-REST API protocols (G1b-G1d):
- G1b: GraphQL (gql builtin or post+jp pattern)
- G1c: gRPC (tool server approach — too complex for builtin)
- G1d: Server-Sent Events / SSE (streaming LLM responses)

https://claude.ai/code/session_01RY1CvsjoNPCwPt3eWQP1WT
danieljohnmorris added a commit that referenced this pull request May 17, 2026
Multi-fn file dispatch had a silent mis-routing edge: when the
leading positional was not ident-shaped (a path like top200.csv, a
digit-prefixed string, a sigil) it fell through to 'first declared
function' even when the file defined main. ilo main_v5.ilo top200.csv
ran the first-declared fn (e.g. hav) with top200.csv as arg #1,
producing a confusing type/arity error far from the user's intent.

When main is defined and the user didn't pick a different fn name,
main is the strong intent signal. Route the positionals to main with
type-aware arg parsing (parse_cli_args_typed) so they match main's
declared signature.

Companion to the helper-extension commit. Files with no main keep
the legacy first-fn passthrough so unwrap_*_inline and the existing
multi-fn-data-arg tests (numeric / quoted / bracketed leading args
on a no-main file) continue to work unchanged.

gis-analyst rerun6 and devops-sre rerun6 surfaced this independently
- the persona workloads differ but both wrote main + helpers with a
non-ident positional, hit the same dispatch bug.
danieljohnmorris added a commit that referenced this pull request May 17, 2026
Multi-fn file dispatch had a silent mis-routing edge: when the
leading positional was not ident-shaped (a path like top200.csv, a
digit-prefixed string, a sigil) it fell through to 'first declared
function' even when the file defined main. ilo main_v5.ilo top200.csv
ran the first-declared fn (e.g. hav) with top200.csv as arg #1,
producing a confusing type/arity error far from the user's intent.

When main is defined and the user didn't pick a different fn name,
main is the strong intent signal. Route the positionals to main with
type-aware arg parsing (parse_cli_args_typed) so they match main's
declared signature.

Companion to the helper-extension commit. Files with no main keep
the legacy first-fn passthrough so unwrap_*_inline and the existing
multi-fn-data-arg tests (numeric / quoted / bracketed leading args
on a no-main file) continue to work unchanged.

gis-analyst rerun6 and devops-sre rerun6 surfaced this independently
- the persona workloads differ but both wrote main + helpers with a
non-ident positional, hit the same dispatch bug.
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.

1 participant