File: moveonly_optional_operations_2.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 (100 lines) | stat: -rw-r--r-- 2,944 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// RUN: %target-swift-frontend -emit-silgen -parse-stdlib -module-name Swift %s | %FileCheck %s

@_marker protocol Copyable {}
@_marker protocol Escapable {}

enum Optional<Wrapped: ~Copyable>: ~Copyable {
    case none
    case some(Wrapped)
}

extension Optional: Copyable where Wrapped: Copyable { }

func _diagnoseUnexpectedNilOptional(_filenameStart: Builtin.RawPointer,
                                    _filenameLength: Builtin.Word,
                                    _filenameIsASCII: Builtin.Int1,
                                    _line: Builtin.Word,
                                    _isImplicitUnwrap: Builtin.Int1) {
}

precedencegroup AssignmentPrecedence {}

struct NC: ~Copyable {
    borrowing func b() {}
    mutating func m() {}
    consuming func c() {}

    consuming func c2() -> NC { c2() } // expected-warning{{}}
    consuming func c3() -> NCAO { c3() } // expected-warning{{}}
}

struct NCAO: ~Copyable {
    var x: Any

    borrowing func b() {}
    mutating func m() {}
    consuming func c() {}

    consuming func c2() -> NC { c2() } // expected-warning{{}}
    consuming func c3() -> NCAO { c3() } // expected-warning{{}}
}

struct NCPair: ~Copyable {
    var first: NC? = .none
    var second: NCAO? = .none
}

func consumingSwitchSubject(nc: consuming NC?,
                            ncao: consuming NCAO?) {
    switch nc?.c2() {
    default:
      break
    }
    switch ncao?.c2() {
    default:
      break
    }
}

func consumingSwitchSubject2(nc: consuming NC?,
                             ncao: consuming NCAO?) {
    switch nc?.c3() {
    default:
      break
    }
    switch ncao?.c3() {
    default:
      break
    }
}

// CHECK-LABEL: sil {{.*}}@${{.*}}23consumingSwitchSubject3
func consumingSwitchSubject3(ncp: consuming NCPair) {
    // CHECK:   [[PAIR_ACCESS:%.*]] = begin_access [deinit] [unknown] {{.*}} : $*NCPair
    // CHECK:   [[PAIR_MARK:%.*]] = mark_unresolved_non_copyable_value [assignable_but_not_consumable] [[PAIR_ACCESS]]
    // CHECK:   [[FIELD:%.*]] = struct_element_addr [[PAIR_MARK]]
    // CHECK:   [[FIELD_ACCESS:%.*]] = begin_access [deinit] [static] [no_nested_conflict] [[FIELD]]
    // CHECK:   cond_br {{.*}}, [[SOME_BB:bb[0-9]+]], [[NONE_BB:bb[0-9]+]]
    // CHECK: [[SOME_BB]]:
    // CHECK:   [[PAYLOAD_ADDR:%.*]] = unchecked_take_enum_data_addr [[FIELD_ACCESS]]
    // CHECK:   [[PAYLOAD:%.*]] = load [take] [[PAYLOAD_ADDR]]
    // CHECK:   apply {{.*}}({{.*}}, [[PAYLOAD]]) : ${{.*}} (@owned NC)
    // CHECK-NOT: destroy_addr
    // CHECK-NOT: destroy_value
    // CHECK:   end_access [[FIELD_ACCESS]]
    // CHECK-NEXT: end_access [[PAIR_ACCESS]]
    // CHECK-NEXT: inject_enum_addr 
    // CHECK-NEXT: br 
    // CHECK: [[NONE_BB]]:
    // CHECK:   destroy_addr [[FIELD_ACCESS]]
    // CHECK-NEXT: end_access [[FIELD_ACCESS]]

    switch ncp.first?.c3() {
    default:
      break
    }
    switch ncp.second?.c3() {
    default:
      break
    }
}