Make MultiProducerSingleConsumerAsyncChannel internals compatible with library evolution#426
Open
adityasingh2400 wants to merge 1 commit into
Open
Make MultiProducerSingleConsumerAsyncChannel internals compatible with library evolution#426adityasingh2400 wants to merge 1 commit into
adityasingh2400 wants to merge 1 commit into
Conversation
…h library evolution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MultiProducerSingleConsumerAsyncChannel, introduced in 1.1.0, fails to compile when the consuming module is built with library evolution enabled (BUILD_LIBRARY_FOR_DISTRIBUTION=YES, i.e.-enable-library-evolution). This blocks every team that distributes a binary SDK as an XCFramework depending onswift-async-algorithms; the 1.0.x line is currently the only usable version for them.Two classes of error come from
Sources/AsyncAlgorithms/MultiProducerSingleConsumerChannel/MultiProducerSingleConsumerAsyncChannel+Internal.swift:'consume' can only be used to partially consume storage— the@inlinable mutating funcmethods on the non-@frozen_StateMachinestruct (and the_InternalBackpressureStrategyenum) doswitch consume self._state/switch consume self. Under library evolution a non-frozen type's stored properties are reached through resilient accessors, which do not vend the direct ownershipconsumerequires.initializer for class '_Storage' is '@inlinable' and must delegate to another initializer, plus the related'let' property ... may not be initialized directlyerrors on the@inlinableinitializers of the~Copyablepayload structs. Under library evolution an@inlinableinitializer of a resilient type may only assign through a delegatingself.init/self = ..., not set stored properties directly.These reproduce on 1.1.0–1.1.3;
mainis still affected.Changes:
@usableFromInline) types whose stored storage isconsumed or directly initialized in@inlinablemembers as@frozen, so their layout is fixed and direct storage access /consumeis permitted under library evolution:_StateMachine,_Stateand itsChanneling/SourceFinished/Finishedpayloads,_InternalBackpressureStrategyand its_Watermark, theResumeElement/ResumeElementAndProducers/ResumeFailurewrappers, andSendableConsumeOnceBox. These are all already@usableFromInlineinternal types, so freezing them is not a public-API or source-stability change._TinyArrayand itsStorageenum@frozenfor the same reason (they back the frozen payloads)._Storage.init(backpressureStrategy:)from@inlinableto@usableFromInline, since an@inlinabledesignated class initializer must delegate under library evolution and this one sets a stored property directly.No public API changes and no behavioral changes — only resilience-attribute additions on internal types and one inlinability downgrade on an internal initializer.
Testing:
swift build --target AsyncAlgorithms -Xswiftc -enable-library-evolutionnow succeeds (it fails onmainwith the errors above).swift build(normal, non-evolution) succeeds.swift test --filter MultiProducerSingleConsumerpasses — 37 tests, 0 failures.Fixes #405.