-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Closed
Copy link
Labels
SILGenArea → compiler: The SIL generation stageArea → compiler: The SIL generation stagecompilerThe Swift compiler itselfThe Swift compiler itselfconformancesFeature → protocol: protocol conformancesFeature → protocol: protocol conformancescrashBug: A crash, i.e., an abnormal termination of softwareBug: A crash, i.e., an abnormal termination of softwarestatic declarationsFeature → declarations: Static declarationsFeature → declarations: Static declarationsswift 6.2
Description
Description
A Swift protocol
cannot have class func
, and the compiler recommends turning them into static func
instead.
Objective-C class methods are imported as class func
.
If one tries to use the SIL verifier and conform an existing Obj-C class method with a protocol static func
, the compiler crashes.
Reproduction
import Photos
protocol MockingPHAssetCreationRequest {
static func forAsset() -> Self
func addResource(with type: PHAssetResourceType, data: Data, options: PHAssetResourceCreationOptions?)
}
extension PHAssetCreationRequest: MockingPHAssetCreationRequest {}
let phAssetResourceCreationRequestType: MockingPHAssetCreationRequest.Type = PHAssetCreationRequest.self
public func saveImage(data: Data) async throws {
let creationRequest = phAssetResourceCreationRequestType.forAsset()
creationRequest.addResource(with: .photo, data: data, options: nil)
}
With both Xcode 16.3 and Xcode 26:
xcrun swiftc -Xfrontend -sil-verify-all PhotosFrameworkTest.swift
(the stack dump is for Xcode 26)
Stack dump
error: compile command failed due to signal 6 (use -v to see invocation)
parameter type mismatch!
argument: %0 = argument of bb0 : $@thick @dynamic_self PHAssetCreationRequest.Type // user: %1
expected: $@thick PHAssetCreationRequest.Type
SIL verification failed: entry point argument types do not match function type: matched
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0. Program arguments: /Applications/Xcode_26.0.0_17A5305f.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file PhotosFrameworkTest.swift -target arm64-apple-macosx15.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Applications/Xcode_26.0.0_17A5305f.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX26.0.sdk -color-diagnostics -Xcc -fcolor-diagnostics -new-driver-path /Applications/Xcode_26.0.0_17A5305f.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver -sil-verify-all -empty-abi-descriptor -no-auto-bridging-header-chaining -module-name PhotosFrameworkTest -disable-clang-spi -target-sdk-version 26.0 -target-sdk-name macosx26.0 -external-plugin-path /Applications/Xcode_26.0.0_17A5305f.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode_26.0.0_17A5305f.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode_26.0.0_17A5305f.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode_26.0.0_17A5305f.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -in-process-plugin-server-path /Applications/Xcode_26.0.0_17A5305f.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/libSwiftInProcPluginServer.dylib -plugin-path /Applications/Xcode_26.0.0_17A5305f.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Applications/Xcode_26.0.0_17A5305f.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins -o /var/folders/5_/s35y652x7k7dlfv4hmts4x5w0000gn/T/TemporaryDirectory.ChMu0Z/PhotosFrameworkTest-1.o
1. Apple Swift version 6.2 (swiftlang-6.2.0.19.9 clang-1700.3.19.1)
2. Compiling with effective version 5.10
3. While evaluating request ASTLoweringRequest(Lowering AST to SIL for file "PhotosFrameworkTest.swift")
4. While generating SIL witness table protocol conformance PHAssetCreationRequest: MockingPHAssetCreationRequest at extension of PHAssetCreationRequest (at PhotosFrameworkTest.swift:8:1)
5. While generating protocol witness thunk SIL function "@$sSo22PHAssetCreationRequestC19PhotosFrameworkTest07MockingabC0A2cDP8forAssetxyFZTW".
for 'forAsset()' (in module 'Photos')
6. While silgen emitForeignToNativeThunk SIL function "@$sSo22PHAssetCreationRequestC8forAssetABXDyFZTO".
for 'forAsset()' (in module 'Photos')
7. While verifying SIL function "@$sSo22PHAssetCreationRequestC8forAssetABXDyFZTO".
for 'forAsset()' (in module 'Photos')
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0 swift-frontend 0x0000000106d59bcc llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1 swift-frontend 0x0000000106d5755c llvm::sys::RunSignalHandlers() + 112
2 swift-frontend 0x0000000106d5a1f8 SignalHandler(int, __siginfo*, void*) + 344
3 libsystem_platform.dylib 0x000000019f1216a4 _sigtramp + 56
4 libsystem_pthread.dylib 0x000000019f0e788c pthread_kill + 296
5 libsystem_c.dylib 0x000000019eff0a3c abort + 124
6 swift-frontend 0x00000001013fadc4 swift::verificationFailure(llvm::Twine const&, swift::SILInstruction const*, swift::SILArgument const*, std::__1::function<void ()> const&) + 1788
7 swift-frontend 0x0000000101401118 (anonymous namespace)::SILVerifier::visitSILFunction(swift::SILFunction*) + 3664
8 swift-frontend 0x00000001013fb82c swift::SILFunction::verify(swift::CalleeCache*, bool, bool, bool) const + 440
9 swift-frontend 0x0000000101485018 swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 1816
10 swift-frontend 0x00000001015dc4d0 swift::Lowering::SILGenFunction::emitDynamicMethodRef(swift::SILLocation, swift::SILDeclRef, swift::CanTypeWrapper<swift::SILFunctionType>) + 168
11 swift-frontend 0x00000001015afb50 swift::Lowering::SILGenFunction::emitProtocolWitness(swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::SILDeclRef, swift::SubstitutionMap, swift::SILDeclRef, swift::SubstitutionMap, swift::Lowering::IsFreeFunctionWitness_t, bool, bool, std::__1::optional<swift::ActorIsolation>) + 3260
12 swift-frontend 0x00000001015e7fb4 swift::Lowering::SILGenModule::emitProtocolWitness(swift::ProtocolConformanceRef, swift::SILLinkage, swift::SerializedKind_t, swift::SILDeclRef, swift::SILDeclRef, swift::Lowering::IsFreeFunctionWitness_t, swift::Witness) + 4148
13 swift-frontend 0x00000001015ec45c (anonymous namespace)::SILGenWitnessTable<(anonymous namespace)::SILGenConformance>::addMethodImplementation(swift::SILDeclRef, swift::SILDeclRef, swift::Witness) + 424
14 swift-frontend 0x00000001015ebf74 (anonymous namespace)::SILGenWitnessTable<(anonymous namespace)::SILGenConformance>::addMethod(swift::SILDeclRef) + 1080
15 swift-frontend 0x00000001015eb8c8 swift::SILWitnessVisitor<(anonymous namespace)::SILGenConformance>::visitProtocolDecl(swift::ProtocolDecl*) + 1020
16 swift-frontend 0x00000001015e6b2c swift::Lowering::SILGenModule::getWitnessTable(swift::NormalProtocolConformance*) + 548
17 swift-frontend 0x00000001015eb3e0 SILGenExtension::emitExtension(swift::ExtensionDecl*) + 660
18 swift-frontend 0x00000001014846d0 swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 308
19 swift-frontend 0x000000010148b538 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 2364
20 swift-frontend 0x00000001015d161c swift::SimpleRequest<swift::ASTLoweringRequest, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>> (swift::ASTLoweringDescriptor), (swift::RequestFlags)17>::evaluateRequest(swift::ASTLoweringRequest const&, swift::Evaluator&) + 208
21 swift-frontend 0x000000010148ffc0 swift::ASTLoweringRequest::OutputType swift::Evaluator::getResultUncached<swift::ASTLoweringRequest, swift::ASTLoweringRequest::OutputType swift::evaluateOrFatal<swift::ASTLoweringRequest>(swift::Evaluator&, swift::ASTLoweringRequest)::'lambda'()>(swift::ASTLoweringRequest const&, swift::ASTLoweringRequest::OutputType swift::evaluateOrFatal<swift::ASTLoweringRequest>(swift::Evaluator&, swift::ASTLoweringRequest)::'lambda'()) + 572
22 swift-frontend 0x0000000100993708 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 964
23 swift-frontend 0x0000000100996a7c performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1764
24 swift-frontend 0x000000010099568c swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3580
25 swift-frontend 0x0000000100916c6c swift::mainEntry(int, char const**) + 5412
26 dyld 0x000000019ed46b98 start + 6076
Expected behavior
The SIL verification should be successful. A protocol static func
can be conformed by a type `class func.
Environment
Xcode 16.4
swift-driver version: 1.120.5 Apple Swift version 6.1.2 (swiftlang-6.1.2.1.2 clang-1700.0.13.5)
Target: arm64-apple-macosx15.0
Xcode 26
swift-driver version: 1.127.14.1 Apple Swift version 6.2 (swiftlang-6.2.0.19.9 clang-1700.3.19.1)
Target: arm64-apple-macosx15.0
Additional information
Without -Xfrontend -sil-verification-all
the compilation succeeds and the code works as expected without problems.
When compiling an asserts toolchain from GitHub, -sil-verification-all
is enabled by default, which triggers this error.
Metadata
Metadata
Assignees
Labels
SILGenArea → compiler: The SIL generation stageArea → compiler: The SIL generation stagecompilerThe Swift compiler itselfThe Swift compiler itselfconformancesFeature → protocol: protocol conformancesFeature → protocol: protocol conformancescrashBug: A crash, i.e., an abnormal termination of softwareBug: A crash, i.e., an abnormal termination of softwarestatic declarationsFeature → declarations: Static declarationsFeature → declarations: Static declarationsswift 6.2