Files
metal2vulkan/validation/src/lib.rs
T
Anees Iqbal 08970cacd2 Consolidate translation, linkage, and validation work
Squash 147 commits (2026-08-20 through 2026-08-31) into one change on top
of the exact-kernel-grid work. Covers native lowering and pointer/layout
construction, AIR intrinsic and funnel-shift coverage, BDA address
preservation across aggregate calls, CFG structurization, function-constant
and visible-function specialization, the 30-second translation ceiling, the
authored-case corpus and linkage validation suite, and refreshed byte-exact
MoltenVK evidence.

The kernel-grid lowering in this tree supersedes the 324-line variant in
the parent commit; that file is reduced to its current 139-line form here.

Resulting tree is identical to 7174c7b. Prior history remains reachable at
tag pre-squash-backup and branch backup/pre-squash-7174c7b.

Claude-Session: https://claude.ai/code/session_01D1u4vU7Mr5QNWrnnRHC8iS
2026-08-31 09:03:42 +03:00

105 lines
2.7 KiB
Rust

//! Authored-case validation infrastructure for metal2vulkan.
//!
//! Harvesting, manifests, observations, and translation A/B are deliberately separate. Nothing in
//! this crate infers execution inputs or repairs a manifest.
pub mod ab;
pub mod air;
pub mod candidate;
pub mod case;
pub mod check;
pub mod executor_contract;
pub mod hash;
pub mod index;
pub mod jsonl;
pub mod library_module;
pub mod literal;
pub mod metal;
pub mod normalize;
pub mod observation;
pub mod observation_contract;
pub mod requirement;
pub mod review;
pub mod source;
pub mod store;
pub mod translation_audit;
pub mod triage;
use std::fs;
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicU64, Ordering};
static SCRATCH_COUNTER: AtomicU64 = AtomicU64::new(0);
pub struct ScratchDir {
path: PathBuf,
}
impl ScratchDir {
pub fn new(purpose: &str) -> Result<Self, String> {
let safe: String = purpose
.chars()
.map(|ch| {
if ch.is_ascii_alphanumeric() || matches!(ch, '-' | '_') {
ch
} else {
'_'
}
})
.collect();
loop {
let serial = SCRATCH_COUNTER.fetch_add(1, Ordering::Relaxed);
let path = std::env::temp_dir().join(format!(
"metal2vulkan-validation-{}-{serial}-{safe}",
std::process::id()
));
match fs::create_dir(&path) {
Ok(()) => return Ok(Self { path }),
Err(error) if error.kind() == std::io::ErrorKind::AlreadyExists => continue,
Err(error) => return Err(format!("create {}: {error}", path.display())),
}
}
}
pub fn path(&self) -> &Path {
&self.path
}
}
impl Drop for ScratchDir {
fn drop(&mut self) {
let _ = fs::remove_dir_all(&self.path);
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn scratch_directory_is_removed_on_drop() {
let path = {
let scratch = ScratchDir::new("cleanup-test").unwrap();
let path = scratch.path().to_path_buf();
fs::write(path.join("file"), b"temporary").unwrap();
path
};
assert!(!path.exists());
}
#[test]
fn scratch_directory_skips_a_stale_process_serial() {
let serial = SCRATCH_COUNTER.load(Ordering::Relaxed);
let stale = std::env::temp_dir().join(format!(
"metal2vulkan-validation-{}-{serial}-stale-serial-test",
std::process::id()
));
fs::create_dir(&stale).unwrap();
let scratch = ScratchDir::new("stale-serial-test").unwrap();
assert_ne!(scratch.path(), stale);
fs::remove_dir(&stale).unwrap();
}
}