-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
[Runtime] Unify debug variable parsing from the environment and avoid getenv when possible. #32137
Conversation
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.
This definitely is going to improve working on the runtime! Thanks for doing this.
|
||
// Define backing variables. | ||
#define VARIABLE(name, type, defaultValue, help) \ | ||
type Environment::name ## _variable; |
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.
Should this not be static type ...
?
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.
No, this and initializeToken
get exposed to other files through the inline getter functions in the header, so they need to be non-static
.
} | ||
|
||
// Initialization code. | ||
OnceToken_t Environment::initializeToken; |
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.
Should this not be static
?
da26553
to
a8edaca
Compare
@compnerd Thanks for the feedback! I just pushed changes to address the comments I didn't reply to. Let me know if you see anything else. |
@swift-ci please test |
Build failed |
Build failed |
a8edaca
to
fbcb335
Compare
@swift-ci please test |
Build failed |
Build failed |
fbcb335
to
5ea8bc3
Compare
@swift-ci please test |
Build failed |
Build failed |
@@ -0,0 +1,41 @@ | |||
//===--- CompatibiltyOverride.h - Debug variables. --------------*- C++ -*-===// |
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.
//===--- CompatibiltyOverride.h - Debug variables. --------------*- C++ -*-===// | |
//===--- EnvironmentVariables.h - Debug variables. --------------*- C++ -*-===// |
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.
D'oh, good catch. Thank you!
@@ -0,0 +1,182 @@ | |||
//===--- CompatibiltyOverride.h - Debug variables. --------------*- C++ -*-===// |
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.
//===--- CompatibiltyOverride.h - Debug variables. --------------*- C++ -*-===// | |
//===--- EnvironmentVariables.cpp - Debug variables. ------------*- C++ -*-===// |
… getenv when possible. There are a few environment variables used to enable debugging options in the runtime, and we'll likely add more over time. These are implemented with scattered getenv() calls at the point of use. This is inefficient, as most/all OSes have to do a linear scan of the environment for each call. It's also not discoverable, since the only way to find these variables is to inspect the source. This commit places all of these variables in a central location. stdlib/public/runtime/EnvironmentVariables.def defines all of the debug variables including their name, type, default value, and a help string. On OSes which make an `environ` array available, the entire array is scanned in a single pass the first time any debug variable is requested. By quickly rejecting variables that do not start with `SWIFT_`, we optimize for the common case where no debug variables are set. We also have a fallback to repeated `getenv()` calls when a full scan is not possible. Setting `SWIFT_HELP=YES` will print out all available debug variables along with a brief description of what they do.
5ea8bc3
to
f2fb539
Compare
@swift-ci please test |
Build failed |
Build failed |
@swift-ci please test |
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.
Nice! I like how you've organized this. Should be pretty easy to build on in the future.
@@ -5655,10 +5656,8 @@ void swift::verifyMangledNameRoundtrip(const Metadata *metadata) { | |||
// variable lets us easily turn on verification to find and fix these | |||
// bugs. Remove this and leave it permanently on once everything works | |||
// with it enabled. | |||
bool verificationEnabled = |
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.
Remove the last sentence of the comment above, since we no longer plan to remove this verification code.
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.
Good idea. I'll do that in a followup, since I just got the thing through PR testing and I'd rather not continue that particular struggle....
In swiftlang#32137 direct environment variable parsing was introduced, the availability of which is branched by a preprocessor symbol (`ENVIRON`) if the environment is available directly on the platform, or if getenv must be used. The message expectation in the unit test in the however diverged on the non-`ENVIRON` branch, causing a unit test failure. This PR fixes the expectation, but also, while we're here, OpenBSD supports the `ENVIRON` branch anyway.
There are a few environment variables used to enable debugging options in the
runtime, and we'll likely add more over time. These are implemented with
scattered getenv() calls at the point of use. This is inefficient, as most/all
OSes have to do a linear scan of the environment for each call. It's also not
discoverable, since the only way to find these variables is to inspect the
source.
This commit places all of these variables in a central location.
stdlib/public/runtime/EnvironmentVariables.def defines all of the debug
variables including their name, type, default value, and a help string. On OSes
which make an
environ
array available, the entire array is scanned in a singlepass the first time any debug variable is requested. By quickly rejecting
variables that do not start with
SWIFT_
, we optimize for the common case whereno debug variables are set. We also have a fallback to repeated
getenv()
callswhen a full scan is not possible.
Setting
SWIFT_HELP=YES
will print out all available debug variables along witha brief description of what they do.