|
| 1 | +// RUN: %target-swift-emit-silgen -module-name implicit_property_initializers -Xllvm -sil-full-demangle -enable-testing %s | %FileCheck %s |
| 2 | + |
| 3 | +// CHECK: struct HasDefaultTupleOfNils { |
| 4 | +// CHECK: @_hasStorage @_hasInitialValue var x: (Int?, Int?) |
| 5 | +// CHECK: @_hasStorage @_hasInitialValue var y: Int? |
| 6 | +// CHECK: @_hasStorage var z: Int |
| 7 | +// CHECK: @_hasStorage @_hasInitialValue var w: ((Int?, (), Int?), (Int?, Int?)) |
| 8 | +// CHECK: init(x: (Int?, Int?) = (nil, nil), |
| 9 | +// CHECK-SAME: y: Int? = nil, |
| 10 | +// CHECK-SAME: z: Int, |
| 11 | +// CHECK-SAME: w: ((Int?, (), Int?), (Int?, Int?)) = ((nil, (), nil), (nil, nil))) |
| 12 | +// CHECK: } |
| 13 | +struct HasDefaultTupleOfNils { |
| 14 | + var x: (Int?, Int?) |
| 15 | + var y: Int? |
| 16 | + var z: Int |
| 17 | + var w: ((Int?, (), Int?), (Int?, Int?)) |
| 18 | +} |
| 19 | + |
| 20 | +// The default value initializer for 'x' should have type (Optional<Int>, Optional<Int>) |
| 21 | + |
| 22 | +// CHECK: sil [transparent] [ossa] @$[[X_VALUE_INIT:s30implicit_property_initializers21HasDefaultTupleOfNilsV1xSiSg_AEtvpfi]] : $@convention(thin) () -> (Optional<Int>, Optional<Int>) { |
| 23 | +// CHECK: bb0: |
| 24 | +// CHECK: %0 = enum $Optional<Int>, #Optional.none!enumelt |
| 25 | +// CHECK: %1 = enum $Optional<Int>, #Optional.none!enumelt |
| 26 | +// CHECK: %2 = tuple (%0 : $Optional<Int>, %1 : $Optional<Int>) |
| 27 | +// CHECK: return %2 : $(Optional<Int>, Optional<Int>) |
| 28 | +// CHECK: } |
| 29 | + |
| 30 | +// The default value initializer for 'y' should have type Optional<Int> |
| 31 | + |
| 32 | +//CHECK: sil [transparent] [ossa] @$s30implicit_property_initializers21HasDefaultTupleOfNilsV1ySiSgvpfi : $@convention(thin) () -> Optional<Int> { |
| 33 | +//CHECK: bb0: |
| 34 | +//CHECK: %0 = enum $Optional<Int>, #Optional.none!enumelt // user: %1 |
| 35 | +//CHECK: return %0 : $Optional<Int> // id: %1 |
| 36 | +//CHECK: } |
| 37 | + |
| 38 | +// There should not be a default value initializer for 'z'. |
| 39 | + |
| 40 | +// CHECK-NOT: @$s30implicit_property_initializers21HasDefaultTupleOfNilsV1zSivpfi |
| 41 | + |
| 42 | +// The default value initializer for 'w' should flatten to type (Optional<Int>, Optional<Int>, Optional<Int>, Optional<Int>) |
| 43 | + |
| 44 | +//CHECK: sil [transparent] [ossa] @$[[W_VALUE_INIT:s30implicit_property_initializers21HasDefaultTupleOfNilsV1wSiSg_ytAEt_AE_AEttvpfi]] : $@convention(thin) () -> (Optional<Int>, Optional<Int>, Optional<Int>, Optional<Int>) { |
| 45 | +//CHECK: bb0: |
| 46 | +//CHECK: %0 = enum $Optional<Int>, #Optional.none!enumelt // user: %4 |
| 47 | +//CHECK: %1 = enum $Optional<Int>, #Optional.none!enumelt // user: %4 |
| 48 | +//CHECK: %2 = enum $Optional<Int>, #Optional.none!enumelt // user: %4 |
| 49 | +//CHECK: %3 = enum $Optional<Int>, #Optional.none!enumelt // user: %4 |
| 50 | +//CHECK: %4 = tuple (%0 : $Optional<Int>, %1 : $Optional<Int>, %2 : $Optional<Int>, %3 : $Optional<Int>) // user: %5 |
| 51 | +//CHECK: return %4 : $(Optional<Int>, Optional<Int>, Optional<Int>, Optional<Int>) // id: %5 |
| 52 | +//CHECK: } |
| 53 | + |
| 54 | +// The default arg generator for 'x' inside the memberwise init should have type (Optional<Int>, Optional<Int>) |
| 55 | + |
| 56 | +// CHECK: sil [ossa] @$s30implicit_property_initializers21HasDefaultTupleOfNilsV1x1y1z1wACSiSg_AHt_AHSiAH_ytAHt_AH_AHtttcfcfA_ : $@convention(thin) () -> (Optional<Int>, Optional<Int>) { |
| 57 | +// CHECK: bb0: |
| 58 | +// CHECK: %0 = function_ref @$[[X_VALUE_INIT]] : $@convention(thin) () -> (Optional<Int>, Optional<Int>) // user: %1 |
| 59 | +// CHECK: %1 = apply %0() : $@convention(thin) () -> (Optional<Int>, Optional<Int>) |
| 60 | +// CHECK: (%2, %3) = destructure_tuple %1 : $(Optional<Int>, Optional<Int>) |
| 61 | +// CHECK: %4 = tuple (%2 : $Optional<Int>, %3 : $Optional<Int>) |
| 62 | +// CHECK: return %4 : $(Optional<Int>, Optional<Int>) |
| 63 | +// CHECK: } |
| 64 | + |
| 65 | +// There should not be a default arg generator for 'y' because it's just a nil literal and clients construct it directly. |
| 66 | + |
| 67 | +// CHECK-NOT: @$s30implicit_property_initializers21HasDefaultTupleOfNilsV1x1y1z1wACSiSg_AHt_AHSiAH_ytAHt_AH_AHtttcfcfA0_ |
| 68 | + |
| 69 | +// There should not be a default arg generator for 'z' |
| 70 | + |
| 71 | +// CHECK-NOT: @$s30implicit_property_initializers21HasDefaultTupleOfNilsV1x1y1z1wACSiSg_AHt_AHSiAH_ytAHt_AH_AHtttcfcfA1_ |
| 72 | + |
| 73 | +// The default arg generator for 'w' should flatten to type (Optional<Int>, Optional<Int>, Optional<Int>, Optional<Int>) |
| 74 | + |
| 75 | +// CHECK: sil [ossa] @$s30implicit_property_initializers21HasDefaultTupleOfNilsV1x1y1z1wACSiSg_AHt_AHSiAH_ytAHt_AH_AHtttcfcfA2_ : $@convention(thin) () -> (Optional<Int>, Optional<Int>, Optional<Int>, Optional<Int>) { |
| 76 | +// CHECK: bb0: |
| 77 | +// CHECK: %0 = function_ref @$[[W_VALUE_INIT]] : $@convention(thin) () -> (Optional<Int>, Optional<Int>, Optional<Int>, Optional<Int>) |
| 78 | +// CHECK: %1 = apply %0() : $@convention(thin) () -> (Optional<Int>, Optional<Int>, Optional<Int>, Optional<Int>) |
| 79 | +// CHECK: (%2, %3, %4, %5) = destructure_tuple %1 : $(Optional<Int>, Optional<Int>, Optional<Int>, Optional<Int>) |
| 80 | +// CHECK: %6 = tuple (%2 : $Optional<Int>, %3 : $Optional<Int>, %4 : $Optional<Int>, %5 : $Optional<Int>) |
| 81 | +// CHECK: return %6 : $(Optional<Int>, Optional<Int>, Optional<Int>, Optional<Int>) |
| 82 | +// CHECK: } |
0 commit comments