Skip to content

[Runtime] Static constructors and destructors should be an error here. #38562

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
Jul 28, 2021

Conversation

al45tair
Copy link
Contributor

Except for a handful of places we know about, there should be no static constructors or destructors in the runtime; they're undesirable because they inflate start up or shut down times, and in the case of destructors we can't even guarantee that they will actually run (e.g. if the program declares that it supports fast termination, they just won't).

It should be OK to change the warnings to errors as a result.

rdar://80965245

Except for a handful of places we know about, there should be no static
constructors or destructors in the runtime; they're undesirable because
they inflate start up or shut down times, and in the case of destructors
we can't even guarantee that they will actually run (e.g. if the program
declares that it supports fast termination, they just won't).

It should be OK to change the warnings to errors as a result.

rdar://80965245
@al45tair
Copy link
Contributor Author

@swift-ci Please smoke test

@al45tair
Copy link
Contributor Author

@swift-ci Please smoke test macOS platform

@al45tair al45tair requested a review from mikeash July 22, 2021 17:45
@mikeash
Copy link
Contributor

mikeash commented Jul 22, 2021

LGTM. @compnerd any pitfalls with this that we might not have thought of?

@al45tair
Copy link
Contributor Author

@swift-ci Please smoke test macOS platform

1 similar comment
@al45tair
Copy link
Contributor Author

@swift-ci Please smoke test macOS platform

@drodriguez
Copy link
Contributor

This might need to be gated by platform somehow. There are some platforms (Cygwin, Android, Haiku, Wasi) that do not support mutexes without destructors. I think I might have "fixed" Android in #38686, but the other platforms might still fail.

@mikeash
Copy link
Contributor

mikeash commented Jul 29, 2021

Unfortunate. Can we disable the warnings/errors at the specific point of use on those platforms?

compnerd added a commit to compnerd/apple-swift that referenced this pull request Jul 30, 2021
Replace the `static std::mutex` with Swift's `StaticMutex` so that we
avoid triggering an error due to an exit time destructor.  Repairs the
build after swiftlang#38562.
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.

3 participants