Skip to content

refactor(rewrite): zero-shift injection with original-source error display#607

Merged
rocketman-code merged 2 commits intomainfrom
refactor/zero-shift-error-remapping
Mar 28, 2026
Merged

refactor(rewrite): zero-shift injection with original-source error display#607
rocketman-code merged 2 commits intomainfrom
refactor/zero-shift-error-remapping

Conversation

@rocketman-code
Copy link
Copy Markdown
Owner

@rocketman-code rocketman-code commented Mar 28, 2026

Summary

  • Injections no longer add new lines: guards go on the brace line, file-level items appended after user code
  • Error cleaning replaced with original-source line substitution: on compilation error, structured JSON spans identify which source lines to replace, and the original (uninstrumented) file provides clean content
  • Manifest file, manifest IPC, and all manifest-based string cleaning deleted
  • is_piano_diagnostic tightened with backtick-delimited patterns to prevent false positives on user identifiers
  • Allocator injection preserves line count: Case 2 on single line, Case 3 split into Replace (same lines) + Append (fallback after user code)
  • negate_cfg handles cfg_attr with depth-aware predicate extraction (fixes pre-existing always-true fallback bug)
  • Production code: -90 net lines. Tests: +327 net lines (16-cell proof matrix).

Test plan

  • 438 workspace tests pass (242 lib + 196 integration)
  • 16/16 exhaustive proof matrix cells pass (injection type x grammar production x diagnostic category)
  • error_line_remap tests verify original line numbers preserved
  • clean_rendered unit tests verify span-based source replacement
  • is_piano_diagnostic tests verify no false positives on user identifiers

…splay

Replace the injection manifest and regex-based error cleaning with
original-source line substitution driven by structured JSON spans.

Injection changes:
- Zero-shift formatting: guards on brace line, items appended after
  user code, no new lines added to user source
- StringInjector.apply() returns only modified source (no manifest)
- Allocator Case 2: init on same line as static (preserves line count)
- Allocator Case 3: split into Replace (same line count) + Append
  (fallback after user code). Fixes zero-shift violation.
- negate_cfg: handle #[cfg_attr(PRED, ...)] with depth-aware parsing.
  Fixes pre-existing bug where fallback was always-true.

Error handling changes:
- Delete manifest file, manifest IPC, manifest-based string cleaning
- Add clean_rendered: for each diagnostic span referencing a modified
  file, replace the instrumented source line in rendered output with
  the original source line read from the unmodified file
- Tighten is_piano_diagnostic with backtick-delimited patterns to
  prevent false positives on user identifiers
- build_instrumented receives modified file set for span filtering

Eliminates 7 bugs: manifest write race (B4), stale accumulation (B6),
bare ")" corruption (B2), dead manifest entries (B1), macro guard gap
(B3), is_piano_diagnostic false positives (B5), dead _source_len (B7).
16 integration tests covering all injection type x grammar production
x diagnostic category combinations. Each test creates a real project
with a deliberate compilation error, runs piano build, and asserts
the output shows original source at correct line numbers with zero
injection artifacts.

The matrix is finite because both the Rust grammar (as it interacts
with piano injections) and piano's injection set are finite
enumerations. Complete coverage of all cells constitutes a
constructive proof by exhaustive enumeration.

Matrix cells: sync guard (T1-T3), async wrapper (T4-T5), impl-Future
(T6/B2 regression), lifecycle (T7-T8), allocator wrap (T9), cfg-gated
allocator (T10), macro expansion (T11), piano diagnostic filtering
(T12), lifetime error with help suggestion (T13), async borrow (T14),
multi-injection combined (T15). Plus renamed multi_injection test.
@rocketman-code rocketman-code force-pushed the refactor/zero-shift-error-remapping branch from 2b6c03a to 3c218df Compare March 28, 2026 04:25
@rocketman-code rocketman-code changed the title refactor(rewrite): zero-shift injection with manifest-based error cleaning refactor(rewrite): zero-shift injection with original-source error display Mar 28, 2026
@rocketman-code rocketman-code merged commit f8919df into main Mar 28, 2026
11 checks passed
@rocketman-code rocketman-code deleted the refactor/zero-shift-error-remapping branch March 28, 2026 04:30
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