partially_const.carbon 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/int.carbon
  6. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  7. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  8. //
  9. // AUTOUPDATE
  10. // TIP: To test this file alone, run:
  11. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/struct/partially_const.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/struct/partially_const.carbon
  14. fn Make(n: i32) -> {.a: i32, .b: i32, .c: i32} {
  15. return {.a = 0, .b = n, .c = 0};
  16. }
  17. // CHECK:STDOUT: --- partially_const.carbon
  18. // CHECK:STDOUT:
  19. // CHECK:STDOUT: constants {
  20. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  21. // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
  22. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  23. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  24. // CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
  25. // CHECK:STDOUT: %struct_type.a.b.c.0b6: type = struct_type {.a: %i32, .b: %i32, .c: %i32} [concrete]
  26. // CHECK:STDOUT: %pattern_type.8ae: type = pattern_type %struct_type.a.b.c.0b6 [concrete]
  27. // CHECK:STDOUT: %Make.type: type = fn_type @Make [concrete]
  28. // CHECK:STDOUT: %Make: %Make.type = struct_value () [concrete]
  29. // CHECK:STDOUT: %int_0.5c6: Core.IntLiteral = int_value 0 [concrete]
  30. // CHECK:STDOUT: %struct_type.a.b.c.1ee: type = struct_type {.a: Core.IntLiteral, .b: %i32, .c: Core.IntLiteral} [concrete]
  31. // CHECK:STDOUT: %ImplicitAs.type.cc7: type = generic_interface_type @ImplicitAs [concrete]
  32. // CHECK:STDOUT: %ImplicitAs.generic: %ImplicitAs.type.cc7 = struct_value () [concrete]
  33. // CHECK:STDOUT: %ImplicitAs.type.205: type = facet_type <@ImplicitAs, @ImplicitAs(%i32)> [concrete]
  34. // CHECK:STDOUT: %Convert.type.1b6: type = fn_type @Convert.1, @ImplicitAs(%i32) [concrete]
  35. // CHECK:STDOUT: %To: Core.IntLiteral = bind_symbolic_name To, 0 [symbolic]
  36. // CHECK:STDOUT: %Convert.type.0f9: type = fn_type @Convert.2, @ImplicitAs.impl.4f9(%To) [symbolic]
  37. // CHECK:STDOUT: %Convert.f06: %Convert.type.0f9 = struct_value () [symbolic]
  38. // CHECK:STDOUT: %ImplicitAs.impl_witness.c75: <witness> = impl_witness imports.%ImplicitAs.impl_witness_table.a2f, @ImplicitAs.impl.4f9(%int_32) [concrete]
  39. // CHECK:STDOUT: %Convert.type.035: type = fn_type @Convert.2, @ImplicitAs.impl.4f9(%int_32) [concrete]
  40. // CHECK:STDOUT: %Convert.956: %Convert.type.035 = struct_value () [concrete]
  41. // CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.205 = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.c75) [concrete]
  42. // CHECK:STDOUT: %.9c3: type = fn_type_with_self_type %Convert.type.1b6, %ImplicitAs.facet [concrete]
  43. // CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %int_0.5c6, %Convert.956 [concrete]
  44. // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.956, @Convert.2(%int_32) [concrete]
  45. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %int_0.5c6, %Convert.specific_fn [concrete]
  46. // CHECK:STDOUT: %int_0.6a9: %i32 = int_value 0 [concrete]
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT:
  49. // CHECK:STDOUT: imports {
  50. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  51. // CHECK:STDOUT: .Int = %Core.Int
  52. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  53. // CHECK:STDOUT: import Core//prelude
  54. // CHECK:STDOUT: import Core//prelude/...
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/parts/int, Int, loaded [concrete = constants.%Int.generic]
  57. // CHECK:STDOUT: %Core.ImplicitAs: %ImplicitAs.type.cc7 = import_ref Core//prelude/parts/as, ImplicitAs, loaded [concrete = constants.%ImplicitAs.generic]
  58. // CHECK:STDOUT: %Core.import_ref.a5b: @ImplicitAs.impl.4f9.%Convert.type (%Convert.type.0f9) = import_ref Core//prelude/parts/int, loc16_39, loaded [symbolic = @ImplicitAs.impl.4f9.%Convert (constants.%Convert.f06)]
  59. // CHECK:STDOUT: %ImplicitAs.impl_witness_table.a2f = impl_witness_table (%Core.import_ref.a5b), @ImplicitAs.impl.4f9 [concrete]
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: file {
  63. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  64. // CHECK:STDOUT: .Core = imports.%Core
  65. // CHECK:STDOUT: .Make = %Make.decl
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT: %Core.import = import Core
  68. // CHECK:STDOUT: %Make.decl: %Make.type = fn_decl @Make [concrete = constants.%Make] {
  69. // CHECK:STDOUT: %n.patt: %pattern_type.7ce = binding_pattern n [concrete]
  70. // CHECK:STDOUT: %n.param_patt: %pattern_type.7ce = value_param_pattern %n.patt, call_param0 [concrete]
  71. // CHECK:STDOUT: %return.patt: %pattern_type.8ae = return_slot_pattern [concrete]
  72. // CHECK:STDOUT: %return.param_patt: %pattern_type.8ae = out_param_pattern %return.patt, call_param1 [concrete]
  73. // CHECK:STDOUT: } {
  74. // CHECK:STDOUT: %int_32.loc15_25: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  75. // CHECK:STDOUT: %i32.loc15_25: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  76. // CHECK:STDOUT: %int_32.loc15_34: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  77. // CHECK:STDOUT: %i32.loc15_34: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  78. // CHECK:STDOUT: %int_32.loc15_43: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  79. // CHECK:STDOUT: %i32.loc15_43: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  80. // CHECK:STDOUT: %struct_type.a.b.c: type = struct_type {.a: %i32, .b: %i32, .c: %i32} [concrete = constants.%struct_type.a.b.c.0b6]
  81. // CHECK:STDOUT: %n.param: %i32 = value_param call_param0
  82. // CHECK:STDOUT: %.loc15: type = splice_block %i32.loc15_12 [concrete = constants.%i32] {
  83. // CHECK:STDOUT: %int_32.loc15_12: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  84. // CHECK:STDOUT: %i32.loc15_12: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  85. // CHECK:STDOUT: }
  86. // CHECK:STDOUT: %n: %i32 = bind_name n, %n.param
  87. // CHECK:STDOUT: %return.param: ref %struct_type.a.b.c.0b6 = out_param call_param1
  88. // CHECK:STDOUT: %return: ref %struct_type.a.b.c.0b6 = return_slot %return.param
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: fn @Make(%n.param: %i32) -> %return.param: %struct_type.a.b.c.0b6 {
  93. // CHECK:STDOUT: !entry:
  94. // CHECK:STDOUT: %int_0.loc16_16: Core.IntLiteral = int_value 0 [concrete = constants.%int_0.5c6]
  95. // CHECK:STDOUT: %n.ref: %i32 = name_ref n, %n
  96. // CHECK:STDOUT: %int_0.loc16_32: Core.IntLiteral = int_value 0 [concrete = constants.%int_0.5c6]
  97. // CHECK:STDOUT: %.loc16_33.1: %struct_type.a.b.c.1ee = struct_literal (%int_0.loc16_16, %n.ref, %int_0.loc16_32)
  98. // CHECK:STDOUT: %impl.elem0.loc16_33.1: %.9c3 = impl_witness_access constants.%ImplicitAs.impl_witness.c75, element0 [concrete = constants.%Convert.956]
  99. // CHECK:STDOUT: %bound_method.loc16_33.1: <bound method> = bound_method %int_0.loc16_16, %impl.elem0.loc16_33.1 [concrete = constants.%Convert.bound]
  100. // CHECK:STDOUT: %specific_fn.loc16_33.1: <specific function> = specific_function %impl.elem0.loc16_33.1, @Convert.2(constants.%int_32) [concrete = constants.%Convert.specific_fn]
  101. // CHECK:STDOUT: %bound_method.loc16_33.2: <bound method> = bound_method %int_0.loc16_16, %specific_fn.loc16_33.1 [concrete = constants.%bound_method]
  102. // CHECK:STDOUT: %int.convert_checked.loc16_33.1: init %i32 = call %bound_method.loc16_33.2(%int_0.loc16_16) [concrete = constants.%int_0.6a9]
  103. // CHECK:STDOUT: %.loc16_33.2: init %i32 = converted %int_0.loc16_16, %int.convert_checked.loc16_33.1 [concrete = constants.%int_0.6a9]
  104. // CHECK:STDOUT: %.loc16_33.3: ref %i32 = struct_access %return, element0
  105. // CHECK:STDOUT: %.loc16_33.4: init %i32 = initialize_from %.loc16_33.2 to %.loc16_33.3 [concrete = constants.%int_0.6a9]
  106. // CHECK:STDOUT: %.loc16_33.5: ref %i32 = struct_access %return, element1
  107. // CHECK:STDOUT: %.loc16_33.6: init %i32 = initialize_from %n.ref to %.loc16_33.5
  108. // CHECK:STDOUT: %impl.elem0.loc16_33.2: %.9c3 = impl_witness_access constants.%ImplicitAs.impl_witness.c75, element0 [concrete = constants.%Convert.956]
  109. // CHECK:STDOUT: %bound_method.loc16_33.3: <bound method> = bound_method %int_0.loc16_32, %impl.elem0.loc16_33.2 [concrete = constants.%Convert.bound]
  110. // CHECK:STDOUT: %specific_fn.loc16_33.2: <specific function> = specific_function %impl.elem0.loc16_33.2, @Convert.2(constants.%int_32) [concrete = constants.%Convert.specific_fn]
  111. // CHECK:STDOUT: %bound_method.loc16_33.4: <bound method> = bound_method %int_0.loc16_32, %specific_fn.loc16_33.2 [concrete = constants.%bound_method]
  112. // CHECK:STDOUT: %int.convert_checked.loc16_33.2: init %i32 = call %bound_method.loc16_33.4(%int_0.loc16_32) [concrete = constants.%int_0.6a9]
  113. // CHECK:STDOUT: %.loc16_33.7: init %i32 = converted %int_0.loc16_32, %int.convert_checked.loc16_33.2 [concrete = constants.%int_0.6a9]
  114. // CHECK:STDOUT: %.loc16_33.8: ref %i32 = struct_access %return, element2
  115. // CHECK:STDOUT: %.loc16_33.9: init %i32 = initialize_from %.loc16_33.7 to %.loc16_33.8 [concrete = constants.%int_0.6a9]
  116. // CHECK:STDOUT: %.loc16_33.10: init %struct_type.a.b.c.0b6 = struct_init (%.loc16_33.4, %.loc16_33.6, %.loc16_33.9) to %return
  117. // CHECK:STDOUT: %.loc16_34: init %struct_type.a.b.c.0b6 = converted %.loc16_33.1, %.loc16_33.10
  118. // CHECK:STDOUT: return %.loc16_34 to %return
  119. // CHECK:STDOUT: }
  120. // CHECK:STDOUT: