Skip to content

WIP improve List.reserve docs - #10852

Open
Anton-4 wants to merge 1 commit into
mainfrom
improve-reserve-docs
Open

WIP improve List.reserve docs#10852
Anton-4 wants to merge 1 commit into
mainfrom
improve-reserve-docs

Conversation

@Anton-4

@Anton-4 Anton-4 commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

@greptile-apps

greptile-apps Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Expands the built-in API documentation for list capacity management and adds corresponding guidance to Dict.reserve.

  • Adds examples and performance guidance for List.with_capacity.
  • Documents List.reserve usage, allocation behavior, and loop complexity.
  • Relates Dict.reserve usage to list reservation behavior.

Confidence Score: 4/5

The PR appears safe to merge after correcting the non-blocking inaccuracies in the documented allocation semantics.

The executable implementation is unchanged, but the new public documentation incorrectly promises exact capacity in a reachable reserve case and unconditional allocation-and-copy behavior.

Files Needing Attention: src/build/roc/Builtin.roc

Important Files Changed

Filename Overview
src/build/roc/Builtin.roc Documentation-only changes substantially clarify reserve usage, but two categorical allocation claims do not hold for all implementation paths.

Reviews (1): Last reviewed commit: "improve List.reserve docs" | Re-trigger Greptile

Comment thread src/build/roc/Builtin.roc
Comment on lines +3787 to +3791
## `reserve(spare)` sizes the allocation to hold exactly `List.len(list) + spare`
## items; it trusts the request instead of rounding it up. If the list is not
## shared and already has room for `spare` more items, it does nothing.
## Otherwise it always performs a heap allocation and copies the existing items
## into it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Allocation guarantees are overstated

The documentation promises that reserve(spare) always allocates exactly List.len(list) + spare capacity and copies the existing items, but reserving one slot on a full exclusive list invokes geometric growth, while allocator reallocation can extend storage in place without copying. Users therefore cannot rely on either guarantee when reasoning about capacity or allocation costs.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@Anton-4 Anton-4 changed the title improve List.reserve docs WIP improve List.reserve docs Aug 18, 2026
@mpizenberg

Copy link
Copy Markdown
Collaborator

Isn’t it a bit verbose in contrast to the other docs?

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.

2 participants