File: switch_resilience.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 (52 lines) | stat: -rw-r--r-- 1,794 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
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module -enable-library-evolution -emit-module-path=%t/resilient_struct.swiftmodule %S/../Inputs/resilient_struct.swift
// RUN: %target-swift-emit-silgen -I %t %s | %FileCheck %s

import resilient_struct

// CHECK-LABEL: sil hidden [ossa] @$s17switch_resilience29resilientTupleEltCaseEnumTestyyF : $@convention(thin) () -> () {
// CHECK: bb0:
// CHECK:   [[STACK_SLOT:%.*]] = alloc_stack $Enum
//
// CHECK: bb1:
// CHECK:   [[VALUE:%.*]] = unchecked_take_enum_data_addr [[STACK_SLOT]] : $*Enum
// CHECK:   [[STACK_SLOT_COPY:%.*]] = alloc_stack [lexical] [var_decl] $(url: ResilientRef, void: ()), let, name "value"
// CHECK:   copy_addr [[VALUE]] to [init] [[STACK_SLOT_COPY]]
// CHECK:   cond_br {{%.*}}, bb2, bb3
//
// CHECK: bb2:
// CHECK: destroy_addr [[STACK_SLOT_COPY]]
// CHECK-NEXT: dealloc_stack [[STACK_SLOT_COPY]]
// CHECK-NEXT: destroy_addr [[VALUE]]
// CHECK-NEXT: dealloc_stack [[STACK_SLOT]]
// CHECK-NEXT: br bb4
//
// CHECK: bb3:
// CHECK-NEXT: destroy_addr [[STACK_SLOT_COPY]]
// CHECK-NEXT: dealloc_stack [[STACK_SLOT_COPY]]
// CHECK-NEXT: [[REPROJECT:%.*]] = tuple_element_addr [[VALUE]]
// CHECK: destroy_addr [[REPROJECT]]
// CHECK-NEXT: dealloc_stack [[STACK_SLOT]]
// CHECK: br bb4
//
// CHECK: } // end sil function '$s17switch_resilience29resilientTupleEltCaseEnumTestyyF'
func resilientTupleEltCaseEnumTest() {
  enum Enum {
  case first(url: ResilientRef, void: Void)
  }

  func getEnum() -> Enum {
    let url = ResilientRef(r: Referent())
    return .first(url: url, void: ())
  }
  func getBool() -> Bool { return false }
  func urlUser(_ u: ResilientRef) {}
  func kraken() {}

  switch getEnum() {
  case let .first(value) where getBool():
    urlUser(value.0)
  case .first:
    kraken()
  }
}