Skip to content

Doc request: what modification is allowed to RawTable while holding RawIter #165

@CAD97

Description

@CAD97

More context on urlo and my questionable code.

What operations are allowed on RawTable while holding a RawIter?

Per my reading, the implementation currently suggests:

  • Required(?) for exposed behavior:
    • non-mutating inspection of the RawTable
    • eraseing the most recently yielded Bucket
  • Definitely not allowed (UB):
    • anything that causes a reallocation
    • erasing a bucket "ahead" of the iterator that has yet to be yielded
  • Potentially allowed:
    • erasing a bucket "behind" the iterator head that has previously been yielded but is not the most recently yielded bucket

I would benefit from the above "delayed erasing" being guaranteed sound (for the use case linked above).

Side note: it would be useful to make RawIter's debug_assert that it iterated all the expected items say what went wrong. Something simple like "exhausted iterator before expected; this likely indicates modification of a hash table while iterating it, which is UB" would definitely make hitting that assertion more obvious than the default message of "200 != 0" from inside of hashbrown's internals.

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