Skip to content

Conversation

rxwei
Copy link
Contributor

@rxwei rxwei commented Feb 26, 2022

This PR implements support for buildPartialBlock as proposed in https://forums.swift.org/t/pitch-buildpartialblock-for-result-builders/55561. This is similar to the existing support for buildBlock(combining:into:) except that it also checks for availability when deciding whether to fall back to plain old buildBlock.

In the result builder transform, the compiler will look for static members buildPartialBlock(first:) and buildPartialBlock(accumulated:next:) in the builder type. If the following conditions are met:

  • Both methods buildPartialBlock(first:) and buildPartialBlock(accumulated:next:) exist.
  • The availability of the enclosing declaration is greater than or equal to the availability of buildPartialBlock(first:) and buildPartialBlock(accumulated:next:).

When there's no available buildPartialBlock to call and there's no buildBlock, emit a diagnostic:

result builder 'Builder' does not implement any 'buildBlock' or a combination of 'buildPartialBlock(first:)' and 'buildPartialBlock(accumulated:next:)' with sufficient availability for this call site

@rxwei rxwei requested review from DougGregor and hborla February 26, 2022 06:12
@rxwei
Copy link
Contributor Author

rxwei commented Feb 26, 2022

@swift-ci please test

@rxwei
Copy link
Contributor Author

rxwei commented Feb 26, 2022

@swift-ci please test

@rxwei rxwei force-pushed the buildpartialblock branch from 5d0bd38 to b4376d3 Compare February 28, 2022 05:30
@rxwei
Copy link
Contributor Author

rxwei commented Feb 28, 2022

@swift-ci please clean test

@rxwei
Copy link
Contributor Author

rxwei commented Mar 2, 2022

@swift-ci please build toolchain macOS

This PR implements support for `buildPartialBlock` as proposed in https://forums.swift.org/t/pitch-buildpartialblock-for-result-builders/55561. This is similar to the existing support for `buildBlock(combining:into:)` except that it also checks for availability when deciding whether to fall back to plain old `buildBlock`.

> In the result builder transform, the compiler will look for static members `buildPartialBlock(first:)` and `buildPartialBlock(accumulated:next:)` in the builder type. If the following conditions are met:
> - Both methods `buildPartialBlock(first:)` and `buildPartialBlock(accumulated:next:)` exist.
> - The availability of the enclosing declaration is greater than or equal to the availability of `buildPartialBlock(first:)` and `buildPartialBlock(accumulated:next:)`.

When there's no available `buildPartialBlock` to call and there's no `buildBlock`, emit a diagnostic:
```console
result builder 'Builder' does not implement any 'buildBlock' or a combination of 'buildPartialBlock(first:)' and 'buildPartialBlock(accumulated:next:)' with sufficient availability for this call site
```
@rxwei rxwei force-pushed the buildpartialblock branch from b4376d3 to b1f020b Compare March 4, 2022 08:24
@rxwei
Copy link
Contributor Author

rxwei commented Mar 4, 2022

@swift-ci please test

@rxwei rxwei merged commit f9b2395 into swiftlang:main Mar 4, 2022
@rxwei rxwei deleted the buildpartialblock branch March 4, 2022 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants