use archmage::{SimdToken, X64V3Token};
fn main() {
println!("=== archmage safety counterexample ===\n");
println!("1. Safe path: X64V3Token::summon()");
match X64V3Token::summon() {
Some(_token) => {
println!(" AVX2+FMA confirmed by runtime detection.");
println!(" Safe to call any #[arcane] function with this token.\n");
}
None => {
println!(" CPU lacks AVX2+FMA. summon() returned None.");
println!(" Graceful fallback — no crash, no UB.\n");
}
}
println!("2. Dangerous path: forge_token_dangerously()");
println!(" This creates a token WITHOUT checking CPU features.");
println!(" The token is a lie — it claims AVX2+FMA support");
println!(" even if the CPU has neither.\n");
#[allow(deprecated, unused_variables)]
let forged = unsafe { X64V3Token::forge_token_dangerously() };
println!(" Token forged. On a CPU without AVX2, calling any");
println!(" #[arcane] function with this token would cause:");
println!(" - SIGILL (illegal instruction) on real hardware");
println!(" - Silent undefined behavior in the general case\n");
println!("3. What #[arcane] does under the hood:");
println!(" #[target_feature(enable = \"avx2,fma,...\")]");
println!(" fn inner(...) {{ /* AVX2 intrinsics here */ }}");
println!(" unsafe {{ inner(...) }} // <-- THIS is the unsafe call");
println!();
println!(" The token proves the unsafe call is sound.");
println!(" summon() → real proof. forge() → fake proof.\n");
println!("4. Feature information from the token:");
println!(" NAME: {}", X64V3Token::NAME);
println!(" TARGET_FEATURES: {}", X64V3Token::TARGET_FEATURES);
println!(
" ENABLE_FLAGS: {}",
X64V3Token::ENABLE_TARGET_FEATURES
);
println!(
" DISABLE_FLAGS: {}",
X64V3Token::DISABLE_TARGET_FEATURES
);
println!();
println!("=== End of counterexample ===");
println!("In real code: always use summon(), never forge.");
}