Fix Swift 6.2 library evolution build failures caused by @inlinable initializer restrictions - #122
Open
JHeisecke wants to merge 4 commits into
Open
Fix Swift 6.2 library evolution build failures caused by @inlinable initializer restrictions#122JHeisecke wants to merge 4 commits into
JHeisecke wants to merge 4 commits into
Conversation
…olution
Swift 6.2 with SWIFT_ENABLE_LIBRARY_EVOLUTION=YES rejects @inlinable
designated initializers that directly assign stored properties
(self.foo = ...). The compiler cannot guarantee binary compatibility
if stored property layout changes after clients have inlined the body.
Fix: remove @inlinable from all affected designated initializers
across
11 files. Inits called from @inlinable functions are annotated
@usableFromInline instead of being left internal (which would cause a
separate "cannot be referenced from @inlinable function" error).
Affected types:
- ASN1.ParserNode, ASN1.ParseResult (→ @usableFromInline)
- ASN1Node, ASN1NodeCollection, ASN1NodeCollection.Iterator (→
@usableFromInline)
- ASN1.LazySetOfSequence.Iterator (→ @usableFromInline)
- ASN1Identifier (shortIdentifier init → @usableFromInline;
tagWithNumber → public only)
- IntegerBytesCollection.Index (→ @usableFromInline)
- DER.Serializer, ASN1OctetString, ASN1BitString, ObjectIdentifier,
ASN1Any, UTCTime, GeneralizedTime, all ASN1String variants
(→ public, no inlining attribute)
…nd LazySetOfSequence
Lukasa
requested changes
May 11, 2026
Lukasa
left a comment
Contributor
There was a problem hiding this comment.
Thanks for this patch!
SwiftASN1 does not support BUILD_LIBRARY_FOR_DISTRIBUTION. Specifically, we do not provide a stable ABI, and at this time have no intention of doing so. To that end we do not recommend using SwiftASN1 in this way.
We would be willing to accept a patch that fixes the build in that environment, but we would not be willing to do so at the cost of performance without that flag. This change removes some @inlinable flags, which will harm the performance of the stack. If you can provide a version of this patch that meets your use-case and doesn't regress your stack, I'll happily accept it.
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.
Motivation:
Swift 6.2 enforces stricter definite initialization rules for
@inlinableinitializers under library evolution mode (BUILD_LIBRARY_FOR_DISTRIBUTION=YES). Two distinct violations occur acrossswift-asn1:@inlinablebecause the definite initialization proof cannot be verified across module boundaries withoutself = .init(...)syntax.ASN1Null.init(derEncoded:withIdentifier:)) returns normally after validation but never explicitly sets self, which Swift 6.2 now flags as an error.This prevents
swift-asn1from compiling as a distributed binary framework (XCFramework or any library evolution target) under Swift 6.2.Modifications:
@inlinable →
@usableFromInline(or removed) on designated initializers acrossASN1.swift,ASN1BitString.swift,ASN1Identifier.swift,ASN1Integer.swift,ASN1OctetString.swift,ASN1Strings.swift,GeneralizedTime.swift,ObjectIdentifier.swift,UTCTime.swift, andDER.swift; these inits assign storedproperties directly and cannot satisfy @inlinable definite initialization requirements.
ASN1Null.init(derEncoded:withIdentifier:), addedself = .init()at end of success path, keeping the init@inlinable.ASN1Any, extracted a@usableFromInlinedesignatedinit(_serializedBytes:), then converted the two throwing@inlinablepublic inits to delegate viaself.init(_serializedBytes:...)instead of assigning the stored property directly. Removed@inlinablefrominit(derEncoded:)(non-throwing, directly assigns a computed property).Result:
swift-asn1compiles cleanly under Swift 6.2 with library evolution enabled. No behavior change, all public APIs remain callable from inlinable client code via @usableFromInline internal inits.