-
Notifications
You must be signed in to change notification settings - Fork 458
[SwiftIfConfig] Add StaticBuildConfiguration #3154
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
[SwiftIfConfig] Add StaticBuildConfiguration #3154
Conversation
Introduce StaticBuildConfiguration, a data structure that describes all of the aspects of a build configuration that are needed for `#if` evaluation. It is Codable so that it can be stored and replayed later.
09e6ae7
to
2fd4ea7
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.
Is TestingBuildConfiguration
still needed, or can it be fully subsumed by StaticBuildConfiguration
?
languageVersion: VersionTuple = VersionTuple(6), | ||
compilerVersion: VersionTuple = VersionTuple(6, 2) |
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.
I'm not super keen on having more places that we need to update version, does this need to be defaulted here?
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.
I suppose we don't have to default it here, no
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, we can do without
It's still used to test places where the evaluation can throw errors. I subsumed it where I could. |
…tion Introduce the option "--build-configuration" to this test program. The input is JSON for a static build configuration, and that configuration will be applied to the parse tree to remove all inactive #if regions before doing anything else with the parse command (printing diagnostics, printing the tree, etc.). Also add a "print" subcommand that prints back the tree after applying whatever transformations are described above. One can use this to implement a basic "preprocess" step that removes all inactive #if regions from the source code.
@swift-ci please test |
1 similar comment
@swift-ci please test |
The (optional) build configuration provides information about the context in which the macro-generated code will be compiled. It allows one to inspect various aspects of the configuration, including available attributes and features, the target architecture/OS/environment/etc., and any custom settings passed via `-D` on the command line.
@swift-ci please test |
The set of imported modules in StaticBuildConfiguration cannot really be complete, because canImport can trigger module lookups that only the compiler can do. Remove it from the configuration, and have canImport always throw an error to indicate the issue.
…e parser The language mode and experimental features are available in the new static build configuration. When it's thread, thread them down into the parser used to create the syntax tree passed along macro implementations. This is the swift-syntax part of rdar://129687671.
6342a41
to
a8472a9
Compare
@swift-ci please test |
@swift-ci please test |
1 similar comment
@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 improvement. As usual, I have a few nitpicky / API design comments 😉
Also, should we add a way that allows users of assertMacroExpansion
to pass in a build configuration?
public var attributes: Set<String> = [] | ||
|
||
/// The active target OS names, e.g., "Windows", "iOS". | ||
public var targetOSNames: Set<String> = [] |
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.
I would call this targetOSs
since none of the other properties contain the Names
suffix, eg. it’s not called targetArchitectureNames
.
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.
targetOSs
reads so weirdly. I guess we can do that.
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.
I thought the same the Names
suffix also seems inconsistent. If you have a semi-strong opinion on the naming here, I can also be convinced to stick with targetOSNames
.
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.
Maybe targetOSes
? targetOperatingSystems
could also work, although it might feel a bit strange to expand OS in a way that is not done in most settings anymore.
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're already abbreviating OperatingSystem
to OS
in the corresponding BuildConfiguration
, so I don't want to write it out expanded here. targetOSes
and targetOSs
are... equally weird to me.
Easy enough, sure. |
@swift-ci please test |
@swift-ci please test |
@swift-ci please test Windows |
@swift-ci please test |
@swift-ci please test macOS |
Introduce
StaticBuildConfiguration
, a data structure that describes all of the aspects of a build configuration that are needed for#if
evaluation. It is Codable so that it can be stored and replayed later.This also extends swift-parser-cli with a new option,
--build-configuration
. The input is JSON for a static build configuration, and that configuration will be applied to the parse tree to remove all inactive#if
regions before doing anything else with the parse command (printing diagnostics, printing the tree, etc.). Finally, it adds aprint
subcommand toswift-parser-cli
that prints back the tree after applying whatever transformations are described above. One can use this toimplement a basic "preprocess" step that removes all inactive
#if
regions from the source code.