Skip to content

The unsafe-code report walks a checked term by its shape - #990

Draft
nicolas-abril wants to merge 1 commit into
mainfrom
term-refs-typed
Draft

nicolas-abril wants to merge 1 commit into
mainfrom
term-refs-typed

Conversation

@nicolas-abril

Copy link
Copy Markdown
Collaborator

The unsafe-code report walks a checked term by its shape

cli_report decides which of a file's defs rely on unsafe or foreign code by walking the elaborated term of every def reachable from the file, Base's included. The walk was generic: Object.entries on every object, into every field but the span. That allocates a pair array per field per node, and it descends into the checker's type annotations, which Check and Infer store as the value of a Var on every checked subterm: about half of the nodes it visits, many of them shared and visited again.

term_refs now switches on the node's tag and recurses into its known children. The annotations are still walked, so the ref set of every def and every verdict is unchanged: identical on all 16 demos and on the six tests that expect a verdict (io/far_types, io/marshal_imported_nullary_type, import/unsafe_used, import/unsafe_lib, check/unsafe_field, check/unsafe_relies), which pass locally.

Measured with --check-only, wall time and peak memory:

before after
demos/app_slash_boss_3d 0.48 s, 540 MB 0.32 s, 440 MB
2000 defs, each a wide U32 literal 0.28 s, 365 MB 0.18 s, 240 MB
the walk alone, boss demo 192 ms 48 ms

The walk was 40% of the boss demo's check time. In the other demos it is under 20 ms, so this is a large-program cost. Skipping the annotations would halve the walk again, but a dependency carried only by a constructor's field type would then be missed, so they stay.

bun gates/repo.ts is PASS: 46 / 46. tsc over bend2/pack reports nothing in main.ts. The cluster gates were not run from here.

Found while reviewing #936: this walk was about half of that PR's gain, and it is independent of how a literal is represented.

🤖 Generated with Claude Code

cli_report finds the defs that rely on unsafe or foreign code by walking
the elaborated term of every def reachable from the file. term_refs did
it with Object.entries on every object, which allocates a pair array per
field per node. It now switches on the node's tag and recurses into the
known children. The type annotations a checked subterm carries are still
walked, so every ref set and every verdict is unchanged.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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