File: remove_unused_global_vars.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 (74 lines) | stat: -rw-r--r-- 2,093 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// RUN: %target-swift-frontend -parse-as-library -primary-file %s -O -module-name=test -emit-sil | %FileCheck %s

import SwiftShims

@_optimize(none) public func make_test(_ x: Int) -> Int {
  return x
}

struct Foo {
  let x : Int
  let y : Int
  func both() -> Int { x + y }
}

// CHECK-NOT: sil_global private [let] {{.*}}unused1{{.*}}
private let unused1 = 0
// CHECK-NOT: sil_global private {{.*}}unused2{{.*}}
private var unused2 = 42
// CHECK: sil_global private @${{.*}}used1{{.*}} : $Int
private var used1 = 0
// CHECK: sil_global private @${{.*}}used2{{.*}} : $Int
private var used2 = 0

// non-constant / non-trivial values
// CHECK-NOT: sil_global private {{.*}}unused7{{.*}}
private let unused7 = make_test(42)
// CHECK-NOT: sil_global private {{.*}}unused8{{.*}}
private let unused8 = Foo(x: 1, y: 1)
// CHECK-NOT: sil_global private {{.*}}unused9{{.*}}
private let unused9 = Foo(x: 1, y: 1).both()

// CHECK: sil_global [let] @${{.*}}unused3{{.*}} : $Int
public let unused3 = 0
// CHECK: sil_global @${{.*}}unused4{{.*}} : $Int
public var unused4 = 0

// These should only be optimized with -wmo.
// CHECK: sil_global hidden [let] @${{.*}}unused5{{.*}} : $Int
// CHECK-WMO-NOT: sil_global hidden [let] @${{.*}}unused5{{.*}} : $Int
let unused5 = 0
// CHECK: sil_global hidden @${{.*}}unused6{{.*}} : $Int
// CHECK-WMO-NOT: sil_global hidden @${{.*}}unused6{{.*}} : $Int
var unused6 = 0

// Edge case: static and static with computed valued
// See Baz - line 71
// CHECK: sil_global [let] {{.*}}darwin{{.*}} : $Baz

// CHECK-LABEL: sil [Onone] @${{.*}}test{{.*}}
@_optimize(none) public func test(x: Int) -> Int {
  return used1 + used2 + x
}

// CHECK-LABEL: sil @${{.*}}storageVar{{.*}}
@inlinable
internal var storageVar: _SwiftEmptyArrayStorage {
  // CHECK: return %2 : $_SwiftEmptyArrayStorage
  return _swiftEmptyArrayStorage
}

public struct Bar {
  let storage: _SwiftEmptyArrayStorage
  
  init () {
    storage = storageVar
  }
}

public struct Baz {
  public init() { }

  public static let darwin = Baz()
  public static var currentPlatform: Baz { return .darwin }
}