swiftlang / swift

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

couldn't IRGen expression when using ~Copyable #76369

Open nervenes opened 1 month ago

nervenes commented 1 month ago

Description

I was playing around in Xcode playground with swift 5.10 to learn more about the ownership aspect of swift, so i tried fiddling with noncopyable types and the consuming keyword and ended up with this error:

error: couldn't IRGen expression. Please enable the expression log by running "log enable lldb expr", then run the failing expression again, and file a bug report with the log output.

i tried running the suggested command log enable lldb expr in the folder the playground is at, but log doesn't seem to have a command enable:thinking:

Reproduction

struct Counter: ~Copyable {
    var count: Int = 0

    mutating func increment() {
        count += 1
    }
}

func takeAndGive(counter: consuming Counter) -> Counter {
    counter.increment()
    return counter
}

func main() {
    let c1 = Counter()
    takeAndGive(counter: c1)
}

main()

Expected behavior

run as expected

Environment

swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4) Target: arm64-apple-macosx14.0

Additional information

No response

nervenes commented 1 month ago

looks like ~Copyable is what's causing the issue?

struct User: ~Copyable {
    var name: String
}

let newUser = User(name: "Anonymous")

this errors out as well, with the same exact error as above.

nervenes commented 1 month ago

noncopyable structs are supported since 5.9 according to this https://github.com/swiftlang/swift-evolution/blob/main/proposals/0390-noncopyable-structs-and-enums.md

nervenes commented 1 month ago
Screenshot 2024-09-10 at 14 56 26
nervenes commented 1 month ago

further experimenting, it looks like it's a problem with xcode playgrounds as this code works in a regular swift package. where should i report this, or will someone from the swift team carry the report over to the xcode team?