Wave icon indicating copy to clipboard operation
Wave copied to clipboard

Reconcile writable str indexing with readonly string-literal storage

Open LunaStev opened this issue 3 weeks ago • 0 comments

Problem

Writing through a str initialized from a literal is accepted, although the generated literal has readonly LLVM storage. The same accepted source crashes or silently loses its write depending on optimization.

Reproduction and evidence

Audited canonical master 69a67c6e0fb700f37ee6114f5a66d37ee13771a5 (0.0.1-alpha-dev). Matching checkout-built compiler/std were used for compiler probes on Linux amd64 with Rust 1.89.0 and LLVM 21.1.8. Artifact inspection, mocked/projection checks and foreign-target object emission are identified below and are not native execution on those operating systems.

fun main()->i32{var a:str="abc"; a[0]=65;return 0;}
target/debug/wavec --std-root "$PWD/std" build repro.wave -O0 --run --out-dir out-O0
target/debug/wavec --std-root "$PWD/std" build repro.wave -O2 --run --out-dir out-O2

Linux amd64: check/build succeed, O0 execution terminates with SIGSEGV, and O2 exits 0 with the store eliminated. This is generated Wave code, not a Rust std/compiler vulnerability.

Scope

Decide how readonly literal provenance and writable buffer-backed str values are represented. Preserve working mutable-buffer use cases.

Starting points: llvm/src/expression/rvalue/literals.rs:125, front/parser/src/verification/expression.rs:440.

Design discussion required

Recommended: track readonly provenance and reject writes to literal-backed storage while allowing mutable buffers. Alternatives include an explicit mutable string/buffer type or owned-copy semantics; copying introduces allocation/lifetime decisions. Do not simply ban every str write without a compatibility decision.

Please mention @LunaStev to discuss the design before starting implementation.

Completion criteria

  • [ ] Approved readonly writes are diagnosed or handled consistently before undefined behavior.
  • [ ] Document and test literal-backed and mutable-buffer-backed strings, including aliases and casts.
  • [ ] O0/O2 have the same approved observable behavior.

Related: #1035, #879. Related broad trackers or completed implementations are context, not claims that their entire scope is unfinished.

LunaStev avatar Nov 12 '26 12:11 LunaStev