use std::cell::Cell;
use crate::fusion_pipeline::{FusionOptions, FusionTarget};
thread_local! {
static ACTIVE_TARGET: Cell<Option<FusionTarget>> = const { Cell::new(None) };
static ACTIVE_OPTS: Cell<Option<FusionOptions>> = const { Cell::new(None) };
}
pub fn active_fusion_target() -> Option<FusionTarget> {
ACTIVE_TARGET.with(|c| c.get())
}
pub fn active_fusion_options() -> Option<FusionOptions> {
ACTIVE_OPTS.with(|c| c.get())
}
pub fn with_fusion_target<T>(target: FusionTarget, f: impl FnOnce() -> T) -> T {
with_fusion_context(target, FusionOptions::default(), f)
}
pub fn with_fusion_context<T>(
target: FusionTarget,
opts: FusionOptions,
f: impl FnOnce() -> T,
) -> T {
ACTIVE_TARGET.with(|t| {
ACTIVE_OPTS.with(|o| {
let prev_t = t.get();
let prev_o = o.get();
t.set(Some(target));
o.set(Some(opts));
let out = f();
t.set(prev_t);
o.set(prev_o);
out
})
})
}