Stabilize default_alloc_error_handler#102318
Conversation
|
r? @lcnr (rust-highfive has picked a reviewer for you, use r? to override) |
|
considering that the FCP was 2 years ago, i would expect us to go through another FCP which explains the reason why stabilization was blocked. Won't block this without an FCP, but i definitely want someone to look at this who's a bit more knowledgeable about this than me r? compiler |
e16fad7 to
15aba25
Compare
|
When using this with cg_clif I get: It seems that the current implementation depends on pub mod __alloc_error_handler {
use crate::alloc::Layout;
// called via generated `__rust_alloc_error_handler`
// if there is no `#[alloc_error_handler]`
#[rustc_std_internal_symbol]
pub unsafe fn __rdl_oom(size: usize, _align: usize) -> ! {
panic!("memory allocation of {size} bytes failed")
}
// if there is an `#[alloc_error_handler]`
#[rustc_std_internal_symbol]
pub unsafe fn __rg_oom(size: usize, align: usize) -> ! {
let layout = unsafe { Layout::from_size_align_unchecked(size, align) };
extern "Rust" {
#[lang = "oom"]
fn oom_impl(layout: Layout) -> !;
}
unsafe { oom_impl(layout) }
}
}
|
|
I guess this is fine, but for people using alloc without global error handling at all (the current unstable |
|
We should probably have a test that uses this in a way we expect it to be used without requiring other feature gates. The tests touched by this PR all use other feature gates. |
This comment was marked as resolved.
This comment was marked as resolved.
The new implementation doesn't use weak lang items and instead changes `#[alloc_error_handler]` to an attribute macro just like `#[global_allocator]`. The attribute will generate the `__rg_oom` function which is called by the compiler-generated `__rust_alloc_error_handler`. If no `__rg_oom` function is defined in any crate then the compiler shim will call `__rdl_oom` in the alloc crate which will simply panic. This also fixes link errors with `-C link-dead-code` with `default_alloc_error_handler`: `__rg_oom` was previously defined in the alloc crate and would attempt to reference the `oom` lang item, even if it didn't exist. This worked as long as `__rg_oom` was excluded from linking since it was not called. This is a prerequisite for the stabilization of `default_alloc_error_handler` (rust-lang#102318).
…r, r=bjorn3 Rewrite implementation of `#[alloc_error_handler]` The new implementation doesn't use weak lang items and instead changes `#[alloc_error_handler]` to an attribute macro just like `#[global_allocator]`. The attribute will generate the `__rg_oom` function which is called by the compiler-generated `__rust_alloc_error_handler`. If no `__rg_oom` function is defined in any crate then the compiler shim will call `__rdl_oom` in the alloc crate which will simply panic. This also fixes link errors with `-C link-dead-code` with `default_alloc_error_handler`: `__rg_oom` was previously defined in the alloc crate and would attempt to reference the `oom` lang item, even if it didn't exist. This worked as long as `__rg_oom` was excluded from linking since it was not called. This is a prerequisite for the stabilization of `default_alloc_error_handler` (rust-lang#102318).
15aba25 to
2db1dec
Compare
|
cc @davidtwco, @compiler-errors, @JohnTitor, @estebank, @TaKO8Ki |
2db1dec to
f5e0b76
Compare
|
@rustbot ready |
63: Remove alloc_error_handler r=adamgreig a=jannic With rust-lang/rust#102318 default_alloc_error_handler has been stabilized, ie. the default error handler is enabled by default. Therefore, it's no longer necessary to provide an alloc_error_handler if the desired error handling is equivalent to a panic. Co-authored-by: Jan Niehusmann <jan@gondor.com>
As of 2022-12-18, we can rely on the `default_alloc_error_handler` feature which was stabilized in rust-lang/rust#102318. The behavior of the default handler is to panic, essentially the same as our current custom one.
As of 2022-12-18, we can rely on the `default_alloc_error_handler` feature which was stabilized in rust-lang/rust#102318. The behavior of the default handler is to panic, essentially the same as our current custom one.
As of 2022-12-18, we can rely on the `default_alloc_error_handler` feature which was stabilized in rust-lang/rust#102318. The behavior of the default handler is to panic, essentially the same as our current custom one.
As of 2022-12-18, we can rely on the `default_alloc_error_handler` feature which was stabilized in rust-lang/rust#102318. The behavior of the default handler is to panic, essentially the same as our current custom one.
As of 2022-12-18, we can rely on the `default_alloc_error_handler` feature which was stabilized in rust-lang/rust#102318. The behavior of the default handler is to panic, essentially the same as our current custom one.
As of 2022-12-18, we can rely on the `default_alloc_error_handler` feature which was stabilized in rust-lang/rust#102318. The behavior of the default handler is to panic, essentially the same as our current custom one.
As of 2022-12-18, we can rely on the `default_alloc_error_handler` feature which was stabilized in rust-lang/rust#102318. The behavior of the default handler is to panic, essentially the same as our current custom one.
As of 2022-12-18, we can rely on the `default_alloc_error_handler` feature which was stabilized in rust-lang/rust#102318. The behavior of the default handler is to panic, essentially the same as our current custom one.
As of 2022-12-18, we can rely on the `default_alloc_error_handler` feature which was stabilized in rust-lang/rust#102318. The behavior of the default handler is to panic, essentially the same as our current custom one.
As of 2022-12-18, we can rely on the `default_alloc_error_handler` feature which was stabilized in rust-lang/rust#102318. The behavior of the default handler is to panic, essentially the same as our current custom one.
The new implementation doesn't use weak lang items and instead changes `#[alloc_error_handler]` to an attribute macro just like `#[global_allocator]`. The attribute will generate the `__rg_oom` function which is called by the compiler-generated `__rust_alloc_error_handler`. If no `__rg_oom` function is defined in any crate then the compiler shim will call `__rdl_oom` in the alloc crate which will simply panic. This also fixes link errors with `-C link-dead-code` with `default_alloc_error_handler`: `__rg_oom` was previously defined in the alloc crate and would attempt to reference the `oom` lang item, even if it didn't exist. This worked as long as `__rg_oom` was excluded from linking since it was not called. This is a prerequisite for the stabilization of `default_alloc_error_handler` (rust-lang#102318).
As of 2022-12-18, we can rely on the `default_alloc_error_handler` feature which was stabilized in rust-lang/rust#102318. The behavior of the default handler is to panic, essentially the same as our current custom one.
As of 2022-12-18, we can rely on the `default_alloc_error_handler` feature which was stabilized in rust-lang/rust#102318. The behavior of the default handler is to panic, essentially the same as our current custom one.
As of 2022-12-18, we can rely on the `default_alloc_error_handler` feature which was stabilized in rust-lang/rust#102318. The behavior of the default handler is to panic, essentially the same as our current custom one.
As of 2022-12-18, we can rely on the `default_alloc_error_handler` feature which was stabilized in rust-lang/rust#102318. The behavior of the default handler is to panic, essentially the same as our current custom one.
As of 2022-12-18, we can rely on the `default_alloc_error_handler` feature which was stabilized in rust-lang/rust#102318. The behavior of the default handler is to panic, essentially the same as our current custom one.
As of 2022-12-18, we can rely on the `default_alloc_error_handler` feature which was stabilized in rust-lang/rust#102318. The behavior of the default handler is to panic, essentially the same as our current custom one.
As of 2022-12-18, we can rely on the `default_alloc_error_handler` feature which was stabilized in rust-lang/rust#102318. The behavior of the default handler is to panic, essentially the same as our current custom one.
As of 2022-12-18, we can rely on the `default_alloc_error_handler` feature which was stabilized in rust-lang/rust#102318. The behavior of the default handler is to panic, essentially the same as our current custom one.
Tracking issue: #66741
This turns
feature(default_alloc_error_handler)on by default, which causes the compiler to automatically generate a default OOM handler which panics if#[alloc_error_handler]is not provided.The FCP completed over 2 years ago but the stabilization was blocked due to an issue with unwinding. This was fixed by #88098 so stabilization can be unblocked.
Closes #66741