Fix Embedded Swift support for Entity decoding#24
Merged
Conversation
Resolves to the concrete CoreModelError under Embedded Swift (where any Error existentials are disallowed) and to any Swift.Error otherwise, so callers can adopt throws(ModelDataDecodingError) with no behavior change off-Embedded.
The generic decode/decodeRelationship helpers threw untyped (any Error), forcing a boxing thunk the compiler rejects under Embedded Swift once specialized for a concrete type. Adopt the typed throws clause and replace the throwing objectIDs.map with an explicit loop, since the rethrows overload erases the thrown type back to any Error.
The untyped throws requirement forced every throwing witness to synthesize an any Error boxing thunk in the witness table, which Embedded Swift rejects. encode() is left untyped since no witness throws.
An always-built (Embedded-gated) concrete Entity conformance that specializes the generic init(from:)/decode path the wasm-embedded CI job never reaches through the test target, guarding against error-boxing regressions.
Code Coverage OverviewLanguages: Swift Swift / code-coverage/llvm-covThe overall coverage remains at 96%, unchanged from the branch. Code Coverage is in Public Preview. Learn more and provide us with your feedback. |
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.
Summary
Adds proper Embedded Swift support for the generic
Entity-based decode path. The library target already compiled standalone under Embedded and theswift-wasmCI job passed — but neither ever instantiated the genericEntity.init(from:)/ModelData.decodepath for a concrete conforming type (those types live in the test target, which the embedded job doesn't build). So the bug was latent: the moment a downstream package declares a concreteEntityand callsinit(from:)under Embedded, it fails with:Root cause
Two places throw a concrete
CoreModelErrorfrom a function declared as untypedthrows(sugar forthrows(any Error)). Under Embedded Swift, boxing a concrete error intoany Erroris disallowed, so the compiler rejects it once the path is specialized for a real type:Entity.init(from:)— the protocol requirement itself is untypedthrows, forcing a boxing thunk in every throwing witness's table entry.ModelData.decode/decodeRelationship— plainthrows, but under Embedded they call factories returning concreteCoreModelError.Error.swiftalready returned the concrete type conditionally under Embedded — it just never propagated that into thethrowsclauses of its callers.Fix
Introduce one typealias —
ModelDataDecodingError— resolving toCoreModelErrorunder Embedded andany Swift.Errorotherwise, and use it as thethrows(...)type on the requirement and the four generic decode helpers. On non-Embedded platformsthrows(ModelDataDecodingError)is byte-for-byte identical to the old plainthrows: zero behavior change, no API break for existing conformers on Darwin/Linux/Windows.One spot needed more than a signature swap: the
objectIDs.map { throw … }indecodeRelationship(_:forKey:)for to-many goes through therethrowsoverload, which erases the thrown type back toany Error. It's rewritten as an explicit loop so the typed error propagates.encode()is left untyped — every witness is non-throwing today, so there's nothing to box.Regression coverage
Adds an always-built, Embedded-gated concrete
Entityfixture (EmbeddedFixture.swift) that forces the compiler to specialize the generic decode path — the exact instantiation CI was missing. Without it, this regression can silently reappear.Out of scope
The other Embedded caveat —
ModelStorage's genericfetch/insert/delete/countandViewContext— is a separate upstream compiler bug (swiftlang/swift#78811), unrelated to error-boxing, and is not touched here.Verification
swift build --target CoreModel✅swift build --target CoreModel --swift-sdk swift-6.3.3-RELEASE_wasm-embedded✅ (fails without the loop fix)swift build(full package) ✅swift test✅ 22 tests, 7 suites