Skip to content

Add noalloc annotation RFC#235

Open
SeanTAllen wants to merge 1 commit into
mainfrom
noalloc-rfc
Open

Add noalloc annotation RFC#235
SeanTAllen wants to merge 1 commit into
mainfrom
noalloc-rfc

Conversation

@SeanTAllen

Copy link
Copy Markdown
Member

This RFC proposes noalloc, a compile-time annotation that verifies a method, and everything it transitively calls, performs no heap allocation. You mark a hot method; in release builds the compiler fails the build if anything under it allocates, including code you didn't write and didn't annotate. The check runs after optimization on the shipped binary, so whatever stays on the stack passes. It also goes on interface and trait methods, where it forces every implementer to be noalloc, which is what lets a noalloc method dispatch through an interface.

The open questions are about the compiler error: whether it can point at the specific allocation, and what it reports when more than one allocation caused the failure.

@ponylang-main ponylang-main added discuss during sync Should be discussed during an upcoming sync status - new The RFC is new and ready for discussion. labels Jul 4, 2026
@SeanTAllen SeanTAllen force-pushed the noalloc-rfc branch 2 times, most recently from 9bbdbab to 3fe769a Compare July 4, 2026 03:46
@SeanTAllen SeanTAllen changed the title Add noalloc RFC Add noalloc annotation RFC Jul 4, 2026
@SeanTAllen

SeanTAllen commented Jul 11, 2026

Copy link
Copy Markdown
Member Author

we discussed.

allow noalloc on trait methods. disallow on interface.

like the no supertype annotation's interaction with the type system, we can require any trait method that is \noalloc\ to require its implementers to have \noalloc\ on the same methods. however it isn't required. that's an open question.

at the time that we are doing our check for allocations, we can see all trait possibilities at virtual dispatch call sites and verify that none will allocate because by the time we are past heap2stack and optimizations, we have a fully closed world.

for interfaces, we have to use the same closed world at any virtual dispatch site to see if any implementers would alloc and if yes, disallow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

discuss during sync Should be discussed during an upcoming sync status - new The RFC is new and ready for discussion.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants