Skip to content

Paper cuts: Vec ranges as []T views, let-else return inference, usize Display, str.as_bytes (#1632 #1623 #1673 #1633 #1617 #1626) - #1702

Merged
ehartford merged 3 commits into
mainfrom
paper-cuts
Sep 26, 2026
Merged

ehartford merged 3 commits into
mainfrom
paper-cuts

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Fixes #1632, #1623, #1673, #1633; pins #1617 and #1626 (already fixed on main). #1587 (str ranges) is refused loudly with the existing spellings until the str-range view representation is ruled. No ownership/drop change; batches freely. Draft until the battery is posted.

Eric Hartford added 2 commits September 25, 2026 22:58
…'s type, usize/isize print, str.as_bytes() (#1632 #1623 #1673 #1633 #1617 #1626; #1587 refused loudly)

- check_slice returned 0 for a Vec base with no diagnostic, so `total(v[..])`
  reached MIR as a Unit operand (#1632). §4.8a: a slice is a view into any
  contiguous storage — a Vec range is `[]T`, a view of the Vec (D27), through
  a reference too. Codegen already sliced any struct base through field 0.
- A range of a str is refused with the spellings that exist (`s.slice(a, b)`,
  `s.as_bytes()[a..b]`): a `&str` points at the string object, so a
  sub-range has no view type yet (#1587 stays open for that ruling).
- body_return_type_info skipped a let-else's else, a binding's value, a
  `with` body and labeled/scoped blocks, so `fn main:` with `let Ok(x) = …
  else: return 1` inferred Unit and MIR's return local disagreed with the
  `return` (#1623).
- Display for usize and isize (#1673); str.as_bytes() as the §16.5 byte view
  (#1633) — spelled `(*self) as []u8`: `self as []u8` on a `&str` receiver
  casts the reference and reads garbage (filed separately).
- #1617 (static fn through an instance) and #1626 (`&Unit` cast chain) pass
  on main; pinned so they stay closed.

Verified on a stage1 of this tree: the six new tests pass and `check
src/main.w` is ok.
…s []u8` views the string, not the reference

- ComptimeValue gains CV_FLOAT with an f64 payload and the literal's own
  text. The evaluator reads a float literal (rounded once through strtod,
  correctly rounded, so a folded value equals the run-time one), negates,
  adds/subtracts/multiplies/divides with floats or ints, compares, and
  interpolates it; ComptimeTransform folds it back as the literal's text or
  17 significant digits, which LLVM rounds to the same double. §9.1b's
  `const PI = 3.14159` compiles; `const TAU = PI * 2.0` folds.
- lower_cast: a reference to a str/array/slice cast to a slice reads
  through the reference (§3.7). It cast the pointer's bytes as the string
  header (str.as_bytes() spelled `self as []u8` returned garbage).

Verified on a stage1 of this tree: behav_const_float.w and the extended
as_bytes test pass; `check src/main.w` ok.
…length; a C cast of the str struct is not a slice (found by emit-c-smoke once the prelude's str.as_bytes() existed)
@ehartford

Copy link
Copy Markdown
Contributor Author

Seed-driven battery at 9cf4b35 (seed nightly-20260925-local-1, WITH=src/main), this host:

9cf4b358 papercuts /Users/eric/.local/with-staging/papercuts
papercuts build  rc=0
papercuts build :fixpoint rc=0
papercuts build :test rc=0
papercuts build :test-green rc=0
papercuts build :last-green rc=0
papercuts build :user-programs-safe rc=0
BATTERY_DONE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Vec range slice v[..] as a call argument lowers to a Unit operand (invalid MIR before codegen)

1 participant