improvements on allocators
- 主要語言
- Rust
- 星號
- 951
- 分支
- 228
- PR 合併指標
- 30 天內沒有已合併 PR
描述
## background
as described in #126, svm runtime gives the user heap to use anyways with or without defining a heap allocator.
~default `BumpAllocator` will store two `usize` on bss section, one indicating the free pointer and the other max len.~
default `BumpAllocator` stores heap free pointer at 0x300000000.
`NoAllocator` now does not allow `alloc` generated heap allocation, and #126 adds a manual allocation for `NoAllocator`.
## a few thoughts
1. `NoAllocator`'s name is confusing. it is able to let user to claim heap memory, but it cannot let `alloc` crate to get memory.
2. `NoAllocator` is very dev-unfriendly (maybe we can introduce some static check to avoid overlap?)
3. using allocating functions in crate `alloc` like `Box::new` will introduces some rust runtime check, like null ptr check. subsequently it emits panic stuff like in #85 .
4. `allocate_unchecked` needs the annoying `#![cfg_attr(target_os = "solana", feature(const_mut_refs))]`
some easy todo improvements:
- [ ] remove `len` field of `BumpAllocator`
- [ ] remove `const` for `allocate_unchecked` (or we wait for toolchain updating to [1.83.0](https://github.com/anza-xyz/rust/blob/89fb68fd3298a1c6998337b891f975eb60b8a4e4/compiler/rustc_feature/src/accepted.rs#L147))
- [ ] add same interface (`allocate_unchecked`) for `BumpAllocator`
- [ ] `allocate_unchecked` should return `&'static mut MaybeUninit`
- [ ] introduce [static_assertions](https://docs.rs/static_assertions/latest/static_assertions/) for `allocate_unchecked` to through compile-time error for assertion (e.g. heap oob)
some challenging ones:
- [ ] compile time overlap check (not sure if it's possible without touching the compiler)
- [ ] bypass `alloc` runtime check (i.e. lightweight panic if allocation fails). i tried but failed. compiler change needed for this one
貢獻指南
這個儲存庫沒有索引到貢獻指南
評估
這個 Issue 還沒有評估資料。