mirror of
https://github.com/apple/swift.git
synced 2026-11-01 23:11:50 +01:00
A protocol's constraint decides the layout of an existential of it: a class-constrained existential is a reference plus witness tables, while an opaque one also has an inline buffer and a metadata pointer. Without reflection metadata, there's no way to tell which case a protocol is, so we need to encode it in DWARF. Assisted-by: claude
28 lines
1.1 KiB
Swift
28 lines
1.1 KiB
Swift
// RUN: %target-swift-frontend %s -emit-ir -g -o - | %FileCheck %s
|
|
|
|
class Base {}
|
|
|
|
protocol Opaque {}
|
|
protocol AnyObjectBound: AnyObject {}
|
|
protocol SuperclassBound: Base {}
|
|
|
|
class C: Opaque, AnyObjectBound {}
|
|
class D: Base, SuperclassBound {}
|
|
|
|
func f() {
|
|
let opaque: any Opaque = C()
|
|
let anyObjectBound: any AnyObjectBound = C()
|
|
let superclassBound: any SuperclassBound = D()
|
|
}
|
|
|
|
// Both a class constraint spelled as AnyObject and one implied by a superclass
|
|
// requirement are annotated, and share the annotation.
|
|
// CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: "AnyObjectBound"{{.*}}annotations: ![[ANNOT:[0-9]+]]
|
|
// CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: "SuperclassBound"{{.*}}annotations: ![[ANNOT]]
|
|
// CHECK-DAG: ![[ANNOT]] = !{![[ENTRY:[0-9]+]]}
|
|
// CHECK-DAG: ![[ENTRY]] = !{!"swift.ClassConstrainedProtocol", i1 true}
|
|
|
|
// An unconstrained protocol carries no annotation, which is what gives it the
|
|
// plain Protocol field descriptor kind.
|
|
// CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: "Opaque"{{.*}}identifier: "{{.*}}6Opaque_pD")
|