use crate::error::{
OwnedRuleAttemptStepError, OwnedRunStepError, RuleAttemptStepError, RunFinishError,
RunStepError,
};
use crate::inspect::RuleView;
use crate::limits::{RuleAttemptCount, StepCount};
use crate::program::{Program, ReturnOutput, RunResult};
use crate::trace::RuntimeStateView;
use super::attempt::{RuleAttemptStableReason, RuleMiss};
use super::engine::RunCore;
use super::session::{
BorrowedRuleAttemptSession, BorrowedRunSession, OwnedRuleAttemptSession, OwnedRunSession,
};
use super::witness::OwnedRuleWitness;
pub enum BorrowedStepTransition<'program> {
Applied(BorrowedAppliedStep<'program>),
Stable(BorrowedStableRun<'program>),
Returned(BorrowedReturnedRun<'program>),
Failed(BorrowedFailedRun<'program>),
}
pub struct BorrowedAppliedStep<'program> {
pub(super) step: StepCount,
pub(super) rule: RuleView<'program>,
pub(super) session: BorrowedRunSession<'program>,
}
pub struct BorrowedStableRun<'program> {
pub(super) steps: StepCount,
pub(super) program: &'program Program,
pub(super) core: RunCore,
}
pub struct BorrowedReturnedRun<'program> {
pub(super) step: StepCount,
pub(super) rule: RuleView<'program>,
pub(super) program: &'program Program,
pub(super) output: ReturnOutput,
}
pub struct BorrowedFailedRun<'program> {
pub(super) error: RunStepError,
pub(super) program: &'program Program,
pub(super) core: RunCore,
}
pub enum BorrowedRuleAttemptTransition<'program> {
Missed(BorrowedMissedRuleAttempt<'program>),
Applied(BorrowedRuleAttemptAppliedStep<'program>),
Stable(BorrowedRuleAttemptStableRun<'program>),
Returned(BorrowedRuleAttemptReturnedRun<'program>),
Failed(BorrowedRuleAttemptFailedRun<'program>),
}
pub struct BorrowedMissedRuleAttempt<'program> {
pub(super) attempt: RuleAttemptCount,
pub(super) miss: RuleMiss<RuleView<'program>>,
pub(super) session: BorrowedRuleAttemptSession<'program>,
}
pub struct BorrowedRuleAttemptAppliedStep<'program> {
pub(super) attempt: RuleAttemptCount,
pub(super) step: StepCount,
pub(super) rule: RuleView<'program>,
pub(super) session: BorrowedRuleAttemptSession<'program>,
}
pub struct BorrowedRuleAttemptStableRun<'program> {
pub(super) attempts: RuleAttemptCount,
pub(super) steps: StepCount,
pub(super) stable_reason: RuleAttemptStableReason<RuleView<'program>>,
pub(super) program: &'program Program,
pub(super) core: RunCore,
}
pub struct BorrowedRuleAttemptReturnedRun<'program> {
pub(super) attempt: RuleAttemptCount,
pub(super) step: StepCount,
pub(super) rule: RuleView<'program>,
pub(super) program: &'program Program,
pub(super) output: ReturnOutput,
}
pub struct BorrowedRuleAttemptFailedRun<'program> {
pub(super) error: RuleAttemptStepError,
pub(super) attempts: RuleAttemptCount,
pub(super) program: &'program Program,
pub(super) core: RunCore,
}
pub enum OwnedStepTransition {
Applied(OwnedAppliedStep),
Stable(OwnedStableRun),
Returned(OwnedReturnedRun),
Failed(OwnedFailedRun),
}
pub struct OwnedAppliedStep {
pub(super) step: StepCount,
pub(super) rule: OwnedRuleWitness,
pub(super) session: OwnedRunSession,
}
pub struct OwnedStableRun {
pub(super) steps: StepCount,
pub(super) program: Program,
pub(super) core: RunCore,
}
pub struct OwnedReturnedRun {
pub(super) step: StepCount,
pub(super) rule: OwnedRuleWitness,
pub(super) program: Program,
pub(super) output: ReturnOutput,
}
pub struct OwnedFailedRun {
pub(super) error: OwnedRunStepError,
pub(super) program: Program,
pub(super) core: RunCore,
}
pub enum OwnedRuleAttemptTransition {
Missed(OwnedMissedRuleAttempt),
Applied(OwnedRuleAttemptAppliedStep),
Stable(OwnedRuleAttemptStableRun),
Returned(OwnedRuleAttemptReturnedRun),
Failed(OwnedRuleAttemptFailedRun),
}
pub struct OwnedMissedRuleAttempt {
pub(super) attempt: RuleAttemptCount,
pub(super) miss: RuleMiss<OwnedRuleWitness>,
pub(super) session: OwnedRuleAttemptSession,
}
pub struct OwnedRuleAttemptAppliedStep {
pub(super) attempt: RuleAttemptCount,
pub(super) step: StepCount,
pub(super) rule: OwnedRuleWitness,
pub(super) session: OwnedRuleAttemptSession,
}
pub struct OwnedRuleAttemptStableRun {
pub(super) attempts: RuleAttemptCount,
pub(super) steps: StepCount,
pub(super) stable_reason: RuleAttemptStableReason<OwnedRuleWitness>,
pub(super) program: Program,
pub(super) core: RunCore,
}
pub struct OwnedRuleAttemptReturnedRun {
pub(super) attempt: RuleAttemptCount,
pub(super) step: StepCount,
pub(super) rule: OwnedRuleWitness,
pub(super) program: Program,
pub(super) output: ReturnOutput,
}
pub struct OwnedRuleAttemptFailedRun {
pub(super) error: OwnedRuleAttemptStepError,
pub(super) attempts: RuleAttemptCount,
pub(super) program: Program,
pub(super) core: RunCore,
}
impl<'program> BorrowedAppliedStep<'program> {
#[must_use]
pub const fn step(&self) -> StepCount {
self.step
}
#[must_use]
pub const fn rule(&self) -> RuleView<'program> {
self.rule
}
#[must_use]
pub fn state(&self) -> RuntimeStateView<'_> {
self.session.state()
}
#[must_use]
pub fn into_session(self) -> BorrowedRunSession<'program> {
self.session
}
}
impl OwnedAppliedStep {
#[must_use]
pub const fn step(&self) -> StepCount {
self.step
}
#[must_use]
pub const fn rule(&self) -> &OwnedRuleWitness {
&self.rule
}
#[must_use]
pub fn state(&self) -> RuntimeStateView<'_> {
self.session.state()
}
#[must_use]
pub fn into_session(self) -> OwnedRunSession {
self.session
}
#[must_use]
pub fn into_parts(self) -> (StepCount, OwnedRuleWitness, OwnedRunSession) {
(self.step, self.rule, self.session)
}
}
impl<'program> BorrowedMissedRuleAttempt<'program> {
#[must_use]
pub const fn attempt(&self) -> RuleAttemptCount {
self.attempt
}
#[must_use]
pub const fn miss(&self) -> &RuleMiss<RuleView<'program>> {
&self.miss
}
#[must_use]
pub fn state(&self) -> RuntimeStateView<'_> {
self.session.state()
}
#[must_use]
pub fn into_session(self) -> BorrowedRuleAttemptSession<'program> {
self.session
}
}
impl OwnedMissedRuleAttempt {
#[must_use]
pub const fn attempt(&self) -> RuleAttemptCount {
self.attempt
}
#[must_use]
pub const fn miss(&self) -> &RuleMiss<OwnedRuleWitness> {
&self.miss
}
#[must_use]
pub fn state(&self) -> RuntimeStateView<'_> {
self.session.state()
}
#[must_use]
pub fn into_session(self) -> OwnedRuleAttemptSession {
self.session
}
#[must_use]
pub fn into_parts(
self,
) -> (
RuleAttemptCount,
RuleMiss<OwnedRuleWitness>,
OwnedRuleAttemptSession,
) {
(self.attempt, self.miss, self.session)
}
}
impl<'program> BorrowedRuleAttemptAppliedStep<'program> {
#[must_use]
pub const fn attempt(&self) -> RuleAttemptCount {
self.attempt
}
#[must_use]
pub const fn step(&self) -> StepCount {
self.step
}
#[must_use]
pub const fn rule(&self) -> RuleView<'program> {
self.rule
}
#[must_use]
pub fn state(&self) -> RuntimeStateView<'_> {
self.session.state()
}
#[must_use]
pub fn into_session(self) -> BorrowedRuleAttemptSession<'program> {
self.session
}
}
impl OwnedRuleAttemptAppliedStep {
#[must_use]
pub const fn attempt(&self) -> RuleAttemptCount {
self.attempt
}
#[must_use]
pub const fn step(&self) -> StepCount {
self.step
}
#[must_use]
pub const fn rule(&self) -> &OwnedRuleWitness {
&self.rule
}
#[must_use]
pub fn state(&self) -> RuntimeStateView<'_> {
self.session.state()
}
#[must_use]
pub fn into_session(self) -> OwnedRuleAttemptSession {
self.session
}
#[must_use]
pub fn into_parts(
self,
) -> (
RuleAttemptCount,
StepCount,
OwnedRuleWitness,
OwnedRuleAttemptSession,
) {
(self.attempt, self.step, self.rule, self.session)
}
}
impl<'program> BorrowedStableRun<'program> {
#[must_use]
pub const fn steps(&self) -> StepCount {
self.steps
}
#[must_use]
pub const fn program(&self) -> &'program Program {
self.program
}
#[must_use]
pub fn state(&self) -> RuntimeStateView<'_> {
self.core.state()
}
pub fn into_result(self) -> Result<RunResult, RunFinishError> {
self.core.into_stable_result(self.steps)
}
}
impl OwnedStableRun {
#[must_use]
pub const fn steps(&self) -> StepCount {
self.steps
}
#[must_use]
pub const fn program(&self) -> &Program {
&self.program
}
#[must_use]
pub fn into_program(self) -> Program {
self.program
}
#[must_use]
pub fn state(&self) -> RuntimeStateView<'_> {
self.core.state()
}
pub fn into_result(self) -> Result<RunResult, RunFinishError> {
self.core.into_stable_result(self.steps)
}
}
impl<'program> BorrowedRuleAttemptStableRun<'program> {
#[must_use]
pub const fn attempts(&self) -> RuleAttemptCount {
self.attempts
}
#[must_use]
pub const fn steps(&self) -> StepCount {
self.steps
}
#[must_use]
pub const fn stable_reason(&self) -> &RuleAttemptStableReason<RuleView<'program>> {
&self.stable_reason
}
#[must_use]
pub const fn program(&self) -> &'program Program {
self.program
}
#[must_use]
pub fn state(&self) -> RuntimeStateView<'_> {
self.core.state()
}
pub fn into_result(self) -> Result<RunResult, RunFinishError> {
self.core.into_stable_result(self.steps)
}
}
impl OwnedRuleAttemptStableRun {
#[must_use]
pub const fn attempts(&self) -> RuleAttemptCount {
self.attempts
}
#[must_use]
pub const fn steps(&self) -> StepCount {
self.steps
}
#[must_use]
pub const fn stable_reason(&self) -> &RuleAttemptStableReason<OwnedRuleWitness> {
&self.stable_reason
}
#[must_use]
pub const fn program(&self) -> &Program {
&self.program
}
#[must_use]
pub fn into_program(self) -> Program {
self.program
}
#[must_use]
pub fn state(&self) -> RuntimeStateView<'_> {
self.core.state()
}
pub fn into_result(self) -> Result<RunResult, RunFinishError> {
self.core.into_stable_result(self.steps)
}
}
impl<'program> BorrowedReturnedRun<'program> {
#[must_use]
pub const fn step(&self) -> StepCount {
self.step
}
#[must_use]
pub const fn program(&self) -> &'program Program {
self.program
}
#[must_use]
pub const fn rule(&self) -> RuleView<'program> {
self.rule
}
#[must_use]
pub const fn output(&self) -> &ReturnOutput {
&self.output
}
#[must_use]
pub fn into_result(self) -> RunResult {
RunResult::from_return(self.output, self.step)
}
}
impl OwnedReturnedRun {
#[must_use]
pub const fn step(&self) -> StepCount {
self.step
}
#[must_use]
pub const fn program(&self) -> &Program {
&self.program
}
#[must_use]
pub const fn rule(&self) -> &OwnedRuleWitness {
&self.rule
}
#[must_use]
pub fn into_program(self) -> Program {
self.program
}
#[must_use]
pub const fn output(&self) -> &ReturnOutput {
&self.output
}
#[must_use]
pub fn into_result(self) -> RunResult {
RunResult::from_return(self.output, self.step)
}
}
impl<'program> BorrowedRuleAttemptReturnedRun<'program> {
#[must_use]
pub const fn attempt(&self) -> RuleAttemptCount {
self.attempt
}
#[must_use]
pub const fn step(&self) -> StepCount {
self.step
}
#[must_use]
pub const fn program(&self) -> &'program Program {
self.program
}
#[must_use]
pub const fn rule(&self) -> RuleView<'program> {
self.rule
}
#[must_use]
pub const fn output(&self) -> &ReturnOutput {
&self.output
}
#[must_use]
pub fn into_result(self) -> RunResult {
RunResult::from_return(self.output, self.step)
}
}
impl OwnedRuleAttemptReturnedRun {
#[must_use]
pub const fn attempt(&self) -> RuleAttemptCount {
self.attempt
}
#[must_use]
pub const fn step(&self) -> StepCount {
self.step
}
#[must_use]
pub const fn program(&self) -> &Program {
&self.program
}
#[must_use]
pub const fn rule(&self) -> &OwnedRuleWitness {
&self.rule
}
#[must_use]
pub fn into_program(self) -> Program {
self.program
}
#[must_use]
pub const fn output(&self) -> &ReturnOutput {
&self.output
}
#[must_use]
pub fn into_result(self) -> RunResult {
RunResult::from_return(self.output, self.step)
}
}
impl<'program> BorrowedFailedRun<'program> {
pub(super) fn new(error: RunStepError, program: &'program Program, core: RunCore) -> Self {
Self {
error,
program,
core,
}
}
#[must_use]
pub const fn error(&self) -> &RunStepError {
&self.error
}
#[must_use]
pub const fn completed_steps(&self) -> StepCount {
self.core.completed_steps()
}
#[must_use]
pub fn program(&self) -> &'program Program {
self.program
}
#[must_use]
pub fn state(&self) -> RuntimeStateView<'_> {
self.core.state()
}
#[must_use]
pub fn into_error(self) -> RunStepError {
self.error
}
}
impl core::fmt::Display for BorrowedFailedRun<'_> {
fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
self.error.fmt(formatter)
}
}
impl core::error::Error for BorrowedFailedRun<'_> {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
Some(&self.error)
}
}
impl<'program> BorrowedRuleAttemptFailedRun<'program> {
pub(super) fn new(
error: RuleAttemptStepError,
attempts: RuleAttemptCount,
program: &'program Program,
core: RunCore,
) -> Self {
Self {
error,
attempts,
program,
core,
}
}
#[must_use]
pub const fn error(&self) -> &RuleAttemptStepError {
&self.error
}
#[must_use]
pub const fn completed_attempts(&self) -> RuleAttemptCount {
self.attempts
}
#[must_use]
pub const fn completed_steps(&self) -> StepCount {
self.core.completed_steps()
}
#[must_use]
pub fn program(&self) -> &'program Program {
self.program
}
#[must_use]
pub fn state(&self) -> RuntimeStateView<'_> {
self.core.state()
}
#[must_use]
pub fn into_error(self) -> RuleAttemptStepError {
self.error
}
}
impl core::fmt::Display for BorrowedRuleAttemptFailedRun<'_> {
fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
self.error.fmt(formatter)
}
}
impl core::error::Error for BorrowedRuleAttemptFailedRun<'_> {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
Some(&self.error)
}
}
impl OwnedFailedRun {
pub(super) fn new(error: OwnedRunStepError, program: Program, core: RunCore) -> Self {
Self {
error,
program,
core,
}
}
#[must_use]
pub const fn error(&self) -> &OwnedRunStepError {
&self.error
}
#[must_use]
pub const fn completed_steps(&self) -> StepCount {
self.core.completed_steps()
}
#[must_use]
pub fn program(&self) -> &Program {
&self.program
}
#[must_use]
pub fn state(&self) -> RuntimeStateView<'_> {
self.core.state()
}
#[must_use]
pub fn into_error(self) -> OwnedRunStepError {
self.error
}
#[must_use]
pub fn into_program(self) -> Program {
self.program
}
#[must_use]
pub fn into_parts(self) -> (OwnedRunStepError, Program) {
(self.error, self.program)
}
}
impl OwnedRuleAttemptFailedRun {
pub(super) fn new(
error: OwnedRuleAttemptStepError,
attempts: RuleAttemptCount,
program: Program,
core: RunCore,
) -> Self {
Self {
error,
attempts,
program,
core,
}
}
#[must_use]
pub const fn error(&self) -> &OwnedRuleAttemptStepError {
&self.error
}
#[must_use]
pub const fn completed_attempts(&self) -> RuleAttemptCount {
self.attempts
}
#[must_use]
pub const fn completed_steps(&self) -> StepCount {
self.core.completed_steps()
}
#[must_use]
pub fn program(&self) -> &Program {
&self.program
}
#[must_use]
pub fn state(&self) -> RuntimeStateView<'_> {
self.core.state()
}
#[must_use]
pub fn into_error(self) -> OwnedRuleAttemptStepError {
self.error
}
#[must_use]
pub fn into_program(self) -> Program {
self.program
}
#[must_use]
pub fn into_parts(self) -> (OwnedRuleAttemptStepError, Program) {
(self.error, self.program)
}
}
impl core::fmt::Display for OwnedRuleAttemptFailedRun {
fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
self.error.fmt(formatter)
}
}
impl core::error::Error for OwnedRuleAttemptFailedRun {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
Some(&self.error)
}
}
impl core::fmt::Display for OwnedFailedRun {
fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
self.error.fmt(formatter)
}
}
impl core::error::Error for OwnedFailedRun {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
Some(&self.error)
}
}