You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Spec §15.4.9 (D116, ruled 2026-10-09). The compiler accepts ++ only on str and has no ++=.
To implement:
a ++ b over any two of Vec, slice, fixed array, list literal with one element type gives Vec[T] ([T; N+M] where demanded); str ++ str stays str; str with a byte sequence is an error.
Operands are observed (D110); at an operand's last use its buffer is reused (D111's last-use facts), so xs = xs ++ more is an append.
Non-Copy elements: an operand not at its last use and not spelled move is an error with move / .clone() fix-its (§2.3).
a ++= b extends in place; v ++= [x] appends; the one-element literal needn't touch the heap (D113).
Tests: each result type, untouched operands, last-use reuse (allocation count under the debug allocator), the non-Copy error and its fix-its, ++=.
Implemented on branch d115-d120 (commit 43bbc50), for the next battery:
a ++ b over any two of a List, a slice, a fixed array and a list literal, one element type, gives List[T]; str ++ str stays str; a str beside a byte sequence is an error naming the rule. Lexer/parser: ++= (TK_PLUS_PLUS_EQ → OP_CONCAT, the compound-assignment table).
Operands are observed: elements append by bits; a str element is retained (D111: a copy is a count increment, with_vec_extend_str); elements that are not Copy move, so a List operand of them is consumed (a later use is the usual moved-value error) and a slice or array of them is refused.
a ++= b, and a = a ++ b spelled out, lower to LIST_EXTEND on the left operand's place (the buffer is reused; 200 appends of [i] cost the literal's allocation and ~9 growths, no new list per step).
A use's element demand reaches literal-typed operands (show(xs ++ ys) with let xs = [1, 2] makes both List[i32], D128).
Both backends (LLVM: LIST_CONCAT/LIST_EXTEND; C: with_vec_extend_bits_es/with_vec_extend_str/with_vec_take_into_es), debug allocator clean, each element dropped once.
Tests: test/behavior/behav_d116_concat_sequences.w, test/compile_errors/err_d116_{str_and_bytes,mixed_elements,moved_operand}.w.
Not done: a [T; N+M] result where a fixed array is demanded; the one-element literal still allocates (that is D119 step 2's guaranteed lowering). Writing the fixture exposed A typed list literal accepts elements of another type: let ys: List[i32] = ["a", "b"] and let zs: List[str] = [1, 2] pass check #2348 (a typed list literal accepts elements of another type).
Activity
ehartford commentedon Oct 11, 2026
Implemented on branch d115-d120 (commit 43bbc50), for the next battery:
a ++ bover any two of a List, a slice, a fixed array and a list literal, one element type, givesList[T];str ++ strstaysstr; astrbeside a byte sequence is an error naming the rule. Lexer/parser:++=(TK_PLUS_PLUS_EQ → OP_CONCAT, the compound-assignment table).strelement is retained (D111: a copy is a count increment,with_vec_extend_str); elements that are not Copy move, so a List operand of them is consumed (a later use is the usual moved-value error) and a slice or array of them is refused.a ++= b, anda = a ++ bspelled out, lower to LIST_EXTEND on the left operand's place (the buffer is reused; 200 appends of[i]cost the literal's allocation and ~9 growths, no new list per step).show(xs ++ ys)withlet xs = [1, 2]makes bothList[i32], D128).with_vec_extend_bits_es/with_vec_extend_str/with_vec_take_into_es), debug allocator clean, each element dropped once.Tests: test/behavior/behav_d116_concat_sequences.w, test/compile_errors/err_d116_{str_and_bytes,mixed_elements,moved_operand}.w.
Not done: a
[T; N+M]result where a fixed array is demanded; the one-element literal still allocates (that is D119 step 2's guaranteed lowering). Writing the fixture exposed A typed list literal accepts elements of another type:let ys: List[i32] = ["a", "b"]andlet zs: List[str] = [1, 2]pass check #2348 (a typed list literal accepts elements of another type).D114/D128 gaps (#2333, #2336, #2343), D111 clones (#2271), D115 Amend…
ehartford commentedon Oct 11, 2026
Merged to main in e4861e1 (#2349), battery green.