use core::fmt::Debug;
use core::hash::Hash;
use super::{CompilationError, CompilationRecording};
use crate::id::KernelId;
use crate::kernel::CubeKernel;
use crate::logging::ServerLogger;
use crate::server::LaunchError;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ArtifactId<V> {
pub kernel: KernelId,
pub variant: V,
}
pub trait ArtifactCompiler: Sync {
type Variant: Clone + Eq + Hash + Debug + Send + Sync;
type Lowered: Send;
type Artifact: Send;
fn lower(
&self,
kernel: &dyn CubeKernel,
id: &ArtifactId<Self::Variant>,
recording: &mut CompilationRecording,
logger: &ServerLogger,
) -> Result<Self::Lowered, LaunchError>;
fn source(lowered: &Self::Lowered) -> Option<&str> {
let _ = lowered;
None
}
fn finalize(
&self,
id: &ArtifactId<Self::Variant>,
lowered: Self::Lowered,
) -> Result<Self::Artifact, LaunchError>;
}
pub type VariantOf<T> = <<T as CompilationTarget>::Compiler as ArtifactCompiler>::Variant;
pub type ArtifactOf<T> = <<T as CompilationTarget>::Compiler as ArtifactCompiler>::Artifact;
pub trait CompilationTarget {
type Compiler: ArtifactCompiler;
type Loaded: Clone;
fn compiler(&self) -> &Self::Compiler;
fn persists(&self) -> bool;
fn stored(&mut self, id: &ArtifactId<VariantOf<Self>>) -> Option<ArtifactOf<Self>>;
fn stored_for_source(&mut self, source: &str) -> Option<ArtifactOf<Self>> {
let _ = source;
None
}
fn load(
&mut self,
id: &ArtifactId<VariantOf<Self>>,
artifact: &ArtifactOf<Self>,
) -> Result<Self::Loaded, CompilationError>;
fn store(
&mut self,
id: &ArtifactId<VariantOf<Self>>,
artifact: ArtifactOf<Self>,
source: Option<&str>,
) -> bool;
}