mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Previously type sizes would be inconsistently sourced from either the LLVM type or the FixedTypeInfo, depending on the call site. This was problematic because TypeInfo operates with a resolution of whole bytes, which means that types such as i1 would get a reported as having a size of 8. This patch now asserts that all occurrences of the same type have the same size as the first, cached occurence. To avoid triggering the cached type verification assertion, this patch avoids caching of storage-sized containers. It also removes the unique identifier from forward declarations, which could lead to type confusion during LTO. rdar://102367872
54 lines
2.0 KiB
Swift
54 lines
2.0 KiB
Swift
// RUN: %target-swift-frontend -module-name generic_args -primary-file %s -emit-ir -verify -g -o - | %FileCheck %s -allow-deprecated-dag-overlap
|
|
|
|
func markUsed<T>(_ t: T) {}
|
|
|
|
protocol AProtocol {
|
|
func f() -> String
|
|
}
|
|
class AClass : AProtocol {
|
|
func f() -> String { return "A" }
|
|
}
|
|
class AnotherClass : AProtocol {
|
|
func f() -> String { return "B" }
|
|
}
|
|
|
|
// CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: "$sq_D",
|
|
// CHECK-DAG: !DILocalVariable(name: "x", arg: 1,{{.*}} type: ![[LET_T:.*]])
|
|
// CHECK-DAG: ![[LET_T]] = !DIDerivedType(tag: DW_TAG_const_type, baseType: ![[T:.*]])
|
|
// CHECK-DAG: ![[T]] = !DICompositeType(tag: DW_TAG_structure_type, name: "$sxD",
|
|
// CHECK-DAG: !DILocalVariable(name: "y", arg: 2,{{.*}} type: ![[LET_Q:.*]])
|
|
// CHECK-DAG: ![[LET_Q]] = !DIDerivedType(tag: DW_TAG_const_type, baseType: ![[Q:.*]])
|
|
// CHECK-DAG: ![[Q]] = !DICompositeType(tag: DW_TAG_structure_type, name: "$sq_D"
|
|
func aFunction<T : AProtocol, Q : AProtocol>(_ x: T, _ y: Q, _ z: String) {
|
|
markUsed("I am in \(z): \(x.f()) \(y.f())")
|
|
}
|
|
|
|
aFunction(AClass(),AnotherClass(),"aFunction")
|
|
|
|
struct Wrapper<T: AProtocol> {
|
|
|
|
init<U>(from : Wrapper<U>) {
|
|
// CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: "$s12generic_args7WrapperVyqd__GD"
|
|
var wrapped = from
|
|
wrapped = from
|
|
_ = wrapped
|
|
}
|
|
|
|
func passthrough(_ t: T) -> T {
|
|
// CHECK-DAG: ![[WRAPPER:.*]] = !DICompositeType({{.*}}name: "$s12generic_args7WrapperVyxGD"
|
|
// CHECK-DAG: !DILocalVariable(name: "local",{{.*}} line: [[@LINE+2]],{{.*}} type: ![[T1:[0-9]+]]
|
|
// CHECK-DAG: ![[T1]] = !DICompositeType(tag: DW_TAG_structure_type, name: "$sxD",
|
|
var local = t
|
|
local = t
|
|
return local
|
|
}
|
|
}
|
|
|
|
// CHECK-DAG: ![[FNTY:.*]] = !DICompositeType({{.*}}identifier: "$sxq_Ignr_D"
|
|
// CHECK-DAG: ![[LET_FNTY:.*]] = !DIDerivedType(tag: DW_TAG_const_type, baseType: ![[FNTY]])
|
|
// CHECK-DAG: !DILocalVariable(name: "f", {{.*}}, line: [[@LINE+1]], type: ![[LET_FNTY]])
|
|
func apply<T, U> (_ x: T, f: (T) -> (U)) -> U {
|
|
return f(x)
|
|
}
|
|
|