Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an "allocator" attribute to mark functions as allocators #23322

Merged
merged 1 commit into from
Mar 13, 2015

Conversation

dotdash
Copy link
Contributor

@dotdash dotdash commented Mar 12, 2015

When this attribute is applied to a function, its return value gets the
noalias attribute, which is how you tell LLVM that the function returns
a "new" pointer that doesn't alias anything accessible to the caller,
i.e. it acts like a memory allocator.

Plain malloc doesn't need this attribute because LLVM already knows
about malloc and adds the attribute itself.

@rust-highfive
Copy link
Collaborator

r? @pcwalton

(rust_highfive has picked a reviewer for you, use r? to override)

@brson
Copy link
Contributor

brson commented Mar 13, 2015

I'm not keen that this teaches trans about jemalloc directly. Is there nowhere in liballoc where this can be annotated?

@dotdash
Copy link
Contributor Author

dotdash commented Mar 13, 2015

The nounwind part could be handled by parts of #21186. For the probably more important noalias part, we could either solve #13996 which looks like it would need an RFC, or maybe go for a feature-gated #[allocator] attribute that makes the compiler set noalias for the function.

When this attribute is applied to a function, its return value gets the
noalias attribute, which is how you tell LLVM that the function returns
a "new" pointer that doesn't alias anything accessible to the caller,
i.e. it acts like a memory allocator.

Plain malloc doesn't need this attribute because LLVM already knows
about malloc and adds the attribute itself.
@dotdash dotdash changed the title Set appropriate function/argument attributes on jemalloc functions Add an "allocator" attribute to mark functions as allocators Mar 13, 2015
@dotdash
Copy link
Contributor Author

dotdash commented Mar 13, 2015

Updated the code to use a feature gated #[allocator] attribute to set the noalias attribute. The nounwind part can wait for #21186, not sure about the nocapture attribute for je_sdallocx. A simple #[deallocator] (or whatever) would force the pointer argument to be passed at a fixed argument index, not sure if that's a great idea, so I'm postponing that part.

@alexcrichton
Copy link
Member

It's all experimental anyway, so it could be something like #[deallocator(pointer_index = "1")] perhaps. Using an attribute is fine by me, r? @brson

@rust-highfive rust-highfive assigned brson and unassigned pcwalton Mar 13, 2015
@brson
Copy link
Contributor

brson commented Mar 13, 2015

Yeah, since this is unstable and gated I feel good about it.

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Mar 13, 2015

@bors r=brson 0942803

Manishearth added a commit to Manishearth/rust that referenced this pull request Mar 13, 2015
 When this attribute is applied to a function, its return value gets the
noalias attribute, which is how you tell LLVM that the function returns
a \"new\" pointer that doesn't alias anything accessible to the caller,
i.e. it acts like a memory allocator.

Plain malloc doesn't need this attribute because LLVM already knows
about malloc and adds the attribute itself.
@bors bors merged commit 0942803 into rust-lang:master Mar 13, 2015
@dotdash dotdash deleted the jemalloc_attrs branch May 8, 2015 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants