Skip to content

CryptoExtras: SHA512256Digest fails ContiguousBytes conformance on the macOS 27 SDK (MemberImportVisibility + missing import Foundation) #449

Description

@NTC

Summary

CryptoExtras fails to compile against the macOS 27 SDK (Xcode 27):

Sources/CryptoExtras/Digests/SHA512256Digest.swift:18:15: error: type 'SHA512256Digest' does not conform to protocol 'ContiguousBytes'
Foundation.ContiguousBytes.withBytes:3:8: note: protocol requires function 'withBytes' with type '<R, E> ((RawSpan) throws(E) -> R) throws(E) -> R'

Adding a single import Foundation to Sources/CryptoExtras/Digests/SHA512256Digest.swift fixes it.

Environment

  • Xcode 27.0 (27A5228h), Apple Swift 6.3.3 (swift-6.3.3-RELEASE), macOS 27.0 SDK
  • swift-crypto 4.5.0. main looks affected too: the file still has no import statements.

Root cause

Three things combine.

  1. The macOS 27 SDK adds an availability-gated requirement to Foundation's ContiguousBytes:
    func withBytes<R, E>(_ body: (RawSpan) throws(E) -> R) throws(E) -> R.
  2. Package.swift enables SE-0444 MemberImportVisibility for every target, in the "STANDARD CROSS-REPO SETTINGS DO NOT EDIT" loop. Under that feature a member declared in another module is only visible when that module is directly imported by the file using it.
  3. Sources/CryptoExtras/Digests/SHA512256Digest.swift has no import statements at all.

So the default implementation Foundation provides for the new requirement is not visible in that file, the requirement is left without a witness, and the conformance fails.

Evidence that this is not a general SDK problem

A minimal conformer implementing only withUnsafeBytes compiles cleanly against the same SDK, at both -target arm64-apple-macos26.0 and -target arm64-apple-macos27.0:

import Foundation

@available(macOS 10.15, *)
public struct MyDigest: ContiguousBytes {
    let bytes: (UInt64, UInt64, UInt64, UInt64)
    public func withUnsafeBytes<R>(_ body: (UnsafeRawBufferPointer) throws -> R) rethrows -> R {
        try Swift.withUnsafeBytes(of: bytes) { try body($0) }
    }
}

Since that type provides no withBytes of its own and still conforms, Foundation does supply a usable default. It is the import visibility that hides it from SHA512256Digest.swift.

Consistent with that, SHA512256Digest.swift is the only file in CryptoExtras that declares a ContiguousBytes-related conformance without importing Foundation. Every other one imports it, including its own sibling SHA512256.swift (which imports Crypto).

Fix

+import Foundation
 //===----------------------------------------------------------------------===//
 //

Verified locally by patching only that file in the resolved checkout: swift build --target CryptoExtras goes from the error above to Build of target: 'CryptoExtras' complete!, with no other change.

Happy to open a PR if that would help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions