Skip to content

Commit d89ecfb

Browse files
committed
Remove #[alloc_error_handler] from the compiler and library
1 parent b2476c9 commit d89ecfb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+80
-850
lines changed

compiler/rustc_ast/src/expand/allocator.rs

-7
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@ pub fn default_fn_name(base: Symbol) -> String {
1414
format!("__rdl_{base}")
1515
}
1616

17-
pub fn alloc_error_handler_name(alloc_error_handler_kind: AllocatorKind) -> &'static str {
18-
match alloc_error_handler_kind {
19-
AllocatorKind::Global => "__rg_oom",
20-
AllocatorKind::Default => "__rdl_oom",
21-
}
22-
}
23-
2417
pub const NO_ALLOC_SHIM_IS_UNSTABLE: &str = "__rust_no_alloc_shim_is_unstable";
2518

2619
pub enum AllocatorTy {

compiler/rustc_builtin_macros/messages.ftl

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
builtin_macros_alloc_error_must_be_fn = alloc_error_handler must be a function
21
builtin_macros_alloc_must_statics = allocators must be statics
32
43
builtin_macros_asm_clobber_abi = clobber_abi

compiler/rustc_builtin_macros/src/alloc_error_handler.rs

-97
This file was deleted.

compiler/rustc_builtin_macros/src/errors.rs

-7
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,6 @@ pub(crate) struct OneCfgPattern {
2020
pub(crate) span: Span,
2121
}
2222

23-
#[derive(Diagnostic)]
24-
#[diag(builtin_macros_alloc_error_must_be_fn)]
25-
pub(crate) struct AllocErrorMustBeFn {
26-
#[primary_span]
27-
pub(crate) span: Span,
28-
}
29-
3023
#[derive(Diagnostic)]
3124
#[diag(builtin_macros_assert_requires_boolean)]
3225
pub(crate) struct AssertRequiresBoolean {

compiler/rustc_builtin_macros/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use rustc_expand::proc_macro::BangProcMacro;
2626
use rustc_fluent_macro::fluent_messages;
2727
use rustc_span::symbol::sym;
2828

29-
mod alloc_error_handler;
3029
mod assert;
3130
mod cfg;
3231
mod cfg_accessible;
@@ -101,7 +100,6 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
101100
}
102101

103102
register_attr! {
104-
alloc_error_handler: alloc_error_handler::expand,
105103
bench: test::expand_bench,
106104
cfg_accessible: cfg_accessible::Expander,
107105
cfg_eval: cfg_eval::expand,

compiler/rustc_codegen_cranelift/example/alloc_example.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(start, core_intrinsics, alloc_error_handler, lang_items)]
1+
#![feature(start, core_intrinsics, lang_items)]
22
#![no_std]
33

44
extern crate alloc;
@@ -22,11 +22,6 @@ fn panic_handler(_: &core::panic::PanicInfo<'_>) -> ! {
2222
core::intrinsics::abort();
2323
}
2424

25-
#[alloc_error_handler]
26-
fn alloc_error_handler(_: alloc::alloc::Layout) -> ! {
27-
core::intrinsics::abort();
28-
}
29-
3025
#[lang = "eh_personality"]
3126
fn eh_personality() -> ! {
3227
loop {}

compiler/rustc_codegen_cranelift/src/allocator.rs

+3-23
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
use crate::prelude::*;
55

66
use rustc_ast::expand::allocator::{
7-
alloc_error_handler_name, default_fn_name, global_fn_name, AllocatorKind, AllocatorTy,
8-
ALLOCATOR_METHODS, NO_ALLOC_SHIM_IS_UNSTABLE,
7+
default_fn_name, global_fn_name, AllocatorKind, AllocatorTy, ALLOCATOR_METHODS,
8+
NO_ALLOC_SHIM_IS_UNSTABLE,
99
};
1010
use rustc_codegen_ssa::base::allocator_kind_for_codegen;
1111
use rustc_session::config::OomStrategy;
@@ -17,21 +17,14 @@ pub(crate) fn codegen(
1717
unwind_context: &mut UnwindContext,
1818
) -> bool {
1919
let Some(kind) = allocator_kind_for_codegen(tcx) else { return false };
20-
codegen_inner(
21-
module,
22-
unwind_context,
23-
kind,
24-
tcx.alloc_error_handler_kind(()).unwrap(),
25-
tcx.sess.opts.unstable_opts.oom,
26-
);
20+
codegen_inner(module, unwind_context, kind, tcx.sess.opts.unstable_opts.oom);
2721
true
2822
}
2923

3024
fn codegen_inner(
3125
module: &mut impl Module,
3226
unwind_context: &mut UnwindContext,
3327
kind: AllocatorKind,
34-
alloc_error_handler_kind: AllocatorKind,
3528
oom_strategy: OomStrategy,
3629
) {
3730
let usize_ty = module.target_config().pointer_type();
@@ -75,19 +68,6 @@ fn codegen_inner(
7568
}
7669
}
7770

78-
let sig = Signature {
79-
call_conv: module.target_config().default_call_conv,
80-
params: vec![AbiParam::new(usize_ty), AbiParam::new(usize_ty)],
81-
returns: vec![],
82-
};
83-
crate::common::create_wrapper_function(
84-
module,
85-
unwind_context,
86-
sig,
87-
"__rust_alloc_error_handler",
88-
&alloc_error_handler_name(alloc_error_handler_kind),
89-
);
90-
9171
let data_id = module.declare_data(OomStrategy::SYMBOL, Linkage::Export, false, false).unwrap();
9272
let mut data = DataDescription::new();
9373
data.set_align(1);

compiler/rustc_codegen_gcc/example/alloc_example.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(start, core_intrinsics, alloc_error_handler, lang_items)]
1+
#![feature(start, core_intrinsics, lang_items)]
22
#![no_std]
33

44
extern crate alloc;
@@ -21,11 +21,6 @@ fn panic_handler(_: &core::panic::PanicInfo) -> ! {
2121
core::intrinsics::abort();
2222
}
2323

24-
#[alloc_error_handler]
25-
fn alloc_error_handler(_: alloc::alloc::Layout) -> ! {
26-
core::intrinsics::abort();
27-
}
28-
2924
#[lang = "eh_personality"]
3025
fn eh_personality() -> ! {
3126
loop {}

compiler/rustc_codegen_gcc/src/allocator.rs

+40-50
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
1-
#[cfg(feature="master")]
1+
#[cfg(feature = "master")]
22
use gccjit::FnAttribute;
33
use gccjit::{FunctionType, GlobalKind, ToRValue};
44
use rustc_ast::expand::allocator::{
5-
alloc_error_handler_name, default_fn_name, global_fn_name, AllocatorKind, AllocatorTy,
6-
ALLOCATOR_METHODS, NO_ALLOC_SHIM_IS_UNSTABLE,
5+
default_fn_name, global_fn_name, AllocatorKind, AllocatorTy, ALLOCATOR_METHODS,
6+
NO_ALLOC_SHIM_IS_UNSTABLE,
77
};
88
use rustc_middle::bug;
99
use rustc_middle::ty::TyCtxt;
1010
use rustc_session::config::OomStrategy;
1111

1212
use crate::GccContext;
1313

14-
pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut GccContext, _module_name: &str, kind: AllocatorKind, alloc_error_handler_kind: AllocatorKind) {
14+
pub(crate) unsafe fn codegen(
15+
tcx: TyCtxt<'_>,
16+
mods: &mut GccContext,
17+
_module_name: &str,
18+
kind: AllocatorKind,
19+
) {
1520
let context = &mods.context;
16-
let usize =
17-
match tcx.sess.target.pointer_width {
18-
16 => context.new_type::<u16>(),
19-
32 => context.new_type::<u32>(),
20-
64 => context.new_type::<u64>(),
21-
tws => bug!("Unsupported target word size for int: {}", tws),
22-
};
21+
let usize = match tcx.sess.target.pointer_width {
22+
16 => context.new_type::<u16>(),
23+
32 => context.new_type::<u32>(),
24+
64 => context.new_type::<u64>(),
25+
tws => bug!("Unsupported target word size for int: {}", tws),
26+
};
2327
let i8 = context.new_type::<i8>();
2428
let i8p = i8.make_pointer();
2529
let void = context.new_type::<()>();
@@ -49,25 +53,43 @@ pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut GccContext, _module_nam
4953
};
5054
let name = global_fn_name(method.name);
5155

52-
let args: Vec<_> = types.iter().enumerate()
56+
let args: Vec<_> = types
57+
.iter()
58+
.enumerate()
5359
.map(|(index, typ)| context.new_parameter(None, *typ, &format!("param{}", index)))
5460
.collect();
55-
let func = context.new_function(None, FunctionType::Exported, output.unwrap_or(void), &args, name, false);
61+
let func = context.new_function(
62+
None,
63+
FunctionType::Exported,
64+
output.unwrap_or(void),
65+
&args,
66+
name,
67+
false,
68+
);
5669

5770
if tcx.sess.target.options.default_hidden_visibility {
58-
#[cfg(feature="master")]
71+
#[cfg(feature = "master")]
5972
func.add_attribute(FnAttribute::Visibility(gccjit::Visibility::Hidden));
6073
}
6174
if tcx.sess.must_emit_unwind_tables() {
6275
// TODO(antoyo): emit unwind tables.
6376
}
6477

6578
let callee = default_fn_name(method.name);
66-
let args: Vec<_> = types.iter().enumerate()
79+
let args: Vec<_> = types
80+
.iter()
81+
.enumerate()
6782
.map(|(index, typ)| context.new_parameter(None, *typ, &format!("param{}", index)))
6883
.collect();
69-
let callee = context.new_function(None, FunctionType::Extern, output.unwrap_or(void), &args, callee, false);
70-
#[cfg(feature="master")]
84+
let callee = context.new_function(
85+
None,
86+
FunctionType::Extern,
87+
output.unwrap_or(void),
88+
&args,
89+
callee,
90+
false,
91+
);
92+
#[cfg(feature = "master")]
7193
callee.add_attribute(FnAttribute::Visibility(gccjit::Visibility::Hidden));
7294

7395
let block = func.new_block("entry");
@@ -81,8 +103,7 @@ pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut GccContext, _module_nam
81103
//llvm::LLVMSetTailCall(ret, True);
82104
if output.is_some() {
83105
block.end_with_return(None, ret);
84-
}
85-
else {
106+
} else {
86107
block.end_with_void_return(None);
87108
}
88109

@@ -91,37 +112,6 @@ pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut GccContext, _module_nam
91112
}
92113
}
93114

94-
let types = [usize, usize];
95-
let name = "__rust_alloc_error_handler".to_string();
96-
let args: Vec<_> = types.iter().enumerate()
97-
.map(|(index, typ)| context.new_parameter(None, *typ, &format!("param{}", index)))
98-
.collect();
99-
let func = context.new_function(None, FunctionType::Exported, void, &args, name, false);
100-
101-
if tcx.sess.target.default_hidden_visibility {
102-
#[cfg(feature="master")]
103-
func.add_attribute(FnAttribute::Visibility(gccjit::Visibility::Hidden));
104-
}
105-
106-
let callee = alloc_error_handler_name(alloc_error_handler_kind);
107-
let args: Vec<_> = types.iter().enumerate()
108-
.map(|(index, typ)| context.new_parameter(None, *typ, &format!("param{}", index)))
109-
.collect();
110-
let callee = context.new_function(None, FunctionType::Extern, void, &args, callee, false);
111-
#[cfg(feature="master")]
112-
callee.add_attribute(FnAttribute::Visibility(gccjit::Visibility::Hidden));
113-
114-
let block = func.new_block("entry");
115-
116-
let args = args
117-
.iter()
118-
.enumerate()
119-
.map(|(i, _)| func.get_param(i as i32).to_rvalue())
120-
.collect::<Vec<_>>();
121-
let _ret = context.new_call(None, callee, &args);
122-
//llvm::LLVMSetTailCall(ret, True);
123-
block.end_with_void_return(None);
124-
125115
let name = OomStrategy::SYMBOL.to_string();
126116
let global = context.new_global(None, GlobalKind::Exported, i8, name);
127117
let value = tcx.sess.opts.unstable_opts.oom.should_panic();

compiler/rustc_codegen_gcc/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,11 @@ impl CodegenBackend for GccCodegenBackend {
165165
}
166166

167167
impl ExtraBackendMethods for GccCodegenBackend {
168-
fn codegen_allocator<'tcx>(&self, tcx: TyCtxt<'tcx>, module_name: &str, kind: AllocatorKind, alloc_error_handler_kind: AllocatorKind) -> Self::Module {
168+
fn codegen_allocator<'tcx>(&self, tcx: TyCtxt<'tcx>, module_name: &str, kind: AllocatorKind) -> Self::Module {
169169
let mut mods = GccContext {
170170
context: Context::default(),
171171
};
172-
unsafe { allocator::codegen(tcx, &mut mods, module_name, kind, alloc_error_handler_kind); }
172+
unsafe { allocator::codegen(tcx, &mut mods, module_name, kind); }
173173
mods
174174
}
175175

0 commit comments

Comments
 (0)