Skip to content
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

Proposal for #SwiftSettings. #2699

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

gottesmm
Copy link
Contributor

Just an initial draft for feedback

@hborla hborla marked this pull request as draft February 19, 2025 17:58
@apple-fcloutier
Copy link

Some compiler settings have a security impact and I don't expect the number of these to go down over time. As we get a new way to change settings, it's spreading the source of truth for what settings are or aren't enabled in any given project. Do we enumerate the ways compiler settings can be modified in an Xcode project or in a SwiftPM project anywhere?

@hborla
Copy link
Member

hborla commented Feb 19, 2025

Please leave design feedback in the forthcoming pitch thread on the forums - it will be posted soon - and leave editorial feedback on this PR.

@gottesmm gottesmm force-pushed the compiler-settings branch 3 times, most recently from 27d96b4 to 78f02f6 Compare February 20, 2025 20:31
@etcwilde
Copy link
Contributor

@rjmccall rjmccall added the LSG Contains topics under the domain of the Language Steering Group label Feb 24, 2025
@gottesmm gottesmm force-pushed the compiler-settings branch 10 times, most recently from b2c6122 to 0034b65 Compare March 6, 2025 02:11
@gottesmm gottesmm force-pushed the compiler-settings branch 3 times, most recently from 8be7d33 to 37244ba Compare March 18, 2025 19:58
@gottesmm gottesmm force-pushed the compiler-settings branch from 37244ba to cf7975e Compare March 18, 2025 20:02
@hborla hborla marked this pull request as ready for review March 19, 2025 15:24
@hborla hborla changed the title [DRAFT] Initial draft of proposal for compilerSettings. Proposal for #SwiftSettings. Mar 19, 2025
Copy link
Member

@hborla hborla left a comment

Choose a reason for hiding this comment

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

This is all editorial feedback, the proposal content itself looks good! I think you've addressed all of the feedback surfaced in the pitch thread.

these flags one module at a time instead of one file at a time. When confronted
with this, users are forced to split the subset of files into a separate module
creating an unnecessary module split. We foresee that this will occur more often
in the future if new features like [Controlling Default Actor Isolation](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0466-control-default-actor-isolation.md)
Copy link
Member

Choose a reason for hiding this comment

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

I think this specific argument isn't compelling, because we really don't want to introduce more features like default actor isolation in the future. I think you can just remove this sentence and say this applies for default actor isolation and also for the various diagnostic control flags.


```swift
extension SwiftSetting {
public static func defaultIsolation(_ isolation: Actor.Type?) -> SwiftSetting { SwiftSetting() }
Copy link
Member

Choose a reason for hiding this comment

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

This should match the package manifest API in SE-0466, which uses MainActor.Type?

parsing of other constructs since the name shadowing rules in the compiler will
ensure that any local macros or types that shadow those names will take
precedence. If the user wishes to still use `#SwiftSettings`, the user can spell
the macro as `#Swift.SwiftSettings` as needed.
Copy link
Member

Choose a reason for hiding this comment

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

Does this work because it's parsed as a freestanding declaration macro? I'm pretty sure that in expression context, #Swift.SwiftSettings is parsed as a #Swift freestanding expression macro with .SwiftSettings as a postfix member. (doesn't really matter for this proposal, only for my curiosity!)


Adopters of this proposal should be aware that while this feature does not
inherently break ABI, enabling options using `#SwiftSettings` that break ABI can
result in ABI breakage.
Copy link
Member

Choose a reason for hiding this comment

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

You can be more explicit here - say that changing default actor isolation on public API is not source compatible and not ABI compatible.

updated state. We think that this approach will make it significantly easier for
larger modules to be migrated to strict concurrency.

#### `strictConcurrency`
Copy link
Member

Choose a reason for hiding this comment

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

I recommend omitting this section and the next one; since you've left strictConcurrency and warningsAsErrors as a future direction, it's not a good use of time for reviewers to comment on the details of how it would be accomplished in the review thread for this proposal.

on the command line are passed as parameters to the static method. The compiler
upon parsing a `#SwiftSettings` macro updates its internal state to set the
appropriate settings before compiling the rest of the file. An example of such a
`#SwiftSettings` invocation is the following:
Copy link
Member

Choose a reason for hiding this comment

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

I didn't see a mention in the detailed design about the reason why you chose this spelling, which is to match the Swift Package Manifest API so there's a consistent spelling for settings in source code. I recommend putting that either here or in the detailed design.


We could also use an "import" syntax to enable features like Python and
Scala. We decided to not follow this approach since `#` is a manner in swift of
saying "compile time".
Copy link
Member

Choose a reason for hiding this comment

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

Further, we'd be introducing a third way of specifying build settings (command line spelling, package manifest spelling, and an import-like spelling). The approach in this proposal was taken primarily to keep a consistent way of spelling build settings in source code.


We could also use a typealiased based syntax. But this would only be able to be
used to specify the current global actor and would not let us add additional
features such as controlling strict concurrency or warnings as errors.
Copy link
Member

Choose a reason for hiding this comment

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

More importantly, a type alias does not work for default actor isolation, because we'd need some type to represent nonisolated. It's also easy to get wrong because misspelling a type alias is still valid Swift code, etc.

settings that semantically can have file wide implications. If we wanted to
support push/pop of compiler settings it would involve different trade-offs and
restrictions on what settings would be able to be used since the restrictions
would necessarily need to be greater. As an example, we could never allow for
Copy link
Member

Choose a reason for hiding this comment

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

There's an unfinished sentence here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LSG Contains topics under the domain of the Language Steering Group
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants