Repository navigation
docs(r12): Rust macros for systems — example 43 + chapter 43 (Deep Dives) - #12
Merged
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The book's first single-language deep dive (Rust only): a cargo workspace with a proc-macro crate
sysmacrosand theappbinary that uses it.Example
43-rust-macros-for-systems(mode: local, langs: [rust])#[derive(SysError)]— a miniaturethiserror:Display+std::error::Errorgenerated from#[error("...")]on named/tuple enum variants via syn 2.0 + quote; malformed input becomes acompile_error!, not a panic.#[instrument]— an attribute macro logging a fn's entry (name+args), exit (return value), andInstant-measured duration.unsafeunaligned read of a#[repr(C)]record from a byte slice, validated clean by miri; a defect-named--oob-readpath reads 4 bytes past the 8-byte buffer, which miri catches as out-of-bounds UB.verify.luaasserts 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.shdispatches rust only,verify.luaskips non-rust, the runner renders cpp/go as-.Chapter 43
To the spine (Part "Deep Dives"): Tools-used box, verbatim
rustexcerpts (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--mode local→ 97 passed / 0 failed / 3 skipped (skips are38-otel, lgtm down)validate.py: OKmiri (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 endatmain.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.