File: devirt_opaque_witness.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 (29 lines) | stat: -rw-r--r-- 1,737 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
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/opaque_conformance.swiftmodule -primary-file %S/Inputs/opaque_conformance.swift
// RUN: %target-swift-frontend -O -emit-sil -primary-file %s -I %t -Xllvm -sil-disable-pass=late-deadfuncelim | %FileCheck %s

import opaque_conformance

public func callsPublicRequirement(_ c: Conformer) {
  c.publicRequirement()
}

// CHECK-LABEL: sil @$s21devirt_opaque_witness22callsPublicRequirementyy0B12_conformance9ConformerVF : $@convention(thin) (Conformer) -> () {
// CHECK:    bb0(%0 : $Conformer):
// CHECK:      [[BOX:%.*]] = alloc_stack $Conformer
// CHECK-NEXT: store %0 to [[BOX]] : $*Conformer
// CHECK:      [[FN:%.*]] = function_ref @$s18opaque_conformance9ConformerVAA14PublicProtocolA2aDP17publicRequirementyyFTW :
// CHECK-NEXT: [[RESULT:%.*]] = apply [[FN]]([[BOX]]) :
// CHECK-NEXT: dealloc_stack [[BOX]] : $*Conformer
// CHECK-NEXT: [[RESULT:%.*]] = tuple ()
// CHECK-NEXT: return [[RESULT]] : $()

// Note that [transparent] here doesn't mean anything since there's no body.
// The important thing is that the witness_method call got devirtualized,
// and the thunk has public linkage and no serialized body (since the body
// references a private symbol of the module opaque_conformance).
// CHECK-LABEL: sil [transparent] [thunk] @$s18opaque_conformance9ConformerVAA14PublicProtocolA2aDP17publicRequirementyyFTW :

// CHECK-LABEL: sil_witness_table public_external Conformer: PublicProtocol module opaque_conformance {
// CHECK-NEXT:    method #PublicProtocol.publicRequirement: <Self where Self : PublicProtocol> (Self) -> () -> () : @$s18opaque_conformance9ConformerVAA14PublicProtocolA2aDP17publicRequirementyyFTW
// CHECK-NEXT: }