swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.32k stars 10.34k forks source link

Use of noncopyable type in an async context can cause compiler hang #75679

Open jamesmmadeira opened 1 month ago

jamesmmadeira commented 1 month ago

Description

Compiling the test case below results in the compiler hanging. The test case was reduced from code that reads from a DEFLATE bitstream.

Sampling suggests that this hang happens in MovedAsyncVarDebugInfoPropagatorTransform::run().

Reproduction

struct BitReader: ~Copyable {

    var currentByte: UInt8
    var nextBit: Void

    mutating func next(
        _ bitCount: Int
    ) async {
        while true {
            if nextBit == () {
                currentByte = 0
            } else {}
            _ = 1 << bitCount
        }
    }

}

Expected behavior

The compiler does not hang.

Environment

swift-driver version: 1.112.3 Apple Swift version 6.0 (swiftlang-6.0.0.6.8 clang-1600.0.23.1) Target: arm64-apple-macosx14.0

Using Xcode 16 beta 4

Additional information

Activity Monitor shows that swift-frontend uses almost 100% CPU while hanging. Sampling the process (ⓘ in Activity Monitor's toolbar > Sample) shows that MovedAsyncVarDebugInfoPropagatorTransform::run() is close to the top of the call stack.

xedin commented 1 month ago

cc @kavon