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

[NFC] Replace PackageConditionProtocol with PackageCondition #7117

Merged
merged 9 commits into from
Dec 5, 2023

Conversation

MaxDesiatov
Copy link
Contributor

@MaxDesiatov MaxDesiatov commented Nov 22, 2023

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 with FIXME 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 are Hashable. 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 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 new PackageCondition enum.

This also allows us to remove a custom conformance to Hashable on ResolvedTarget, unblocking a conversion of ResolvedTarget to a value type and making it Sendable in the future.

@MaxDesiatov MaxDesiatov self-assigned this Nov 22, 2023
@MaxDesiatov
Copy link
Contributor Author

@swift-ci test

1 similar comment
@MaxDesiatov
Copy link
Contributor Author

@swift-ci test

@MaxDesiatov
Copy link
Contributor Author

@swift-ci test windows

@MaxDesiatov
Copy link
Contributor Author

@swift-ci test

@MaxDesiatov
Copy link
Contributor Author

@swift-ci test windows

@MaxDesiatov
Copy link
Contributor Author

@swift-ci test windows

1 similar comment
@MaxDesiatov
Copy link
Contributor Author

@swift-ci test windows

@MaxDesiatov
Copy link
Contributor Author

@swift-ci test linux

@MaxDesiatov MaxDesiatov marked this pull request as draft November 27, 2023 15:36
@MaxDesiatov
Copy link
Contributor Author

@swift-ci test linux

@MaxDesiatov
Copy link
Contributor Author

Marking as draft until "Linux (smoke test)" job is fixed.

@MaxDesiatov
Copy link
Contributor Author

@swift-ci test

1 similar comment
@MaxDesiatov
Copy link
Contributor Author

@swift-ci test

@MaxDesiatov MaxDesiatov added no functional change No user-visible functional changes included and removed no functional change No user-visible functional changes included labels Dec 1, 2023
@MaxDesiatov
Copy link
Contributor Author

@swift-ci test

1 similar comment
@MaxDesiatov
Copy link
Contributor Author

@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.
@MaxDesiatov MaxDesiatov force-pushed the maxd/package-condition branch from 37c0f41 to a6760d9 Compare December 2, 2023 20:39
@MaxDesiatov
Copy link
Contributor Author

@swift-ci test

@MaxDesiatov
Copy link
Contributor Author

@swift-ci test windows

1 similar comment
@MaxDesiatov
Copy link
Contributor Author

@swift-ci test windows

@MaxDesiatov MaxDesiatov marked this pull request as ready for review December 2, 2023 21:30
@MaxDesiatov MaxDesiatov added the no functional change No user-visible functional changes included label Dec 2, 2023
@MaxDesiatov MaxDesiatov changed the title Filter out duplicate package manifest conditions Allow types containing PackageCondition to become value types Dec 2, 2023
MaxDesiatov added a commit that referenced this pull request Dec 3, 2023
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.
@MaxDesiatov MaxDesiatov added the modules graph Modules dependency resolution label Dec 3, 2023
@MaxDesiatov MaxDesiatov changed the title Allow types containing PackageCondition to become value types [NFC] Replace PackageConditionProtocol with PackageCondition Dec 3, 2023
}
}

public var platformsCondition: PlatformsCondition? {
Copy link
Contributor

Choose a reason for hiding this comment

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

are these really required?

Copy link
Contributor Author

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 }).

@MaxDesiatov MaxDesiatov merged commit e9fa373 into main Dec 5, 2023
@MaxDesiatov MaxDesiatov deleted the maxd/package-condition branch December 5, 2023 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
modules graph Modules dependency resolution no functional change No user-visible functional changes included
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants