File: inout_reabstracted_closure_literal.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 (66 lines) | stat: -rw-r--r-- 2,986 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
// RUN: %target-swift-emit-silgen %s

func bar<T>(f: (inout T) throws -> Void) {}

func condition() -> Bool { fatalError() }
func error() -> Error { fatalError() }

func foo(x: @escaping () -> Void) {
    // CHECK-LABEL: sil private [ossa] @${{.*}}3foo{{.*}}U_ :
    // CHECK:       bb0(
    // CHECK-SAME:    [[ARG:%.*]] = $*@callee_guaranteed @substituted <τ_0_0> () -> @out τ_0_0 for <()>,
    // CHECK-SAME:    [[CAPTURE:%.*]] = @closureCapture @guaranteed $@callee_guaranteed () -> ()

    // Reabstract the initial value of the inout parameter
    // CHECK:         [[INITIAL:%.*]] = load [take] [[ARG]]
    // CHECK:         [[INITIAL_CONV:%.*]] = convert_function [[INITIAL]]
    // CHECK:         [[THUNK:%.*]] = function_ref @{{.*}}_TR
    // CHECK:         [[INITIAL_REAB:%.*]] = partial_apply [callee_guaranteed] [[THUNK]]([[INITIAL_CONV]])
    // CHECK:         [[REAB_ARG:%.*]] = alloc_stack
    // CHECK:         store [[INITIAL_REAB]] to [[REAB_ARG]]
    bar {
        // Read from the reabstracted buffer
        //  CHECK: [[ACCESS:%.*]] = begin_access [read] [unknown] [[REAB_ARG]]
        //  CHECK: [[COPY]] = load [copy] [[ACCESS]]
        _ = $0 as () -> Void

        // Assign to the reabstracted buffer
        $0 = x

        // Writeback occurs no matter how we exit the function
        // CHECK:   cond_br {{%.*}}, [[THEN1:bb[0-9]+]], [[ELSE1:bb[0-9]+]]
        if condition() {
            // Throwing:
            // CHECK: [[THEN1]]:
            // Take final reabstracted value from the reabstracted buffer
            // CHECK:   [[FINAL_REAB:%.*]] = load [take] [[REAB_ARG]]
            // Reabstract back to original representation and store back to
            // original buffer
            // CHECK:   [[THUNK_ORIG:%.*]] = function_ref @{{.*}}_TR
            // CHECK:   [[FINAL_CONV:%.*]] = partial_apply [callee_guaranteed] [[THUNK_ORIG]]([[FINAL_REAB]])
            // CHECK:   [[FINAL:%.*]] = convert_function [[FINAL_CONV]]
            // CHECK:   store [[FINAL]] to [[ARG]]
            // CHECK:   throw
            throw error()
        // CHECK: [[ELSE1]]:
        // CHECK:   cond_br {{%.*}}, [[THEN2:bb[0-9]+]], [[ELSE2:bb[0-9]+]]
        } else if condition() {
            // Explicit return
            // CHECK: [[THEN1]]:
            // CHECK:   br [[EPILOG:bb[0-9]+]]
            return
        } else {
            // Fall through
        }
        // CHECK: [[EPILOG]]:
        // Take final reabstracted value from the reabstracted buffer
        // CHECK:   [[FINAL_REAB:%.*]] = load [take] [[REAB_ARG]]
        // Reabstract back to original representation and store back to
        // original buffer
        // CHECK:   [[THUNK_ORIG:%.*]] = function_ref @{{.*}}_TR
        // CHECK:   [[FINAL_CONV:%.*]] = partial_apply [callee_guaranteed] [[THUNK_ORIG]]([[FINAL_REAB]])
        // CHECK:   [[FINAL:%.*]] = convert_function [[FINAL_CONV]]
        // CHECK:   store [[FINAL]] to [[ARG]]
        // CHECK:   return
    }
}