@@ -31,10 +31,23 @@ pub enum AllocatorTy {
3131 Usize ,
3232}
3333
34+ /// Some allocator methods are known to the compiler: they act more like
35+ /// intrinsics/language primitives than library-defined functions.
36+ /// FIXME: ideally this would be derived from attributes like `#[rustc_allocator]`,
37+ /// so we don't have two sources of truth.
38+ #[ derive( Copy , Clone , Debug ) ]
39+ pub enum SpecialAllocatorMethod {
40+ Alloc ,
41+ AllocZeroed ,
42+ Dealloc ,
43+ Realloc ,
44+ }
45+
3446/// A method that will be codegened in the allocator shim.
3547#[ derive( Copy , Clone ) ]
3648pub struct AllocatorMethod {
3749 pub name : Symbol ,
50+ pub special : Option < SpecialAllocatorMethod > ,
3851 pub inputs : & ' static [ AllocatorMethodInput ] ,
3952 pub output : AllocatorTy ,
4053}
@@ -47,11 +60,13 @@ pub struct AllocatorMethodInput {
4760pub static ALLOCATOR_METHODS : & [ AllocatorMethod ] = & [
4861 AllocatorMethod {
4962 name : sym:: alloc,
63+ special : Some ( SpecialAllocatorMethod :: Alloc ) ,
5064 inputs : & [ AllocatorMethodInput { name : "layout" , ty : AllocatorTy :: Layout } ] ,
5165 output : AllocatorTy :: ResultPtr ,
5266 } ,
5367 AllocatorMethod {
5468 name : sym:: dealloc,
69+ special : Some ( SpecialAllocatorMethod :: Dealloc ) ,
5570 inputs : & [
5671 AllocatorMethodInput { name : "ptr" , ty : AllocatorTy :: Ptr } ,
5772 AllocatorMethodInput { name : "layout" , ty : AllocatorTy :: Layout } ,
@@ -60,6 +75,7 @@ pub static ALLOCATOR_METHODS: &[AllocatorMethod] = &[
6075 } ,
6176 AllocatorMethod {
6277 name : sym:: realloc,
78+ special : Some ( SpecialAllocatorMethod :: Realloc ) ,
6379 inputs : & [
6480 AllocatorMethodInput { name : "ptr" , ty : AllocatorTy :: Ptr } ,
6581 AllocatorMethodInput { name : "layout" , ty : AllocatorTy :: Layout } ,
@@ -69,6 +85,7 @@ pub static ALLOCATOR_METHODS: &[AllocatorMethod] = &[
6985 } ,
7086 AllocatorMethod {
7187 name : sym:: alloc_zeroed,
88+ special : Some ( SpecialAllocatorMethod :: AllocZeroed ) ,
7289 inputs : & [ AllocatorMethodInput { name : "layout" , ty : AllocatorTy :: Layout } ] ,
7390 output : AllocatorTy :: ResultPtr ,
7491 } ,
0 commit comments