File: frozen_protocols.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (51 lines) | stat: -rw-r--r-- 2,330 bytes parent folder | download
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
// RUN: %empty-directory(%t)
// 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
// RUN: %target-swift-frontend -I %t -emit-ir -enable-library-evolution %s | %FileCheck %s -DINT=i%target-ptrsize
// RUN: %target-swift-frontend -I %t -emit-ir -enable-library-evolution -O %s

import resilient_protocol

@_fixed_layout public protocol FrozenProtocol {
  func protocolMethod()
}

public func callOtherProtocolMethod<T : OtherFrozenProtocol>(_ t: T) {
  t.protocolMethod()
}

public struct ConformsToFrozenProtocol : FrozenProtocol {
  public func protocolMethod() {}
}

// CHECK-LABEL: @"$s16frozen_protocols24ConformsToFrozenProtocolVAA0eF0AAMc" = {{(dllexport )?}}{{(protected )?}}constant %swift.protocol_conformance_descriptor

// -- the protocol
// CHECK-SAME: @"$s16frozen_protocols14FrozenProtocolMp"

// -- the conforming type
// CHECK-SAME: @"$s16frozen_protocols24ConformsToFrozenProtocolVMn"

// -- the witness table
// CHECK-SAME: @"$s16frozen_protocols24ConformsToFrozenProtocolVAA0eF0AAWP"

// -- flags
// CHECK-SAME: i32 0
// CHECK-SAME: }

// @_fixed_layout protocols still emit protocol requirement descriptors though,
// which allows for a protocol to be retroactively declared as @_fixed_layout
// CHECK-LABEL: @"$s16frozen_protocols14FrozenProtocolP14protocolMethodyyFTq" = {{(dllexport )?}}{{(protected )?}}alias %swift.protocol_requirement

// Requirements in @_fixed_layout protocols are called by direct witness
// table lookup

// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @"$s16frozen_protocols23callOtherProtocolMethodyyx18resilient_protocol0d6FrozenE0RzlF"(ptr noalias %0, ptr %T, ptr %T.OtherFrozenProtocol)
// CHECK: [[ADDR:%.*]] = getelementptr inbounds ptr, ptr %T.OtherFrozenProtocol, i32 1
// CHECK: [[FN:%.*]] = load ptr, ptr [[ADDR]]
// CHECK: call swiftcc void [[FN]](ptr noalias swiftself %0, ptr %T, ptr %T.OtherFrozenProtocol)
// CHECK: ret void

// @_fixed_layout protocols still emit method dispatch thunks though, which
// allows for a protocol to be retroactively declared as @_fixed_layout
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @"$s16frozen_protocols14FrozenProtocolP14protocolMethodyyFTj"(