Skip to main content

logicaffeine_compile/concurrency/
mod.rs

1//! Concurrency determinacy model + classifier.
2//!
3//! This module is the single source of truth for the language's concurrency
4//! *memory model* and the *determinacy classifier* that labels a program as
5//! belonging to the determinate (Kahn-deterministic) or nondeterminate fragment.
6//! The classifier is consumed by AOT mode selection (Phase 8) and translation
7//! validation (Phase 11), so both agree on one boundary.
8
9pub mod bridge;
10pub mod channel;
11pub mod classify;
12pub mod driver;
13pub mod fec;
14pub mod marshal;
15pub mod model;
16pub(crate) mod net_inbox;
17pub mod pnp;
18pub mod send_check;
19pub mod stream;
20pub(crate) mod tcp_registry;
21pub mod vm_driver;
22
23use crate::ast::stmt::Stmt;
24
25/// Does the program use Go-like concurrency (channels / tasks / select) that must
26/// run on the scheduler-driven interpreter path?
27pub fn uses_scheduler(stmts: &[Stmt]) -> bool {
28    stmts.iter().any(stmt_uses_scheduler)
29}
30
31fn stmt_uses_scheduler(s: &Stmt) -> bool {
32    match s {
33        Stmt::LaunchTask { .. }
34        | Stmt::LaunchTaskWithHandle { .. }
35        | Stmt::CreatePipe { .. }
36        | Stmt::SendPipe { .. }
37        | Stmt::ReceivePipe { .. }
38        | Stmt::TrySendPipe { .. }
39        | Stmt::TryReceivePipe { .. }
40        | Stmt::Select { .. }
41        | Stmt::StopTask { .. } => true,
42        Stmt::If {
43            then_block,
44            else_block,
45            ..
46        } => {
47            then_block.iter().any(stmt_uses_scheduler)
48                || else_block.map_or(false, |b| b.iter().any(stmt_uses_scheduler))
49        }
50        Stmt::While { body, .. }
51        | Stmt::Repeat { body, .. }
52        | Stmt::Zone { body, .. }
53        | Stmt::FunctionDef { body, .. } => body.iter().any(stmt_uses_scheduler),
54        Stmt::Concurrent { tasks } | Stmt::Parallel { tasks } => {
55            tasks.iter().any(stmt_uses_scheduler)
56        }
57        Stmt::Inspect { arms, .. } => arms.iter().any(|a| a.body.iter().any(stmt_uses_scheduler)),
58        _ => false,
59    }
60}
61
62pub use classify::{branches_independent, branches_share_mutable_state, classify_program};
63pub use marshal::{materialize, rebuild, MarshalError};
64pub use model::{Determinacy, NondetKind, NondetWitness};
65pub use net_inbox::{net_is_offline, set_net_offline};
66pub use send_check::{check_send_escape, SendDiagnostic};