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
//! Opaque state for stateful models (MLState, macOS 15+).
use ;
use Retained;
use MLState;
/// Opaque per-session state for a stateful model.
///
/// Created by [`Model::make_state`](crate::Model::make_state); mutated in
/// place by [`Model::predict_with_state`](crate::Model::predict_with_state).
///
/// # Concurrency
///
/// `State` is [`Send`] but deliberately **not** [`Sync`]: Apple requires
/// stateful predictions sharing an `MLState` to be serialized, and
/// [`Model::predict_with_state`](crate::Model::predict_with_state) enforces
/// that through `&mut State` exclusivity.
///
/// ```compile_fail
/// fn assert_sync<T: Sync>() {}
/// assert_sync::<coremlit::State>();
/// ```
// SAFETY: exclusive mutation is enforced via &mut in predict_with_state;
// ownership transfer across threads is sound. Every field here is already
// `Send`, so this impl documents the invariant explicitly rather than
// leaving it to auto-derivation.
unsafe