-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Description
Description
Using the version of Swift 6 bundled with Xcode 16 beta 1, the following two snippets of code compile and run fine in iOS 18 (sim/device) and macOS 15, but crash when run in iOS 17 (sim/device) and macOS 14.
Filing as the same issue as I believe they can be related. If not, please let me know and I'll open separate issues.
UPDATE: I wanted to see if this was an issue only with the build of Swift bundled with Xcode 16 beta 1, so I installed the newest and the oldest snapshots of the release/6.0 train from https://www.swift.org/install/macos/ and ran code with Xcode 15.4, confirming the same crash is present in both.
Oldest: Swift 6.0 Development Snapshot 2024-04-29 (a)
Newest: Swift 6.0 Development Snapshot 2024-06-11 (a)
Reproduction
Snippet 1:
import Foundation
protocol TestProtocol {}
extension Optional: TestProtocol {}
struct TestGenericStruct<GenericType: TestProtocol> {
var foo: Date?
}
_ = TestGenericStruct<Date?>(foo: Date())Snippet 2:
import Foundation
protocol TestProtocol {}
@propertyWrapper
struct TestPropertyWrapper<GenericType: TestProtocol>: Codable {
var wrappedValue: String = ""
}
extension Optional: TestProtocol {}
struct TestStruct: Codable {
@TestPropertyWrapper<String?>
var foo: String
}
_ = try JSONEncoder().encode(TestStruct(foo: .init(wrappedValue: "")))Stack dump
Snippet 1:
crash`main:
0x100001918 <+0>: stp x29, x30, [sp, #-0x10]!
0x10000191c <+4>: mov x29, sp
0x100001920 <+8>: sub sp, sp, #0x30
0x100001924 <+12>: adrp x0, 7
0x100001928 <+16>: add x0, x0, #0x0 ; demangling cache variable for type metadata for Swift.Optional<Foundation.Date>
0x10000192c <+20>: bl 0x100001a10 ; __swift_instantiateConcreteTypeFromMangledName at <compiler-generated>
0x100001930 <+24>: stur x0, [x29, #-0x18]
0x100001934 <+28>: ldur x8, [x0, #-0x8]
0x100001938 <+32>: ldr x8, [x8, #0x40]
0x10000193c <+36>: lsr x8, x8, #0
0x100001940 <+40>: add x8, x8, #0xf
0x100001944 <+44>: and x9, x8, #0xfffffffffffffff0
0x100001948 <+48>: stur x9, [x29, #-0x30]
0x10000194c <+52>: adrp x16, 3
0x100001950 <+56>: ldr x16, [x16]
0x100001954 <+60>: blr x16
0x100001958 <+64>: ldur x9, [x29, #-0x30]
0x10000195c <+68>: mov x8, sp
0x100001960 <+72>: subs x0, x8, x9
0x100001964 <+76>: stur x0, [x29, #-0x20]
0x100001968 <+80>: mov sp, x0
0x10000196c <+84>: adrp x0, 7
0x100001970 <+88>: add x0, x0, #0x8 ; demangling cache variable for type metadata for crash.TestGenericStruct<Swift.Optional<Foundation.Date>>
0x100001974 <+92>: bl 0x100001a10 ; __swift_instantiateConcreteTypeFromMangledName at <compiler-generated>
0x100001978 <+96>: ldur x8, [x29, #-0x20]
-> 0x10000197c <+100>: ldur x9, [x0, #-0x8]
0x100001980 <+104>: ldr x9, [x9, #0x40]
0x100001984 <+108>: lsr x9, x9, #0
0x100001988 <+112>: add x9, x9, #0xf
0x10000198c <+116>: and x9, x9, #0xfffffffffffffff0
0x100001990 <+120>: stur x9, [x29, #-0x28]
0x100001994 <+124>: adrp x16, 3
0x100001998 <+128>: ldr x16, [x16]
0x10000199c <+132>: blr x16
0x1000019a0 <+136>: ldur x10, [x29, #-0x28]
0x1000019a4 <+140>: mov x9, sp
0x1000019a8 <+144>: subs x0, x9, x10
0x1000019ac <+148>: stur x0, [x29, #-0x10]
0x1000019b0 <+152>: mov sp, x0
0x1000019b4 <+156>: bl 0x100003994 ; symbol stub for: Foundation.Date.init() -> Foundation.Date
0x1000019b8 <+160>: mov x0, #0x0 ; =0
0x1000019bc <+164>: bl 0x1000039a0 ; symbol stub for: type metadata accessor for Foundation.Date
0x1000019c0 <+168>: mov x3, x0
0x1000019c4 <+172>: ldur x0, [x29, #-0x20]
0x1000019c8 <+176>: ldur x8, [x3, #-0x8]
0x1000019cc <+180>: ldr x8, [x8, #0x38]
0x1000019d0 <+184>: mov w1, #0x0 ; =0
0x1000019d4 <+188>: stur w1, [x29, #-0x4]
0x1000019d8 <+192>: mov w2, #0x1 ; =1
0x1000019dc <+196>: blr x8
0x1000019e0 <+200>: ldur x0, [x29, #-0x20]
0x1000019e4 <+204>: ldur x1, [x29, #-0x18]
0x1000019e8 <+208>: ldur x8, [x29, #-0x10]
0x1000019ec <+212>: adrp x2, 3
0x1000019f0 <+216>: add x2, x2, #0x118 ; protocol witness table for Swift.Optional<τ_0_0> : crash.TestProtocol in crash
0x1000019f4 <+220>: bl 0x100001a7c ; crash.TestGenericStruct.init(foo: Swift.Optional<Foundation.Date>) -> crash.TestGenericStruct<GenericType> at crash.swift:4
0x1000019f8 <+224>: ldur x0, [x29, #-0x10]
0x1000019fc <+228>: bl 0x100001aa8 ; outlined destroy of crash.TestGenericStruct<Swift.Optional<Foundation.Date>> at <compiler-generated>
0x100001a00 <+232>: ldur w0, [x29, #-0x4]
0x100001a04 <+236>: mov sp, x29
0x100001a08 <+240>: ldp x29, x30, [sp], #0x10
0x100001a0c <+244>: ret
Snippet 2:
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
* frame #0: 0x000000019b6c3d50 libswiftCore.dylib`swift::TargetMetadata<swift::InProcess>::getTypeContextDescriptor() const + 4
frame #1: 0x000000019b6c8588 libswiftCore.dylib`swift::TargetMetadata<swift::InProcess>::getGenericArgs() const + 24
frame #2: 0x000000019b6feb38 libswiftCore.dylib`instantiateWitnessTable(swift::TargetMetadata<swift::InProcess> const*, swift::TargetProtocolConformanceDescriptor<swift::InProcess> const*, void const* const*, void**) + 260
frame #3: 0x000000019b6f326c libswiftCore.dylib`swift::_getWitnessTable(swift::TargetProtocolConformanceDescriptor<swift::InProcess> const*, swift::TargetMetadata<swift::InProcess> const*, void const* const*) + 4704
frame #4: 0x0000000100005d98 crash`lazy protocol witness table accessor for type TestPropertyWrapper<String?> and conformance TestPropertyWrapper<A> at <compiler-generated>:0
frame #5: 0x0000000100005cb4 crash`TestStruct.encode() at <compiler-generated>:0
frame #6: 0x000000010000621c crash`protocol witness for Encodable.encode(to:) in conformance TestStruct at <compiler-generated>:0
frame #7: 0x000000019b694fa0 libswiftCore.dylib`dispatch thunk of Swift.Encodable.encode(to: Swift.Encoder) throws -> () + 32
frame #8: 0x000000018ca86e38 Foundation`generic partial specialization <Signature = @escaping @convention(thin) <τ_0_0, τ_0_1 where τ_0_0: Swift.Encodable, τ_0_1 == Foundation._JSONKey> (@guaranteed Foundation.__JSONEncoder, @in_guaranteed τ_0_0) -> (@error @owned Swift.Error)> of closure #1 (Foundation.__JSONEncoder) throws -> () in Foundation.__JSONEncoder.wrapGeneric<τ_0_0, τ_0_1 where τ_0_0: Swift.Encodable, τ_0_1: Swift.CodingKey>(_: τ_0_0, for: Foundation._JSONCodingPathNode, _: Swift.Optional<τ_0_1>) throws -> Swift.Optional<Foundation.JSONReference> + 148
frame #9: 0x000000018ca8aacc Foundation`partial apply forwarder for generic partial specialization <Signature = @escaping @convention(thin) <τ_0_0, τ_0_1 where τ_0_0: Swift.Encodable, τ_0_1 == Foundation._JSONKey> (@guaranteed Foundation.__JSONEncoder, @in_guaranteed τ_0_0) -> (@error @owned Swift.Error)> of closure #1 (Foundation.__JSONEncoder) throws -> () in Foundation.__JSONEncoder.wrapGeneric<τ_0_0, τ_0_1 where τ_0_0: Swift.Encodable, τ_0_1: Swift.CodingKey>(_: τ_0_0, for: Foundation._JSONCodingPathNode, _: Swift.Optional<τ_0_1>) throws -> Swift.Optional<Foundation.JSONReference> + 24
frame #10: 0x000000018ca8703c Foundation`generic specialization <Foundation._JSONKey> of Foundation.__JSONEncoder._wrapGeneric<τ_0_0 where τ_0_0: Swift.CodingKey>(_: (Foundation.__JSONEncoder) throws -> (), for: Foundation._JSONCodingPathNode, _: Swift.Optional<τ_0_0>) throws -> Swift.Optional<Foundation.JSONReference> + 288
frame #11: 0x000000018ca7a0c0 Foundation`generic partial specialization <Signature = @escaping @convention(thin) @convention(method) <τ_0_0, τ_0_1 where τ_0_0: Swift.Encodable, τ_0_1 == Foundation._JSONKey> (@in_guaranteed τ_0_0, @guaranteed Foundation._JSONCodingPathNode, @guaranteed Swift.Optional<Foundation._JSONKey>, @guaranteed Foundation.__JSONEncoder) -> (@owned Swift.Optional<Foundation.JSONReference>, @error @owned Swift.Error)> of Foundation.__JSONEncoder.wrapGeneric<τ_0_0, τ_0_1 where τ_0_0: Swift.Encodable, τ_0_1: Swift.CodingKey>(_: τ_0_0, for: Foundation._JSONCodingPathNode, _: Swift.Optional<τ_0_1>) throws -> Swift.Optional<Foundation.JSONReference> + 2048
frame #12: 0x000000018ca792a4 Foundation`Foundation.JSONEncoder.encode<τ_0_0 where τ_0_0: Swift.Encodable>(τ_0_0) throws -> Foundation.Data + 456
frame #13: 0x000000018ca89240 Foundation`dispatch thunk of Foundation.JSONEncoder.encode<τ_0_0 where τ_0_0: Swift.Encodable>(τ_0_0) throws -> Foundation.Data + 56
frame #14: 0x00000001000048fc crash`main at crash.swift:12:23
frame #15: 0x000000018b2de0e0 dyld`start + 2360
(lldb) dis
libswiftCore.dylib`swift::TargetMetadata<swift::InProcess>::getTypeContextDescriptor:
0x19b6c3d4c <+0>: mov x16, #0x0 ; =0
-> 0x19b6c3d50 <+4>: ldr x8, [x0]
0x19b6c3d54 <+8>: cmp x8, #0x7ff
0x19b6c3d58 <+12>: csel w8, wzr, w8, hi
0x19b6c3d5c <+16>: cmp w8, #0x202
0x19b6c3d60 <+20>: b.gt 0x19b6c3dac ; <+96>
0x19b6c3d64 <+24>: sub w9, w8, #0x200
0x19b6c3d68 <+28>: cmp w9, #0x3
0x19b6c3d6c <+32>: b.hs 0x19b6c3dc8 ; <+124>
0x19b6c3d70 <+36>: ldr x8, [x0, #0x8]!
0x19b6c3d74 <+40>: cbz x8, 0x19b6c3e48 ; <+252>
0x19b6c3d78 <+44>: mov x16, x8
0x19b6c3d7c <+48>: mov x17, x0
0x19b6c3d80 <+52>: movk x17, #0xae86, lsl #48
0x19b6c3d84 <+56>: autda x16, x17
0x19b6c3d88 <+60>: mov x17, x16
0x19b6c3d8c <+64>: xpacd x17
0x19b6c3d90 <+68>: cmp x16, x17
0x19b6c3d94 <+72>: b.eq 0x19b6c3d9c ; <+80>
0x19b6c3d98 <+76>: brk #0xc472
0x19b6c3d9c <+80>: mov x17, #0x85c2 ; =34242
0x19b6c3da0 <+84>: pacdb x16, x17
0x19b6c3da4 <+88>: cbnz x16, 0x19b6c3e0c ; <+192>
0x19b6c3da8 <+92>: b 0x19b6c3e40 ; <+244>
0x19b6c3dac <+96>: cmp w8, #0x203
0x19b6c3db0 <+100>: b.eq 0x19b6c3dbc ; <+112>
0x19b6c3db4 <+104>: cmp w8, #0x204
0x19b6c3db8 <+108>: b.ne 0x19b6c3e40 ; <+244>
0x19b6c3dbc <+112>: ldr x8, [x0, #0x8]!
0x19b6c3dc0 <+116>: cbnz x8, 0x19b6c3ddc ; <+144>
0x19b6c3dc4 <+120>: b 0x19b6c3e48 ; <+252>
0x19b6c3dc8 <+124>: cbnz w8, 0x19b6c3e40 ; <+244>
0x19b6c3dcc <+128>: ldrb w8, [x0, #0x20]
0x19b6c3dd0 <+132>: tbz w8, #0x1, 0x19b6c3e48 ; <+252>
0x19b6c3dd4 <+136>: ldr x8, [x0, #0x40]!
0x19b6c3dd8 <+140>: cbz x8, 0x19b6c3e48 ; <+252>
0x19b6c3ddc <+144>: mov x16, x8
0x19b6c3de0 <+148>: mov x17, x0
0x19b6c3de4 <+152>: movk x17, #0xae86, lsl #48
0x19b6c3de8 <+156>: autda x16, x17
0x19b6c3dec <+160>: mov x17, x16
0x19b6c3df0 <+164>: xpacd x17
0x19b6c3df4 <+168>: cmp x16, x17
0x19b6c3df8 <+172>: b.eq 0x19b6c3e00 ; <+180>
0x19b6c3dfc <+176>: brk #0xc472
0x19b6c3e00 <+180>: mov x17, #0xfd78 ; =64888
0x19b6c3e04 <+184>: pacdb x16, x17
0x19b6c3e08 <+188>: cbz x16, 0x19b6c3e40 ; <+244>
0x19b6c3e0c <+192>: mov x16, x8
0x19b6c3e10 <+196>: mov x17, x0
0x19b6c3e14 <+200>: movk x17, #0xae86, lsl #48
0x19b6c3e18 <+204>: autda x16, x17
0x19b6c3e1c <+208>: mov x17, x16
0x19b6c3e20 <+212>: xpacd x17
0x19b6c3e24 <+216>: cmp x16, x17
0x19b6c3e28 <+220>: b.eq 0x19b6c3e30 ; <+228>
0x19b6c3e2c <+224>: brk #0xc472
0x19b6c3e30 <+228>: mov x17, #0xf445 ; =62533
0x19b6c3e34 <+232>: pacdb x16, x17
0x19b6c3e38 <+236>: mov x0, x16
0x19b6c3e3c <+240>: ret
0x19b6c3e40 <+244>: mov x0, x16
0x19b6c3e44 <+248>: ret
0x19b6c3e48 <+252>: mov x0, #0x0 ; =0
0x19b6c3e4c <+256>: ret
(lldb)
Expected behavior
Code runs normally without crashing like when compiling with Swift 5.
Environment
Xcode 16 beta 1 (16A5171c)
swift-driver version: 1.109.2 Apple Swift version 6.0 (swiftlang-6.0.0.3.300 clang-1600.0.20.10)
Target: arm64-apple-macosx14.0
ProductName: macOS
ProductVersion: 14.5
BuildVersion: 23F79
Additional information
run with: swiftc -g -Onone crash.swift -o crash && lldb crash -o run