Allow noncopyable elements in AsyncStreaming's collect, pipe, forEachBuffer and writer adapters #477
All Vouch review confidence checks passed
Residual risk 0.32 = Change Risk (0.55) × (1 − Review Confidence (0.43)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.55 · 622 lines diff across 7 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.385
Shallow Review Depth
shallow_review_depth
0.344
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #477"
general
weight: 0.35
FranzBusch
This fixes #471.
collect,pipe,forEachBuffer, the writers'finish()conveniences and both writer adapters didn't compile with a noncopyable element type or a noncopyableFinalElement, even though the protocols declare both~Copyable. This makes them all accept noncopyable types, and changes the existing AsyncStreaming tests to use a noncopyable element so that case is always covered.<details><summary>Changes, tests and what to scrutinise (Claude Opus 5.5)</summary>
Cause. Under SE-0503, a
~Copyableprimary associated type defaults toCopyablewherever its protocol appears in a generic signature, unless that same declaration suppresses it. An inverse on the enclosing extension doesn't cancel the default. So incollect<Container: RangeReplaceableContainer<ReadElement> & ~Copyable & ~Escapable>,Container.ElementbecameCopyable, andContainer.Element == ReadElementthen forcedReadElement: Copyable.FinalElementhad the same problem, and the bodies also copied it (== nil,if let,!). #471 has the full analysis.Commits
1. Suppress Copyable on element types (8 files). Adds
where Container.Element: ~Copyable,Writer.WriteElement: ~CopyableandReadElement: ~Copyable/WriteElement: ~Copyableclauses tocollect,pipeand itsdrainhelper,forEachBuffer, thefinish()extensions and both adapters, in the styleCallerAsyncReader.readandCallerAsyncWriter.writealready use.2. Use noncopyable elements in the existing AsyncStreaming tests (17 files). The shared test readers and writers now carry
NoncopyableInt, a noncopyable wrapper aroundInt, and are generic overFinalElement(inferred asVoid). Writers record what they received in aWriteSink, becausefinishandpipeconsume them. Every test in the reader, writer,collect,forEachBuffer,pipeand adapter files uses them (76 tests once commit 3 is in). Thepipeand adapter tests usedDuplexAsyncChannelonly as a convenient reader and writer; the channels need copyableSendableelements, so those tests now use the helpers, and the channel test files are unchanged. The first version's separateNoncopyableElementTests.swiftis folded into the matching suites.3. Allow a noncopyable
FinalElement(13 files). AddsFinalElement: ~Copyable(andWriter.FinalElement: ~Copyable) to the same APIs. The bodies track completion with adoneflag instead of comparing withnil, move the final element out withswitch consumeandtake(), and declare the read closures' parameterconsuming FinalElement?. Each API gets a test that passes a noncopyable final element through and checks it arrives.4. Show the noncopyable constraints in the proposal (1 file). The
forEachBuffer,collectandpipesignatures inNNNN-async-streaming.mdnow carry the same~Copyableclauses as the code.5. Drop
LifetimeTrackerand the separateFinalElementsuites (12 files, from review).NoncopyableIntis a plain wrapper aroundInt, the tests no longer count live elements, and theFinalElementtests now sit in the existing suites. Same 115 tests, in 15 suites instead of 21.These only remove
Copyablerequirements, so existing callers with copyable types are unaffected. The adapter types' generic signatures change, which changes their mangled names, but the module is behind theUnstableAsyncStreamingtrait.Results (macOS only: Apple Swift 6.4.2 from Xcode 27, macOS 27.2 SDK):
--traits UnstableAsyncStreaming: 361 XCTest tests, plus 94, 104 and 115 Swift Testing tests after commits 1, 2 and 3. Commit 4 only touches the proposal, and commit 5 keeps the same 115 tests. With default traits: 361 tests.swift format lint --strictis clean on every changed file.What to scrutinise
DuplexAsyncChannel. Thepipeand adapter tests no longer run against a real channel. Where a test depended on how many writes happen, the helpers now make the split explicit (maximumChunkSize,bufferCapacity) and the tests assert the write count.~Escapablewriters. After commit 3, all fourpipemethods also compile withWriter: ... & ~Escapableon 6.4, which the TODO in the pipe files says isn't possible. As agreed in review, this PR leaves the constraint and the TODO as they are.NNNN-async-streaming.mdnow matches the new signatures, apart from two differences that were already on main:pipeis shown asasync throwsrather than with typed throws, and the non-throwingforEachBufferoverload isn't listed.AsyncStreamingTests(swiftlang/swift#89639), so they'll stay red here too.</details>
Resolves #471.
🤖 Generated with Claude Code