1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
|
// RUN: %target-build-swift -O %s -module-name=test -Xfrontend -sil-verify-all -emit-sil | %FileCheck %s
// RUN: %empty-directory(%t)
// RUN: %target-build-swift -O -module-name=test %s -o %t/a.out
// RUN: %target-run %t/a.out | %FileCheck %s -check-prefix=CHECK-OUTPUT
// REQUIRES: executable_test,swift_stdlib_no_asserts
// REQUIRES: swift_in_compiler
// Test needs to be updated for 32bit.
// rdar://74810823
// UNSUPPORTED: PTRSIZE=32
#if _runtime(_ObjC)
import Foundation
#endif
struct Outer {
struct Inner { }
class InnerClass { }
static let staticString = "static"
}
class C {
@inline(never)
func f() -> String {
return "\(Self.self)"
}
}
// More types are tested in test/stdlib/TypeName.swift and
// test/stdlib/TypeNameInterpolation.swift
// CHECK-LABEL: sil [noinline] @$s4test0A21TypeNameInterpolationSSyF
// CHECK-NOT: apply
// CHECK-NOT: bb1
// CHECK: } // end sil function '$s4test0A21TypeNameInterpolationSSyF'
@inline(never)
public func testTypeNameInterpolation() -> String {
return "-\(Outer.Inner.self)+"
}
// CHECK-LABEL: sil [noinline] @$s4test0A25FoldCompleteInterpolationSSyF
// CHECK-NOT: apply
// CHECK-NOT: bb1
// CHECK: } // end sil function '$s4test0A25FoldCompleteInterpolationSSyF'
@inline(never)
public func testFoldCompleteInterpolation() -> String {
let s = "is"
return "-\([Int].self) \(s) \("cool")+"
}
// CHECK-LABEL: sil [noinline] @$s4test0A13FoldStaticLetSSyF
// CHECK-NOT: apply
// CHECK-NOT: bb1
// CHECK: } // end sil function '$s4test0A13FoldStaticLetSSyF'
@inline(never)
public func testFoldStaticLet() -> String {
return "-\(Outer.staticString)+"
}
// CHECK-LABEL: sil [noinline] @$s4test0A10FoldConcatSSyF
// CHECK-NOT: apply
// CHECK-NOT: bb1
// CHECK: } // end sil function '$s4test0A10FoldConcatSSyF'
@inline(never)
public func testFoldConcat() -> String {
return "a" + "b" + "c"
}
// CHECK-LABEL: sil [noinline] @$s4test0A19UnqualifiedTypeNameSSyF
// CHECK-NOT: apply
// CHECK-NOT: bb1
// CHECK: } // end sil function '$s4test0A19UnqualifiedTypeNameSSyF'
@inline(never)
public func testUnqualifiedTypeName() -> String {
return _typeName(Outer.Inner.self, qualified: false)
}
// CHECK-LABEL: sil [noinline] @$s4test0A17QualifiedTypeNameSSyF
// CHECK-NOT: apply
// CHECK-NOT: bb1
// CHECK: } // end sil function '$s4test0A17QualifiedTypeNameSSyF'
@inline(never)
public func testQualifiedTypeName() -> String {
return _typeName(Outer.Inner.self, qualified: true)
}
// CHECK-LABEL: sil [noinline] @$s4test0A20UnqualifiedLocalTypeSSyF
// CHECK-NOT: apply
// CHECK-NOT: bb1
// CHECK: } // end sil function '$s4test0A20UnqualifiedLocalTypeSSyF'
@inline(never)
public func testUnqualifiedLocalType() -> String {
struct LocalStruct { }
return _typeName(LocalStruct.self, qualified: false)
}
// CHECK-LABEL: sil [noinline] @$s4test0A18QualifiedLocalTypeSSyF
// CHECK: [[F:%[0-9]+]] = function_ref @$ss9_typeName_9qualifiedSSypXp_SbtF
// CHECK: apply [[F]]
// CHECK: } // end sil function '$s4test0A18QualifiedLocalTypeSSyF'
@inline(never)
public func testQualifiedLocalType() -> String {
struct LocalStruct { }
return _typeName(LocalStruct.self, qualified: true)
}
// CHECK-LABEL: sil [noinline] @$s4test0A10InnerClassSSyF
// CHECK-NOT: apply
// CHECK-NOT: bb1
// CHECK: } // end sil function '$s4test0A10InnerClassSSyF'
@inline(never)
public func testInnerClass() -> String {
return _typeName(Outer.InnerClass.self, qualified: true)
}
#if _runtime(_ObjC)
@inline(never)
public func testObjcClassName(qualified: Bool) -> String {
return _typeName(NSObject.self, qualified: qualified)
}
#endif
@inline(never)
func printEmbedded(_ s: String) {
print("<\(s)>")
}
// CHECK-OUTPUT: <-Inner+>
printEmbedded(testTypeNameInterpolation())
// CHECK-OUTPUT: <-Array<Int> is cool+>
printEmbedded(testFoldCompleteInterpolation())
// CHECK-OUTPUT: <-static+>
printEmbedded(testFoldStaticLet())
// CHECK-OUTPUT: <abc>
printEmbedded(testFoldConcat())
// CHECK-OUTPUT: <Inner>
printEmbedded(testUnqualifiedTypeName())
// CHECK-OUTPUT: <test.Outer.Inner>
printEmbedded(testQualifiedTypeName())
// CHECK-OUTPUT: <LocalStruct>
printEmbedded(testUnqualifiedLocalType())
// CHECK-OUTPUT: <test.(unknown context at {{.*}}).LocalStruct>
printEmbedded(testQualifiedLocalType())
// CHECK-OUTPUT: <test.Outer.InnerClass>
printEmbedded(testInnerClass())
// CHECK-OUTPUT: <C>
printEmbedded(C().f())
#if _runtime(_ObjC)
// Can't use check-output here, because for non ObjC runtimes it would not match.
if testObjcClassName(qualified: false) != "NSObject" {
fatalError()
}
if testObjcClassName(qualified: true) != "NSObject" {
fatalError()
}
#endif
|