123. Mutable slice views (cpl::MutView<T>) via existing range-lending rules (2026-11-21)
- Decision. A range slice
xs[l..r](orxs[l..=r],a[D(l)..D(r)],cuts[c1..c2]) of a mutableList<T>or 1D[D]T(nominal, range, or cut domain) is an O(1) fixed-length mutable view (Ty::MutView<T>in IR,cpl::MutView<T>holdingT* ptr+size_t nin C++17,Value::MutViewholding(target: Part, lo, len)in the interpreter). It implementsIndexedMut(at,set_at,swap_idx) so every in-place sequence mutator (sort,reverse,rotate_left,rotate_right,scan_in_place,suffix_scan_in_place,shuffle,next_permutation,prev_permutation,nth_element,fill, element assignmentv[i] = x) works through one shared mechanism with zero copies and no per-method special cases. Length-changingListmethods (push,pop,clear,insert,remove,resize,extend, etc.) are rejected withE0401. - Lending. Reuses the existing lending rules (
cpl-check/src/check/lends.rs) with no core change of character: a slicelet v = xs[l..r]that is mutated (or passedmut) lendsmutoverStep::Slice(l..r)ofxsforv's live range, so any aliasing read or write ofxs(or an overlapping mutable slice) whilevis live is a compile error (E0602), while statically disjoint slices (xs[0..2]andxs[2..4]) both work. Read-only slices of immutable (let) bases orStrremain read-only (E0401on mutation).cpl explainreportsmutable slice view -> cpl::MutView<T> (T* + len), O(1), fixed-length mut lend. - Evidence. Interp/C++17 parity test
crates/cpl-cli/tests/programs/seq_mut_slice.cp(coveringList<Int>,[D]Int,[D.bounds]Int,[0..6]Int, nested and disjoint slices); checker compile-fail tests incrates/cpl-check/src/tests.rs(mutable_slice_views_lend_and_reject_aliasing);cpl explaintest incrates/cpl-cli/src/lib.rs; matched benchmarkbench/seq/slice_sort.cp(xs[l..r].sort()vsstd::sort(xs.data() + l, xs.data() + r)): 1.05x (213.9 ms vs 202.9 ms, 9,393 B emitted C++); port migrations:cf2207h3.cp(678 → 658 tokens, -20,gate.shPASS) andcf2207h1.cp(1,007 → 813 tokens, -194,gate.shPASS). Closesresearch/frictions/cf2207h3.md#1b. - Reverse. Restore
note_readonly_viewfor list/array slices incpl-check/src/check/expr.rs, removeTy::MutView/ExprKind::MutSlice/cpl::MutView, and revertcf2207h3.cp/cf2207h1.cp.