swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.3k stars 10.34k forks source link

Use of `AsyncParsableCommand` triggers TBD validation failure #64900

Open MaxDesiatov opened 1 year ago

MaxDesiatov commented 1 year ago

[...] I suspect it might be this PR, but I'm not sure. I'm seeing a new failure around this time:

cmd.exe /C "cd . && D:\a\swift-build\swift-build\BuildRoot\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe -target x86_64-unknown-windows-msvc -j 2 -num-threads 2 -emit-library -o bin\CrossCompilationDestinationsTool.dll -module-name CrossCompilationDestinationsTool -module-link-name CrossCompilationDestinationsTool -emit-module -emit-module-path swift\CrossCompilationDestinationsTool.swiftmodule -emit-dependencies -DCrossCompilationDestinationsTool_EXPORTS -sdk D:\a\swift-build\swift-build/BuildRoot/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk -O -swift-version 5 -libc MD -Xcc -D_CRT_SECURE_NO_WARNINGS -output-file-map Sources\CrossCompilationDestinationsTool\CMakeFiles\CrossCompilationDestinationsTool.dir\Release\output-file-map.json -I D:\a\swift-build\swift-build\BinaryCache\swift-package-manager\swift -I D:\a\swift-build\swift-build\BinaryCache\swift-argument-parser\swift -I D:\a\swift-build\swift-build\BinaryCache\swift-collections\swift -I D:\a\swift-build\swift-build\BinaryCache\swift-system\swift -I D:\a\swift-build\swift-build\SourceCache\swift-system\Sources\CSystem\include -I D:\a\swift-build\swift-build\BinaryCache\swift-tools-support-core\swift -I D:\a\swift-build\swift-build\BinaryCache\swift-llbuild\products\llbuildSwift -I D:\a\swift-build\swift-build\SourceCache\swift-llbuild\products\libllbuild\include -I D:\a\swift-build\swift-build\BinaryCache\swift-crypto\swift -I D:\a\swift-build\swift-build\SourceCache\swift-crypto\Sources\CCryptoBoringSSL\include -I D:\a\swift-build\swift-build\BinaryCache\swift-certificates\swift -I D:\a\swift-build\swift-build\BinaryCache\swift-asn1\swift @CMakeFiles\CrossCompilationDestinationsTool.rsp    -Xlinker -implib:lib\CrossCompilationDestinationsTool.lib  && cd ."
<unknown>:0: error: symbol '$s32CrossCompilationDestinationsTool18InstallDestinationV14ArgumentParser20AsyncParsableCommandAadEP3runyyYaKFTWTu' (async function pointer to protocol witness for ArgumentParser.AsyncParsableCommand.run() async throws -> () in conformance CrossCompilationDestinationsTool.InstallDestination : ArgumentParser.AsyncParsableCommand in CrossCompilationDestinationsTool) is in generated IR file, but not in TBD file

<unknown>:0: error: please submit a bug report (https://swift.org/contributing/#reporting-bugs), and add '-Xfrontend -validate-tbd-against-ir=none' to squash the errors

<unknown>:0: error: symbol '$s32CrossCompilationDestinationsTool04ListC0V14ArgumentParser20AsyncParsableCommandAadEP3runyyYaKFTWTu' (async function pointer to protocol witness for ArgumentParser.AsyncParsableCommand.run() async throws -> () in conformance CrossCompilationDestinationsTool.ListDestinations : ArgumentParser.AsyncParsableCommand in CrossCompilationDestinationsTool) is in generated IR file, but not in TBD file

<unknown>:0: error: please submit a bug report (https://swift.org/contributing/#reporting-bugs), and add '-Xfrontend -validate-tbd-against-ir=none' to squash the errors

Originally posted by @compnerd in https://github.com/apple/swift-package-manager/issues/6361#issuecomment-1496129406

compnerd commented 1 year ago

Haven't fully reduced this yet, but something like this is along the liens of what is triggering this:

// RUN: %target-swift-frontend -I ... -module-name reduced -parse-as-library -c %s -S -emit-ir -o -
import ArgumentParser
protocol DestinationCommand: AsyncParsableCommand { }
extension DestinationCommand {
    public func run() async throws { }
}
public struct ListDestinations: DestinationCommand {
    public init() {}
}
compnerd commented 1 year ago

Reduced:

P.swift

// RUN: %target-swift-frontend -parse-as-library -emit-module -module-name P -emit-module-path %t\P.swiftmodule %s
public protocol P {
    func f() async throws
}

Q.swift

// RUN: %target-swift-frontend -I%t -parse-as-library -module-name reduced -S -emit-ir -o - %s
import P
protocol Q: P {}
extension Q {
    public func f() async throws { }
}
public struct S: Q {
    public init() { }
}

(thanks to help from @aschwaighofer)

compnerd commented 1 year ago

Resolving this will likely lead to the removal of the workaround at https://github.com/apple/swift/blob/main/include/swift/SIL/SILLinkage.h#L290-L304

~(CC: @jckarter - introduced this in https://github.com/apple/swift/commit/bba87cdc10d411f2f7ee3271aa9e457fc43c9b48)~

CC: @slavapestov - https://github.com/apple/swift/commit/6a83e7303e688566753c22e39f1badac2a6ce906

compnerd commented 1 year ago

Removing the workaround causes a SIL verification failure:

SIL verification failed: function_ref inside fragile function cannot reference a private or hidden symbol: (SingleFunction && RefF->isExternalDeclaration()) || RefF->hasValidLinkageForFragileRef()