Skip to content

Support custom alignment in rawAlloc for refc GC#25478

Closed
Copilot wants to merge 1 commit into
pr_kellarfrom
copilot/sub-pr-25476
Closed

Support custom alignment in rawAlloc for refc GC#25478
Copilot wants to merge 1 commit into
pr_kellarfrom
copilot/sub-pr-25476

Conversation

Copilot AI commented Feb 3, 2026

Copy link
Copy Markdown
Contributor

Small chunks allocate memory in fixed-size cells positioned at exact multiples of cell size, preventing arbitrary alignment. This adds alignment support by forcing big chunk allocation for alignments > MemAlign.

Changes:

  • Added alignOffset: uint16 to BigChunk to track alignment adjustment from data start
  • Extended rawAlloc/rawAlloc0 with alignment and offset parameters (defaults preserve existing behavior)
  • Implemented applyAlignment() to compute aligned cell pointer: aligns (basePtr + offset) then backs up by offset
  • Updated gc.nim to pass typ.base.align when allocating ref objects
  • Fixed pointer arithmetic in allObjects, deallocBigChunk, isAllocatedPtr, getCell, and getObjSizes to account for alignOffset
  • Added tests for 16/32/64/128-byte alignments including nested structures

Example:

type
  MyType128 = object
    a {.align(128).}: int

let x = new MyType128  # Allocated with 128-byte alignment
doAssert cast[int](x) mod 128 == 0

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix rawAlloc to support memory alignment Support custom alignment in rawAlloc for refc GC Feb 3, 2026
Copilot AI requested a review from ringabout February 3, 2026 08:41
@ringabout ringabout closed this Feb 3, 2026
@ringabout ringabout deleted the copilot/sub-pr-25476 branch February 3, 2026 08:43
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