swiftlang / swift

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

Existential Type property is broken on the latest Swift compiler #75744

Open giginet opened 1 month ago

giginet commented 1 month ago

Description

The following simple code causes an internal compiler crash. As far as I noticed, set of a property of protocol seems to cause this situation. To remove set from the property, this compilation would be back to normal.

This situation still occurs using Xcode 16 beta 5. This issue occurs whether using swiftc or xcodebuild both.

Reproduction

import Foundation

protocol SomeItem { }

class SomeClass {
    func doSomething(_ value: any SomeProtocol) {
        print(value.item)
    }
}

protocol SomeProtocol: SomeClass {
    associatedtype Item: SomeItem
    var item: Item { get set }
}

Stack dump

Swift version 6.0-dev (LLVM 57177aa1b91540b, Swift 8be62863326595c)
Target: x86_64-unknown-linux-gnu
Unhandled coercion:
(opened_archetype_type
 address=0x610e24616f80 conforms_to="main.(file).SomeItem@<stdin>:3:10" opened_existential_id="1B852380-5467-11EF-BCCD-E6294A3541A6"
  (interface_type=dependent_member_type assoc_type="main.(file).SomeProtocol.Item@<stdin>:12:20"
    (base=generic_type_param_type depth=0 index=0
))
  (opened_existential=existential_type
    (protocol_type decl="main.(file).SomeProtocol@<stdin>:11:10")))
(lvalue_type
  (existential_type
    (protocol_type decl="main.(file).SomeItem@<stdin>:3:10")))
Stack dump:
0.      Program arguments: /usr/bin/swift-frontend -frontend -interpret - -disable-objc-interop -color-diagnostics -enable-bare-slash-regex -empty-abi-descriptor -Xcc -working-directory -Xcc /app -resource-dir /usr/lib/swift -module-name main -plugin-pa
th /usr/lib/swift/host/plugins -plugin-path /usr/local/lib/swift/host/plugins
1.      Swift version 6.0-dev (LLVM 57177aa1b91540b, Swift 8be62863326595c)
2.      Compiling with effective version 5.10
3.      While evaluating request TypeCheckSourceFileRequest(source_file "<stdin>")
4.      While evaluating request TypeCheckFunctionBodyRequest(main
.(file).SomeClass.doSomething@<stdin>:6:10)
5.      While type-checking statement at [<stdin>
:6:49 - line:8:5] RangeText="{
        print(value.item)
    "
6.      While type-checking expression at [<stdin>:7:9 - line:7:25] RangeText="print(value.item"
7.      While type-checking-target starting at <stdin>:7:9
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  swift-frontend 0x0000610e1f5655a7
1  swift-frontend 0x0000610e1f5632fe
2  swift-frontend 0x0000610e1f565c1a
3  libc.so.6      0x000078a2f08b7520
4  libc.so.6      0x000078a2f090b9fc 
pthread_kill + 300
5  libc.so.6      0x000078a2f08b7476 raise + 22
6  libc.so.6      0x000078a2f089d7f3 abort + 211
7  swift-frontend 0x0000610e19ee1090
8  swift-frontend 0x0000610e19edfa65
9  swift-frontend 0x0000610e19efe200
10 swift-frontend 0x0000610e19ef85d0
11 swift-frontend 0x0000610e19ee64db
12 swift-frontend 0x0000610e1a32e295
13 swift-frontend 0x0000610e1a334cd3
14 swift-frontend 0x0000610e1a330bed
15 swift-frontend 0x0000610e1a32e2fe
16 swift-frontend 0x0000610e1a32e1a3
17 swift-frontend 0x0000610e19edbeb7
18 swift-frontend 0x0000610e19edb3f6
19 swift-frontend 0x0000610e19d50548
20 swift-frontend 0x0000610e19d5037d
21 swift-frontend 0x0000610e19d50258
22 swift-frontend 0x0000610e19e4ca6b
23 swift-frontend 0x0000610e19e5159c
24 swift-frontend 0x0000610e19e4f0bc
25 swift-frontend 0x0000610e19e4e513
26 swift-frontend 0x0000610e19e4e0a5
27 swift-frontend 0x0000610e1a459482
28 swift-frontend 0x0000610e1a3aefa9
29 swift-frontend 0x0000610e1a520b5b
30 swift-frontend 0x0000610e19e9c1d1
31 swift-frontend 0x0000610e19e9e5eb
32 swift-frontend 0x0000610e19e9c0a5
33 swift-frontend 0x0000610e18ae3c69
34 swift-frontend 0x0000610e18adb49e
35 swift-frontend 0x0000610e18adb3e7
36 swift-frontend 0x0000610e187c35a2
37 swift-frontend 0x0000610e187b0717
38 swift-frontend 0x0000610e187aea9c
39 swift-frontend 0x0000610e1855ee6e
40 libc.so.6      0x000078a2f089ed90
41 libc.so.6      0x000078a2f089ee40 __libc_start_main + 128
42 swift-frontend 0x0000610e1855df15
timeout: the monitored command dumped core
Aborted

Expected behavior

Pass build

Environment

Xcode 16 Beta 5 or current main https://github.com/swiftlang/swift/commit/bccf135c9f2e0e553f0c177ff9586df88d60445f

Additional information

No response

JessyCatterwaul commented 1 month ago

Interesting. Changing any SomeProtocol to some Protocol compiles and works.