On this page

0039. Concatenation and interpolation produce str

Context

Print-only interpolation prevents returning, storing or passing built strings. M5.2's region analysis needs a real heap operation first. The agreed order is M5.1 → M5.3a → M5.2 → the remaining M5.3 features.

Decision

"x = {x}" produces str anywhere a string is expected. Parts are integers, bools or strings, using printing's decimal/bool/byte spellings. Currently the only integer is i64. Nested interpolation works. Retire E0311; invalid parts use E0309. str + str concatenates; mixed operands use E0301 with interpolation help. No implicit conversions. Evaluation remains left to right, including snapshotting an earlier mutable local before a later part assigns it.

Direct print arguments retain the allocation-free segment-write path, including output before a later segment traps. Value interpolation evaluates all parts before producing a string. Both backends consume Rvalue::Format { parts, region, pos } and Intrinsic::Concat { in_place } with args, region and pos. These extend ADR-0016 with allocating operations; format's location is the opening quote and concat's is +. IR version stays 1; absent additions print nothing. Program.arenas == 0 means no heap use; lowering tracks heap_used.

M5.3a places every allocation in Region::Ret, the single program-lifetime request arena (colour 0 from main), and emits HN_ARENAS 1. No scope analysis, resets or hidden call parameters yet. Region::{Unplaced, Ret, Scope(u32)} retains the planned placement boundary; verification rejects unplaced/dead scope regions. M5.2 replaces this bootstrap placement.

Strings use {data,len,cap}. cap == 0 denotes static bytes/a view; an owned buffer has a preceding used-length word. Concatenation appends only when in_place && cap != 0 && used == len && new_len <= cap; otherwise it allocates max(2*len, new_len, 8) and copies. Old snapshots remain valid. Format allocates a fresh buffer. The interpreter keeps literals interned and built strings in 24-byte Value handles to shared SeqViews, with a RefCell byte buffer and a dynamic tip check. Equality compares visible bytes across both forms.

Alternatives considered

Consequences

Existing goldens, direct-print C and non-heap emitted C remain byte-identical; only the obsolete interpolation-value diagnostic is replaced by a program. M5.2 supersedes the bootstrap request-only placement with scoped allocation and promotion. M5.3 extends + to bytes and adds views/text methods (ADR-0038), retaining the same tip/snapshot rule. Integer types and element APIs follow Lane B. No source ownership annotations or visible builders are added.