@@ -132,26 +132,22 @@ manpages, and SDKs — never a runtime dependency of somebody else's program. |
132 | 132 | a different file, silently. Costs +656 instructions (1.6%) and one allocation, which |
133 | 133 | is what not corrupting a value is worth. It also retired the hazard of recognising |
134 | 134 | `String` by its spelling, since there is no identity case left. |
135 | | -- [x] **Accepting a value that is not valid UTF-8** — reporting it was the safe half; |
136 | | - accepting it is the whole fix, because the operating system does accept `/tmp/\xff` as a |
137 | | - filename and a CLI that cannot receive one cannot open the file. A `PathBuf` or |
138 | | - `OsString` field takes the bytes exactly, through `usage_argv::os_string_from_bytes`. |
139 | | - |
140 | | - **And with no `unsafe` anywhere.** On Unix an `OsString` is an arbitrary byte sequence, |
141 | | - so this is the safe `OsString::from_vec` and every byte survives — which is the case that |
142 | | - matters, since non-UTF-8 filenames are ordinary there. Windows was going to need |
143 | | - `from_encoded_bytes_unchecked`, and jdx approved that, but a *safe* function taking a |
144 | | - `Vec<u8>` cannot enforce its precondition: there is no way to know the bytes came from |
145 | | - `as_encoded_bytes` rather than from anywhere else, and a safe function whose precondition |
146 | | - a caller can violate is unsound however carefully today's callers behave. Greptile flagged |
147 | | - exactly that on #844. So Windows goes through UTF-8 and reports what will not convert, |
148 | | - which gives up only an unpaired-surrogate argument there. |
149 | | - |
150 | | - Cheaper than the text path, not dearer: a `PathBuf` field costs **553 instructions per |
151 | | - parse against a `String` field's 674**, since it skips the UTF-8 validation pass, and both |
152 | | - allocate once. The gate fixture cannot show this — a spec carries no Rust types, so every |
153 | | - shadow field is a `String` — which is why it is measured directly. |
154 | | - |
| 135 | +- [x] **Accepting a value that is not valid UTF-8** — reporting it was the safe half; accepting |
| 136 | + it is the whole fix, because the operating system does accept `/tmp/\xff` as a filename and a |
| 137 | + CLI that cannot receive one cannot open the file. A `PathBuf` or `OsString` field takes the |
| 138 | + bytes exactly, through `usage_argv::os_string_from_bytes`. **And with no `unsafe` anywhere.** On |
| 139 | + Unix an `OsString` is an arbitrary byte sequence, so this is the safe `OsString::from_vec` and |
| 140 | + every byte survives — which is the case that matters, since non-UTF-8 filenames are ordinary |
| 141 | + there. Windows was going to need `from_encoded_bytes_unchecked`, and jdx approved that, but a |
| 142 | + _safe_ function taking a `Vec<u8>` cannot enforce its precondition: there is no way to know the |
| 143 | + bytes came from `as_encoded_bytes` rather than from anywhere else, and a safe function whose |
| 144 | + precondition a caller can violate is unsound however carefully today's callers behave. Greptile |
| 145 | + flagged exactly that on #844. So Windows goes through UTF-8 and reports what will not convert, |
| 146 | + which gives up only an unpaired-surrogate argument there. Cheaper than the text path, not |
| 147 | + dearer: a `PathBuf` field costs **553 instructions per parse against a `String` field's 674**, |
| 148 | + since it skips the UTF-8 validation pass, and both allocate once. The gate fixture cannot show |
| 149 | + this — a spec carries no Rust types, so every shadow field is a `String` — which is why it is |
| 150 | + measured directly. |
155 | 151 | - [ ] **`usage-derive` v1** — everything mise needs: constraints |
156 | 152 | (`requires`/`conflicts`/`overrides`/`required_unless`), `var`, `count`, |
157 | 153 | `env`, defaults, delimiters, the `double_dash` modes, global flags, flatten, |
@@ -201,40 +197,30 @@ carrying them rather than being worked around. |
201 | 197 | that they reach the KDL and that binding is unaffected. `default_subcommand` is |
202 | 198 | checked at compile time to require a subcommand field, since it names one. |
203 | 199 | - [x] **Routing on `default_subcommand`** — the parser reads it now, rather than the property |
204 | | - being emitted and ignored. A word naming no subcommand descends into the named command |
205 | | - and is examined again there, so it can be that command's argument or one of _its_ |
206 | | - subcommands. The declaring command's own positional does not win, which is what makes |
207 | | - the property more than a synonym for an argument — and is mise's shape exactly. Taken at |
208 | | - most once per parse, so a chain of defaults cannot walk a CLI deeper than the user typed. |
209 | | - |
210 | | - No measurable cost: 40,370 instructions against 40,472 before, the branch being reached |
211 | | - only by a word that matched no subcommand. The ±100 is code layout rather than work — |
212 | | - cachegrind is deterministic, and gave the same figure twice. Allocations unchanged: 0 |
213 | | - bare, 4 bound. |
214 | | - |
215 | | - Only a *word* routes: a dash-prefixed token naming no flag arrives as a value and was |
216 | | - never a candidate to select anything, so it binds where it was typed — as usage-lib does, |
217 | | - which stops looking for subcommands at an unrecognised flag. The name may also be an |
218 | | - alias, since usage-lib resolves it against names, aliases and hidden aliases alike. |
219 | | - |
220 | | - The name is resolved by `find_subcommand` during **const evaluation**, so a |
221 | | - `default_subcommand` that no subcommand answers to is a compile error. That retires the |
222 | | - claim in the entry above that the name could not be checked: the variants are indeed |
223 | | - another expansion, but a `const fn` can search the list the parent already holds. |
224 | | - |
225 | | - **What it does not buy on its own:** `mise build` still does not work end to end in the |
226 | | - shadow, because mise's spec gives `run` no positional at all — `src/cli/usage.rs` clears |
227 | | - them and adds `mount run="mise tasks --usage"`, so task names are meant to come from |
228 | | - running that. usage-argv does not execute mounts. Routing *plus* mounts is what would let |
229 | | - mise delete its hand-rolled dispatch; routing alone is half of it. |
230 | | - |
231 | | - One divergence recorded (`default-is-declared-for-the-root`): usage-lib holds the single |
232 | | - name for the whole spec and applies it at whichever command it is standing on, so |
233 | | - `ex config zzz` descends into `config ls` when an unrelated `config` happens to have an |
234 | | - `ls`. Read here as a property of the root, which is the only place it can be declared. |
235 | | - **Worth a decision** — it looks accidental rather than intended, and if you agree it is a |
236 | | - small fix in usage-lib. |
237 | | - |
| 200 | + being emitted and ignored. A word naming no subcommand descends into the named command and is |
| 201 | + examined again there, so it can be that command's argument or one of _its_ subcommands. The |
| 202 | + declaring command's own positional does not win, which is what makes the property more than a |
| 203 | + synonym for an argument — and is mise's shape exactly. Taken at most once per parse, so a chain |
| 204 | + of defaults cannot walk a CLI deeper than the user typed. No measurable cost: 40,370 |
| 205 | + instructions against 40,472 before, the branch being reached only by a word that matched no |
| 206 | + subcommand. The ±100 is code layout rather than work — cachegrind is deterministic, and gave the |
| 207 | + same figure twice. Allocations unchanged: 0 bare, 4 bound. Only a _word_ routes: a dash-prefixed |
| 208 | + token naming no flag arrives as a value and was never a candidate to select anything, so it |
| 209 | + binds where it was typed — as usage-lib does, which stops looking for subcommands at an |
| 210 | + unrecognised flag. The name may also be an alias, since usage-lib resolves it against names, |
| 211 | + aliases and hidden aliases alike. The name is resolved by `find_subcommand` during **const |
| 212 | + evaluation**, so a `default_subcommand` that no subcommand answers to is a compile error. That |
| 213 | + retires the claim in the entry above that the name could not be checked: the variants are indeed |
| 214 | + another expansion, but a `const fn` can search the list the parent already holds. **What it does |
| 215 | + not buy on its own:** `mise build` still does not work end to end in the shadow, because mise's |
| 216 | + spec gives `run` no positional at all — `src/cli/usage.rs` clears them and adds `mount run="mise |
| 217 | +tasks --usage"`, so task names are meant to come from running that. usage-argv does not execute |
| 218 | + mounts. Routing _plus_ mounts is what would let mise delete its hand-rolled dispatch; routing |
| 219 | + alone is half of it. One divergence found and then **fixed in usage-lib** rather than recorded: |
| 220 | + it applied the single declared name at whichever command it was standing on, so `ex config zzz` |
| 221 | + descended into `config ls` when an unrelated `config` happened to have an `ls`. A spec declares |
| 222 | + one name, once, at the top. The corpus vector that recorded the difference is now an ordinary |
| 223 | + agreeing vector — the reference test refused to let the label stay, which is what it is for. |
238 | 224 | - [ ] **A mount on the root command** — the spec accepts `mount` only inside a |
239 | 225 | `cmd` block, so a CLI whose _top-level_ subcommands are discovered by running |
240 | 226 | something cannot say so. Worth deciding whether that is a gap or a deliberate |
|