-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SR-15871] [IRGen] Crash while compiling PythonKit in release mode #58136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
|
I'm unable to reproduce the issue (from the minimal reproducer) on ec20619 @philipturner will you please confirm whether it is fixed? |
The build failed, although my toolchain may not have been built 100% correctly. I added this in log2.txt. Could you reproduce the absence of a crash on arm64 macOS? log2.txt |
Sorry, my bad. Apparently I forgot to add both -g and -O |
This looks like a demangler issue. We always demangle function types with let PyCapsule_New: (@convention(c) @escaping (UnsafeMutableRawPointer?) -> Void) -> Void =
loadSymbol(name: "PyCapsule_New") |
@philipturner what was the crash? |
The same crash that is demonstrated in the logs above. For reference, I added a crash log from compiling PythonKit on the March 9, 2022 toolchain. Previous logs just showed crashes from the reproducer, not PythonKit itself. |
In order to resolve the issue I'd like to hear some input from fellow swift-ers. Tagging @slavapestov@DougGregor Here is the full story:
I'm seeing two solutions of this problem:
Please advice 🙂 |
For the first solution mentioned above, it would break existing code that works with Swift right now. The unit tests could be modified to remove There is a precedent to a source-breaking change without a major version change. After concurrency was released, someone realized that pointers should not conform to |
@philipturner The existing code is already potentially broken. As we cannot distinguish between escaping and noescaping C functions (at symbol level). Certainly "disallow" could be downgraded from error to, say, warning. But we're talking about intended semantics here (which should come first). We can decide wrt the backward compatibility things later on. I do not see why PythonKit added |
I added #if swift(>=5.7)
... (function with @convention(c))
#else
... (function with @escaping @convention(c))
#endif That would make it compile without crashing on all Swift versions, except a few months worth of developer snapshots spanning from winter to summer 2022. This would be more tedious for me, because my work on S4TF relies on being able to test every snapshot that comes out for AutoDiff bug fixes. I would also need to copy that into Swift-Colab 2.0, which contains a copy of PythonKit's source files. Swift-Colab 2.0 could technically work for the snapshots ranging from winter to summer 2022. I would just have to hard-code a workaround that detects dates in that range and modifies JIT compilation accordingly. Overall, I think the correct choice is to make |
Nevermind. The |
Fix submitted as #42189 |
Fixed in #42478 |
Attachment: Download
Additional Detail from JIRA
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.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:
The text was updated successfully, but these errors were encountered: