aggregate.carbon 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. var tuple_copy: (i32, i32) = (1, 2) as (i32, i32);
  7. var struct_copy: {.a: i32, .b: i32, .c: i32} = {.c = 3, .b = 2, .a = 1} as {.b: i32, .a: i32, .c: i32};
  8. var tuple_index: [i32; 1] = (0,) as [i32; (5, 7, 1, 9)[2]];
  9. var struct_access: [i32; 1] = (0,) as [i32; {.a = 3, .b = 1}.b];
  10. // CHECK:STDOUT: --- aggregate.carbon
  11. // CHECK:STDOUT:
  12. // CHECK:STDOUT: constants {
  13. // CHECK:STDOUT: %.1: type = tuple_type (type, type) [template]
  14. // CHECK:STDOUT: %.2: type = tuple_type (i32, i32) [template]
  15. // CHECK:STDOUT: %.3: type = ptr_type (i32, i32) [template]
  16. // CHECK:STDOUT: %.4: i32 = int_literal 1 [template]
  17. // CHECK:STDOUT: %.5: i32 = int_literal 2 [template]
  18. // CHECK:STDOUT: %.6: (i32, i32) = tuple_value (%.4, %.5) [template]
  19. // CHECK:STDOUT: %.7: type = struct_type {.a: i32, .b: i32, .c: i32} [template]
  20. // CHECK:STDOUT: %.8: type = ptr_type {.a: i32, .b: i32, .c: i32} [template]
  21. // CHECK:STDOUT: %.9: i32 = int_literal 3 [template]
  22. // CHECK:STDOUT: %.10: type = struct_type {.c: i32, .b: i32, .a: i32} [template]
  23. // CHECK:STDOUT: %.11: type = struct_type {.b: i32, .a: i32, .c: i32} [template]
  24. // CHECK:STDOUT: %.12: type = ptr_type {.b: i32, .a: i32, .c: i32} [template]
  25. // CHECK:STDOUT: %.13: {.b: i32, .a: i32, .c: i32} = struct_value (%.5, %.4, %.9) [template]
  26. // CHECK:STDOUT: %.14: {.a: i32, .b: i32, .c: i32} = struct_value (%.4, %.5, %.9) [template]
  27. // CHECK:STDOUT: %.15: type = array_type %.4, i32 [template]
  28. // CHECK:STDOUT: %.16: type = ptr_type [i32; 1] [template]
  29. // CHECK:STDOUT: %.17: i32 = int_literal 0 [template]
  30. // CHECK:STDOUT: %.18: type = tuple_type (i32) [template]
  31. // CHECK:STDOUT: %.19: i32 = int_literal 5 [template]
  32. // CHECK:STDOUT: %.20: i32 = int_literal 7 [template]
  33. // CHECK:STDOUT: %.21: i32 = int_literal 9 [template]
  34. // CHECK:STDOUT: %.22: type = tuple_type (i32, i32, i32, i32) [template]
  35. // CHECK:STDOUT: %.23: type = ptr_type (i32, i32, i32, i32) [template]
  36. // CHECK:STDOUT: %.24: (i32, i32, i32, i32) = tuple_value (%.19, %.20, %.4, %.21) [template]
  37. // CHECK:STDOUT: %.25: [i32; 1] = tuple_value (%.17) [template]
  38. // CHECK:STDOUT: %.26: type = struct_type {.a: i32, .b: i32} [template]
  39. // CHECK:STDOUT: %.27: type = ptr_type {.a: i32, .b: i32} [template]
  40. // CHECK:STDOUT: %.28: {.a: i32, .b: i32} = struct_value (%.9, %.4) [template]
  41. // CHECK:STDOUT: }
  42. // CHECK:STDOUT:
  43. // CHECK:STDOUT: file {
  44. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  45. // CHECK:STDOUT: .tuple_copy = %tuple_copy
  46. // CHECK:STDOUT: .struct_copy = %struct_copy
  47. // CHECK:STDOUT: .tuple_index = %tuple_index
  48. // CHECK:STDOUT: .struct_access = %struct_access
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT: %.loc7_26.1: (type, type) = tuple_literal (i32, i32)
  51. // CHECK:STDOUT: %.loc7_26.2: type = converted %.loc7_26.1, constants.%.2 [template = constants.%.2]
  52. // CHECK:STDOUT: %tuple_copy.var: ref (i32, i32) = var tuple_copy
  53. // CHECK:STDOUT: %tuple_copy: ref (i32, i32) = bind_name tuple_copy, %tuple_copy.var
  54. // CHECK:STDOUT: %.loc9: type = struct_type {.a: i32, .b: i32, .c: i32} [template = constants.%.7]
  55. // CHECK:STDOUT: %struct_copy.var: ref {.a: i32, .b: i32, .c: i32} = var struct_copy
  56. // CHECK:STDOUT: %struct_copy: ref {.a: i32, .b: i32, .c: i32} = bind_name struct_copy, %struct_copy.var
  57. // CHECK:STDOUT: %.loc11_24: i32 = int_literal 1 [template = constants.%.4]
  58. // CHECK:STDOUT: %.loc11_25: type = array_type %.loc11_24, i32 [template = constants.%.15]
  59. // CHECK:STDOUT: %tuple_index.var: ref [i32; 1] = var tuple_index
  60. // CHECK:STDOUT: %tuple_index: ref [i32; 1] = bind_name tuple_index, %tuple_index.var
  61. // CHECK:STDOUT: %.loc13_26: i32 = int_literal 1 [template = constants.%.4]
  62. // CHECK:STDOUT: %.loc13_27: type = array_type %.loc13_26, i32 [template = constants.%.15]
  63. // CHECK:STDOUT: %struct_access.var: ref [i32; 1] = var struct_access
  64. // CHECK:STDOUT: %struct_access: ref [i32; 1] = bind_name struct_access, %struct_access.var
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT:
  67. // CHECK:STDOUT: fn @__global_init() {
  68. // CHECK:STDOUT: !entry:
  69. // CHECK:STDOUT: %.loc7_31: i32 = int_literal 1 [template = constants.%.4]
  70. // CHECK:STDOUT: %.loc7_34: i32 = int_literal 2 [template = constants.%.5]
  71. // CHECK:STDOUT: %.loc7_35.1: (i32, i32) = tuple_literal (%.loc7_31, %.loc7_34)
  72. // CHECK:STDOUT: %.loc7_49.1: (type, type) = tuple_literal (i32, i32)
  73. // CHECK:STDOUT: %.loc7_49.2: type = converted %.loc7_49.1, constants.%.2 [template = constants.%.2]
  74. // CHECK:STDOUT: %.loc7_35.2: ref i32 = tuple_access file.%tuple_copy.var, element0
  75. // CHECK:STDOUT: %.loc7_35.3: init i32 = initialize_from %.loc7_31 to %.loc7_35.2 [template = constants.%.4]
  76. // CHECK:STDOUT: %.loc7_35.4: ref i32 = tuple_access file.%tuple_copy.var, element1
  77. // CHECK:STDOUT: %.loc7_35.5: init i32 = initialize_from %.loc7_34 to %.loc7_35.4 [template = constants.%.5]
  78. // CHECK:STDOUT: %.loc7_35.6: init (i32, i32) = tuple_init (%.loc7_35.3, %.loc7_35.5) to file.%tuple_copy.var [template = constants.%.6]
  79. // CHECK:STDOUT: %.loc7_35.7: init (i32, i32) = converted %.loc7_35.1, %.loc7_35.6 [template = constants.%.6]
  80. // CHECK:STDOUT: assign file.%tuple_copy.var, %.loc7_35.7
  81. // CHECK:STDOUT: %.loc9_54: i32 = int_literal 3 [template = constants.%.9]
  82. // CHECK:STDOUT: %.loc9_62: i32 = int_literal 2 [template = constants.%.5]
  83. // CHECK:STDOUT: %.loc9_70: i32 = int_literal 1 [template = constants.%.4]
  84. // CHECK:STDOUT: %.loc9_71.1: {.c: i32, .b: i32, .a: i32} = struct_literal (%.loc9_54, %.loc9_62, %.loc9_70)
  85. // CHECK:STDOUT: %.loc9_102: type = struct_type {.b: i32, .a: i32, .c: i32} [template = constants.%.11]
  86. // CHECK:STDOUT: %.loc9_71.2: {.b: i32, .a: i32, .c: i32} = struct_value (%.loc9_62, %.loc9_70, %.loc9_54) [template = constants.%.13]
  87. // CHECK:STDOUT: %.loc9_71.3: {.b: i32, .a: i32, .c: i32} = converted %.loc9_71.1, %.loc9_71.2 [template = constants.%.13]
  88. // CHECK:STDOUT: %.loc9_71.4: i32 = struct_access %.loc9_71.3, element1 [template = constants.%.4]
  89. // CHECK:STDOUT: %.loc9_71.5: ref i32 = struct_access file.%struct_copy.var, element1
  90. // CHECK:STDOUT: %.loc9_71.6: init i32 = initialize_from %.loc9_71.4 to %.loc9_71.5 [template = constants.%.4]
  91. // CHECK:STDOUT: %.loc9_71.7: i32 = struct_access %.loc9_71.3, element0 [template = constants.%.5]
  92. // CHECK:STDOUT: %.loc9_71.8: ref i32 = struct_access file.%struct_copy.var, element0
  93. // CHECK:STDOUT: %.loc9_71.9: init i32 = initialize_from %.loc9_71.7 to %.loc9_71.8 [template = constants.%.5]
  94. // CHECK:STDOUT: %.loc9_71.10: i32 = struct_access %.loc9_71.3, element2 [template = constants.%.9]
  95. // CHECK:STDOUT: %.loc9_71.11: ref i32 = struct_access file.%struct_copy.var, element2
  96. // CHECK:STDOUT: %.loc9_71.12: init i32 = initialize_from %.loc9_71.10 to %.loc9_71.11 [template = constants.%.9]
  97. // CHECK:STDOUT: %.loc9_71.13: init {.a: i32, .b: i32, .c: i32} = struct_init (%.loc9_71.6, %.loc9_71.9, %.loc9_71.12) to file.%struct_copy.var [template = constants.%.14]
  98. // CHECK:STDOUT: %.loc9_71.14: init {.a: i32, .b: i32, .c: i32} = converted %.loc9_71.3, %.loc9_71.13 [template = constants.%.14]
  99. // CHECK:STDOUT: assign file.%struct_copy.var, %.loc9_71.14
  100. // CHECK:STDOUT: %.loc11_30: i32 = int_literal 0 [template = constants.%.17]
  101. // CHECK:STDOUT: %.loc11_32.1: (i32,) = tuple_literal (%.loc11_30)
  102. // CHECK:STDOUT: %.loc11_44: i32 = int_literal 5 [template = constants.%.19]
  103. // CHECK:STDOUT: %.loc11_47: i32 = int_literal 7 [template = constants.%.20]
  104. // CHECK:STDOUT: %.loc11_50: i32 = int_literal 1 [template = constants.%.4]
  105. // CHECK:STDOUT: %.loc11_53: i32 = int_literal 9 [template = constants.%.21]
  106. // CHECK:STDOUT: %.loc11_54.1: (i32, i32, i32, i32) = tuple_literal (%.loc11_44, %.loc11_47, %.loc11_50, %.loc11_53)
  107. // CHECK:STDOUT: %.loc11_56: i32 = int_literal 2 [template = constants.%.5]
  108. // CHECK:STDOUT: %.loc11_54.2: (i32, i32, i32, i32) = tuple_value (%.loc11_44, %.loc11_47, %.loc11_50, %.loc11_53) [template = constants.%.24]
  109. // CHECK:STDOUT: %.loc11_54.3: (i32, i32, i32, i32) = converted %.loc11_54.1, %.loc11_54.2 [template = constants.%.24]
  110. // CHECK:STDOUT: %.loc11_57: i32 = tuple_index %.loc11_54.3, %.loc11_56 [template = constants.%.4]
  111. // CHECK:STDOUT: %.loc11_58: type = array_type %.loc11_57, i32 [template = constants.%.15]
  112. // CHECK:STDOUT: %.loc11_5: ref [i32; 1] = splice_block file.%tuple_index.var {}
  113. // CHECK:STDOUT: %.loc11_32.2: i32 = int_literal 0 [template = constants.%.17]
  114. // CHECK:STDOUT: %.loc11_32.3: ref i32 = array_index %.loc11_5, %.loc11_32.2
  115. // CHECK:STDOUT: %.loc11_32.4: init i32 = initialize_from %.loc11_30 to %.loc11_32.3 [template = constants.%.17]
  116. // CHECK:STDOUT: %.loc11_32.5: init [i32; 1] = array_init (%.loc11_32.4) to %.loc11_5 [template = constants.%.25]
  117. // CHECK:STDOUT: %.loc11_32.6: init [i32; 1] = converted %.loc11_32.1, %.loc11_32.5 [template = constants.%.25]
  118. // CHECK:STDOUT: assign file.%tuple_index.var, %.loc11_32.6
  119. // CHECK:STDOUT: %.loc13_32: i32 = int_literal 0 [template = constants.%.17]
  120. // CHECK:STDOUT: %.loc13_34.1: (i32,) = tuple_literal (%.loc13_32)
  121. // CHECK:STDOUT: %.loc13_51: i32 = int_literal 3 [template = constants.%.9]
  122. // CHECK:STDOUT: %.loc13_59: i32 = int_literal 1 [template = constants.%.4]
  123. // CHECK:STDOUT: %.loc13_60.1: {.a: i32, .b: i32} = struct_literal (%.loc13_51, %.loc13_59)
  124. // CHECK:STDOUT: %.loc13_60.2: {.a: i32, .b: i32} = struct_value (%.loc13_51, %.loc13_59) [template = constants.%.28]
  125. // CHECK:STDOUT: %.loc13_60.3: {.a: i32, .b: i32} = converted %.loc13_60.1, %.loc13_60.2 [template = constants.%.28]
  126. // CHECK:STDOUT: %.loc13_61: i32 = struct_access %.loc13_60.3, element1 [template = constants.%.4]
  127. // CHECK:STDOUT: %.loc13_63: type = array_type %.loc13_61, i32 [template = constants.%.15]
  128. // CHECK:STDOUT: %.loc13_5: ref [i32; 1] = splice_block file.%struct_access.var {}
  129. // CHECK:STDOUT: %.loc13_34.2: i32 = int_literal 0 [template = constants.%.17]
  130. // CHECK:STDOUT: %.loc13_34.3: ref i32 = array_index %.loc13_5, %.loc13_34.2
  131. // CHECK:STDOUT: %.loc13_34.4: init i32 = initialize_from %.loc13_32 to %.loc13_34.3 [template = constants.%.17]
  132. // CHECK:STDOUT: %.loc13_34.5: init [i32; 1] = array_init (%.loc13_34.4) to %.loc13_5 [template = constants.%.25]
  133. // CHECK:STDOUT: %.loc13_34.6: init [i32; 1] = converted %.loc13_34.1, %.loc13_34.5 [template = constants.%.25]
  134. // CHECK:STDOUT: assign file.%struct_access.var, %.loc13_34.6
  135. // CHECK:STDOUT: return
  136. // CHECK:STDOUT: }
  137. // CHECK:STDOUT: