|
| 1 | +// RUN: %empty-directory(%t) |
| 2 | +// RUN: %target-swift-frontend -emit-module -enable-library-evolution -emit-module-path=%t/resilient_protocol.swiftmodule -module-name=resilient_protocol %S/../Inputs/resilient_protocol.swift |
| 3 | +// RUN: %target-swift-frontend -I %t -emit-ir -enable-library-evolution %s | %FileCheck %s -DINT=i%target-ptrsize |
| 4 | +// RUN: %target-swift-frontend -I %t -emit-ir -enable-library-evolution -O %s |
| 5 | + |
| 6 | +import resilient_protocol |
| 7 | + |
| 8 | +@_fixed_layout public protocol FrozenProtocol { |
| 9 | + func protocolMethod() |
| 10 | +} |
| 11 | + |
| 12 | +public func callOtherProtocolMethod<T : OtherFrozenProtocol>(_ t: T) { |
| 13 | + t.protocolMethod() |
| 14 | +} |
| 15 | + |
| 16 | +public struct ConformsToFrozenProtocol : FrozenProtocol { |
| 17 | + public func protocolMethod() {} |
| 18 | +} |
| 19 | + |
| 20 | +// CHECK-LABEL: @"$s16frozen_protocols24ConformsToFrozenProtocolVAA0eF0AAMc" = {{(dllexport )?}}{{(protected )?}}constant %swift.protocol_conformance_descriptor |
| 21 | + |
| 22 | +// -- the protocol |
| 23 | +// CHECK-SAME: @"$s16frozen_protocols14FrozenProtocolMp" |
| 24 | + |
| 25 | +// -- the conforming type |
| 26 | +// CHECK-SAME: @"$s16frozen_protocols24ConformsToFrozenProtocolVMn" |
| 27 | + |
| 28 | +// -- the witness table |
| 29 | +// CHECK-SAME: @"$s16frozen_protocols24ConformsToFrozenProtocolVAA0eF0AAWP" |
| 30 | + |
| 31 | +// -- flags |
| 32 | +// CHECK-SAME: i32 0 |
| 33 | +// CHECK-SAME: } |
| 34 | + |
| 35 | +// @_fixed_layout protocols still emit protocol requirement descriptors though, |
| 36 | +// which allows for a protocol to be retroactively declared as @_fixed_layout |
| 37 | +// CHECK-LABEL: @"$s16frozen_protocols14FrozenProtocolP14protocolMethodyyFTq" = {{(dllexport )?}}{{(protected )?}}alias %swift.protocol_requirement |
| 38 | + |
| 39 | +// Requirements in @_fixed_layout protocols are called by direct witness |
| 40 | +// table lookup |
| 41 | + |
| 42 | +// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @"$s16frozen_protocols23callOtherProtocolMethodyyx18resilient_protocol0d6FrozenE0RzlF"(%swift.opaque* noalias nocapture %0, %swift.type* %T, i8** %T.OtherFrozenProtocol) |
| 43 | +// CHECK: [[ADDR:%.*]] = getelementptr inbounds i8*, i8** %T.OtherFrozenProtocol, i32 1 |
| 44 | +// CHECK: [[FN:%.*]] = load i8*, i8** [[ADDR]] |
| 45 | +// CHECK: [[CAST:%.*]] = bitcast i8* [[FN]] to void (%swift.opaque*, %swift.type*, i8**)* |
| 46 | +// CHECK: call swiftcc void %3(%swift.opaque* noalias nocapture swiftself %0, %swift.type* %T, i8** %T.OtherFrozenProtocol) |
| 47 | +// CHECK: ret void |
| 48 | + |
| 49 | +// @_fixed_layout protocols still emit method dispatch thunks though, which |
| 50 | +// allows for a protocol to be retroactively declared as @_fixed_layout |
| 51 | +// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @"$s16frozen_protocols14FrozenProtocolP14protocolMethodyyFTj"( |
| 52 | + |
0 commit comments