-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
[SR-9291] SIGSEGV with large array in SILGen #51762
Comments
I don't know if it's reasonable to allow this use case yet. I'd have to dig in further. But even if we don't allow it, that should be diagnosed properly in release builds. |
andreasw (JIRA User) it's great that you're filing these bugs, and we're fixing quadratic behavior in the compiler. But as an implementation technique, statically initializing a giant Swift array doesn't make much sense, since it's going to generate a giant sequence of instructions to initialize each element. Writing a loop that appends elements probably makes more sense. You could statically initialize a C array and import it into Swift as |
Comment by Andreas Wendleder (JIRA) > But as an implementation technique, statically initializing a giant Swift array doesn't make much sense, since it's going to generate a giant sequence of instructions to initialize each element. In the graphics community (pbrt.org) for example static arrays with ~50.000 elements are used to generate Sobol sequences to distribute samples: https://raw.githubusercontent.com/mmp/pbrt-v3/master/src/core/sobolmatrices.cpp So I think it makes much sense. Do you have an alternative? I would be happy to consider it. I like the static approach because a) I don't have to ship an extra file because everything is in the binary and b) it has virtually zero startup cost and c) simple things should be simple. > Writing a loop that appends elements probably makes more sense See point b) above, that has to be done every time at startup right? Maybe it is possible with template metaprogramming but why make it unnecessarily complicated? > You could statically initialize a C array and import it into Swift as `UnsafeBufferPointer<Int>` When a compiler engineer tells me to use another language I have the feeling that something is wrong. FWIW, I did a little survey on the most used languages according to the TIOBE index (excluding SQL). Here are my results with a 50.000 element array. "No problem" means compilation time is less than a second and execution time for printing one random element is less than a second. Java: Doesn't work: "code too large". With workaround*: No problem. *The Java workaround is to split the array into smaller arrays of 8000 elements into different classes. So Swift would be the only language that crashes/asserts/is very slow. Finally, this one thing (large arrays) exposed quadratic complexity in the SILVerifier, found dead code in debug locations, still shows quadratic complexity in RedundantLoadElimination, fixed quadratic behaviour in the inliner and now crashes the compiler in non-assert builds (which I have to use because of the quadratic complexity in the SILVerifier). I think that alone makes it a valuable testcase. That and the fact, that it might trigger in the future each time quadratic or worse complexity is unintentionally added. |
andreasw (JIRA User) I never questioned your use case. I'm explaining that Swift arrays aren't intrinsically a good fit for that use case and that there's an easy workaround when you run into compiler problems. I personally think these are extremely valuable bugs and want them all to be fixed. Note that Swift does have an optimization specifically for static array intialization that eliminates initiailization at startup time. In that respect, Swift will be much better than other high level languages. You may want to look at your app's disassembly when compiling with Swift arrays are fundamentally different from the C-based languages that you listed. I think it would be nice if the language allowed us to explicitly declare an immutable fixed size array that is guaranteed to be initialized statically, even at My comment about using a loop vs. a literal expression really had more to do with code size. At If you want Swift language/compiler developers to be more aware of your use case, I would bring it up on the dev forum. |
Comment by Andreas Wendleder (JIRA) @atrick Thanks for the insight. I will write something up on the dev forum. |
Comment by Andreas Wendleder (JIRA) You can find my article here: https://forums.swift.org/t/compile-performance-with-large-constant-arrays/18143 |
@swift-ci create. |
Comment by Andreas Wendleder (JIRA) Nearly 300 views and no reply. It seems nobody is interested in fixing a crashing/slow compiler. 🙁 |
The right fix isn't obvious. The parameter limit is in place because the underlying design doesn't support 60k+ parameters in a reasonable way. Hopefully someone will have time to work on the underlying design. If you don't see any activity on the bug in the next month please comment again so it isn't forgotten. |
Comment by Andreas Wendleder (JIRA) This still happens with Xcode 10.2 and Swift 5.0. |
andreasw (JIRA User) thanks for keeping on top of this. |
Comment by Andreas Wendleder (JIRA) Xcode 10.2.1 still crashes (immediately), the latest snapshot (2019-04-16) doesn't crash anymore but takes 12 minutes to compile. |
Comment by Andreas Wendleder (JIRA) Swift 5.0.1 on Linux crashes immediately:
|
Comment by Andreas Wendleder (JIRA) Swift 5.1 macOS still crashes. Stack dump:
|
Comment by Andreas Wendleder (JIRA) Swift 5.1.1 on Linux crashes. This bug crashes Swift for nearly one year now. |
Comment by Andreas Wendleder (JIRA) Swift 5.2.4 LInux doesn't crash anymore. However, it takes more than six minutes to compile for 65.536 elements. |
Swift 5.7 doesn't crash. 65.536 elements: 3.5s cc @eeckstein @atrick @gottesmm #50243 is probably related. |
Swift 5.8 Linux: |
The crash is gone, so I think we should close this. @atrick Any recollection of what fixed this? |
Attachment: Download
Environment
Linux with release no-assertions build of swift with the above mentioned patches applied.Makefile
Additional Detail from JIRA
md5: f3b2ee52855e03d9f071a263a4b97f47
Issue Description:
I am trying to compile a large array (70.000 elements) with a release no-assertions build.
Swift stops with:
The stack trace is:
I applied the two patches from @atrick fixing quadratic behaviour in the inliner:
https://github.com/apple/swift/pull/20630/commits
His comment was:
@slavapestov might be interested since he added this assertion.
I used the attached Makefile to generate the source.
The text was updated successfully, but these errors were encountered: