File: xref-private-type.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,732 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-build-swift -swift-version 4 -O -Xllvm -sil-disable-pass=compute-side-effects -Xllvm -sil-disable-pass=cmo -whole-module-optimization -emit-module-path %t/LibCore.swiftmodule %S/Inputs/xref-private-type/LibCore.swift
// RUN: %target-build-swift -swift-version 4 -O -Xllvm -sil-disable-pass=compute-side-effects -Xllvm -sil-disable-pass=cmo -I %t  -whole-module-optimization -emit-module-path %t/Lib.swiftmodule %S/Inputs/xref-private-type/Lib.swift 
// RUN: %target-build-swift -swift-version 4 -O -I %t -emit-sil %s | %FileCheck %s

import Lib

// CHECK: sil{{.*}} @[[TEST1:[^ ]+5test1[^ ]+]] :
func test1() {
  // The important lines in this test are the strong_retains, which refer to
  // private types defined in LibCore. Normally we shouldn't have references to
  // non-public declarations in inlinable code, but because SIL passes can break
  // apart non-resilient structs and enums we can end up in that situation.
  // Worse, this can happen *across module boundaries.*
  //
  // In this test, the addressor for each global defined in Lib ends up
  // referencing private types defined in LibCore. Using those globals in
  // default argument position leads to the addressor getting inlined into
  // calling code in Swift 4 and later. This results in an attempt to not just
  // reference a private type, but to *resolve a cross-reference to a private
  // type.*
  //
  // This is the situation in https://github.com/apple/swift/issues/49423
  // (simplified). I'm not sure of a simpler way to reliably trigger the issue.
  // But if this test breaks, please try to find one.
  //
  // (We may want to revisit this whole thing later, as it violates the model.
  // But it's also useful for performance in non-resilient code.)

  // CHECK: [[ADDR:%.+]] = global_addr @{{[^ ]+}}3Lib7lazyFoo
  // CHECK: [[LOADED:%.+]] = load [[ADDR]] : $*Foo
  // CHECK: [[REF:%.+]] = struct_extract [[LOADED]] : $Foo, #Foo.ref
  // CHECK: strong_retain [[REF]] : $TopLevelInternalClass
  // CHECK: apply {{%.+}}([[LOADED]])
  testFoo()

  // CHECK: [[ADDR:%.+]] = global_addr @{{[^ ]+}}3Lib7lazyBar
  // CHECK: [[LOADED:%.+]] = load [[ADDR]] : $*Bar
  // CHECK: [[REF:%.+]] = struct_extract [[LOADED]] : $Bar, #Bar.ref
  // CHECK: strong_retain [[REF]] : $Bar.NestedInternalClass
  // CHECK: apply {{%.+}}([[LOADED]])
  testBar()

  // CHECK: [[ADDR:%.+]] = global_addr @{{[^ ]+}}3Lib7lazyBaz
  // CHECK: [[LOADED:%.+]] = load [[ADDR]] : $*Baz
  // CHECK: [[REF:%.+]] = struct_extract [[LOADED]] : $Baz, #Baz.ref
  // CHECK: strong_retain [[REF]] : $Baz.NestedInternalClass.DoublyNestedInternalClass
  // CHECK: apply {{%.+}}([[LOADED]])
  testBaz()
} // CHECK: end sil function '[[TEST1]]'