File: consuming_parameter.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-- 3,331 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-emit-silgen %s | %FileCheck %s

func bar(_: String) {}

// CHECK-LABEL: sil {{.*}} @${{.*}}3foo
func foo(y: consuming String, z: String) -> () -> String {
    // CHECK: bb0(%0 : @noImplicitCopy @_eagerMove @owned $String, %1 : @guaranteed $String):
    // CHECK:   [[BOX:%.*]] = alloc_box ${ var @moveOnly String }
    // CHECK:   [[BOX_LIFETIME:%.*]] = begin_borrow [var_decl] [[BOX]]
    // CHECK:   [[Y:%.*]] = project_box [[BOX_LIFETIME]]
    // CHECK:   [[UNWRAP:%.*]] = moveonlywrapper_to_copyable_addr [[Y]]
    // CHECK:   store %0 to [init] [[UNWRAP]]

    // CHECK:   [[YCAPTURE:%.*]] = copy_value [[BOX_LIFETIME]]
    // CHECK:   [[UNWRAP:%.*]] = moveonlywrapper_to_copyable_box [[YCAPTURE]]
    // CHECK:   partial_apply {{.*}} {{%.*}}([[UNWRAP]])
    let r = { y }

    // CHECK:   [[ZCOPY:%.*]] = copy_value %1
    // CHECK:   [[YACCESS:%.*]] = begin_access [modify] [unknown] [[Y]]
    // CHECK:   [[MARK:%.*]] = mark_unresolved_non_copyable_value [assignable_but_not_consumable] [[YACCESS]]
    // CHECK:   [[UNWRAP:%.*]] = moveonlywrapper_to_copyable_addr [[MARK]]
    // CHECK:   assign [[ZCOPY]] to [[UNWRAP]]
    y = z

    // CHECK:   [[YACCESS:%.*]] = begin_access [read] [unknown] [[Y]]
    // CHECK:   [[MARK:%.*]] = mark_unresolved_non_copyable_value [no_consume_or_assign] [[YACCESS]]
    // CHECK:   [[YVAL:%.*]] = load [copy] [[MARK]]
    // CHECK:   [[BORROW:%.*]] = begin_borrow [[YVAL]]
    // CHECK:   [[UNWRAP:%.*]] = moveonlywrapper_to_copyable [guaranteed] [[BORROW]]
    // CHECK:   apply {{%.*}}([[UNWRAP]]
    bar(y)

    return r
}

struct Butt {
    var value: String

    func bar() {}

    // CHECK-LABEL: sil {{.*}} @${{.*}}4Butt{{.*}}6merged
    consuming func merged(with other: Butt) -> () -> Butt {
        // CHECK: bb0(%0 : @guaranteed $Butt, %1 : @noImplicitCopy @_eagerMove @owned $Butt):
        // CHECK:   [[BOX:%.*]] = alloc_box ${ var @moveOnly Butt }
        // CHECK:   [[BOX_LIFETIME:%.*]] = begin_borrow [var_decl] [[BOX]]
        // CHECK:   [[SELF:%.*]] = project_box [[BOX_LIFETIME]]
        // CHECK:   [[UNWRAP:%.*]] = moveonlywrapper_to_copyable_addr [[SELF]]
        // CHECK:   store %1 to [init] [[UNWRAP]]

        // CHECK:   [[SELFCAPTURE:%.*]] = copy_value [[BOX_LIFETIME]]
        // CHECK:   [[UNWRAP:%.*]] = moveonlywrapper_to_copyable_box [[SELFCAPTURE]]
        // CHECK:   partial_apply {{.*}} {{%.*}}([[UNWRAP]])
        let r = { self }

        // CHECK:   [[OCOPY:%.*]] = copy_value %0
        // CHECK:   [[SELFACCESS:%.*]] = begin_access [modify] [unknown] [[SELF]]
        // CHECK:   [[MARK:%.*]] = mark_unresolved_non_copyable_value [assignable_but_not_consumable] [[SELFACCESS]]
        // CHECK:   [[UNWRAP:%.*]] = moveonlywrapper_to_copyable_addr [[MARK]]
        // CHECK:   assign [[OCOPY]] to [[UNWRAP]]
        self = other

        // CHECK:   [[SELFACCESS:%.*]] = begin_access [read] [unknown] [[SELF]]
        // CHECK:   [[MARK:%.*]] = mark_unresolved_non_copyable_value [no_consume_or_assign] [[SELFACCESS]]
        // CHECK:   [[SELFVAL:%.*]] = load [copy] [[MARK]]
        // CHECK:   [[BORROW:%.*]] = begin_borrow [[SELFVAL]]
        // CHECK:   [[UNWRAP:%.*]] = moveonlywrapper_to_copyable [guaranteed] [[BORROW]]
        // CHECK:   apply {{%.*}}([[UNWRAP]]

        self.bar()

        return r
    }
}