Attachment: Download
Additional Detail from JIRA
|
|
| Votes |
0 |
| Component/s |
|
| Labels |
Bug |
| Assignee |
None |
| Priority |
Medium |
md5: e94e403b786cb56d8c14e47dcd662f6b
Issue Description:
PythonKit recently added lambdas and subclassing, which requires the "PyCapsule" API. The PyCapsule_New function takes a function pointer as a parameter, which is @convention(c).
The compiler crashed in release mode when it encountered the new PyCapsule_New function pointer. This crash went away when the closure parameter was removed, or the @convention(c) decorator was removed from the closure. The crash also went away when compiling in debug mode. The following code reproduces the crash.
public func pythonObject() {
_ = PyCapsule_New({ _ in })
}
let PyCapsule_New: (@convention(c) (UnsafeMutableRawPointer?) -> Void) -> Void =
loadSymbol(name: "PyCapsule_New")
func loadSymbol<T>(name: String, type: T.Type = T.self) -> T {
fatalError()
}
The crash happened on toolchains varying from November 12, 2021 to February 03, 2022. This means it has existed since at least November 2021. A log is attached below as "log.txt". I narrowed down PythonKit, erasing everything except one file, which includes the excerpt above. Then, I compiled with swift build -c release.
Here is the shortened crash stack trace:
1. Apple Swift version 5.7-dev (LLVM cd2992b90c95d01, Swift ab85807f0646caa)
2. Compiling with the current language version
3. While emitting IR SIL function "@$s9PythonKit13PyCapsule_New_WZ".
for declaration 0x14e94d890 (at /Users/philipturner/Documents/building-tensorflow/PythonKit/PythonKit/Python.swift:5:1)
...
6 swift-frontend 0x000000010512894c (anonymous namespace)::IRGenDebugInfoImpl::getOrCreateType(swift::irgen::DebugTypeInfo) (.cold.30) + 0
7 swift-frontend 0x0000000100f8c214 bool swift::SILLocation::isNode<swift::ConstructorDecl>(llvm::PointerUnion<swift::Stmt*, swift::Expr*, swift::Decl*, swift::Pattern*>) const + 0
8 swift-frontend 0x0000000100f8c974 (anonymous namespace)::IRGenDebugInfoImpl::createParameterType(llvm::SmallVectorImpl<llvm::Metadata*>&, swift::SILType) + 124
9 swift-frontend 0x0000000100f8c6d4 (anonymous namespace)::IRGenDebugInfoImpl::createParameterTypes(swift::CanTypeWrapper<swift::SILFunctionType>) + 404
10 swift-frontend 0x0000000100f85f14 (anonymous namespace)::IRGenDebugInfoImpl::emitFunction(swift::SILDebugScope const*, llvm::Function*, swift::SILFunctionTypeRepresentation, swift::SILType, swift::DeclContext*) + 1732
11 swift-frontend 0x0000000100f856b4 (anonymous namespace)::IRGenDebugInfoImpl::getOrCreateScope(swift::SILDebugScope const*) + 948
12 swift-frontend 0x0000000100f85478 (anonymous namespace)::IRGenDebugInfoImpl::getOrCreateScope(swift::SILDebugScope const*) + 376
13 swift-frontend 0x0000000100f84650 (anonymous namespace)::IRGenDebugInfoImpl::setCurrentLoc(swift::irgen::IRBuilder&, swift::SILDebugScope const*, swift::SILLocation) + 80
14 swift-frontend 0x0000000100fada5c (anonymous namespace)::IRGenSILFunction::emitSILFunction() + 7556
15 swift-frontend 0x0000000100fab6e4 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 896
16 swift-frontend 0x0000000100e9abc0 swift::irgen::IRGenerator::emitLazyDefinitions() + 1400
17 swift-frontend 0x0000000100f75118 swift::performIRGeneration(swift::ModuleDecl*, swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, llvm::GlobalVariable**) + 1360
18 swift-frontend 0x0000000100c03bac performCompileStepsPostSILGen(swift::CompilerInstance&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 1636
19 swift-frontend 0x0000000100c031d8 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1028
20 swift-frontend 0x0000000100c04c74 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2940
21 swift-frontend 0x0000000100b40900 swift::mainEntry(int, char const**) + 500
22 dyld 0x000000010d6190f4 start + 520
Attachment: Download
Additional Detail from JIRA
md5: e94e403b786cb56d8c14e47dcd662f6b
Issue Description:
PythonKit recently added lambdas and subclassing, which requires the "PyCapsule" API. The
PyCapsule_Newfunction takes a function pointer as a parameter, which is@convention(c).The compiler crashed in release mode when it encountered the new
PyCapsule_Newfunction pointer. This crash went away when the closure parameter was removed, or the@convention(c)decorator was removed from the closure. The crash also went away when compiling in debug mode. The following code reproduces the crash.The crash happened on toolchains varying from November 12, 2021 to February 03, 2022. This means it has existed since at least November 2021. A log is attached below as "log.txt". I narrowed down PythonKit, erasing everything except one file, which includes the excerpt above. Then, I compiled with
swift build -c release.Here is the shortened crash stack trace: