Split AllocatorKind::fn_name in global_fn_name and default_fn_name

This commit is contained in:
bjorn3 2021-07-03 17:50:53 +02:00 committed by bjorn3
parent 4ce20663f7
commit 6ba7c5db07
6 changed files with 17 additions and 18 deletions

View File

@ -6,13 +6,12 @@ pub enum AllocatorKind {
Default, Default,
} }
impl AllocatorKind { pub fn global_fn_name(base: Symbol) -> String {
pub fn fn_name(&self, base: Symbol) -> String { format!("__rust_{base}")
match *self { }
AllocatorKind::Global => format!("__rust_{base}"),
AllocatorKind::Default => format!("__rdl_{base}"), pub fn default_fn_name(base: Symbol) -> String {
} format!("__rdl_{base}")
}
} }
pub fn alloc_error_handler_name(alloc_error_handler_kind: AllocatorKind) -> &'static str { pub fn alloc_error_handler_name(alloc_error_handler_kind: AllocatorKind) -> &'static str {

View File

@ -1,7 +1,7 @@
use crate::util::check_builtin_macro_attribute; use crate::util::check_builtin_macro_attribute;
use rustc_ast::expand::allocator::{ use rustc_ast::expand::allocator::{
AllocatorKind, AllocatorMethod, AllocatorTy, ALLOCATOR_METHODS, global_fn_name, AllocatorMethod, AllocatorTy, ALLOCATOR_METHODS,
}; };
use rustc_ast::ptr::P; use rustc_ast::ptr::P;
use rustc_ast::{self as ast, AttrVec, Expr, FnHeader, FnSig, Generics, Param, StmtKind}; use rustc_ast::{self as ast, AttrVec, Expr, FnHeader, FnSig, Generics, Param, StmtKind};
@ -90,7 +90,7 @@ impl AllocFnFactory<'_, '_> {
})); }));
let item = self.cx.item( let item = self.cx.item(
self.span, self.span,
Ident::from_str_and_span(&AllocatorKind::Global.fn_name(method.name), self.span), Ident::from_str_and_span(&global_fn_name(method.name), self.span),
self.attrs(), self.attrs(),
kind, kind,
); );

View File

@ -4,7 +4,7 @@
use crate::prelude::*; use crate::prelude::*;
use rustc_ast::expand::allocator::{ use rustc_ast::expand::allocator::{
alloc_error_handler_name, AllocatorKind, AllocatorTy, ALLOCATOR_METHODS, alloc_error_handler_name, default_fn_name, AllocatorKind, AllocatorTy, ALLOCATOR_METHODS,
}; };
use rustc_codegen_ssa::base::allocator_kind_for_codegen; use rustc_codegen_ssa::base::allocator_kind_for_codegen;
use rustc_session::config::OomStrategy; use rustc_session::config::OomStrategy;
@ -69,7 +69,7 @@ fn codegen_inner(
unwind_context, unwind_context,
sig, sig,
&format!("__rust_{}", method.name), &format!("__rust_{}", method.name),
&AllocatorKind::Default.fn_name(method.name), &default_fn_name(method.name),
); );
} }
} }

View File

@ -2,7 +2,7 @@
use gccjit::FnAttribute; use gccjit::FnAttribute;
use gccjit::{FunctionType, GlobalKind, ToRValue}; use gccjit::{FunctionType, GlobalKind, ToRValue};
use rustc_ast::expand::allocator::{ use rustc_ast::expand::allocator::{
alloc_error_handler_name, AllocatorKind, AllocatorTy, ALLOCATOR_METHODS, alloc_error_handler_name, default_fn_name, AllocatorKind, AllocatorTy, ALLOCATOR_METHODS,
}; };
use rustc_middle::bug; use rustc_middle::bug;
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
@ -61,7 +61,7 @@ pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut GccContext, _module_nam
// TODO(antoyo): emit unwind tables. // TODO(antoyo): emit unwind tables.
} }
let callee = AllocatorKind::Default.fn_name(method.name); let callee = default_fn_name(method.name);
let args: Vec<_> = types.iter().enumerate() let args: Vec<_> = types.iter().enumerate()
.map(|(index, typ)| context.new_parameter(None, *typ, &format!("param{}", index))) .map(|(index, typ)| context.new_parameter(None, *typ, &format!("param{}", index)))
.collect(); .collect();

View File

@ -1,7 +1,7 @@
use crate::attributes; use crate::attributes;
use libc::c_uint; use libc::c_uint;
use rustc_ast::expand::allocator::{ use rustc_ast::expand::allocator::{
alloc_error_handler_name, AllocatorKind, AllocatorTy, ALLOCATOR_METHODS, alloc_error_handler_name, default_fn_name, AllocatorKind, AllocatorTy, ALLOCATOR_METHODS,
}; };
use rustc_middle::bug; use rustc_middle::bug;
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
@ -71,7 +71,7 @@ pub(crate) unsafe fn codegen(
attributes::apply_to_llfn(llfn, llvm::AttributePlace::Function, &[uwtable]); attributes::apply_to_llfn(llfn, llvm::AttributePlace::Function, &[uwtable]);
} }
let callee = AllocatorKind::Default.fn_name(method.name); let callee = default_fn_name(method.name);
let callee = let callee =
llvm::LLVMRustGetOrInsertFunction(llmod, callee.as_ptr().cast(), callee.len(), ty); llvm::LLVMRustGetOrInsertFunction(llmod, callee.as_ptr().cast(), callee.len(), ty);
llvm::LLVMRustSetVisibility(callee, llvm::Visibility::Hidden); llvm::LLVMRustSetVisibility(callee, llvm::Visibility::Hidden);

View File

@ -4,7 +4,7 @@ use crate::errors;
use crate::locator::{CrateError, CrateLocator, CratePaths}; use crate::locator::{CrateError, CrateLocator, CratePaths};
use crate::rmeta::{CrateDep, CrateMetadata, CrateNumMap, CrateRoot, MetadataBlob}; use crate::rmeta::{CrateDep, CrateMetadata, CrateNumMap, CrateRoot, MetadataBlob};
use rustc_ast::expand::allocator::AllocatorKind; use rustc_ast::expand::allocator::{alloc_error_handler_name, global_fn_name, AllocatorKind};
use rustc_ast::{self as ast, *}; use rustc_ast::{self as ast, *};
use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::svh::Svh; use rustc_data_structures::svh::Svh;
@ -1044,7 +1044,7 @@ fn global_allocator_spans(krate: &ast::Crate) -> Vec<Span> {
} }
} }
let name = Symbol::intern(&AllocatorKind::Global.fn_name(sym::alloc)); let name = Symbol::intern(&global_fn_name(sym::alloc));
let mut f = Finder { name, spans: Vec::new() }; let mut f = Finder { name, spans: Vec::new() };
visit::walk_crate(&mut f, krate); visit::walk_crate(&mut f, krate);
f.spans f.spans
@ -1066,7 +1066,7 @@ fn alloc_error_handler_spans(krate: &ast::Crate) -> Vec<Span> {
} }
} }
let name = Symbol::intern(&AllocatorKind::Global.fn_name(sym::oom)); let name = Symbol::intern(alloc_error_handler_name(AllocatorKind::Global));
let mut f = Finder { name, spans: Vec::new() }; let mut f = Finder { name, spans: Vec::new() };
visit::walk_crate(&mut f, krate); visit::walk_crate(&mut f, krate);
f.spans f.spans