-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SIL] Accesses to globals are deinit barriers. #65309
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
18c6826
to
af9007a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to be so pessimistic about all globals. We generally want to optimize globals that are internal to the module.
We at least need to conservatively handle globals defined outside the module. This will cover the important errno
case. In that case, a deinit makes a system call, and we want to make sure we don't run that deinit before some other code that reads errno. In general, the deinit barrier is trying to account for "externally visible side effects". To be true to the spirit of the barrier, we could be a little more conservative and avoid reordering a deinit with any externally visible global:
storage.getGlobal().isPossiblyUsedExternally()
?
89d6c78
to
09c938f
Compare
Added check for possible external use and test case. |
@swift-ci please test |
@swift-ci please benchmark |
After discussing this and realizing there's no real obvious distinction between "external" globals and globals in general, I'm fine just being pessimistic in the presence of any global variable access. (Hopefully we'll be able to stop treating top-level variables as globals soon.) |
Accesses to globals can't be reordered with deinits since deinits could read such globals. rdar://98542123
09c938f
to
5b6c1d6
Compare
@swift-ci please test |
Removed check for external use and modified test case; changed variable name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Accesses to globals which can be used externally (e.g. errno being written to elsewhere) can't be reordered with deinits since deinits could read such globals.
rdar://98542123