Commit 3179cfc
committed
feat!: add opt-in interior mutability via a
Shared `Variable` and `Array` declarations were reachable through many
`Literal::Variable` references but could not be edited, since `Arc<T>`
hands out no `&mut`. Adding/removing variables and constraints already
worked (those are plain `Vec`s the caller owns); mutating the interior of
a shared declaration did not, which is what a presolve or rewriting pass
needs.
Every public generic type now carries a trailing `Ref` parameter,
defaulted to `Immutable`:
helpers::Immutable -> Of<T> = Arc<T> (today's behaviour)
helpers::Mutable -> Of<T> = Arc<RwLock<T>>
let fzn: FlatZinc<String, Mutable> = FlatZinc::from_fzn(rdr)?;
var.write().unwrap().ty = Type::Int(Some(RangeList::from(0..=1)));
A defaulted type parameter is the only opt-in that stays source
compatible; a cargo feature would be unification-unsafe for a published
library, silently changing the public API when two dependents disagree.
`Mutable::Of<T>` is just `Arc<RwLock<T>>`, so edits go through the normal
lock API and no `with_mut` helper is needed. `ArcKey` and `cloned_key`
are untouched: `ArcKey<T>` is generic over `T` and already serves both
markers as `ArcKey<RwLock<Variable<..>>>`.
BREAKING CHANGE: `NamedRef::name` returns `Cow<'_, str>` rather than
`&str`; the name lives behind a lock under `Mutable`, so no borrow can
escape. `Cow` derefs to `str`, so most call sites are unaffected.
BREAKING CHANGE: `Argument`'s parameters are now `<Identifier, Ref, L>`.
`L` defaults to `Literal<Identifier, Ref>`, and a default cannot forward
-reference a later parameter, so `Ref` has to precede `L` here even
though it trails on the other eleven types.
BREAKING CHANGE: the `From<Arc<..>> for NamedRef` conversions are now
implemented per marker rather than generically. An associated type is
opaque, so the compiler cannot rule out `Ref::Of<Array<..>>` and
`Ref::Of<Variable<..>>` naming the same type, and the generic impls
overlap. Generic code should construct the variants directly.
Corpus fixtures are unchanged: `Immutable` is the default and its `Debug`
and `Display` output forwards exactly as `Arc` did. The `Mutable`
deadlock hazard — `NamedRef`'s `Hash`, `Ord`, and `PartialEq` take a read
lock to reach the name — is documented on both types.Ref type parameter1 parent 5212855 commit 3179cfc
6 files changed
Lines changed: 706 additions & 202 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
231 | 232 | | |
232 | 233 | | |
233 | 234 | | |
234 | | - | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
235 | 238 | | |
236 | 239 | | |
237 | 240 | | |
| |||
241 | 244 | | |
242 | 245 | | |
243 | 246 | | |
244 | | - | |
| 247 | + | |
245 | 248 | | |
246 | 249 | | |
247 | | - | |
| 250 | + | |
248 | 251 | | |
249 | 252 | | |
250 | 253 | | |
| |||
608 | 611 | | |
609 | 612 | | |
610 | 613 | | |
| 614 | + | |
611 | 615 | | |
612 | 616 | | |
613 | 617 | | |
| |||
811 | 815 | | |
812 | 816 | | |
813 | 817 | | |
814 | | - | |
| 818 | + | |
815 | 819 | | |
816 | 820 | | |
817 | 821 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
5 | 7 | | |
6 | 8 | | |
7 | | - | |
| 9 | + | |
8 | 10 | | |
9 | 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 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
10 | 138 | | |
11 | 139 | | |
12 | 140 | | |
| |||
47 | 175 | | |
48 | 176 | | |
49 | 177 | | |
50 | | - | |
| 178 | + | |
51 | 179 | | |
52 | 180 | | |
53 | 181 | | |
54 | 182 | | |
55 | 183 | | |
56 | | - | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
57 | 187 | | |
58 | 188 | | |
59 | 189 | | |
| |||
0 commit comments