Skip to content

[Performance diagnostics] Enable checking of throw instructions #77752

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

Merged
merged 5 commits into from
Dec 2, 2024

Conversation

DougGregor
Copy link
Member

When performance diagnostics were introduced, typed throws didn't exist
so it was not generally possible to have throws anywhere without
triggering performance diagnostics. As a short term hack, we disabled
checking of throw instructions and the basic blocks that terminate
in a throw.

Now that typed throws is available and can be used to eliminate
allocations with error handling, remove all of the hacks. We'll now
diagnose attempts to throw or catch existential values (e.g., the any Error used for untyped throws), but typed throws are fine.

@DougGregor
Copy link
Member Author

This builds on #77748. That PR made typed throws avoid allocations in practice, lifting a restriction. This PR removes the hack that allowed untyped throws through the performance-annotation checker, even though they would allocate. So this PR tightens up performance annotation checking in a way that may reject existing code (that should always have been rejected).

@DougGregor
Copy link
Member Author

@swift-ci please smoke test

Copy link
Contributor

@eeckstein eeckstein left a comment

Choose a reason for hiding this comment

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

Please remove the declaration of neBlocks, too. And at that occasion also in visitFunctionEmbeddedSwift.
You can remove the NonErrorHandlingBlocks utility at all. It's not used anywhere else and we will not need it anymore - at least not in C++.

Prior to throwing, Swift emits a call to `swift_willThrow(Typed)`,
which allows various diagnostic tools (such as debuggers and testing
libraries) to intercept errors at the point where they are initially
thrown.

Since `swift_willThrow(Typed)` can be hooked by arbitrary code at
runtime, there is no way for it to meet performance constraints like
@_noLocks or @_noAllocation. Therefore, in a function that has those
performance constraints specified, disable emission of the call to
`swift_willThrow(Typed)`.

Fixes rdar://140230684.
@DougGregor DougGregor force-pushed the perf-diag-check-throws branch from c354f90 to 7d73aab Compare November 21, 2024 18:24
@DougGregor DougGregor requested a review from a team as a code owner November 21, 2024 18:24
@DougGregor
Copy link
Member Author

Rebased on top of #77780, removed NonErrorHandlingBlocks.

@DougGregor
Copy link
Member Author

@swift-ci please smoke test

Copy link
Contributor

@eeckstein eeckstein left a comment

Choose a reason for hiding this comment

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

lgtm, thanks!

@DougGregor DougGregor force-pushed the perf-diag-check-throws branch from 7d73aab to 131bd17 Compare November 21, 2024 20:46
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

When performance diagnostics were introduced, typed throws didn't exist
so it was not generally possible to have throws anywhere without
triggering performance diagnostics. As a short term hack, we disabled
checking of `throw` instructions and the basic blocks that terminate
in a `throw`.

Now that typed throws is available and can be used to eliminate
allocations with error handling, remove all of the hacks. We'll now
diagnose attempts to throw or catch existential values (e.g., the `any
Error` used for untyped throws), but typed throws are fine.
@DougGregor DougGregor force-pushed the perf-diag-check-throws branch from 131bd17 to 1d3332d Compare November 22, 2024 00:08
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

@swift-ci please smoke test macOS

@DougGregor DougGregor enabled auto-merge November 22, 2024 17:30
@DougGregor DougGregor disabled auto-merge December 2, 2024 06:54
@DougGregor DougGregor merged commit a93e8fd into swiftlang:main Dec 2, 2024
3 checks passed
@DougGregor DougGregor deleted the perf-diag-check-throws branch December 2, 2024 06:54
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.

2 participants