-
Notifications
You must be signed in to change notification settings - Fork 1.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
[NFC] Replace PackageConditionProtocol
with PackageCondition
#7117
Conversation
@swift-ci test |
1 similar comment
@swift-ci test |
@swift-ci test windows |
@swift-ci test |
@swift-ci test windows |
@swift-ci test windows |
1 similar comment
@swift-ci test windows |
@swift-ci test linux |
@swift-ci test linux |
Marking as draft until "Linux (smoke test)" job is fixed. |
@swift-ci test |
1 similar comment
@swift-ci test |
@swift-ci test |
1 similar comment
@swift-ci test |
Multiple places in our codebase pass around and store `[any PackageConditionProtocol]` arrays of existentials with `FIXME` notes that those should be sets and not arrays. Adding `Hashable` requirement to `PackageConditionProtocol` doesn't fix the issue, since existentials of this protocol still wouldn't conform to `Hashable`. A simple alternative is to create `enum PackageCondition` with cases for each condition type. We only have two of those types and they're always declared in the same package. There's no use case for externally defined types for this protocol. That allows us to convert uses of `[any PackageConditionProtocol]` to `Set<PackageCondition>`. Existing protocol kept around until clients of SwiftPM can migrate to the new `PackageCondition` enum.
37c0f41
to
a6760d9
Compare
@swift-ci test |
@swift-ci test windows |
1 similar comment
@swift-ci test windows |
PackageCondition
to become value types
Depends on #7117, unblocks #7160. The `PackageModel` module has no business of defining supported platforms computation for resolved targets, products, and packages. This belongs to `PackageGraph`, but was previously leaking out into `PackageModel` by passing the `derivedXCTestPlatformProvider` closure around. That prevented us from converting marking `SupportedPlatforms` as `Hashable` and marking any of `Resolved*` types as value types and also `Hashable`. In the future, when we'll also need to make them `Sendable`, this could become problematic, passing so much state captured in a closure, mostly by accident.
PackageCondition
to become value typesPackageConditionProtocol
with PackageCondition
} | ||
} | ||
|
||
public var platformsCondition: PlatformsCondition? { |
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.
are these really required?
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.
These are used below in .compactMap(\.configurationCondition)
replacing previous .compactMap({ $0 as? ConfigurationCondition })
.
Unblocks
PackageGraph
value types refactoring in #7160 and macros cross-compilation fix in #7118.Multiple places in our codebase pass around and store
[any PackageConditionProtocol]
arrays of existentials withFIXME
notes that those should be sets and not arrays.We also can't convert types containing these arrays to value types with auto-generated
Hashable
conformance, since neither elements of these arrays nor arrays themselves areHashable
. AddingHashable
requirement toPackageConditionProtocol
doesn't fix the issue, since existentials of this protocol still wouldn't conform toHashable
.A simple alternative is to create
enum PackageCondition
with cases for each condition type. We only have two of those types and they're always declared in the same module. There's no use case for externally defined types for this protocol. That allows us to convert uses of[any PackageConditionProtocol]
to[PackageCondition]
. Existing protocol is kept around until clients of SwiftPM can migrate to the newPackageCondition
enum.This also allows us to remove a custom conformance to
Hashable
onResolvedTarget
, unblocking a conversion ofResolvedTarget
to a value type and making itSendable
in the future.