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

Fix Log.ItemFormat result builders in Swift 5.8 🪵 #263

Merged
merged 1 commit into from
Apr 6, 2023

Conversation

p4checo
Copy link
Member

@p4checo p4checo commented Apr 5, 2023

Checklist

Motivation and Context

Due to recent improvements to Result Builders in Swift 5.8 / Xcode 14.3 the existing Log.ItemFormat.Builder implementation resulted in some ambiguities due to it being used with two final result types:

  • Formatting<Output>: merged formatting closure witness
  • [Formatting<Output>]: array of formatting witnesses representing a group to which we apply transformations, most notably adding separators where we require the independent un-merged format group elements.

While in the previous result builder implementation the result type was propagated to the inner builder closure, that is no longer the case in the new version which causes the ambiguity.

Despite not being as compact, the simplest solution was to have two different builders where each specializes in its own result type. It causes a bit of duplication, but makes the Swift 5.8 compiler happy and requires no changes at the point of usage of current code, while being backwards compatible with Swift 5.7.

Description

  • Create new Log.ItemFormat.GroupBuilder and use where item format groups are required.

  • Fix and add relevant UTs.

References

@codecov
Copy link

codecov bot commented Apr 5, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.01 🎉

Comparison is base (b8f3f67) 96.04% compared to head (f137cdd) 96.05%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #263      +/-   ##
==========================================
+ Coverage   96.04%   96.05%   +0.01%     
==========================================
  Files         100      101       +1     
  Lines        4976     4995      +19     
==========================================
+ Hits         4779     4798      +19     
  Misses        197      197              
Impacted Files Coverage Δ
.../ItemFormat/Log+ItemFormat+GenericComponents.swift 95.78% <ø> (ø)
...g/ItemFormat/Builders/Log+ItemFormat.Builder.swift 100.00% <100.00%> (ø)
...mFormat/Builders/Log+ItemFormat.GroupBuilder.swift 100.00% <100.00%> (ø)
...ing/ItemFormat/Log+ItemFormat+ItemComponents.swift 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Due to recent improvements to Result Builders in Swift 5.8 / Xcode 14.3
the existing `Log.ItemFormat.Builder` implementation resulted in some
ambiguities due to it being used with two final result types:

- `Formatting<Output>`: merged formatting closure witness
- `[Formatting<Output>]`: array of formatting witnesses representing a
group to which we apply transformations, most notably adding separators
where we require the independent un-merged format group elements.

While in the previous result builder implementation the result type was
propagated to the inner builder closure, that is no longer the case in
the new version which causes the ambiguity.

Despite not being as compact, the simplest solution was to have two
different builders where each specializes in its own result type. It
causes a bit of duplication, but makes the Swift 5.8 compiler happy and
requires no changes at the point of usage of current code, while being
backwards compatible with Swift 5.7.

## Changes

- Create new `Log.ItemFormat.GroupBuilder` and use where item format
groups are required.

- Fix and add relevant UTs.

## References

- https://forums.swift.org/t/improved-result-builder-implementation-in-swift-5-8/63192
- https://github.com/apple/swift-evolution/blob/main/proposals/0289-result-builders.md#changes-from-the-first-revision
@p4checo p4checo merged commit 91c7187 into master Apr 6, 2023
10 checks passed
@p4checo p4checo deleted the fix-log-result-builders branch April 6, 2023 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants