Skip to content

The accumulator lint names no builder, and warns when a variable holds a copy of the accumulator on every pass (D219, #919) - #3455

Merged
ehartford merged 2 commits into
mainfrom
append-lint
Nov 19, 2026
Merged

ehartford merged 2 commits into
mainfrom
append-lint

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Closes #919. Ruled by Eric (D219): D34-C stands, D111's sentence describes the implementation, StringBuilder leaves the prelude, and the lint covers what is still slow.

  • Advice that works. For a non-append shape (s = piece ++ s) the warning no longer names StringBuilder: append instead, building in the other direction, or collect the pieces and join them once.
  • A shared accumulator. s = s ++ piece appends in place while s is the only holder of its text. When a variable is assigned s in the same loop (prev = s), it shares the text at the next append, which copies all of it. Measured: 20,000 passes 15 ms, 40,000 passes 54 ms; the plain append does 200,000 in 3 ms. Both orders warn.
  • Only what is certain. A let copy in the loop body is not flagged (it can die before the next append), nor a copy made outside an inner loop (one copy).
  • StringBuilder was already import-gated (use std.string.StringBuilder), and the normative spec has no builder sentence, so no spec text changes.

Two tests: the warnings, and what stays quiet. Battery green on the branch tip.

@ehartford
ehartford merged commit a2caf21 into main Nov 19, 2026
@ehartford
ehartford deleted the append-lint branch November 19, 2026 04:41
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.

D34-C: ++ accumulation on str becomes amortized-efficient; StringBuilder retires; accumulator lint deleted

1 participant