Repository navigation
Description
Goal
Step 2 of #10546 (part of #10522): a Rust fn that returns Vec<T> and builds the result only by push / extend_from_slice converts in the out-buffer form, the move #9098 made for an owned String. The fn takes a last out: []T parameter and returns usize, the number of elements the Rust fn would have returned; the oracle checks the written prefix. A returned Vec that the fn also reads or changes in another way, a second Vec, or any other way of building the result stays refused, with a reason that says which.
Why this matters
The step-1 dogfood (#10648, five repositories at t27 7496ed2, trios 483dd9ee, trinity 0770abb9, trinity-fpga 20bf4c418, 999-multibots-telegraf 6e5512881) left type Vec the first refusal of 1,126 fns. 534 of them return a bare Vec<T>. Only a part of those build the result as a list that grows by push; the rest return a vec![..] literal, a collect(), a clone or a delegated call. The measure is in the PR, before and after, so the share of the 16 % that this form can reach is a number and not a guess.
Source of truth
specs/tools/t27o/rust_convert.t27: the subset header (the out-buffer form for an owned String, #9098), string_out_form and out_str_stmt as the model, vectors for the oracle; rust_std.t27 is not needed (a push is out[w] = e; w = w + 1).
Boundary
- specs/tools/t27o/rust_convert.t27
- gen/rust/tools/t27o/rust_convert.rs
- .trinity/seals/t27o_T27oRust.json
- Must not touch:
cli/tri/src/main.rs,spice_convert.t27,rust_std.t27, any ledger ordocs/reports/t27b_expectations.json.
User Scenarios
- Given
fn bits(x: u8) -> Vec<bool> { let mut v = Vec::new(); for i in 0..8 { v.push((x >> i) & 1 == 1); } v }, Whentri t27oconverts it, Then the spec hasfn bits(x: u8, out: []bool) -> usize, which writesout[w] = ewhilew < out.len, countswon past the end, and returns it, and the oracle asserts the count and every written element against what Rust returned, once with a 256-element buffer and once with a zero-length one. - Given a fn that also reads its Vec (
v.len(),v[0]), resizes it (insert,pop,sort), assigns into it, hands it on (&v,&mut v) or keeps a second Vec, When it is converted, Then it is refused with a reason that names the use, and never converted with a capacity the source does not state. - Given a fn that calls a fn converted in the out-buffer form, When it is converted, Then it is refused with a reason that names the call, because the caller would have to own an unbounded buffer.
Requirements
- FR-001: The converter MUST lower a fn whose result is
Vec<T>(T an integer, float or bool type) into the out-buffer form when the result is one local made byVec::new(),Vec::with_capacity(n)orvec![], changed only bypush(e)andextend_from_slice(s), and returned (return v, the tailv, or an emptyVec::new()/vec![]). - FR-002: The out-buffer form MUST NOT approximate a capacity: the capacity is the caller's, an element past
out.lenis counted and not written, and the result is the number of elements the Rust fn returns. - FR-003: The oracle MUST record the written prefix: the count, and every element of a result of at most 256 elements, once with a 256-element buffer and once with a zero-length buffer.
- FR-004: A returned Vec that the fn reads or changes beyond push / extend_from_slice, that is not the one local, or a second Vec local MUST be refused with a reason that names the use; a call of an out-buffer fn MUST be refused with a reason that names the call.
- FR-005: The change MUST add no hand-written Rust: the rule is the spec and
gen/rust/tools/t27o/rust_convert.rsis regenerated; the converter's tests MUST pass undert27b testwith 0 vacuous passes undert27c test-reportand coverage of every fn by a test at 100 %. - FR-006: The PR MUST report, on the same five repositories and commits, the count of fns that return
Vec<T>, how many convert, and the first-refusal counts of typeVecbefore and after, and no converted output may change except where a Vec result was involved.
Success Criteria
t27b test specs/tools/t27o/rust_convert.t27passes, andt27c test-reporton it reportsvacuous passes 0t27c coverage specs/tools/t27o/rust_convert.t27reports every fn covered (100 %)- 0 files go from a passing
--checkto a failing one on the replayed files - 0 net hand-written Rust lines added (the own-language gate prints nothing and exits 0)
Activity
t27o: a fn returning Vec<T> built by push converts in the out-buffer …
t27o: the oracle runs a Vec-result fn on a guarded thread -- 3 s and …
t27o: has_vecfn leaves the slot in HIT like named, so the generated R…
t27o: a fn returning Vec<T> built by push converts in the out-buffer …
t27o: the oracle runs a Vec-result fn on a guarded thread -- 3 s and …
t27o: has_vecfn leaves the slot in HIT like named, so the generated R…
t27o: re-save the seal of rust_convert.t27 after the rebase onto mast…
t27o: a list looped over whose element type is not told is refused na…