Skip to content

Conversation

grynspan
Copy link
Contributor

@grynspan grynspan commented May 5, 2022

This change adds the gnu::returns_nonnull* attribute to swift_slowAlloc() and functions directly derived from it. Any code that calls these functions can be further optimized by the compiler because it knows that any paths assuming a null return value are unreachable.

This attribute is distinct from Apple's _Nonnull extension, which (in C/C++) is advisory only and does not affect codegen.

* For MSVC++, _Ret_notnull_ is substituted. This macro has no impact on codegen but may produce better diagnostics when annotated functions are misused.

Resolves #58686.

@grynspan
Copy link
Contributor Author

grynspan commented May 5, 2022

@swift-ci please smoke test

@grynspan grynspan force-pushed the jgrynspan/58686-nonnull-allocation-annotations branch from 40eb782 to 8511a51 Compare May 5, 2022 15:13
Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The top-most commit looks good. A small nit: the commit message could be improved. The immediate reaction was - this is probably a bad idea, it might cause trouble for some compilers. Being more explicit with something like "attribute allocators as unfailable" might be more precise.

@grynspan grynspan force-pushed the jgrynspan/58686-nonnull-allocation-annotations branch 2 times, most recently from 0a877e1 to f6848b0 Compare May 5, 2022 16:15
@grynspan grynspan requested a review from kubamracek May 5, 2022 16:15
@grynspan
Copy link
Contributor Author

grynspan commented May 5, 2022

The immediate reaction was - this is probably a bad idea, it might cause trouble for some compilers.

Can you elaborate what you mean here?

Edit: I updated the PR description to clarify what happens when gnu::returns_nonnull is unavailable.

@grynspan grynspan requested a review from compnerd May 5, 2022 16:35
@grynspan grynspan force-pushed the jgrynspan/58686-nonnull-allocation-annotations branch 2 times, most recently from 12d41ac to dea7e2f Compare May 5, 2022 17:15
@grynspan grynspan requested a review from mikeash May 5, 2022 17:16
@grynspan grynspan force-pushed the jgrynspan/58686-nonnull-allocation-annotations branch 3 times, most recently from 954986c to 2a34757 Compare May 5, 2022 18:13
@grynspan
Copy link
Contributor Author

grynspan commented May 5, 2022

@swift-ci please test

@grynspan grynspan marked this pull request as ready for review May 5, 2022 22:04
@grynspan grynspan force-pushed the jgrynspan/58686-nonnull-allocation-annotations branch 3 times, most recently from b795fd4 to b4c04b2 Compare May 6, 2022 03:13
@grynspan grynspan force-pushed the jgrynspan/58686-nonnull-allocation-annotations branch from b4c04b2 to 770fd10 Compare May 6, 2022 03:18
@grynspan
Copy link
Contributor Author

grynspan commented May 6, 2022

@swift-ci please smoke test

@grynspan grynspan merged commit 54b9aff into swiftlang:main May 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants