1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//! Batch execution on a rayon thread pool.
//!
//! Enabled by the `parallel` feature. Job results are merged by the engine in
//! input order, so runs stay deterministic despite parallel execution.
use crateCancelToken;
use crateExecutor;
use crateJob;
use crateOutcome;
/// An [`Executor`] that runs a round's job batch on a rayon thread pool.
///
/// Useful for batch compilation workloads where intra-round parallelism pays
/// off. Cancellation is checked before each job starts; jobs already in
/// flight are allowed to finish, but their results past the first cancelled
/// slot are discarded and the affected nodes simply remain pending for the
/// next run.
///
/// For LSP-style interactive use, prefer [`SerialExecutor`] on a background
/// thread with a [`CancelToken`] — the responsiveness comes from cancelling
/// between batches, not from intra-round parallelism.
///
/// # Examples
///
/// ```
/// use increparse::{CancelToken, Engine, Outcome, ParseTree, Pass, RayonExecutor, Schedule, Span, Status};
///
/// struct MarkDone;
/// impl Pass for MarkDone {
/// type Ctx = ();
/// fn parse(&self, _source: &str, _span: Span, _ctx: &()) -> Outcome<()> {
/// Outcome::Done
/// }
/// }
///
/// # fn main() {
/// let mut schedule = Schedule::new();
/// schedule.push(MarkDone);
///
/// let engine = Engine::new(schedule);
/// let mut tree = ParseTree::new(0, Span::new(0, 3, 0), ());
/// let report = engine.run("abc", &mut tree, &RayonExecutor, &CancelToken::new());
///
/// assert!(report.reached_fixpoint);
/// assert_eq!(tree.status(tree.root()), Status::Done);
/// # }
/// ```
;