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
|
// RUN: %target-swift-frontend -enable-experimental-move-only -parse-stdlib -module-name Swift -enable-sil-opaque-values -parse-as-library -emit-sil -Onone %s | %FileCheck %s
// Like opaque_values_Onone.swift but for code that needs to be compiled with
// -parse-stdlib.
protocol Error {}
enum Never : Error{}
precedencegroup AssignmentPrecedence { assignment: true }
precedencegroup CastingPrecedence {}
public protocol _ObjectiveCBridgeable {}
@_marker public protocol Copyable {}
public protocol _ExpressibleByBuiltinBooleanLiteral {
init(_builtinBooleanLiteral value: Builtin.Int1)
}
struct Bool : _ExpressibleByBuiltinBooleanLiteral {
var _value: Builtin.Int1
@_silgen_name("Bool_init_noargs")
init()
init(_ v: Builtin.Int1) { self._value = v }
init(_ value: Bool) { self = value }
init(_builtinBooleanLiteral value: Builtin.Int1) {
self._value = value
}
}
@_silgen_name("typeof")
@_semantics("typechecker.type(of:)")
public func type<T, Metatype>(of value: T) -> Metatype
class X {}
func consume(_ x : __owned X) {}
func foo(@_noImplicitCopy _ x: __owned X) {
consume(copy x)
consume(x)
}
// CHECK-LABEL: sil hidden @getRawPointer : {{.*}} {
// CHECK: {{bb[0-9]+}}([[ADDR:%[^,]+]] : $*T):
// CHECK: [[PTR:%[^,]+]] = address_to_pointer [stack_protection] [[ADDR]]
// CHECK: return [[PTR]]
// CHECK-LABEL: } // end sil function 'getRawPointer'
@_silgen_name("getRawPointer")
func getRawPointer<T>(to value: T) -> Builtin.RawPointer {
return Builtin.addressOfBorrow(value)
}
// CHECK-LABEL: sil hidden @getUnprotectedRawPointer : {{.*}} {
// CHECK: {{bb[0-9]+}}([[ADDR:%[^,]+]] : $*T):
// CHECK: [[PTR:%[^,]+]] = address_to_pointer [[ADDR]]
// CHECK: return [[PTR]]
// CHECK-LABEL: } // end sil function 'getUnprotectedRawPointer'
@_silgen_name("getUnprotectedRawPointer")
func getUnprotectedRawPointer<T>(to value: T) -> Builtin.RawPointer {
return Builtin.unprotectedAddressOfBorrow(value)
}
// CHECK-LABEL: sil hidden @getBridgeObject : {{.*}} {
// CHECK: [[OBJECT_ADDR:%[^,]+]] = unchecked_addr_cast {{%[^,]+}} : $*T to $*Builtin.BridgeObject
// CHECK: [[OBJECT:%[^,]+]] = load [[OBJECT_ADDR]]
// CHECK: return [[OBJECT]]
// CHECK-LABEL: } // end sil function 'getBridgeObject'
@_silgen_name("getBridgeObject")
func toObject<T>(_ object: inout T) -> Builtin.BridgeObject {
Builtin.reinterpretCast(object)
}
// CHECK-LABEL: sil hidden @getAnotherType : {{.*}} {
// CHECK: {{bb[0-9]+}}([[RETADDR:%[^,]+]] : $*U, {{%[^,]+}} : $*T, {{%[^,]+}} : $@thick U.Type):
// CHECK: [[OTHER_TY_ADDR:%[^,]+]] = unchecked_addr_cast {{%[^,]+}} : $*T to $*U
// CHECK: copy_addr [[OTHER_TY_ADDR]] to [init] [[RETADDR]] : $*U
// CHECK-LABEL: } // end sil function 'getAnotherType'
@_silgen_name("getAnotherType")
func getAnotherType<T, U>(_ object: inout T, to ty: U.Type) -> U {
Builtin.reinterpretCast(object)
}
@_silgen_name("isOfTypeOfAnyObjectType")
func isOfTypeOfAnyObjectType(fromAny any: Any) -> Bool {
type(of: any) is Builtin.AnyObject.Type
}
@available(SwiftStdlib 5.1, *)
struct UnsafeContinuation<T, E: Error> {
@usableFromInline internal var context: Builtin.RawUnsafeContinuation
// CHECK-LABEL: sil {{.*}}@unsafeContinuationResumeNoThrow : {{.*}} {
// CHECK: {{bb[0-9]+}}([[VALUE:%[^,]+]] : $*T, [[CONTINUATION:%[^,]+]] : $UnsafeContinuation<T, Never>):
// CHECK: [[STACK:%[^,]+]] = alloc_stack $T
// CHECK: [[CONTEXT:%[^,]+]] = struct_extract [[CONTINUATION]]
// CHECK: copy_addr [[VALUE]] to [init] [[STACK]]
// CHECK: builtin "resumeNonThrowingContinuationReturning"<T>([[CONTEXT]] : $Builtin.RawUnsafeContinuation, [[STACK]] : $*T)
// CHECK: destroy_addr [[VALUE]]
// CHECK-LABEL: } // end sil function 'unsafeContinuationResumeNoThrow'
@_silgen_name("unsafeContinuationResumeNoThrow")
@_alwaysEmitIntoClient
public func resume(returning value: __owned T) where E == Never {
#if compiler(>=5.5) && $BuiltinContinuation
Builtin.resumeNonThrowingContinuationReturning(context, value)
#endif
}
// CHECK-LABEL: sil {{.*}}@unsafeContinuationResumeThrow : {{.*}} {
// CHECK: {{bb[0-9]+}}([[VALUE:%[^,]+]] : $*T, [[CONTINUATION:%[^,]+]] : $UnsafeContinuation<T, E>):
// CHECK: [[STACK:%[^,]+]] = alloc_stack $T
// CHECK: [[CONTEXT:%[^,]+]] = struct_extract [[CONTINUATION]]
// CHECK: copy_addr [[VALUE]] to [init] [[STACK]]
// CHECK: builtin "resumeThrowingContinuationReturning"<T>([[CONTEXT]] : $Builtin.RawUnsafeContinuation, [[STACK]] : $*T)
// CHECK: destroy_addr [[VALUE]]
// CHECK-LABEL: } // end sil function 'unsafeContinuationResumeThrow'
@_silgen_name("unsafeContinuationResumeThrow")
@_alwaysEmitIntoClient
public func resume(returning value: __owned T) {
#if compiler(>=5.5) && $BuiltinContinuation
Builtin.resumeThrowingContinuationReturning(context, value)
#endif
}
}
|