Skip to content
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-15245] [Concurrency] Compiler crashes on attached input #57567

Closed
ZPedro opened this issue Sep 25, 2021 · 8 comments
Closed

[SR-15245] [Concurrency] Compiler crashes on attached input #57567

ZPedro opened this issue Sep 25, 2021 · 8 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself concurrency Feature: umbrella label for concurrency language features hang Bug: Execution is not seen to halt SILOptimizer Area → compiler: SIL optimization passes swift 5.5

Comments

@ZPedro
Copy link

ZPedro commented Sep 25, 2021

Previous ID SR-15245
Radar None
Original Reporter @ZPedro
Type Bug

Attachment: Download

Environment

Xcode 13.0 release

Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 5ceed28caa5ff461ebae8d4ad9c376de

Issue Description:

When attempting to use the concurrency features of Swift 5.5, I get a compiler hang. Not a runtime hang: the swift-frontend process itself, on the build machine, was still running after ~5 minutes (at which point I killed it).

Needless to say, I don't expect the compiler to get stuck like that, especially with code that is not particularly trying to trick it.

First attachment is the code that reproduces the issue; unfortunately, I have not found a way to meaningfully reduce that test case. Second attachment is the sample of the swift-frontend process.

Note: while the code is provided as an Xcode project, I can reproduce the issue with a manual invocation of the compiler, so I can only assume this is a Swift issue. I believe this issue is but a descendant of #56470.

@ZPedro
Copy link
Author

ZPedro commented Oct 25, 2021

Still reproducible with Xcode 13.1 (downloaded as 13.1 RC)

@ZPedro
Copy link
Author

ZPedro commented Oct 26, 2021

I would add that this kind of issue is particularly time-consuming to encounter, given Swift's propensity for long compile times: at first I have to assume this is one of these cases, and therefore attempt to reduce inference complexity among other sources of long compiles, before I am allowed to conclude this is an infinite loop in the compiler. In fact, every time I have to reproduce it I have to make sure this isn't the case; in pratice I let the build spin for one hour (60 minutes) before I can conclude I have reproduced the problem. Needless to say, this doe not help testcase reduction either.

@ZPedro
Copy link
Author

ZPedro commented Oct 30, 2021

Reproducible on Xcode 13.2 beta, for what it’s worth.

@ZPedro
Copy link
Author

ZPedro commented Nov 27, 2021

Reproducible on Xcode 13.2 beta 2, for what it's worth.

@ZPedro
Copy link
Author

ZPedro commented Dec 18, 2021

Still reproducible on Xcode 13.2.1 (13C100)

@ZPedro
Copy link
Author

ZPedro commented Feb 21, 2022

Breakthrough! I have figured out the bug occurs in a specific situation: when a function that actually captures state refers to itself in a non-escaping manner (e.g. passed as a non-escaping parameter to another function); the function may also need to be async, but that I have no way of knowing.

  • I know the function needs to actually capture state to reproduce the issue because there is no issue with function iteratePossibleLeftNodesFakeDispatchAsync(), which is also async and also refers to itself in a non-escaping manner, but does not actually capture state (it is top level).

  • I know the function needs to refer to itself in a non-escaping manner, because there is no issue with function iteratePossibleLeftNodes(), which is also async and also captures state, but refers to itself only in an escaping manner.

And why do I know the issue is not with these functions? Because I found a workaround that I only needed to apply to function iteratePossibleLeftNodesDispatch(), which matched the description before I applied the workaround. The workaround, such as it is, consists of creating a iteratePossibleLeftNodesDispatchLoop15() that refers to iteratePossibleLeftNodesDispatchLoop14(), a iteratePossibleLeftNodesDispatchLoop14() that refers to iteratePossibleLeftNodesDispatchLoop13(), and so forth, until I get to iteratePossibleLeftNodesDispatchLoop0() which goes into fatalError rather than refer to anything else. Otherwise, all with identical bodies of course.

In my whole carrier, I can't remember ever having to write so seemingly pointless code in order to satisfy a compiler; and remember I used to write BASIC on the APPLE ][e.

@ZPedro
Copy link
Author

ZPedro commented Mar 14, 2022

AsyncCountdown.zip

Attaching the latest version of the project so you can look at the workaround in context.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@ZPedro
Copy link
Author

ZPedro commented Apr 4, 2023

While no one has gotten back to me, I no longer reproduce the issue with Xcode 14.2, so it was fixed some time between 13.2 (excluded) and that version (sorry I can't be more accurate, I haven't been very diligent on checking this issue). If I had to guess, I would say this was fixed by #41826

@ZPedro ZPedro closed this as completed Apr 4, 2023
@AnthonyLatsis AnthonyLatsis added hang Bug: Execution is not seen to halt swift 5.5 SILOptimizer Area → compiler: SIL optimization passes concurrency Feature: umbrella label for concurrency language features labels Apr 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself concurrency Feature: umbrella label for concurrency language features hang Bug: Execution is not seen to halt SILOptimizer Area → compiler: SIL optimization passes swift 5.5
Projects
None yet
Development

No branches or pull requests

2 participants