Skip to content

docs: track making the generated Rust crate no_std#90

Draft
mario4tier wants to merge 1 commit into
devfrom
docs/rust-crate-no-std
Draft

docs: track making the generated Rust crate no_std#90
mario4tier wants to merge 1 commit into
devfrom
docs/rust-crate-no-std

Conversation

@mario4tier

@mario4tier mario4tier commented Jun 22, 2026

Copy link
Copy Markdown
Member

Tracking PR (don't forget) — do not merge as-is

Complete plan kept in this description (the in-repo docs/plans/*.md will be cleaned up once implemented).

Captures a deferred follow-on: migrating the generated Rust crate to #![no_std]. Filed so it isn't lost; it is not a blocker for the Rust abstract/introspection layer work (that module is already no_std-clean by design).

Assumption to validate

Crate-wide no_std is strictly better and feasible. Benefits: runs on any target with (eventually without) an allocator — WASM, embedded — and enforces the same zero-/bounded-allocation discipline the C reference already has with stack temp buffers.

Current state

  • The generated crate ta_codegen_output/rust/ is std-only (declares no_std nowhere).
  • The only heap blocker is runtime-sized Vec<f64> temp/scratch buffers in 17 of 163 indicator files. No String/format! anywhere in indicator code.
  • The forthcoming abstract/introspection module is no_std-clean by design (&'static/const tables, enums, slices), so it adds no debt.

The 17 files: accbands, adxr, apo, atr, bbands, dema, ma, macd, macdext, mavp, natr, ppo, stoch, stochf, stochrsi, tema, trix

Example (atr.rs): range-sized scratch buffer mirroring the C reference's stack temp buffers.

Approach (the fix lives in the GENERATOR — tools/ta_codegen/src/backends/rust_lang.rs + scaffolding in main.rs — never hand-edit ta_codegen_output/)

  • A — extern crate alloc (minimal, low risk, recommended first): emit #![no_std] + extern crate alloc; and switch temp buffers to alloc::vec::Vec. Runs on any allocator target incl. WASM; no algorithm/signature changes.
  • B — true zero-alloc (higher fidelity to C, more work): replace runtime-sized Vec scratch with caller-provided/bounded/stack buffers, removing the allocator requirement. Touches the 17 functions and possibly the public surface. Defer unless a no-allocator target is required.

Recommended: A first, revisit B only if an allocator-free target becomes a real need.

Acceptance criteria

  • Crate builds with #![no_std] (e.g. a no_std smoke/CI target)
  • ta_regtest --codegen --language=rust still 161/161 — no behavior change
  • No hot-path (per-bar compute) perf regression vs the current std build
  • The abstract/introspection module remains no_std-clean
  • Change lives in the generator + scaffolding; ta_codegen_output/ is regenerated, never hand-edited

🤖 Generated with Claude Code

Tracking note (deferred follow-on, not a blocker) for migrating the
generated Rust crate to #![no_std]. The sole heap blocker is runtime-sized
Vec<f64> temp buffers in 17 of 163 indicator files (no String usage); the
upcoming abstract/introspection module is already no_std-clean.

Records the two approaches (extern crate alloc first; true zero-alloc later),
that the fix lives in the generator (rust_lang.rs + scaffolding) not the
generated output, and acceptance criteria (no_std build + ta_regtest 161/161
unchanged + no hot-path regression).

Co-Authored-By: Claude Opus 4.8 (1M context) <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