You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(allocator): remove unsound Send impl and tighten Sync requirement for HashMap (#13203)
Same as #13041.
It's unsound for `oxc_allocator::HashMap` to be `Send` because if you can move a `HashMap` to another thread, you can call `insert` on it and it may allocate in the arena. This is unsound because another thread may be simultaneously be doing the same with another `HashMap`, and `Bump` is not thread-safe.
Remove the `Send` impl on `HashMap`.
However, we do want `HashMap` to be `Sync`. There's no reason why you shouldn't have 2 `&HashMap` references on different threads, as `&HashMap` doesn't allow mutating the `HashMap` in any way.
Tighten up the trait bounds so `HashMap<K, V>` is `Sync` only if `K` and `V` both are.
This is not yet completely sound. There are a couple of holes I'm aware of:
1. `allocator` method which allows obtaining a `&Bump` from a `&HashMap`.
2. `clone` which allocates into arena, taking only an immutable `&self` reference.
This PR closes those holes as much as possible without a major refactor. It's not *completely* sound, but it's at least now quite difficult to commit UB - it'd be unlikely to happen by accident.
So, not perfect, but at least there's now only a crack in the window, rather than the front door swinging wide open.
---
The reason these 2 impls were added originally was as a quick fix to make `oxc_semantic::Scoping` `Send` and `Sync`. That is addressed in the next PR in this stack.
0 commit comments