Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions Sources/Testing/ABI/ABI.Record.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,26 @@ extension ABI.Record: Codable {
init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)

let versionNumber = try container.decode(VersionNumber.self, forKey: .version)
if versionNumber != V.versionNumber {
func validateVersionNumber(_ versionNumber: VersionNumber) throws {
if versionNumber == V.versionNumber {
return
}
#if !hasFeature(Embedded)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have to strictly match the patch version on embedded?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it's due to a more fundamental limitation: in Embedded Swift, there are no metatypes at all, so an expression such as V.self is not valid

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm no longer as enamoured of the "versions are types" approach and will probably make this code non-generic in a future release.

// Allow for alternate version numbers if they correspond to the expected
// record version (e.g. "1.2.3" might map to `v1_2_0` without a problem.)
if ABI.version(forVersionNumber: versionNumber) == V.self {
return
}
#endif
throw DecodingError.dataCorrupted(
DecodingError.Context(
codingPath: decoder.codingPath + CollectionOfOne(CodingKeys.version as any CodingKey),
debugDescription: "Unexpected record version \(versionNumber) (expected \(V.versionNumber))."
)
)
}
let versionNumber = try container.decode(VersionNumber.self, forKey: .version)
try validateVersionNumber(versionNumber)

switch try container.decode(String.self, forKey: .kind) {
case "test":
Expand Down
2 changes: 1 addition & 1 deletion Sources/Testing/ABI/ABI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ extension ABI {
}

/// The current supported ABI version (ignoring any experimental versions.)
typealias CurrentVersion = v0
typealias CurrentVersion = v6_3

/// The highest defined and supported ABI version (including any experimental
/// versions.)
Expand Down
Loading