Skip to content

[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

Merged
merged 1 commit into from
Apr 21, 2023

Conversation

nate-chandler
Copy link
Contributor

@nate-chandler nate-chandler commented Apr 20, 2023

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

@nate-chandler nate-chandler changed the title [SIL] Access to globals are deinit barriers. [SIL] Accesses to globals are deinit barriers. Apr 20, 2023
Copy link
Contributor

@atrick atrick left a 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()?

@nate-chandler nate-chandler force-pushed the rdar98542123 branch 2 times, most recently from 89d6c78 to 09c938f Compare April 20, 2023 15:02
@nate-chandler
Copy link
Contributor Author

Added check for possible external use and test case.

@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler
Copy link
Contributor Author

@swift-ci please benchmark

@nate-chandler nate-chandler requested a review from atrick April 20, 2023 15:04
@nate-chandler nate-chandler changed the title [SIL] Accesses to globals are deinit barriers. [SIL] Accesses to globals may be deinit barriers. Apr 20, 2023
@atrick
Copy link
Contributor

atrick commented Apr 21, 2023

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
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler
Copy link
Contributor Author

Removed check for external use and modified test case; changed variable name isInteresting -> retval.

@nate-chandler nate-chandler changed the title [SIL] Accesses to globals may be deinit barriers. [SIL] Accesses to globals are deinit barriers. Apr 21, 2023
Copy link
Contributor

@atrick atrick left a comment

Choose a reason for hiding this comment

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

👍

@nate-chandler nate-chandler merged commit c972a93 into swiftlang:main Apr 21, 2023
@nate-chandler nate-chandler deleted the rdar98542123 branch April 21, 2023 14:02
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