Skip to content

docs(r12): Rust macros for systems — example 43 + chapter 43 (Deep Dives) - #12

Merged
patterncatalyst merged 1 commit into
mainfrom
docs/r12-rust-macros
Jul 26, 2026
Merged

patterncatalyst merged 1 commit into
mainfrom
docs/r12-rust-macros

Conversation

@patterncatalyst

Copy link
Copy Markdown
Owner

The book's first single-language deep dive (Rust only): a cargo workspace with a proc-macro crate sysmacros and the app binary that uses it.

Example 43-rust-macros-for-systems (mode: local, langs: [rust])

  • #[derive(SysError)] — a miniature thiserror: Display + std::error::Error generated from #[error("...")] on named/tuple enum variants via syn 2.0 + quote; malformed input becomes a compile_error!, not a panic.
  • #[instrument] — an attribute macro logging a fn's entry (name+args), exit (return value), and Instant-measured duration.
  • A sound unsafe unaligned read of a #[repr(C)] record from a byte slice, validated clean by miri; a defect-named --oob-read path reads 4 bytes past the 8-byte buffer, which miri catches as out-of-bounds UB.
  • verify.lua asserts behaviour on the pinned stable toolchain (PASS 8 / FAIL 0); miri (nightly) is exercised by the chapter, not the CI gate.

First single-language example: demo.sh dispatches rust only, verify.lua skips non-rust, the runner renders cpp/go as -.

Chapter 43

To the spine (Part "Deep Dives"): Tools-used box, verbatim rust excerpts (no tri-language codetabs), Figures 43.1 (proc-macro pipeline) + 43.2 (miri bounds check), verified footer with the real miri diagnostic.

Gate

  • --only 43 → 1 passed / 0 failed
  • full --mode local → 97 passed / 0 failed / 3 skipped (skips are 38-otel, lgtm down)
  • validate.py: OK

miri (first-hand): sound path exit 0 (no UB); --oob-read → Undefined Behavior: memory access failed: attempting to access 8 bytes, but got alloc25+0x4 which is only 4 bytes from the end at main.rs:57. Stable vs miri timing: 4µs vs 491785µs. Crates: syn 2.0, quote 1.0, proc-macro2 1.0; stable 1.97.1 + nightly miri.

…ves)

The book's first single-language deep dive (Rust only): a cargo workspace
with a proc-macro crate `sysmacros` and the `app` binary that uses it.

Example 43-rust-macros-for-systems (mode: local, langs: [rust]):
- #[derive(SysError)] — a miniature thiserror: Display + std::error::Error
  generated from #[error("...")] on named/tuple enum variants via syn 2.0 +
  quote; malformed input becomes a compile_error!, not a panic.
- #[instrument] — an attribute macro that logs a fn's entry (name+args),
  exit (return value), and Instant-measured duration.
- a sound unsafe unaligned read of a #[repr(C)] record from a byte slice,
  validated clean by miri; a defect-named --oob-read path reads 4 bytes past
  the 8-byte buffer, which miri catches as out-of-bounds UB.
- verify.lua asserts behaviour on the pinned stable toolchain (PASS 8/FAIL 0);
  miri (nightly) is exercised by the chapter, not the CI gate.

First single-language example: demo.sh dispatches rust only, verify.lua skips
non-rust; the runner renders the cpp/go columns as "-".

Chapter 43 to the spine (Part "Deep Dives"): Tools-used box, verbatim rust
excerpts (no tri-language codetabs), Figures 43.1 (proc-macro pipeline) +
43.2 (miri bounds check), verified footer with the real miri diagnostic.

Gate: --only 43 → 1 passed/0 failed; full --mode local → 97 passed/0 failed/
3 skipped (skips are 38-otel, lgtm down). validate: OK. Crates: syn 2.0,
quote 1.0, proc-macro2 1.0; stable 1.97.1 + nightly miri.
@patterncatalyst
patterncatalyst merged commit 2463656 into main Jul 26, 2026
8 checks passed
@patterncatalyst
patterncatalyst deleted the docs/r12-rust-macros branch July 26, 2026 15:39
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