Skip to content

Add hashbrown refactor goal - #835

Open
clarfonthey wants to merge 2 commits into
rust-lang:mainfrom
clarfonthey:hashbrown
Open

clarfonthey wants to merge 2 commits into
rust-lang:mainfrom
clarfonthey:hashbrown

Conversation

@clarfonthey

@clarfonthey clarfonthey commented Oct 26, 2026 •

Copy link
Copy Markdown

@clarfonthey clarfonthey added the C-goal-proposal This is a goal proposal label Oct 26, 2026
@rustbot

rustbot commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

A #goals/proposed topic was opened to discuss this issue.

@teor2345 teor2345 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just a minor typo and nit/suggestion

View changes since this review

Comment thread src/2026/hashbrown-refactor.md Resolved
Co-authored-by: teor <teor@riseup.net>

@nxsaken nxsaken left a comment •

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.

Minor/editing comments; needs a libs champion (which could be you) and, because the ask is large, a lead sign-off (informal).

View changes since this review


## Summary

The `hashbrown` crate should be modernized and have most of its API surface moved to the standard library under the `alloc` crate.

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.

Suggested change
The `hashbrown` crate should be modernized and have most of its API surface moved to the standard library under the `alloc` crate.
Modernize the `hashbrown` crate and move most of its API to the standard library under the `alloc` crate.


### The status quo

Right now, the standard library's implementation of `HashMap` and `HashSet` rely on the implementation in the `hashbrown` crate. This crate contains both the hash table implementation and the concrete uses of `Map` and `Set`, but it also has a lot of APIs that have not been moved into the standard library which provide lots of real use cases like `entry_ref`, which allows using the `Entry` API without eagerly promoting types to their owned version.

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.

Suggested change
Right now, the standard library's implementation of `HashMap` and `HashSet` rely on the implementation in the `hashbrown` crate. This crate contains both the hash table implementation and the concrete uses of `Map` and `Set`, but it also has a lot of APIs that have not been moved into the standard library which provide lots of real use cases like `entry_ref`, which allows using the `Entry` API without eagerly promoting types to their owned version.
Right now, the standard library's implementation of `HashMap` and `HashSet` relies on the implementation in the `hashbrown` crate. This crate contains both the hash table implementation and the concrete uses of `Map` and `Set`, but it also has a lot of APIs that satisfy real use cases and have not been moved into the standard library. For example, `entry_ref` allows using the `Entry` API without eagerly promoting types to their owned version.


Right now, the standard library's implementation of `HashMap` and `HashSet` rely on the implementation in the `hashbrown` crate. This crate contains both the hash table implementation and the concrete uses of `Map` and `Set`, but it also has a lot of APIs that have not been moved into the standard library which provide lots of real use cases like `entry_ref`, which allows using the `Entry` API without eagerly promoting types to their owned version.

The implementation for hashbrown is also very old, designed before the standard library had correctly described its semantics for `MaybeUninit`, without any safety comments for tracking the invariants held by its unsafe code.

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.

Suggested change
The implementation for hashbrown is also very old, designed before the standard library had correctly described its semantics for `MaybeUninit`, without any safety comments for tracking the invariants held by its unsafe code.
The implementation for `hashbrown` is also very old, designed before the standard library had correctly described its semantics for `MaybeUninit`, without any safety comments for tracking the invariants held by its unsafe code.


### What we propose to do about it

Simply put, the `hashbrown` crate needs a lot of work done to refactor its internals and audit unsafe code, with the end goal of effectively all of its API surface being moved into the standard library *and* ecosystem crates being able to start depending on the standard library instead of `hashbrown`.

@nxsaken nxsaken Oct 26, 2026 •

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.

What happens to hashbrown once that's done? Will it become obsolete for non-legacy purposes?

View changes since the review

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I think that the point about API experimentation is still valuable, just, we'd have hopefully converted all the existing stuff from "experiment" to actually being stable

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.

I'm trying to grasp the diff between how the standard library, hashbrown, and external crates relate to each other today and after this goal (as someone who's unfamiliar with how that's set up).

Is the goal for hashbrown to become similar to itertools, where the standard library no longer depends on it and the ecosystem uses it for extra APIs that may or may not be upstreamed eventually? Or is it something else?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

So, at this point, hashbrown is an interesting situation. I think longer-term we do actually want to have big implementations for the standard library separated out into different crates, because we get the benefit of API experimentation (you can change the API without worrying about stability) and the ability to test out performance changes easily. There are also probably aspects of the implementation that might be useful to add for stuff like the compiler that aren't necessarily worth including in the standard library.

So, longer-term, hashbrown remains as it is, but the standard library is in a good place, and most people don't actually depend directly on it unless they want to experiment with the API or do very weird and cursed things with it, like the compiler.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-goal-proposal This is a goal proposal

Projects

Status: To Do

Development

Successfully merging this pull request may close these issues.

4 participants