-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Runtime Crash at "__swift_instantiateConcreteTypeFromMangledName" #74303
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 believe this could be the same issue: #74333 |
I tried a bunch and i noticed if i comment out this line in public var flags: IntBitField<DiscordApplication.Flag>? So
|
This issue is still present in Xcode 16 beta 3. |
Which commit should I be using with beta 3? I tried |
I would also really appreciate it if there are any workarounds to this so I can apply so earlier Swift versions can also continue to work properly 🙂. |
Still an issue in Xcode 16 beta 4. |
Still an issue on Xcode 16 beta 2. Pretty frustrating. I don't even know if looking around in the Swift repo is any good considering this only happens on macOS and Xcode contains a fork of the Swift repo, not the repo itself :/ |
@mikeash not sure what "commit" but any of the toolchains bundled with the Xcode versions I've mentioned should not have any trouble reproducing the issue. |
Sorry, I meant which commit in the DiscordBM repository should I use to try to reproduce this? |
Ah hmm really any recent commit. Just checkout main branch. |
I don't recall what trouble I had previously, but I tried again (with the latest The cause of the enormous stack frame appears to be the |
@mikeash thank you, I'll take that workaround. |
To be clear that enum's size is 100% legitimate. It's an enum with a case for each different type of Discord API payloads, so the size of the enum is not really under my control. Also would be nice to have a compile error instead of a runtime crash, at least. |
Also ... why crash on macOS but not Linux? Just curious. |
Yeah, not casting blame here, just describing the root of the issue. Something about how the stack frame layout code works causes it to make a separate area for each enum case's payload, rather using the same space for all of them. This is especially troublesome in debug builds, release builds may stand a better chance at using stack space more efficiently. Stack space is an odd thing where most systems just sort of handwave the fact that the stack is finite and not particularly large. We just sort of assume it's going to be big enough, without any particular guarantee that it is. Usually you need a lot more recursion to run into the limit, though. This function is a really extreme case where a single function call eats up the whole stack. I'd guess your Linux is running with a large stack, and so it manages not to run off the end. |
Is this in debug builds? I had to deal with a similar problem working with enums that had many payload cases: The debug builds would use an enormous amount of stack space, but release builds were quite reasonable. Here's the basic problem: Consider this:
In a debug build, the stack frame for this function will have a separate stack slot for every one of the above variables -- aa, ab, ac, bb, bc, bd, etc, etc. That is necessary to ensure that you can inspect any one of them at any time in the debugger. In a release build, the compiler will do some additional optimizations: It will overlay the variables for each case so that aa/ab/ac use the same stack area as bb/bc/bd, and so on This dramatically reduces the amount of stack space required, but means that none of the variables in the switch can be inspected after the end of the switch (because the debugger doesn't know which overlaid variables are really valid). One way I found to work around this is to rewrite the above in a somewhat roundabout way:
That is, each complex case handler gets put into a separate closure that's invoked immediately. In Debug builds, these closures end up as separate functions with separate stack frames. That avoids the main function having to reserve stack space for every path in the switch. In release builds, these closures get inlined and then optimized, so the final result in that case is the same as in the first version above. Does this help? |
No worries, I didn't notice any 🙂. |
Hmm i don't recall trying on macOS with a release build, but macOS debug builds would crash while Ubuntu debug or release builds were both fine. |
Is this the same crash?
Reported on MacOS 11.7.0 only as far as I have heard so far. Most other users do not seem to be affected. Code was compiled with Xcode 16.1. |
Hard to tell without more info. The VM Region Info from an Apple crash log would show pretty definitively if we ran out of stack space or had some other problem. Looking at this backtrace, I think this is something else. The only stack frame that could potentially use a huge amount of stack would be #14 ( Given the crash is in |
That block of core on #14 is the block seen here:
I decompiled the code and matched the address and it was inside the block being dispatched on the
|
VM region near:
and
|
Also forgot to say that this crash appears to have started after I upgraded from Xcode 15.3 to 16.1 |
|
@mikeash Thanks for pointing it out. I compared the previous application bundles and it was present until the most recent version, so I need to see what went wrong. |
I reviewed my |
I rebuilt the application with Xcode 15.3 and the problem went away. I tried building with 16.1 and 16.2 beta 3 and embedding Reported the issue to Apple via https://feedbackassistant.apple.com/feedback/15937972 |
Thank you for the feedback report. That made its way to me and I've located the issue. The problem is an incorrect path referenced for libswift_Concurrency.dylib. When targeting OS versions that need the back-deployment library, the executable needs to use an This will fix it: #77980. Of course, I can't comment as to when that might find its way into an Xcode release. The good news is that it should be pretty easy to work around. Add a postprocessing step to your builds (a shell script build phase would work nicely) to fix the path by running this command:
|
@mikeash I downgraded to Xcode 15.3 and I verified the with
Here's the output of
Any ideas of what else might be wrong? I don't know how to confirm I have fixed the crash without access to a system with the issue |
Description
DiscordBM crashes at
__swift_instantiateConcreteTypeFromMangledName
.Reproduction
BOT_TOKEN=aaaaaa swift test --filter IntegrationTests.DiscordClientTests.testGateway
.BOT_TOKEN
as an env var with any value, and run thetestGateway()
test.Stack dump
Expected behavior
No crash.
Environment
Not reproducible on Linux.
Additional information
No response
The text was updated successfully, but these errors were encountered: