reorder_fields.carbon 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // AUTOUPDATE
  6. // TIP: To test this file alone, run:
  7. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/struct/reorder_fields.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/struct/reorder_fields.carbon
  10. fn MakeI32() -> i32;
  11. fn MakeF64() -> f64;
  12. fn F() -> {.a: i32, .b: f64} {
  13. let x: {.a: i32, .b: f64} = {.b = MakeF64(), .a = MakeI32()};
  14. let y: {.b: f64, .a: i32} = x;
  15. return y;
  16. }
  17. // CHECK:STDOUT: --- reorder_fields.carbon
  18. // CHECK:STDOUT:
  19. // CHECK:STDOUT: constants {
  20. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  21. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  22. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  23. // CHECK:STDOUT: %MakeI32.type: type = fn_type @MakeI32 [template]
  24. // CHECK:STDOUT: %MakeI32: %MakeI32.type = struct_value () [template]
  25. // CHECK:STDOUT: %.2: i32 = int_literal 64 [template]
  26. // CHECK:STDOUT: %Float.type: type = fn_type @Float [template]
  27. // CHECK:STDOUT: %Float: %Float.type = struct_value () [template]
  28. // CHECK:STDOUT: %MakeF64.type: type = fn_type @MakeF64 [template]
  29. // CHECK:STDOUT: %MakeF64: %MakeF64.type = struct_value () [template]
  30. // CHECK:STDOUT: %.3: type = struct_type {.a: i32, .b: f64} [template]
  31. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  32. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  33. // CHECK:STDOUT: %.4: type = ptr_type %.3 [template]
  34. // CHECK:STDOUT: %.5: type = struct_type {.b: f64, .a: i32} [template]
  35. // CHECK:STDOUT: %.6: type = ptr_type %.5 [template]
  36. // CHECK:STDOUT: }
  37. // CHECK:STDOUT:
  38. // CHECK:STDOUT: imports {
  39. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  40. // CHECK:STDOUT: .Int32 = %import_ref.1
  41. // CHECK:STDOUT: .Float = %import_ref.2
  42. // CHECK:STDOUT: import Core//prelude
  43. // CHECK:STDOUT: import Core//prelude/operators
  44. // CHECK:STDOUT: import Core//prelude/types
  45. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  46. // CHECK:STDOUT: import Core//prelude/operators/as
  47. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  48. // CHECK:STDOUT: import Core//prelude/operators/comparison
  49. // CHECK:STDOUT: import Core//prelude/types/bool
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  52. // CHECK:STDOUT: %import_ref.2: %Float.type = import_ref Core//prelude/types, inst+35, loaded [template = constants.%Float]
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: file {
  56. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  57. // CHECK:STDOUT: .Core = imports.%Core
  58. // CHECK:STDOUT: .MakeI32 = %MakeI32.decl
  59. // CHECK:STDOUT: .MakeF64 = %MakeF64.decl
  60. // CHECK:STDOUT: .F = %F.decl
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT: %Core.import = import Core
  63. // CHECK:STDOUT: %MakeI32.decl: %MakeI32.type = fn_decl @MakeI32 [template = constants.%MakeI32] {} {
  64. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  65. // CHECK:STDOUT: %.loc11_17.1: type = value_of_initializer %int.make_type_32 [template = i32]
  66. // CHECK:STDOUT: %.loc11_17.2: type = converted %int.make_type_32, %.loc11_17.1 [template = i32]
  67. // CHECK:STDOUT: %return: ref i32 = var <return slot>
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT: %MakeF64.decl: %MakeF64.type = fn_decl @MakeF64 [template = constants.%MakeF64] {} {
  70. // CHECK:STDOUT: %.loc12_17.1: i32 = int_literal 64 [template = constants.%.2]
  71. // CHECK:STDOUT: %float.make_type: init type = call constants.%Float(%.loc12_17.1) [template = f64]
  72. // CHECK:STDOUT: %.loc12_17.2: type = value_of_initializer %float.make_type [template = f64]
  73. // CHECK:STDOUT: %.loc12_17.3: type = converted %float.make_type, %.loc12_17.2 [template = f64]
  74. // CHECK:STDOUT: %return: ref f64 = var <return slot>
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {} {
  77. // CHECK:STDOUT: %int.make_type_32.loc14: init type = call constants.%Int32() [template = i32]
  78. // CHECK:STDOUT: %.loc14_16.1: type = value_of_initializer %int.make_type_32.loc14 [template = i32]
  79. // CHECK:STDOUT: %.loc14_16.2: type = converted %int.make_type_32.loc14, %.loc14_16.1 [template = i32]
  80. // CHECK:STDOUT: %.loc14_25.1: i32 = int_literal 64 [template = constants.%.2]
  81. // CHECK:STDOUT: %float.make_type.loc14: init type = call constants.%Float(%.loc14_25.1) [template = f64]
  82. // CHECK:STDOUT: %.loc14_25.2: type = value_of_initializer %float.make_type.loc14 [template = f64]
  83. // CHECK:STDOUT: %.loc14_25.3: type = converted %float.make_type.loc14, %.loc14_25.2 [template = f64]
  84. // CHECK:STDOUT: %.loc14_28: type = struct_type {.a: i32, .b: f64} [template = constants.%.3]
  85. // CHECK:STDOUT: %return: ref %.3 = var <return slot>
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT:
  89. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: fn @MakeI32() -> i32;
  92. // CHECK:STDOUT:
  93. // CHECK:STDOUT: fn @Float(%size: i32) -> type = "float.make_type";
  94. // CHECK:STDOUT:
  95. // CHECK:STDOUT: fn @MakeF64() -> f64;
  96. // CHECK:STDOUT:
  97. // CHECK:STDOUT: fn @F() -> %return: %.3 {
  98. // CHECK:STDOUT: !entry:
  99. // CHECK:STDOUT: %int.make_type_32.loc15: init type = call constants.%Int32() [template = i32]
  100. // CHECK:STDOUT: %.loc15_15.1: type = value_of_initializer %int.make_type_32.loc15 [template = i32]
  101. // CHECK:STDOUT: %.loc15_15.2: type = converted %int.make_type_32.loc15, %.loc15_15.1 [template = i32]
  102. // CHECK:STDOUT: %.loc15_24.1: i32 = int_literal 64 [template = constants.%.2]
  103. // CHECK:STDOUT: %float.make_type.loc15: init type = call constants.%Float(%.loc15_24.1) [template = f64]
  104. // CHECK:STDOUT: %.loc15_24.2: type = value_of_initializer %float.make_type.loc15 [template = f64]
  105. // CHECK:STDOUT: %.loc15_24.3: type = converted %float.make_type.loc15, %.loc15_24.2 [template = f64]
  106. // CHECK:STDOUT: %.loc15_27: type = struct_type {.a: i32, .b: f64} [template = constants.%.3]
  107. // CHECK:STDOUT: %MakeF64.ref: %MakeF64.type = name_ref MakeF64, file.%MakeF64.decl [template = constants.%MakeF64]
  108. // CHECK:STDOUT: %MakeF64.call: init f64 = call %MakeF64.ref()
  109. // CHECK:STDOUT: %MakeI32.ref: %MakeI32.type = name_ref MakeI32, file.%MakeI32.decl [template = constants.%MakeI32]
  110. // CHECK:STDOUT: %MakeI32.call: init i32 = call %MakeI32.ref()
  111. // CHECK:STDOUT: %.loc15_62.1: %.5 = struct_literal (%MakeF64.call, %MakeI32.call)
  112. // CHECK:STDOUT: %.loc15_62.2: i32 = value_of_initializer %MakeI32.call
  113. // CHECK:STDOUT: %.loc15_62.3: i32 = converted %MakeI32.call, %.loc15_62.2
  114. // CHECK:STDOUT: %.loc15_62.4: f64 = value_of_initializer %MakeF64.call
  115. // CHECK:STDOUT: %.loc15_62.5: f64 = converted %MakeF64.call, %.loc15_62.4
  116. // CHECK:STDOUT: %struct.loc15: %.3 = struct_value (%.loc15_62.3, %.loc15_62.5)
  117. // CHECK:STDOUT: %.loc15_63: %.3 = converted %.loc15_62.1, %struct.loc15
  118. // CHECK:STDOUT: %x: %.3 = bind_name x, %.loc15_63
  119. // CHECK:STDOUT: %.loc16_15.1: i32 = int_literal 64 [template = constants.%.2]
  120. // CHECK:STDOUT: %float.make_type.loc16: init type = call constants.%Float(%.loc16_15.1) [template = f64]
  121. // CHECK:STDOUT: %.loc16_15.2: type = value_of_initializer %float.make_type.loc16 [template = f64]
  122. // CHECK:STDOUT: %.loc16_15.3: type = converted %float.make_type.loc16, %.loc16_15.2 [template = f64]
  123. // CHECK:STDOUT: %int.make_type_32.loc16: init type = call constants.%Int32() [template = i32]
  124. // CHECK:STDOUT: %.loc16_24.1: type = value_of_initializer %int.make_type_32.loc16 [template = i32]
  125. // CHECK:STDOUT: %.loc16_24.2: type = converted %int.make_type_32.loc16, %.loc16_24.1 [template = i32]
  126. // CHECK:STDOUT: %.loc16_27: type = struct_type {.b: f64, .a: i32} [template = constants.%.5]
  127. // CHECK:STDOUT: %x.ref: %.3 = name_ref x, %x
  128. // CHECK:STDOUT: %.loc16_31.1: f64 = struct_access %x.ref, element1
  129. // CHECK:STDOUT: %.loc16_31.2: i32 = struct_access %x.ref, element0
  130. // CHECK:STDOUT: %struct.loc16: %.5 = struct_value (%.loc16_31.1, %.loc16_31.2)
  131. // CHECK:STDOUT: %.loc16_32: %.5 = converted %x.ref, %struct.loc16
  132. // CHECK:STDOUT: %y: %.5 = bind_name y, %.loc16_32
  133. // CHECK:STDOUT: %y.ref: %.5 = name_ref y, %y
  134. // CHECK:STDOUT: %.loc17_10.1: i32 = struct_access %y.ref, element1
  135. // CHECK:STDOUT: %.loc17_10.2: ref i32 = struct_access %return, element1
  136. // CHECK:STDOUT: %.loc17_10.3: init i32 = initialize_from %.loc17_10.1 to %.loc17_10.2
  137. // CHECK:STDOUT: %.loc17_10.4: f64 = struct_access %y.ref, element0
  138. // CHECK:STDOUT: %.loc17_10.5: ref f64 = struct_access %return, element0
  139. // CHECK:STDOUT: %.loc17_10.6: init f64 = initialize_from %.loc17_10.4 to %.loc17_10.5
  140. // CHECK:STDOUT: %.loc17_10.7: init %.3 = struct_init (%.loc17_10.3, %.loc17_10.6) to %return
  141. // CHECK:STDOUT: %.loc17_11: init %.3 = converted %y.ref, %.loc17_10.7
  142. // CHECK:STDOUT: return %.loc17_11 to %return
  143. // CHECK:STDOUT: }
  144. // CHECK:STDOUT: