Skip to content

[NFC] SPMBuildCore: make BuildSystemProvider.Provider a protocol #6984

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

Merged
merged 1 commit into from
Oct 11, 2023

Conversation

MaxDesiatov
Copy link
Contributor

@MaxDesiatov MaxDesiatov commented Oct 10, 2023

Motivation:

When requirements are expressed as a closure type (BuildSystemProvider.Provider in this case), it confuses the type checker when working on any related code. Multi-line closure type inference has been known to be suboptimal in Swift, and converting it to a protocol localizes "Type of expression is ambiguous without a type annotation" to a specific line that causes the error instead of attaching it to the whole closure.

Modifications:

Created a new protocol BuildSystemFactory with a makeBuildSystem method that replaces the previous BuildSystemProvider.Provider closure typealias. Added new private struct NativeBuildSystemFactory and private struct XcodeBuildSystemFactory in BuildSystemSupport.swift, which conform to the new protocol and are used in the implementation of defaultBuildSystemProvider computed property.

Result:

It's much easier to work with BuildSystemFactory protocol: it no longer confuses the type checker when changes to the closure body are made or need to be made. Additionally, the new protocol method can use named function arguments instead of unnamed ones, since closures don't support the former.

### Motivation:

When expressed as a closure, it confuses the type checker when working on any related code. Multi-line closure type inference has been known to be suboptimal in Swift, and converting it to a protocol localizes "Type of expression is ambiguous without a type annotation" to a specific line that causes the error instead of attaching it to the whole closure.

### Modifications:

Created a new `protocol BuildSystemFactory` with a `makeBuildSystem` method that replaces the previous `BuildSystemProvider.Provider` closure typealias. Added new `private struct NativeBuildSystemFactory` and `private struct XcodeBuildSystemFactory` in `BuildSystemSupport.swift`, which conform to the new protocol and are used in the implementation of `defaultBuildSystemProvider` computed property.

### Result:

It's much easier to work with `BuildSystemFactory` protocol: it no longer confuses the type checker when changes to the closure body are made or need to be made. Additionally, the new protocol method can use named function arguments instead of unnamed ones, since closures don't support the former.

(cherry picked from commit 7f81baf)
@MaxDesiatov MaxDesiatov added build system Changes to interactions with build systems no functional change No user-visible functional changes included labels Oct 10, 2023
@MaxDesiatov MaxDesiatov self-assigned this Oct 10, 2023
@MaxDesiatov
Copy link
Contributor Author

@swift-ci test

@MaxDesiatov
Copy link
Contributor Author

@swift-ci test windows

@MaxDesiatov MaxDesiatov enabled auto-merge (squash) October 10, 2023 18:24
@MaxDesiatov MaxDesiatov merged commit 3251a55 into main Oct 11, 2023
@MaxDesiatov MaxDesiatov deleted the maxd/build-system-factory branch October 11, 2023 01:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build system Changes to interactions with build systems no functional change No user-visible functional changes included
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants