Skip to content

Commit 6ba7c5d

Browse files
committed
Split AllocatorKind::fn_name in global_fn_name and default_fn_name
1 parent 4ce2066 commit 6ba7c5d

File tree

6 files changed

+17
-18
lines changed

6 files changed

+17
-18
lines changed

compiler/rustc_ast/src/expand/allocator.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ pub enum AllocatorKind {
66
Default,
77
}
88

9-
impl AllocatorKind {
10-
pub fn fn_name(&self, base: Symbol) -> String {
11-
match *self {
12-
AllocatorKind::Global => format!("__rust_{base}"),
13-
AllocatorKind::Default => format!("__rdl_{base}"),
14-
}
15-
}
9+
pub fn global_fn_name(base: Symbol) -> String {
10+
format!("__rust_{base}")
11+
}
12+
13+
pub fn default_fn_name(base: Symbol) -> String {
14+
format!("__rdl_{base}")
1615
}
1716

1817
pub fn alloc_error_handler_name(alloc_error_handler_kind: AllocatorKind) -> &'static str {

compiler/rustc_builtin_macros/src/global_allocator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::util::check_builtin_macro_attribute;
22

33
use rustc_ast::expand::allocator::{
4-
AllocatorKind, AllocatorMethod, AllocatorTy, ALLOCATOR_METHODS,
4+
global_fn_name, AllocatorMethod, AllocatorTy, ALLOCATOR_METHODS,
55
};
66
use rustc_ast::ptr::P;
77
use rustc_ast::{self as ast, AttrVec, Expr, FnHeader, FnSig, Generics, Param, StmtKind};
@@ -90,7 +90,7 @@ impl AllocFnFactory<'_, '_> {
9090
}));
9191
let item = self.cx.item(
9292
self.span,
93-
Ident::from_str_and_span(&AllocatorKind::Global.fn_name(method.name), self.span),
93+
Ident::from_str_and_span(&global_fn_name(method.name), self.span),
9494
self.attrs(),
9595
kind,
9696
);

compiler/rustc_codegen_cranelift/src/allocator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use crate::prelude::*;
55

66
use rustc_ast::expand::allocator::{
7-
alloc_error_handler_name, AllocatorKind, AllocatorTy, ALLOCATOR_METHODS,
7+
alloc_error_handler_name, default_fn_name, AllocatorKind, AllocatorTy, ALLOCATOR_METHODS,
88
};
99
use rustc_codegen_ssa::base::allocator_kind_for_codegen;
1010
use rustc_session::config::OomStrategy;
@@ -69,7 +69,7 @@ fn codegen_inner(
6969
unwind_context,
7070
sig,
7171
&format!("__rust_{}", method.name),
72-
&AllocatorKind::Default.fn_name(method.name),
72+
&default_fn_name(method.name),
7373
);
7474
}
7575
}

compiler/rustc_codegen_gcc/src/allocator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use gccjit::FnAttribute;
33
use gccjit::{FunctionType, GlobalKind, ToRValue};
44
use rustc_ast::expand::allocator::{
5-
alloc_error_handler_name, AllocatorKind, AllocatorTy, ALLOCATOR_METHODS,
5+
alloc_error_handler_name, default_fn_name, AllocatorKind, AllocatorTy, ALLOCATOR_METHODS,
66
};
77
use rustc_middle::bug;
88
use rustc_middle::ty::TyCtxt;
@@ -61,7 +61,7 @@ pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut GccContext, _module_nam
6161
// TODO(antoyo): emit unwind tables.
6262
}
6363

64-
let callee = AllocatorKind::Default.fn_name(method.name);
64+
let callee = default_fn_name(method.name);
6565
let args: Vec<_> = types.iter().enumerate()
6666
.map(|(index, typ)| context.new_parameter(None, *typ, &format!("param{}", index)))
6767
.collect();

compiler/rustc_codegen_llvm/src/allocator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::attributes;
22
use libc::c_uint;
33
use rustc_ast::expand::allocator::{
4-
alloc_error_handler_name, AllocatorKind, AllocatorTy, ALLOCATOR_METHODS,
4+
alloc_error_handler_name, default_fn_name, AllocatorKind, AllocatorTy, ALLOCATOR_METHODS,
55
};
66
use rustc_middle::bug;
77
use rustc_middle::ty::TyCtxt;
@@ -71,7 +71,7 @@ pub(crate) unsafe fn codegen(
7171
attributes::apply_to_llfn(llfn, llvm::AttributePlace::Function, &[uwtable]);
7272
}
7373

74-
let callee = AllocatorKind::Default.fn_name(method.name);
74+
let callee = default_fn_name(method.name);
7575
let callee =
7676
llvm::LLVMRustGetOrInsertFunction(llmod, callee.as_ptr().cast(), callee.len(), ty);
7777
llvm::LLVMRustSetVisibility(callee, llvm::Visibility::Hidden);

compiler/rustc_metadata/src/creader.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::errors;
44
use crate::locator::{CrateError, CrateLocator, CratePaths};
55
use crate::rmeta::{CrateDep, CrateMetadata, CrateNumMap, CrateRoot, MetadataBlob};
66

7-
use rustc_ast::expand::allocator::AllocatorKind;
7+
use rustc_ast::expand::allocator::{alloc_error_handler_name, global_fn_name, AllocatorKind};
88
use rustc_ast::{self as ast, *};
99
use rustc_data_structures::fx::FxHashSet;
1010
use rustc_data_structures::svh::Svh;
@@ -1044,7 +1044,7 @@ fn global_allocator_spans(krate: &ast::Crate) -> Vec<Span> {
10441044
}
10451045
}
10461046

1047-
let name = Symbol::intern(&AllocatorKind::Global.fn_name(sym::alloc));
1047+
let name = Symbol::intern(&global_fn_name(sym::alloc));
10481048
let mut f = Finder { name, spans: Vec::new() };
10491049
visit::walk_crate(&mut f, krate);
10501050
f.spans
@@ -1066,7 +1066,7 @@ fn alloc_error_handler_spans(krate: &ast::Crate) -> Vec<Span> {
10661066
}
10671067
}
10681068

1069-
let name = Symbol::intern(&AllocatorKind::Global.fn_name(sym::oom));
1069+
let name = Symbol::intern(alloc_error_handler_name(AllocatorKind::Global));
10701070
let mut f = Finder { name, spans: Vec::new() };
10711071
visit::walk_crate(&mut f, krate);
10721072
f.spans

0 commit comments

Comments
 (0)