Skip to content

D116: implement ++ over sequences and ++= #2291

Closed

Description

@ehartford

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, ++=.

Activity

  1. ehartford commented on Oct 11, 2026

    @ehartford
    ContributorAuthor

    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).
  2. added a commit that references this issue on Oct 11, 2026
  3. ehartford commented on Oct 11, 2026

    @ehartford
    ContributorAuthor

    Merged to main in e4861e1 (#2349), battery green.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions