Skip to content

[SILGen] Disable swift_willThrow(Typed) call in functions that cannot allocate #77748

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

Conversation

DougGregor
Copy link
Member

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.

… allocate

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
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.

This is not good enough, because performance constraints also apply to all called functions.

I think we can just ignore swift_willThrow in performance diagnostics and call it user responsibility to not hook any allocating/locking function to this runtime function.

@DougGregor
Copy link
Member Author

This is not good enough, because performance constraints also apply to all called functions.

I think we can just ignore swift_willThrow in performance diagnostics and call it user responsibility to not hook any allocating/locking function to this runtime function.

Okay, I've come around to this point of view. I'm closing this PR in favor of #77780 that treats the swift_willThrow* entry points as @_noLocks.

@DougGregor DougGregor closed this Nov 21, 2024
@DougGregor DougGregor deleted the no-willthrow-under-performance-constraints branch November 22, 2024 04:52
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