Skip to main content

aligned_vmem/
lazy_commit_is_honored.rs

1/// Whether this platform's backend actually HONORS the `initial_commit`
2/// argument of [`reserve_aligned_lazy`](crate::api::reserve_aligned_lazy) — i.e. whether "lazy" is real here.
3///
4/// - `true` — the reservation commits exactly `initial_commit` bytes up front
5///   and the tail stays reserved-but-uncommitted until you commit it. Touching
6///   the tail before committing it faults.
7/// - `false` — `initial_commit` is IGNORED and the whole span is committed by
8///   the reserve call itself. Committing more is a well-formed no-op, and the
9///   tail was writable all along.
10///
11/// A compile-time property of the backend, not a runtime observation: only the
12/// Windows native backend performs a genuine two-phase
13/// reserve-then-commit-prefix. The Unix backend has no separate reserve/commit
14/// distinction at this granularity and delegates straight to the eager path;
15/// miri models no RSS; and the `--cfg aligned_vmem_mock` backend deliberately
16/// chains to the eager path, so a mocked (no-op) commit cannot leave the tail
17/// unwritable.
18///
19/// Without this query the difference is invisible from outside the crate — it
20/// was previously discoverable only by reading the backend source. It is the
21/// third member of the same family as
22/// [`Reservation::decommit_reclaims_and_zeroes`](crate::Reservation::decommit_reclaims_and_zeroes) and [`Reservation::is_huge`](crate::Reservation::is_huge):
23/// where a platform difference or a best-effort outcome exists, this crate
24/// exposes it as something you can branch on instead of a caveat in prose.
25///
26/// [`LazyReservation`](crate::lazy_reservation::LazyReservation) consults this internally, so its
27/// [`committed_len`](crate::lazy_reservation::LazyReservation::committed_len) is already the platform
28/// truth — you do not need this query merely to interpret it. Reach for it when
29/// the DIFFERENCE itself is the subject: RSS accounting, a benchmark that must
30/// not report a no-op as a saving, or deciding whether a lazy reservation buys
31/// anything at all on the current target.
32#[must_use]
33#[cfg(feature = "lazy-commit")]
34#[cfg_attr(docsrs, doc(cfg(feature = "lazy-commit")))]
35pub const fn lazy_commit_is_honored() -> bool {
36    cfg!(all(windows, not(miri), not(aligned_vmem_mock)))
37}