pub struct CompileContext { /* private fields */ }Expand description
The main compilation context. Orchestrates the full pipeline: BlockGraph -> Bloq.
Compiled circuit templates live in the context’s cache shard, which
new keeps private and
with_shared_cache shares with other contexts —
see SharedCompileCache.
Implementations§
Source§impl CompileContext
impl CompileContext
Sourcepub fn new(config: CompileConfig) -> Self
pub fn new(config: CompileConfig) -> Self
Creates a context with a private template cache. Templates it compiles are reused by its own later compilations and by nothing else.
Creates a context backed by cache, so it reuses (and contributes)
templates compiled by every other context sharing that cache at this
CompileConfig. Contexts sharing a cache may compile concurrently.
Sharing does not change compiled output: see SharedCompileCache.
Sourcepub fn config(&self) -> CompileConfig
pub fn config(&self) -> CompileConfig
The configuration this context compiles at.
Front ends that display or re-derive a context’s settings read them
here instead of keeping their own copy of what was passed to
new.
Sourcepub fn with_progress_observer(
self,
observer: impl Fn(CompileStage) + Send + Sync + 'static,
) -> Self
pub fn with_progress_observer( self, observer: impl Fn(CompileStage) + Send + Sync + 'static, ) -> Self
Observe stage starts for compilations made with this context. The default context emits no events. Retries may repeat stages; these events are not a completion fraction. The callback runs synchronously and should stay cheap. Concurrent calls on one context may interleave.
Sourcepub fn with_cancellation(self, token: CancellationToken) -> Self
pub fn with_cancellation(self, token: CancellationToken) -> Self
Makes this context’s compilations cooperatively cancellable.
Cancellation is scoped to this context’s request, including native module workers. Checks occur at stage, template, and normalization boundaries; no partial artifact is returned. Cached complete templates remain reusable. Use a new token for a later request.
Sourcepub fn summarize(
&self,
program: &BlockGraph,
limits: ModuleCertificationLimits,
) -> Result<Arc<ModuleSummary>, ModuleCertificationError>
pub fn summarize( &self, program: &BlockGraph, limits: ModuleCertificationLimits, ) -> Result<Arc<ModuleSummary>, ModuleCertificationError>
Certifies and summarizes a module hierarchy, reusing this context’s logical cache independently of physical compile configuration.
§Errors
Returns module validation, resource-limit, or certification errors.
Sourcepub fn summarize_with_jobs(
&self,
program: &BlockGraph,
limits: ModuleCertificationLimits,
jobs: NonZeroUsize,
) -> Result<Arc<ModuleSummary>, ModuleCertificationError>
pub fn summarize_with_jobs( &self, program: &BlockGraph, limits: ModuleCertificationLimits, jobs: NonZeroUsize, ) -> Result<Arc<ModuleSummary>, ModuleCertificationError>
Sourcepub fn compile_object(
&self,
program: &BlockGraph,
) -> Result<CompiledObject, CompileError>
pub fn compile_object( &self, program: &BlockGraph, ) -> Result<CompiledObject, CompileError>
Compile a target-specific block-graph object for repeated linking. Both fixed and symbolic inputs cache their finished IR. Exact definition variants remain reusable across different root programs.
§Errors
Returns CompileError when module validation, certification, or
lowering fails.
Sourcepub fn link_object(
&self,
object: &CompiledObject,
) -> Result<CompileArtifacts, CompileError>
pub fn link_object( &self, object: &CompiledObject, ) -> Result<CompileArtifacts, CompileError>
Link a compiled object to an independently editable Bloq snapshot.
§Errors
Returns a target mismatch. Compilation errors are reported when building the object.
Sourcepub fn compile_and_validate(
&self,
graph: &BlockGraph,
) -> Result<CompileArtifacts, CompileError>
pub fn compile_and_validate( &self, graph: &BlockGraph, ) -> Result<CompileArtifacts, CompileError>
Compile graph, then explicitly audit the resulting Bloq IR.
The audit inherits this context’s Boolean limits; its other resource
limits retain the IR validator’s defaults.
§Errors
Returns a compilation or full IR validation error.
§Examples
use bloq_compile::{CompileConfig, CompileContext};
use bloq_graph::GalleryItem;
let context = CompileContext::new(CompileConfig::default());
let artifacts = context.compile_and_validate(&GalleryItem::CNOT.build())?;
assert!(artifacts.bloq.quantum_node_count() > 0);Sourcepub fn compile(
&self,
graph: &BlockGraph,
) -> Result<CompileArtifacts, CompileError>
pub fn compile( &self, graph: &BlockGraph, ) -> Result<CompileArtifacts, CompileError>
Compile a block graph, including its module hierarchy, into Bloq IR.
Takes &self: the template cache is internally synchronized, so
contexts sharing a SharedCompileCache may
compile concurrently from &-borrows.
§Errors
Any structural, per-block, or lowering failure graph provokes under
this context’s CompileConfig.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for CompileContext
impl !UnwindSafe for CompileContext
impl Freeze for CompileContext
impl Send for CompileContext
impl Sync for CompileContext
impl Unpin for CompileContext
impl UnsafeUnpin for CompileContext
Blanket Implementations§
§impl<T, BorrowedSelf> BitwiseMutViaBorrow<BorrowedSelf> for T
impl<T, BorrowedSelf> BitwiseMutViaBorrow<BorrowedSelf> for T
fn assign_index(&mut self, index: usize, to: bool)
fn negate_index(&mut self, index: usize)
fn clear_bits(&mut self)
fn assign_random(
&mut self,
bit_count: usize,
random_number_generator: &mut impl RngExt,
)where
BorrowedSelf: BitLength,
§impl<Bits, Other, BorrowedSelf, BorrowedOther> BitwisePairMutViaBorrow<Other, BorrowedSelf, BorrowedOther> for Bits
impl<Bits, Other, BorrowedSelf, BorrowedOther> BitwisePairMutViaBorrow<Other, BorrowedSelf, BorrowedOther> for Bits
fn assign(&mut self, other: &Other)
fn bitxor_assign(&mut self, other: &Other)
fn bitand_assign(&mut self, other: &Other)
fn bitor_assign(&mut self, other: &Other)
§impl<T, Other, BorrowedSelf, BorrowedOther> BitwisePairViaBorrow<Other, BorrowedSelf, BorrowedOther> for T
impl<T, Other, BorrowedSelf, BorrowedOther> BitwisePairViaBorrow<Other, BorrowedSelf, BorrowedOther> for T
§impl<T, BorrowedSelf> BitwiseViaBorrow<BorrowedSelf> for T
impl<T, BorrowedSelf> BitwiseViaBorrow<BorrowedSelf> for T
fn index(&self, index: usize) -> bool
fn weight(&self) -> usize
fn parity(&self) -> bool
fn is_zero(&self) -> bool
fn is_unit(&self, index: usize) -> bool
fn support<'a>(&'a self) -> impl SortedIteratorwhere
BorrowedSelf: 'a,
fn max_support(&self) -> Option<usize>
fn min_support(&self) -> Option<usize>
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<'src, T> IntoMaybe<'src, T> for Twhere
T: 'src,
impl<'src, T> IntoMaybe<'src, T> for Twhere
T: 'src,
§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling [Attribute] value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi [Quirk] value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the [Condition] value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);