Skip to content

Clean up dead code, stale docs, and local duplication - #9

Draft
t04dJ14n9 wants to merge 5 commits into
mainfrom
cursor/gig-code-cleanup-2d21
Draft

t04dJ14n9 wants to merge 5 commits into
mainfrom
cursor/gig-code-cleanup-2d21

Conversation

@t04dJ14n9

@t04dJ14n9 t04dJ14n9 commented Aug 13, 2026 •

Copy link
Copy Markdown
Owner

Summary

A code-quality evaluation of gig plus safe, verified cleanups, and an evaluation of the interpreter's fast-path ("block plan") design. The codebase already passes a strict golangci-lint config (default: all) with 0 issues, go vet clean, gosec clean. All changes here are behavior-preserving (full -race suite green) and, for the hot-path change, benchmark-neutral.

Commits

  1. Remove dead code masked by linter exclusions (unused is disabled for internal/interp/ and test files): reflectFromCellValue, deferRecord.pos, unused recvSlot, orphaned test helpers; fixed a mislabeled doc comment.
  2. Refresh stale package comments and drop dead scaffolding: removed abandoned bytecode-VM / "Phase" language, a wrong bytecode.CompiledProgram reference, a comment claiming debug_dump.go avoids importing io (it uses it); removed dead program.fset and _ = os.Stderr.
  3. Extract hostPkgPath to dedupe package-path resolution.
  4. Extract readArgs for SSA-argument materialization repeated 3× in runCall and once in runDefer.
  5. Simplify fast-block dispatch: removed the fastOp/fastOpKind single-variant wrapper (use []fastInstr), dropped the always-nil []value.Value from runFastBlock/runFastInstr, and removed dead contReturn branches in the fast paths.

Fast-path ("block plan") evaluation

The block plan has two tiers: a per-instruction typed fast path (predecoded int/bool BinOp/If/Jump + fused int-slice IndexAddr) and a whole-block tight loop (runFastBlock) for blocks that are entirely fast and end in If/Jump. Both were suspected of being confusing/redundant. Benchmarks (int-heavy workloads, this VM) settle it:

Benchmark Full fast path Per-instruction only (no whole-block) No typed fast path
ArithmeticSum ~48.4µs ~61.4µs (+27%) ~274µs (~5.7×)
FibIterative ~3.48µs ~4.28µs (+23%) ~16.8µs (~4.8×)
NestedLoops ~56.2µs ~72.3µs (+29%) ~313µs (~5.6×)
BubbleSort ~188µs ~207µs (+11%) ~1070µs (~5.7×)
Sieve ~202µs ~223µs (+10%) ~967µs (~4.8×)
GCD ~77.8µs ~83.6µs (+7%) ~214µs (~2.75×)
SliceSum ~112µs ~126µs (+12%) ~561µs (~5.0×)

Conclusion: do not remove it. The typed fast path is worth ~3–6× on exactly the workloads that are already gig's weak spot, and the whole-block tier adds a further ~10–29%. The right response to the confusion is unification/cleanup, not deletion. Commit 5 removes the accidental complexity at zero perf cost.

Recommended follow-up (separate, MED-risk PR): unify the three parallel per-instruction arrays (fastInstrs, fastIndexAddrs, fusedIndexAddrConsumers) plus the raw SSA loop into a single decoded op stream per block, where each op is either a typed fast op or a "generic SSA" fallback, executed by one loop (keeping an "all-fast" tight-loop variant to preserve the whole-block speedup). Also fold/remove the test-only frameLayout.fusedIndexAddr map (duplicates the per-block consumer slices). This is the true "unify normal + fast path" and deserves its own benchmarked PR.

Validation

go test -race ./... pass · golangci-lint 0 issues · gosec 0 issues · go vet clean · fast-path change benchmarked before/after with no change beyond noise.

Open in Web Open in Cursor 

cursoragent and others added 4 commits August 13, 2026 15:21
The .golangci.yml disables the 'unused' linter for internal/interp and for
all test files, which hid several genuinely-unreferenced private symbols.
Removed (verified unused via staticcheck U1000 and grep):

- internal/interp: (*program).reflectFromCellValue, deferRecord.pos field,
  and the unused local recvSlot type in runSelect.
- tests: orphaned helpers runDiagProgram, newBoundaryRejectionRegistry,
  hostAcceptAny, and the embeddedHostImportPath const.

Also fixed a stale doc comment (reflectValue was documented as
composeReflectValue). No behavior change; full -race suite still passes.

Co-authored-by: t04dJ14n9 <t04dJ14n9@users.noreply.github.com>
Several package/function comments described the abandoned bytecode-VM
design and migration 'Phase' milestones for features that are fully
implemented (interpreter dispatch, defer/panic, goroutines, host bridge),
and one comment claimed debug_dump.go avoids importing io while it clearly
uses it. Rewrote them to match the current v2 SSA interpreter.

Also removed dead code:
- program.fset (written at construction, never read).
- debug_dump.go: dead '_ = os.Stderr' and its now-unused os import.

No behavior change.

Co-authored-by: t04dJ14n9 <t04dJ14n9@users.noreply.github.com>
callHostFunc and callHostFuncDirect contained identical blocks resolving
a function's package path from its SSA package with a type-checker-object
fallback. Extracted a small pure hostPkgPath(fn) helper.

Co-authored-by: t04dJ14n9 <t04dJ14n9@users.noreply.github.com>
runCall (invoke, direct-function, and indirect-closure paths) and
runDefer each repeated the same make+readValue loop to turn SSA
arguments into interpreter values. Factored into a single
(*program).readArgs helper. No behavior change.

Co-authored-by: t04dJ14n9 <t04dJ14n9@users.noreply.github.com>
@cursor cursor Bot changed the title refactor: remove dead code masked by linter exclusions Clean up dead code, stale docs, and local duplication Aug 13, 2026
The whole-block fast path carried accidental complexity that made the
two execution paths (generic vs fast) harder to follow:

- fastOp/fastOpKind wrapped a single fastInstr behind a one-variant tag.
  Replaced []fastOp with []fastInstr; runFastBlock iterates directly.
- runFastBlock/runFastInstr returned an always-nil []value.Value and the
  callers had dead 'contReturn' branches (fast instrs only continue or
  jump, never return). Dropped the value tuple and the dead branches.

Benchmarked before/after on int-heavy workloads (ArithmeticSum,
FibIterative, Sieve, BubbleSort, NestedLoops, GCD, SliceSum): no change
beyond noise. Full 'go test -race ./...' passes. Pure clarity refactor;
the whole-block fast path itself is retained because it is worth
10-29% on those workloads (and the typed fast path overall ~3-6x).

Co-authored-by: t04dJ14n9 <t04dJ14n9@users.noreply.github.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.

2 participants