See the Expansion

Compare the source with real cargo-expand output

Choose a target and compare your source with real cargo expand output. Desktop shows both columns; mobile tabs stay visible as you scroll.

How to read these expansions

These are complete module expansions from Rust 1.99.0 and cargo-expand 1.0.126. Each fixture is type-checked before capture. Rust has already evaluated architecture and Cargo gates: an empty module means its function was excluded on that target. The generated architecture guards are automatic. This view shows macro expansion, not optimized assembly or a performance promise.

One direct feature body

The name stays unchanged. The function exists only on x86-64 and requires a covered feature context.

As written

pub mod direct {
    use archmage::prelude::*;
    #[attune(v3)]
    pub fn add_one(x: u32) -> u32 {
        x + 1
    }
}

Download all source

After cargo expand

pub mod direct {
    use archmage::prelude::*;
    #[target_feature(
        enable = "sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,cmpxchg16b,avx,avx2,fma,bmi1,bmi2,f16c,lzcnt,movbe"
    )]
    #[inline]
    pub fn add_one(x: u32) -> u32 {
        x + 1
    }
}

Download this target’s expansions

Infer a direct tier

The _v3 suffix selects the same direct feature context.

As written

pub mod inferred {
    use archmage::prelude::*;
    #[attune]
    pub fn add_one_v3(x: u32) -> u32 {
        x + 1
    }
}

Download all source

After cargo expand

pub mod inferred {
    use archmage::prelude::*;
    #[target_feature(
        enable = "sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,cmpxchg16b,avx,avx2,fma,bmi1,bmi2,f16c,lzcnt,movbe"
    )]
    #[inline]
    pub fn add_one_v3(x: u32) -> u32 {
        x + 1
    }
}

Download this target’s expansions

Wrap an existing proof

An ordinary callable proof wrapper enters a private feature body.

As written

pub mod wrap {
    use archmage::prelude::*;
    #[attune(wrap)]
    pub fn add_one(_token: X64V3Token, x: u32) -> u32 {
        x + 1
    }
}

Download all source

After cargo expand

pub mod wrap {
    use archmage::prelude::*;
    #[doc(hidden)]
    #[target_feature(
        enable = "sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,cmpxchg16b,avx,avx2,fma,bmi1,bmi2,f16c,lzcnt,movbe"
    )]
    #[inline]
    fn __arcane_add_one(_token: X64V3Token, x: u32) -> u32 {
        x + 1
    }
    #[inline(always)]
    pub fn add_one(__archmage_token: X64V3Token, x: u32) -> u32 {
        let _: () = <X64V3Token>::__ARCHMAGE_ASSERT_TIER_F38B284B;
        unsafe { __arcane_add_one(__archmage_token, x) }
    }
}

Download this target’s expansions

Infer a proof wrapper

The _v3_t suffix inserts a proof parameter when the source omits one.

As written

pub mod inferred_wrap {
    use archmage::prelude::*;
    #[attune]
    pub fn add_one_v3_t(x: u32) -> u32 {
        x + 1
    }
}

Download all source

After cargo expand

pub mod inferred_wrap {
    use archmage::prelude::*;
    #[doc(hidden)]
    #[target_feature(
        enable = "sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,cmpxchg16b,avx,avx2,fma,bmi1,bmi2,f16c,lzcnt,movbe"
    )]
    #[inline]
    fn __arcane_add_one_v3_t(__attune_token: ::archmage::X64V3Token, x: u32) -> u32 {
        x + 1
    }
    #[inline(always)]
    pub fn add_one_v3_t(__attune_token: ::archmage::X64V3Token, x: u32) -> u32 {
        let _: () = <::archmage::X64V3Token>::__ARCHMAGE_ASSERT_TIER_F38B284B;
        unsafe { __arcane_add_one_v3_t(__attune_token, x) }
    }
}

Download this target’s expansions

Generate direct variants

The wildcard uses V3, NEON, WASM128 and scalar. Architecture guards leave the variants applicable to this target.

As written

pub mod direct_family {
    use archmage::prelude::*;
    #[attune(_*)]
    pub fn add_one(x: u32) -> u32 {
        x + 1
    }
}

Download all source

After cargo expand

pub mod direct_family {
    use archmage::prelude::*;
    #[target_feature(
        enable = "sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,cmpxchg16b,avx,avx2,fma,bmi1,bmi2,f16c,lzcnt,movbe"
    )]
    #[inline]
    pub fn add_one_v3(x: u32) -> u32 {
        x + 1
    }
    #[inline]
    pub fn add_one_scalar(x: u32) -> u32 {
        x + 1
    }
}

Download this target’s expansions

Generate proof wrappers

Each applicable default tier gets an ordinary callable function with a token parameter.

As written

pub mod proof_family {
    use archmage::prelude::*;
    #[attune(_*_t)]
    pub fn add_one(x: u32) -> u32 {
        x + 1
    }
}

Download all source

After cargo expand

pub mod proof_family {
    use archmage::prelude::*;
    #[target_feature(
        enable = "sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,cmpxchg16b,avx,avx2,fma,bmi1,bmi2,f16c,lzcnt,movbe"
    )]
    #[inline]
    fn __attune_add_one_v3(x: u32) -> u32 {
        x + 1
    }
    #[inline(always)]
    #[allow(clippy::inline_always, dead_code)]
    pub fn add_one_v3_t(__attune_token: ::archmage::X64V3Token, x: u32) -> u32 {
        unsafe { __attune_add_one_v3(x) }
    }
    #[inline]
    fn __attune_add_one_scalar(x: u32) -> u32 {
        x + 1
    }
    #[inline(always)]
    #[allow(clippy::inline_always, dead_code)]
    pub fn add_one_scalar_t(__attune_token: ::archmage::ScalarToken, x: u32) -> u32 {
        __attune_add_one_scalar(x)
    }
}

Download this target’s expansions

Generate a dispatcher

The public function keeps its ordinary signature; its tier implementations are private.

As written

pub mod dispatcher {
    use archmage::prelude::*;
    #[attune(dispatch)]
    pub fn scale(values: &mut [f32], factor: f32) {
        for value in values {
            *value *= factor;
        }
    }
}

Download all source

After cargo expand

pub mod dispatcher {
    use archmage::prelude::*;
    #[target_feature(
        enable = "sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,cmpxchg16b,avx,avx2,fma,bmi1,bmi2,f16c,lzcnt,movbe"
    )]
    #[inline]
    fn __attune_scale_v3(values: &mut [f32], factor: f32) {
        for value in values {
            *value *= factor;
        }
    }
    #[inline(always)]
    #[allow(clippy::inline_always)]
    fn __attune_scale_v3_t(
        __attune_token: ::archmage::X64V3Token,
        values: &mut [f32],
        factor: f32,
    ) {
        unsafe { __attune_scale_v3(values, factor) }
    }
    #[inline]
    fn __attune_scale_scalar(values: &mut [f32], factor: f32) {
        for value in values {
            *value *= factor;
        }
    }
    #[inline(always)]
    #[allow(clippy::inline_always)]
    fn __attune_scale_scalar_t(
        __attune_token: ::archmage::ScalarToken,
        values: &mut [f32],
        factor: f32,
    ) {
        __attune_scale_scalar(values, factor)
    }
    pub fn scale(values: &mut [f32], factor: f32) {
        '__attune_dispatch: {
            {
                if let Some(__attune_proof) = <::archmage::X64V3Token as ::archmage::SimdToken>::summon() {
                    break '__attune_dispatch __attune_scale_v3_t(
                        __attune_proof,
                        values,
                        factor,
                    );
                }
            }
            {
                break '__attune_dispatch __attune_scale_scalar_t(
                    ::archmage::ScalarToken,
                    values,
                    factor,
                );
            }
        }
    }
}

Download this target’s expansions

Generate every output form

all combines direct variants, proof wrappers and the central dispatcher.

As written

pub mod all_outputs {
    use archmage::prelude::*;
    #[attune(all)]
    pub fn add_one(x: u32) -> u32 {
        x + 1
    }
}

Download all source

After cargo expand

pub mod all_outputs {
    use archmage::prelude::*;
    #[target_feature(
        enable = "sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,cmpxchg16b,avx,avx2,fma,bmi1,bmi2,f16c,lzcnt,movbe"
    )]
    #[inline]
    pub fn add_one_v3(x: u32) -> u32 {
        x + 1
    }
    #[inline(always)]
    #[allow(clippy::inline_always, dead_code)]
    pub fn add_one_v3_t(__attune_token: ::archmage::X64V3Token, x: u32) -> u32 {
        unsafe { add_one_v3(x) }
    }
    #[inline]
    pub fn add_one_scalar(x: u32) -> u32 {
        x + 1
    }
    #[inline(always)]
    #[allow(clippy::inline_always, dead_code)]
    pub fn add_one_scalar_t(__attune_token: ::archmage::ScalarToken, x: u32) -> u32 {
        add_one_scalar(x)
    }
    pub fn add_one(x: u32) -> u32 {
        '__attune_dispatch: {
            {
                if let Some(__attune_proof) = <::archmage::X64V3Token as ::archmage::SimdToken>::summon() {
                    break '__attune_dispatch add_one_v3_t(__attune_proof, x);
                }
            }
            {
                break '__attune_dispatch add_one_scalar_t(::archmage::ScalarToken, x);
            }
        }
    }
}

Download this target’s expansions

Add and remove tiers

Compare x86-64 with and without avx512. Removing NEON leaves scalar as the AArch64 fallback.

As written

pub mod gates {
    use archmage::prelude::*;
    #[attune(_*, dispatch, +v4x(cfg(avx512)), -_neon)]
    pub fn add_one(x: u32) -> u32 {
        x + 1
    }
}

Download all source

After cargo expand

pub mod gates {
    use archmage::prelude::*;
    #[target_feature(
        enable = "sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,cmpxchg16b,avx,avx2,fma,bmi1,bmi2,f16c,lzcnt,movbe"
    )]
    #[inline]
    pub fn add_one_v3(x: u32) -> u32 {
        x + 1
    }
    #[inline(always)]
    #[allow(clippy::inline_always)]
    fn __attune_add_one_v3_t(__attune_token: ::archmage::X64V3Token, x: u32) -> u32 {
        unsafe { add_one_v3(x) }
    }
    #[inline]
    pub fn add_one_scalar(x: u32) -> u32 {
        x + 1
    }
    #[inline(always)]
    #[allow(clippy::inline_always)]
    fn __attune_add_one_scalar_t(
        __attune_token: ::archmage::ScalarToken,
        x: u32,
    ) -> u32 {
        add_one_scalar(x)
    }
    pub fn add_one(x: u32) -> u32 {
        '__attune_dispatch: {
            {
                if let Some(__attune_proof) = <::archmage::X64V3Token as ::archmage::SimdToken>::summon() {
                    break '__attune_dispatch __attune_add_one_v3_t(__attune_proof, x);
                }
            }
            {
                break '__attune_dispatch __attune_add_one_scalar_t(
                    ::archmage::ScalarToken,
                    x,
                );
            }
        }
    }
}

Download this target’s expansions

Choose visibility and inlining

The V3 output becomes pub(crate); scalar remains private. Inline policies apply to their selected outputs.

As written

pub mod output_options {
    use archmage::prelude::*;
    #[attune(_v3(pub(crate), inline(never)), _scalar, dispatch(pub, inline(always)))]
    fn add_one(x: u32) -> u32 {
        x + 1
    }
}

Download all source

After cargo expand

pub mod output_options {
    use archmage::prelude::*;
    #[target_feature(
        enable = "sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,cmpxchg16b,avx,avx2,fma,bmi1,bmi2,f16c,lzcnt,movbe"
    )]
    #[inline(never)]
    pub(crate) fn add_one_v3(x: u32) -> u32 {
        x + 1
    }
    #[inline(always)]
    #[allow(clippy::inline_always)]
    fn __attune_add_one_v3_t(__attune_token: ::archmage::X64V3Token, x: u32) -> u32 {
        unsafe { add_one_v3(x) }
    }
    #[inline]
    fn add_one_scalar(x: u32) -> u32 {
        x + 1
    }
    #[inline(always)]
    #[allow(clippy::inline_always)]
    fn __attune_add_one_scalar_t(
        __attune_token: ::archmage::ScalarToken,
        x: u32,
    ) -> u32 {
        add_one_scalar(x)
    }
    #[inline(always)]
    pub fn add_one(x: u32) -> u32 {
        '__attune_dispatch: {
            {
                if let Some(__attune_proof) = <::archmage::X64V3Token as ::archmage::SimdToken>::summon() {
                    break '__attune_dispatch __attune_add_one_v3_t(__attune_proof, x);
                }
            }
            {
                break '__attune_dispatch __attune_add_one_scalar_t(
                    ::archmage::ScalarToken,
                    x,
                );
            }
        }
    }
}

Download this target’s expansions

Define a vector alias

Each body binds f32x8 to its actual tier token. Construction still uses the published _t API.

As written

pub mod vectors {
    use archmage::prelude::*;
    #[attune(dispatch, define(f32x8))]
    pub fn scale(values: &mut [f32], factor: f32) {
        let token = Token::from_context();
        let multiplier = f32x8::splat_t(token, factor);
        let (chunks, tail) = f32x8::partition_slice_mut_t(token, values);
        for chunk in chunks {
            (f32x8::load_t(token, chunk) * multiplier).store(chunk);
        }
        for value in tail {
            *value *= factor;
        }
    }
}

Download all source

After cargo expand

pub mod vectors {
    use archmage::prelude::*;
    #[target_feature(
        enable = "sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,cmpxchg16b,avx,avx2,fma,bmi1,bmi2,f16c,lzcnt,movbe"
    )]
    #[inline]
    fn __attune_scale_v3(values: &mut [f32], factor: f32) {
        #[allow(non_camel_case_types, dead_code)]
        type f32x8 = ::magetypes::simd::generic::f32x8<::archmage::X64V3Token>;
        let token = ::archmage::X64V3Token::from_context();
        let multiplier = f32x8::splat_t(token, factor);
        let (chunks, tail) = f32x8::partition_slice_mut_t(token, values);
        for chunk in chunks {
            (f32x8::load_t(token, chunk) * multiplier).store(chunk);
        }
        for value in tail {
            *value *= factor;
        }
    }
    #[inline(always)]
    #[allow(clippy::inline_always)]
    fn __attune_scale_v3_t(
        __attune_token: ::archmage::X64V3Token,
        values: &mut [f32],
        factor: f32,
    ) {
        unsafe { __attune_scale_v3(values, factor) }
    }
    #[inline]
    fn __attune_scale_scalar(values: &mut [f32], factor: f32) {
        #[allow(non_camel_case_types, dead_code)]
        type f32x8 = ::magetypes::simd::generic::f32x8<::archmage::ScalarToken>;
        let token = ::archmage::ScalarToken::from_context();
        let multiplier = f32x8::splat_t(token, factor);
        let (chunks, tail) = f32x8::partition_slice_mut_t(token, values);
        for chunk in chunks {
            (f32x8::load_t(token, chunk) * multiplier).store(chunk);
        }
        for value in tail {
            *value *= factor;
        }
    }
    #[inline(always)]
    #[allow(clippy::inline_always)]
    fn __attune_scale_scalar_t(
        __attune_token: ::archmage::ScalarToken,
        values: &mut [f32],
        factor: f32,
    ) {
        __attune_scale_scalar(values, factor)
    }
    pub fn scale(values: &mut [f32], factor: f32) {
        '__attune_dispatch: {
            {
                if let Some(__attune_proof) = <::archmage::X64V3Token as ::archmage::SimdToken>::summon() {
                    break '__attune_dispatch __attune_scale_v3_t(
                        __attune_proof,
                        values,
                        factor,
                    );
                }
            }
            {
                break '__attune_dispatch __attune_scale_scalar_t(
                    ::archmage::ScalarToken,
                    values,
                    factor,
                );
            }
        }
    }
}

Download this target’s expansions

Call a helper in context

Inside each generated body, attuned! selects a covered helper without another runtime probe.

As written

pub mod covered_calls {
    use archmage::prelude::*;
    #[attune(_*)]
    fn scale_one(value: f32, factor: f32) -> f32 {
        value * factor
    }
    #[attune(dispatch)]
    pub fn scale(values: &mut [f32], factor: f32) {
        for value in values {
            *value = attuned!(scale_one(*value, factor));
        }
    }
}

Download all source

After cargo expand

pub mod covered_calls {
    use archmage::prelude::*;
    #[target_feature(
        enable = "sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,cmpxchg16b,avx,avx2,fma,bmi1,bmi2,f16c,lzcnt,movbe"
    )]
    #[inline]
    fn scale_one_v3(value: f32, factor: f32) -> f32 {
        value * factor
    }
    #[inline]
    fn scale_one_scalar(value: f32, factor: f32) -> f32 {
        value * factor
    }
    #[target_feature(
        enable = "sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,cmpxchg16b,avx,avx2,fma,bmi1,bmi2,f16c,lzcnt,movbe"
    )]
    #[inline]
    fn __attune_scale_v3(values: &mut [f32], factor: f32) {
        for value in values {
            *value = { '__attune_call_0: { { scale_one_v3(*value, factor) } } };
        }
    }
    #[inline(always)]
    #[allow(clippy::inline_always)]
    fn __attune_scale_v3_t(
        __attune_token: ::archmage::X64V3Token,
        values: &mut [f32],
        factor: f32,
    ) {
        unsafe { __attune_scale_v3(values, factor) }
    }
    #[inline]
    fn __attune_scale_scalar(values: &mut [f32], factor: f32) {
        for value in values {
            *value = { '__attune_call_0: { { scale_one_scalar(*value, factor) } } };
        }
    }
    #[inline(always)]
    #[allow(clippy::inline_always)]
    fn __attune_scale_scalar_t(
        __attune_token: ::archmage::ScalarToken,
        values: &mut [f32],
        factor: f32,
    ) {
        __attune_scale_scalar(values, factor)
    }
    pub fn scale(values: &mut [f32], factor: f32) {
        '__attune_dispatch: {
            {
                if let Some(__attune_proof) = <::archmage::X64V3Token as ::archmage::SimdToken>::summon() {
                    break '__attune_dispatch __attune_scale_v3_t(
                        __attune_proof,
                        values,
                        factor,
                    );
                }
            }
            {
                break '__attune_dispatch __attune_scale_scalar_t(
                    ::archmage::ScalarToken,
                    values,
                    factor,
                );
            }
        }
    }
}

Download this target’s expansions

Wrap an intrinsic result

from_raw wraps a native register without a token argument inside the matching feature context.

As written

pub mod raw_register {
    use archmage::prelude::*;
    #[attune(v3, import_intrinsics, define(f32x8))]
    pub fn broadcast(value: f32) -> [f32; 8] {
        f32x8::from_raw(_mm256_set1_ps(value)).to_array()
    }
}

Download all source

After cargo expand

pub mod raw_register {
    use archmage::prelude::*;
    #[target_feature(
        enable = "sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,cmpxchg16b,avx,avx2,fma,bmi1,bmi2,f16c,lzcnt,movbe"
    )]
    #[inline]
    pub fn broadcast(value: f32) -> [f32; 8] {
        #[allow(unused_imports)]
        use archmage::intrinsics::x86_64::*;
        #[allow(non_camel_case_types, dead_code)]
        type f32x8 = ::magetypes::simd::generic::f32x8<::archmage::X64V3Token>;
        f32x8::from_raw(_mm256_set1_ps(value)).to_array()
    }
}

Download this target’s expansions

Keep generic parameters

The dispatcher and each tier implementation retain the generic bound.

As written

pub mod generic {
    use archmage::prelude::*;
    #[attune(dispatch)]
    pub fn map<F: Fn(f32) -> f32 + Copy>(values: &mut [f32], f: F) {
        for value in values {
            *value = f(*value);
        }
    }
}

Download all source

After cargo expand

pub mod generic {
    use archmage::prelude::*;
    #[target_feature(
        enable = "sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,cmpxchg16b,avx,avx2,fma,bmi1,bmi2,f16c,lzcnt,movbe"
    )]
    #[inline]
    fn __attune_map_v3<F: Fn(f32) -> f32 + Copy>(values: &mut [f32], f: F) {
        for value in values {
            *value = f(*value);
        }
    }
    #[inline(always)]
    #[allow(clippy::inline_always)]
    fn __attune_map_v3_t<F: Fn(f32) -> f32 + Copy>(
        __attune_token: ::archmage::X64V3Token,
        values: &mut [f32],
        f: F,
    ) {
        unsafe { __attune_map_v3::<F>(values, f) }
    }
    #[inline]
    fn __attune_map_scalar<F: Fn(f32) -> f32 + Copy>(values: &mut [f32], f: F) {
        for value in values {
            *value = f(*value);
        }
    }
    #[inline(always)]
    #[allow(clippy::inline_always)]
    fn __attune_map_scalar_t<F: Fn(f32) -> f32 + Copy>(
        __attune_token: ::archmage::ScalarToken,
        values: &mut [f32],
        f: F,
    ) {
        __attune_map_scalar::<F>(values, f)
    }
    pub fn map<F: Fn(f32) -> f32 + Copy>(values: &mut [f32], f: F) {
        '__attune_dispatch: {
            {
                if let Some(__attune_proof) = <::archmage::X64V3Token as ::archmage::SimdToken>::summon() {
                    break '__attune_dispatch __attune_map_v3_t::<
                        F,
                    >(__attune_proof, values, f);
                }
            }
            {
                break '__attune_dispatch __attune_map_scalar_t::<
                    F,
                >(::archmage::ScalarToken, values, f);
            }
        }
    }
}

Download this target’s expansions

Generate inherent methods

Receiver methods can generate sibling variants. Trait implementations have additional restrictions described in the reference.

As written

pub mod method {
    use archmage::prelude::*;
    pub struct Gain(pub f32);
    impl Gain {
        #[attune(_*, dispatch)]
        pub fn scale(&self, values: &mut [f32]) {
            for value in values {
                *value *= self.0;
            }
        }
    }
}
Download all source

After cargo expand

pub mod method {
    use archmage::prelude::*;
    pub struct Gain(pub f32);
    impl Gain {
        #[target_feature(
            enable = "sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,cmpxchg16b,avx,avx2,fma,bmi1,bmi2,f16c,lzcnt,movbe"
        )]
        #[inline]
        pub fn scale_v3(&self, values: &mut [f32]) {
            for value in values {
                *value *= self.0;
            }
        }
        #[inline(always)]
        #[allow(clippy::inline_always)]
        fn __attune_scale_v3_t(
            &self,
            __attune_token: ::archmage::X64V3Token,
            values: &mut [f32],
        ) {
            unsafe { self.scale_v3(values) }
        }
        #[inline]
        pub fn scale_scalar(&self, values: &mut [f32]) {
            for value in values {
                *value *= self.0;
            }
        }
        #[inline(always)]
        #[allow(clippy::inline_always)]
        fn __attune_scale_scalar_t(
            &self,
            __attune_token: ::archmage::ScalarToken,
            values: &mut [f32],
        ) {
            self.scale_scalar(values)
        }
        pub fn scale(&self, values: &mut [f32]) {
            '__attune_dispatch: {
                {
                    if let Some(__attune_proof) = <::archmage::X64V3Token as ::archmage::SimdToken>::summon() {
                        break '__attune_dispatch self
                            .__attune_scale_v3_t(__attune_proof, values);
                    }
                }
                {
                    break '__attune_dispatch self
                        .__attune_scale_scalar_t(::archmage::ScalarToken, values);
                }
            }
        }
    }
}
Download this target’s expansions

The full reference covers the remaining syntax and restrictions. Reproduce these views from the repository with just docs-expand; just docs-expand-check verifies the committed outputs.

Found an error or it needs a clarification? Open an issue on GitHub.
Substantiated corrections will be incorporated with attribution.