Skip to content
Arshgill01Public

About

Causal debugger for compiler decisions in Rust — executes controlled counterfactuals to explain LLVM optimizations and failures.

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

WhyVec

WhyVec is becoming a causal debugger for compiler decisions.

Compilers describe the final program they received. WhyVec executes controlled counterfactuals to answer two questions they generally do not answer directly:

Which tested change is sufficient to produce this compiler failure?

Which tested compiler assumption is sufficient to change this optimization decision under the recorded toolchain, target, flags, and pipeline?

The LLVM alias/trip-count analyzer remains the first deep optimization pack. It now runs inside an adapter-aware experiment architecture alongside build-causality queries. Executable fixtures cover Clang 21 and rustc 1.96.1 with LLVM 22; every result records whether its optimizer pipeline is exact, independently confirmed, or only a surrogate.

The full re-foundation and defect register live in docs/REFOUNDATION_AUDIT.md.

Install and run

The local install places the Rust CLI and both pinned-LLVM helpers together:

cargo install --path crates/whyvec-cli --root .local
python3 scripts/build_helpers.py --output .local/bin
.local/bin/whyvec doctor

Configure any CMake project with CMAKE_EXPORT_COMPILE_COMMANDS=ON, then use one normal command; no function name, LLVM parameter index, or helper path is required:

whyvec analyze path/to/source.c:LINE

The complete executable demonstration is:

./scripts/demo

It installs/uses the WhyVec Codex plugin, hands over a fresh agent packet, and runs the model-authored candidate through differential, mutation, sanitizer, structured-record, and benchmark gates. ./scripts/demo --ci reruns the same compiler and validation workflow using the exact retained candidate from the actual installed-skill session. The pinned judge image is built and executed by containers/judge/build.sh.

Build causality

The executable build query supports Cargo/rustc, direct Clang and GCC translation units, and TypeScript projects:

cargo run -p whyvec-cli -- explain-build \
  --base HEAD \
  --diagnostic E0308 \
  --at src/lib.rs \
  -- cargo check

WhyVec verifies that the base passes, reconstructs the working-tree change in isolated detached worktrees, identifies sufficient changed-file sets for the selected rustc diagnostic, refines successful text files into independently tested Rust syntax-item groups backed by exact Git hunks, and then removes each sufficient set from the full patch to measure which diagnostics disappear with it. See Build causality for the evidence model and refusal surface.

Every completed query retains content-digested intervention snapshots and raw compiler streams. Re-execute and compare the normalized semantic result with:

whyvec replay-build .whyvec/analyses/<analysis-id>/report.json

TypeScript uses the pinned compiler API adapter:

cd tools/typescript-adapter && npm ci
whyvec explain-build --diagnostic TS2345 --at src/consumer.ts \
  -- whyvec-typescript tsconfig.json

GCC and Clang receive native structured-diagnostic flags inside the same Bubblewrap isolation boundary, for example -- g++ -fsyntax-only src/main.cpp.

Optimization causality

The normal C product path consumes the real compilation database and performs function, pointer-parameter, and helper discovery automatically:

whyvec analyze demo/src/kernel.c:4
whyvec doctor

The expert path accepts an explicit Clang source/IR mapping and evaluates typed LLVM parameter assumptions:

whyvec explain-opt src/kernel.c:5 \
  --function add_vectors_ \
  --parameter output:0 --parameter input:1 --parameter count:2 \
  --transformer /path/to/whyvec-llvm-transform \
  --identity-tool /path/to/whyvec-llvm-loop-identity

The complete build installs or builds the pinned-LLVM helpers; explicit helper paths remain expert overrides. It records equivalent_confirmed fidelity and never converts a successful LLVM assumption into source authorization.

If a source location maps to more than one LLVM loop, the query retains identity.ambiguous with the helper evidence and stops before pipeline replay or variants. It does not select a nearby loop heuristically.

Completed optimization queries can be re-executed from their retained inputs:

whyvec replay-opt .whyvec/analyses/<analysis-id>/report.json

Replay verifies every declared artifact, the report's normalized semantic digest, the source digest, and all four tool fingerprints before rerunning the same bounded search. It refuses changed evidence, inputs, tools, or outcomes.

GCC has a separate observation surface because its records and cost model are not LLVM assumptions:

whyvec observe-gcc-opt src/kernel.c:5 --function add_vectors_ \
  --llvm-report .whyvec/analyses/<llvm-analysis>/report.json
whyvec replay-gcc-opt .whyvec/analyses/<gcc-analysis>/report.json

The optional comparison reports only whether the two recorded compiler classifications agree or diverge for the same canonical source subject.

For a positive C bound-alias report, derive the source access obligation separately:

whyvec derive-obligation .whyvec/analyses/<optimization-analysis>/report.json
whyvec replay-obligation .whyvec/analyses/<obligation-analysis>/report.json

The derivation names the pointer-loaded bound object, every supported indexed write region, the induction domain, overflow checks, and the unchanged fallback requirement. It remains a candidate obligation until repository evidence or a runtime guard enforces it.

The executable guarded-repair fixture and its retained validation evidence are documented in Guarded repair validation.

The installable Codex skill consumes the compact packet and creates an auditable repository decision before a source edit:

python3 integrations/codex/whyvec/skills/whyvec-optimize/scripts/plan_action.py \
  --packet .whyvec/agent-packets/<analysis-id>.json \
  --validation-report <validation-report.json> \
  --candidate-source <candidate.c> \
  --output <new-action-trace.json>

The packet locates WhyVec and its linked reports without five manual paths. The planner verifies replay and artifact integrity and compares restrict, a guarded path, an API change, and refusal. Its tracked-text discovery is only a preliminary inventory; Codex must still establish repository contracts and uncertain caller edges. The report claims differential agreement only on covered executions and keeps the original pointer-loaded loop as the overlap and arithmetic-uncertainty fallback.

An actual fresh Codex CLI 0.144.3 / gpt-5.6-sol run, sanitized observable session, complete patch, evidence ledger, and linked action trace are retained under evidence/codex-live/2026-07-21. The independently sourced SuperLU case is retained under evidence/real-world/superlu-a9314310; WhyVec observed its real compiler miss and made a principled refusal after the declared search found no tested sufficient assumption.

Product contract

WhyVec separates three kinds of reasoning that must never be conflated:

  1. Compiler observation — what the pinned compiler did in the baseline build.
  2. Counterfactual evidence — what changed when one declared assumption was altered in an otherwise identical shadow compilation.
  3. Repository decision — whether callers and tests justify restrict, require runtime versioning, or make the optimization unsafe to apply.

The compiler engine is deterministic. GPT-5.6 and Codex operate on its evidence; they do not invent the compiler result.

source location
      │
      ▼
baseline compilation ──► missed vectorization record
      │
      ▼
bounded assumption search ──► successful counterfactual
      │
      ▼
semantic obligation ──► repository and caller analysis
      │
      ├── enforceable ──► patch + regression tests + benchmark
      └── unsupported ──► explicit refusal with evidence

Representative interaction

$ whyvec explain-opt src/kernel.c:5 --function add_vectors_ \
    --parameter output:0 --parameter input:1 --parameter count:2 \
    --transformer /path/to/whyvec-llvm-transform \
    --identity-tool /path/to/whyvec-llvm-loop-identity

OPTIMIZATION CAUSALITY
  baseline: missed
  pipeline fidelity: equivalent_confirmed
  loop fingerprint: <recorded fingerprint>
  smallest sufficient set found: parameter.count.noalias
  Under the recorded toolchain and equivalent-confirmed pipeline, parameter.count.noalias was a tested sufficient assumption for the matched loop to vectorize.
  report: .whyvec/analyses/<analysis-id>/report.json

Run derive-obligation on that report before considering a source action. The result is a candidate obligation or typed decline; repository analysis remains required and the counterfactual alone never authorizes restrict.

Engineering principles

  • Never mutate the user's source during an experiment.
  • Never describe a counterfactual observation as proof that a caller contract is true.
  • Never narrow LLVM parameter-level noalias into a byte-range promise without separate access analysis.
  • Pin and report every compiler input that can affect the result.
  • Preserve baseline behavior through an unchanged fallback whenever a runtime guard is selected.
  • Treat refusal as a valid, testable product outcome.
  • Keep human-readable output and the versioned JSON report semantically identical.
  • Preserve every experiment as reproducible evidence rather than transient terminal text.

Repository map

Current implementation

This repository contains executable build-causality, LLVM optimization, GCC-observation, source-obligation, guarded-validation, semantic-replay, and Codex action-planning paths. Their supported and residual surfaces are tracked in PLAN.md, and completed capabilities retain validation evidence in the appropriate log.

License

WhyVec is licensed under the MIT License.

About

Causal debugger for compiler decisions in Rust — executes controlled counterfactuals to explain LLVM optimizations and failures.

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages