File: mandatory_inlining.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 (61 lines) | stat: -rw-r--r-- 1,827 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
// RUN: %target-run-simple-swift

// REQUIRES: executable_test

// This file contains various scenarios that validate that various functional
// behaviors of mandatory inlining work as expected. Please give each test a
// descriptive name and a large comment explaining what you are testing.

import StdlibUnittest

var Tests = TestSuite("MandatoryInlining Functional Tests")
defer { runAllTests() }

func doNotInsertReleaseInLoopIfValueConsumedInLoop(
  callBack: ((String) -> (Void))? = nil) {
  let callBack = callBack ?? { msg in
    print(msg)
  }

  for _ in 0..<1 {
    callBack("foo bar baz")
  }
}

// When using the linear lifetime checker to insert compensating releases, if we
// find a double consume due to a loop, do not insert an apply at that call site
// that is in the loop. There is already a compensating retain in the loop that
// we are ignoring. This test functionally makes sure we no longer do this.
Tests.test("doNotInsertReleaseInLoopIfValueConsumedInLoop") {
  doNotInsertReleaseInLoopIfValueConsumedInLoop { msg in
      print(msg)
  }
}


@propertyWrapper
public struct Published<Value> {
    public var wrappedValue: Value
    public init(initialValue value: Value) { wrappedValue = value }
}

private class Model {
    var selectedContact: Int? {
        get { _selectedContact }
        set {
            if let contact = newValue {
                self._selectedContact = contact
            }
        }
    }

    @Published private var _selectedContact: Int? = nil
}

Tests.test("testNonOSSAPartialApplyLifetimeExtension") {
  // If we mess this up, when we set model.selectedContact to nil, we release
  // self incorrectly due to mandatory inlining getting the wrong begin lifetime
  // block (which in this case is the entry block).
  let model = Model()
  model.selectedContact = nil
}