File: implicit_property_initializers.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 (82 lines) | stat: -rw-r--r-- 4,788 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
// RUN: %target-swift-emit-silgen -module-name implicit_property_initializers -Xllvm -sil-full-demangle -enable-testing %s | %FileCheck %s

// CHECK: struct HasDefaultTupleOfNils {
// CHECK:   @_hasStorage @_hasInitialValue var x: (Int?, Int?)
// CHECK:   @_hasStorage @_hasInitialValue var y: Int?
// CHECK:   @_hasStorage var z: Int
// CHECK:   @_hasStorage @_hasInitialValue var w: ((Int?, (), Int?), (Int?, Int?))
// CHECK:   init(x: (Int?, Int?) = (nil, nil),
// CHECK-SAME:   y: Int? = nil,
// CHECK-SAME:   z: Int,
// CHECK-SAME:   w: ((Int?, (), Int?), (Int?, Int?)) = ((nil, (), nil), (nil, nil)))
// CHECK: }
struct HasDefaultTupleOfNils {
  var x: (Int?, Int?)
  var y: Int?
  var z: Int
  var w: ((Int?, (), Int?), (Int?, Int?))
}

// The default value initializer for 'x' should have type (Optional<Int>, Optional<Int>)

// CHECK: sil [transparent] [ossa] @$[[X_VALUE_INIT:s30implicit_property_initializers21HasDefaultTupleOfNilsV1xSiSg_AEtvpfi]] : $@convention(thin) () -> (Optional<Int>, Optional<Int>) {
// CHECK: bb0:
// CHECK:   %0 = enum $Optional<Int>, #Optional.none!enumelt
// CHECK:   %1 = enum $Optional<Int>, #Optional.none!enumelt
// CHECK:   %2 = tuple (%0 : $Optional<Int>, %1 : $Optional<Int>)
// CHECK:   return %2 : $(Optional<Int>, Optional<Int>)
// CHECK: }

// The default value initializer for 'y' should have type Optional<Int>

//CHECK: sil [transparent] [ossa] @$s30implicit_property_initializers21HasDefaultTupleOfNilsV1ySiSgvpfi : $@convention(thin) () -> Optional<Int> {
//CHECK: bb0:
//CHECK:   %0 = enum $Optional<Int>, #Optional.none!enumelt // user: %1
//CHECK:   return %0 : $Optional<Int>                      // id: %1
//CHECK: }

// There should not be a default value initializer for 'z'.

// CHECK-NOT: @$s30implicit_property_initializers21HasDefaultTupleOfNilsV1zSivpfi

// The default value initializer for 'w' should flatten to type (Optional<Int>, Optional<Int>, Optional<Int>, Optional<Int>)

//CHECK: sil [transparent] [ossa] @$[[W_VALUE_INIT:s30implicit_property_initializers21HasDefaultTupleOfNilsV1wSiSg_ytAEt_AE_AEttvpfi]] : $@convention(thin) () -> (Optional<Int>, Optional<Int>, Optional<Int>, Optional<Int>) {
//CHECK: bb0:
//CHECK:   %0 = enum $Optional<Int>, #Optional.none!enumelt // user: %4
//CHECK:   %1 = enum $Optional<Int>, #Optional.none!enumelt // user: %4
//CHECK:   %2 = enum $Optional<Int>, #Optional.none!enumelt // user: %4
//CHECK:   %3 = enum $Optional<Int>, #Optional.none!enumelt // user: %4
//CHECK:   %4 = tuple (%0 : $Optional<Int>, %1 : $Optional<Int>, %2 : $Optional<Int>, %3 : $Optional<Int>) // user: %5
//CHECK:   return %4 : $(Optional<Int>, Optional<Int>, Optional<Int>, Optional<Int>) // id: %5
//CHECK: }

// The default arg generator for 'x' inside the memberwise init should have type (Optional<Int>, Optional<Int>)

// CHECK: sil [ossa] @$s30implicit_property_initializers21HasDefaultTupleOfNilsV1x1y1z1wACSiSg_AHt_AHSiAH_ytAHt_AH_AHtttcfcfA_ : $@convention(thin) () -> (Optional<Int>, Optional<Int>) {
// CHECK: bb0:
// CHECK:   %0 = function_ref @$[[X_VALUE_INIT]] : $@convention(thin) () -> (Optional<Int>, Optional<Int>) // user: %1
// CHECK:   %1 = apply %0() : $@convention(thin) () -> (Optional<Int>, Optional<Int>)
// CHECK:   (%2, %3) = destructure_tuple %1 : $(Optional<Int>, Optional<Int>)
// CHECK:   %4 = tuple (%2 : $Optional<Int>, %3 : $Optional<Int>)
// CHECK:   return %4 : $(Optional<Int>, Optional<Int>)
// CHECK: }

// There should not be a default arg generator for 'y' because it's just a nil literal and clients construct it directly.

// CHECK-NOT: @$s30implicit_property_initializers21HasDefaultTupleOfNilsV1x1y1z1wACSiSg_AHt_AHSiAH_ytAHt_AH_AHtttcfcfA0_

// There should not be a default arg generator for 'z'

// CHECK-NOT: @$s30implicit_property_initializers21HasDefaultTupleOfNilsV1x1y1z1wACSiSg_AHt_AHSiAH_ytAHt_AH_AHtttcfcfA1_

// The default arg generator for 'w' should flatten to type (Optional<Int>, Optional<Int>, Optional<Int>, Optional<Int>)

// CHECK: sil [ossa] @$s30implicit_property_initializers21HasDefaultTupleOfNilsV1x1y1z1wACSiSg_AHt_AHSiAH_ytAHt_AH_AHtttcfcfA2_ : $@convention(thin) () -> (Optional<Int>, Optional<Int>, Optional<Int>, Optional<Int>) {
// CHECK: bb0:
// CHECK:   %0 = function_ref @$[[W_VALUE_INIT]] : $@convention(thin) () -> (Optional<Int>, Optional<Int>, Optional<Int>, Optional<Int>)
// CHECK:   %1 = apply %0() : $@convention(thin) () -> (Optional<Int>, Optional<Int>, Optional<Int>, Optional<Int>)
// CHECK:   (%2, %3, %4, %5) = destructure_tuple %1 : $(Optional<Int>, Optional<Int>, Optional<Int>, Optional<Int>)
// CHECK:   %6 = tuple (%2 : $Optional<Int>, %3 : $Optional<Int>, %4 : $Optional<Int>, %5 : $Optional<Int>)
// CHECK:   return %6 : $(Optional<Int>, Optional<Int>, Optional<Int>, Optional<Int>)
// CHECK: }