Skip to content

Conversation

@fitzgen
Copy link
Member

@fitzgen fitzgen commented Jan 26, 2026

Part of #12069

@fitzgen fitzgen requested review from a team as code owners January 26, 2026 22:59
@fitzgen fitzgen requested review from cfallin and pchickey and removed request for a team January 26, 2026 22:59
@fitzgen fitzgen force-pushed the more-oom-handling-boxed-slice-ctors branch from 7d4e831 to de2a430 Compare January 26, 2026 23:01
@github-actions github-actions bot added the cranelift Issues related to the Cranelift code generator label Jan 27, 2026
Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

Another possible idea:

  • One function to return fn(usize) -> Result<Box<[MaybeUninit<T>]>>
  • Another function fn(Iterator<T>, Box<[MaybeUninit<T>]>) -> Result<Box<[T]>>
  • Another function for a fallible iterator
  • Helper functions combining these together

@fitzgen
Copy link
Member Author

fitzgen commented Jan 27, 2026

Another possible idea:

  • One function to return fn(usize) -> Result<Box<[MaybeUninit<T>]>>

  • Another function fn(Iterator<T>, Box<[MaybeUninit<T>]>) -> Result<Box<[T]>>

  • Another function for a fallible iterator

  • Helper functions combining these together

This is sort of what we have, except we don't expose the second function publicly, just as an implementation detail.

What these proposed functions don't collectively cover, however, is when you have an unknown-length iterator, unless I am misunderstanding.

@fitzgen fitzgen force-pushed the more-oom-handling-boxed-slice-ctors branch from de2a430 to ec6e508 Compare January 27, 2026 19:13
@fitzgen
Copy link
Member Author

fitzgen commented Jan 27, 2026

Okay the boxed slice helpers are now implemented on top of our OOM-handling Vec and this PR now depends on #12452 (and therefore also #12448)

@fitzgen fitzgen requested a review from alexcrichton January 27, 2026 19:14
@fitzgen fitzgen force-pushed the more-oom-handling-boxed-slice-ctors branch from ec6e508 to bdcf42e Compare January 27, 2026 20:22
Copy link
Member

@cfallin cfallin left a comment

Choose a reason for hiding this comment

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

This looks correct to me; I think my main question (in addition to the one naming thought below) is why we need to define an error case TooFewItems. I suppose I'm not seeing the callsite(s) here but naively I would expect, given that we've implemented the shrink_to_fit logic, we could always use that if an iterator returns fewer items than expected; do we have cases where we want to guard against that (reallocation) wastefulness and flag a logic error instead?

@fitzgen
Copy link
Member Author

fitzgen commented Jan 27, 2026

do we have cases where we want to guard against that (reallocation) wastefulness and flag a logic error instead?

Basically, yes. We have call sites that know the exact length of various things but which also do not have ExactSizeIterators for Reasons.

@fitzgen fitzgen force-pushed the more-oom-handling-boxed-slice-ctors branch from bdcf42e to f9076a5 Compare January 27, 2026 22:37
@fitzgen fitzgen enabled auto-merge January 27, 2026 22:37
@fitzgen fitzgen force-pushed the more-oom-handling-boxed-slice-ctors branch from 4257de4 to fd976b8 Compare January 27, 2026 23:24
@fitzgen fitzgen added this pull request to the merge queue Jan 27, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 27, 2026
@fitzgen fitzgen added this pull request to the merge queue Jan 28, 2026
Merged via the queue into bytecodealliance:main with commit 35483cc Jan 28, 2026
45 checks passed
@fitzgen fitzgen deleted the more-oom-handling-boxed-slice-ctors branch January 28, 2026 01:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cranelift Issues related to the Cranelift code generator

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants