Summary
Add a invoke_rite() method to all tokens that wraps a closure in the
appropriate #[target_feature] boundary, providing #[arcane]-like
functionality without proc macros.
Motivation
jxl-rs's SimdDescriptor::call() pattern demonstrates a clean way to
create a #[target_feature] boundary using only a method + closure:
if let Some(token) = Desktop64::summon() {
token.invoke_rite(|t| process_simd(t, data))
}
This is useful when:
- A proc-macro dependency is undesirable (lightweight crates)
- Inline one-off dispatch is cleaner than a named
#[arcane] function
- Users want to experiment without pulling in archmage-macros
#[arcane] remains the recommended approach for named entry points.
invoke_rite() fills the gap for inline/closure use cases.
Design Sketch
impl Desktop64 {
pub fn invoke_rite<R>(self, f: impl FnOnce(Self) -> R) -> R {
#[target_feature(enable = "avx2,fma,bmi1,bmi2,f16c")]
unsafe fn inner<R>(
token: Desktop64,
f: impl FnOnce(Desktop64) -> R,
) -> R {
f(token)
}
// SAFETY: Token existence proves CPU features are available.
unsafe { inner(self, f) }
}
}
Generated per-token by xtask from token-registry.toml, like everything else.
Open Questions
- Naming:
invoke_rite(), call(), enter(), cast()?
Thematic preference leans toward invoke_rite or cast.
- Trait vs inherent: Should this be on the
SimdToken trait or per-token inherent methods?
Trait method would require GATs or boxing; inherent methods are simpler.
- Inlining: Should the generated code use
#[inline(never)] (like jxl-rs) or
#[inline]? jxl-rs uses #[inline(never)] to prevent the
feature-enabled code from inlining back into the non-feature caller.
This matches #[arcane] semantics (optimization boundary at entry).
Prior Art
- jxl-rs
SimdDescriptor::call() — same pattern, #[inline(never)]
- archmage
#[arcane] — proc-macro version of the same idea
Summary
Add a
invoke_rite()method to all tokens that wraps a closure in theappropriate
#[target_feature]boundary, providing#[arcane]-likefunctionality without proc macros.
Motivation
jxl-rs's
SimdDescriptor::call()pattern demonstrates a clean way tocreate a
#[target_feature]boundary using only a method + closure:This is useful when:
#[arcane]function#[arcane]remains the recommended approach for named entry points.invoke_rite()fills the gap for inline/closure use cases.Design Sketch
Generated per-token by xtask from token-registry.toml, like everything else.
Open Questions
invoke_rite(),call(),enter(),cast()?Thematic preference leans toward
invoke_riteorcast.SimdTokentrait or per-token inherent methods?Trait method would require GATs or boxing; inherent methods are simpler.
#[inline(never)](like jxl-rs) or#[inline]? jxl-rs uses#[inline(never)]to prevent thefeature-enabled code from inlining back into the non-feature caller.
This matches
#[arcane]semantics (optimization boundary at entry).Prior Art
SimdDescriptor::call()— same pattern,#[inline(never)]#[arcane]— proc-macro version of the same idea