Appearance
Go: slice expressions xs[a:]
Status: accepted · Date: 2026-12-03
Step 4 of the Go plan lists slice expressions xs[a:b] as the next slice item. This record says which of them the proved path accepts, and why the others wait.
The decision
xs[a:]andxs[:]on a slice are on the proved path. The output isGo.sliceFrom xs a, which isList.drop, after the testGo.sliceFromFault xs a: Go panics withslice bounds out of range [a:n], or[a:]for a negativea, unless0 ≤ a ≤ len(xs). Go makes the test after it evaluatesxsanda, and the translation places it among the other checks in that order.- The interpreter gains the same rule (
Eval.sliceFromVal), andtranslate_soundcovers it (sliceFrom_outcome). - The result shares the array of
xs. The ownership check (Owned) already treatsxs[a:]as a read that lets the array escape, so a local that the function changes withappendorxs[i] = ecannot be sliced, and a slice made byxs[a:]cannot be changed. The one exception isxs[a:][i], which reads an element and keeps nothing: it counts as a read of an element, likexs[i].
Refused
- A high bound, as in
xs[a:b]andxs[:b]. Go acceptsbup to the capacity ofxs, not its length, soxs[:b]can show elements pastlen(xs). The list model has no capacity, so it cannot give these elements or the right panic. It needs a slice value that records the capacity and the array, which is larger than one step. - Three-index expressions
xs[a:b:c], for the same reason. - Slice expressions on strings, such as
s[1:]: they need byte offsets checked against UTF-8, a separate step. appendto a slice made byxs[a:], or toxs[a:]itself, andxs[i] = eon either: the two share an array, so the list model would not be exact.for … range xs[a:]directly:rangetakes a local or a parameter, so the corpus writesys := xs[a:]first.- A call that may panic as the argument of
len, as before.
Checks
tests/go/Slices.lean runs both sides on xs[a:], xs[:], a low bound at the length, both panics, a divisor inside the bound, a function that returns xs[a:], and xs[a:][i] on an owned local, and checks each refusal. The corpus package slices gains Rest. The differential generator writes xs[a:][i] and xs[:][i] with literal and computed bounds.
This page is docs/decisions/2026-12-03-go-slice-from.md at commit 5f1d031.
