partially_const.carbon 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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/partially_const.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/struct/partially_const.carbon
  10. fn Make(n: i32) -> {.a: i32, .b: i32, .c: i32} {
  11. return {.a = 0, .b = n, .c = 0};
  12. }
  13. // CHECK:STDOUT: --- partially_const.carbon
  14. // CHECK:STDOUT:
  15. // CHECK:STDOUT: constants {
  16. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  17. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  18. // CHECK:STDOUT: %struct_type.a.b.c.0b6: type = struct_type {.a: %i32, .b: %i32, .c: %i32} [concrete]
  19. // CHECK:STDOUT: %Make.type: type = fn_type @Make [concrete]
  20. // CHECK:STDOUT: %Make: %Make.type = struct_value () [concrete]
  21. // CHECK:STDOUT: %int_0.5c6: Core.IntLiteral = int_value 0 [concrete]
  22. // CHECK:STDOUT: %struct_type.a.b.c.1ee: type = struct_type {.a: Core.IntLiteral, .b: %i32, .c: Core.IntLiteral} [concrete]
  23. // CHECK:STDOUT: %ImplicitAs.type.205: type = facet_type <@ImplicitAs, @ImplicitAs(%i32)> [concrete]
  24. // CHECK:STDOUT: %Convert.type.1b6: type = fn_type @Convert.1, @ImplicitAs(%i32) [concrete]
  25. // CHECK:STDOUT: %impl_witness.d39: <witness> = impl_witness (imports.%Core.import_ref.a5b), @impl.4f9(%int_32) [concrete]
  26. // CHECK:STDOUT: %Convert.type.035: type = fn_type @Convert.2, @impl.4f9(%int_32) [concrete]
  27. // CHECK:STDOUT: %Convert.956: %Convert.type.035 = struct_value () [concrete]
  28. // CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.205 = facet_value Core.IntLiteral, (%impl_witness.d39) [concrete]
  29. // CHECK:STDOUT: %.be7: type = fn_type_with_self_type %Convert.type.1b6, %ImplicitAs.facet [concrete]
  30. // CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %int_0.5c6, %Convert.956 [concrete]
  31. // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.956, @Convert.2(%int_32) [concrete]
  32. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %int_0.5c6, %Convert.specific_fn [concrete]
  33. // CHECK:STDOUT: %int_0.6a9: %i32 = int_value 0 [concrete]
  34. // CHECK:STDOUT: }
  35. // CHECK:STDOUT:
  36. // CHECK:STDOUT: imports {
  37. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  38. // CHECK:STDOUT: .Int = %Core.Int
  39. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  40. // CHECK:STDOUT: import Core//prelude
  41. // CHECK:STDOUT: import Core//prelude/...
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT:
  45. // CHECK:STDOUT: file {
  46. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  47. // CHECK:STDOUT: .Core = imports.%Core
  48. // CHECK:STDOUT: .Make = %Make.decl
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT: %Core.import = import Core
  51. // CHECK:STDOUT: %Make.decl: %Make.type = fn_decl @Make [concrete = constants.%Make] {
  52. // CHECK:STDOUT: %n.patt: %i32 = binding_pattern n
  53. // CHECK:STDOUT: %n.param_patt: %i32 = value_param_pattern %n.patt, call_param0
  54. // CHECK:STDOUT: %return.patt: %struct_type.a.b.c.0b6 = return_slot_pattern
  55. // CHECK:STDOUT: %return.param_patt: %struct_type.a.b.c.0b6 = out_param_pattern %return.patt, call_param1
  56. // CHECK:STDOUT: } {
  57. // CHECK:STDOUT: %int_32.loc11_25: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  58. // CHECK:STDOUT: %i32.loc11_25: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  59. // CHECK:STDOUT: %int_32.loc11_34: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  60. // CHECK:STDOUT: %i32.loc11_34: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  61. // CHECK:STDOUT: %int_32.loc11_43: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  62. // CHECK:STDOUT: %i32.loc11_43: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  63. // CHECK:STDOUT: %struct_type.a.b.c: type = struct_type {.a: %i32, .b: %i32, .c: %i32} [concrete = constants.%struct_type.a.b.c.0b6]
  64. // CHECK:STDOUT: %n.param: %i32 = value_param call_param0
  65. // CHECK:STDOUT: %.loc11: type = splice_block %i32.loc11_12 [concrete = constants.%i32] {
  66. // CHECK:STDOUT: %int_32.loc11_12: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  67. // CHECK:STDOUT: %i32.loc11_12: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT: %n: %i32 = bind_name n, %n.param
  70. // CHECK:STDOUT: %return.param: ref %struct_type.a.b.c.0b6 = out_param call_param1
  71. // CHECK:STDOUT: %return: ref %struct_type.a.b.c.0b6 = return_slot %return.param
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: fn @Make(%n.param_patt: %i32) -> %return.param_patt: %struct_type.a.b.c.0b6 {
  76. // CHECK:STDOUT: !entry:
  77. // CHECK:STDOUT: %int_0.loc12_16: Core.IntLiteral = int_value 0 [concrete = constants.%int_0.5c6]
  78. // CHECK:STDOUT: %n.ref: %i32 = name_ref n, %n
  79. // CHECK:STDOUT: %int_0.loc12_32: Core.IntLiteral = int_value 0 [concrete = constants.%int_0.5c6]
  80. // CHECK:STDOUT: %.loc12_33.1: %struct_type.a.b.c.1ee = struct_literal (%int_0.loc12_16, %n.ref, %int_0.loc12_32)
  81. // CHECK:STDOUT: %impl.elem0.loc12_33.1: %.be7 = impl_witness_access constants.%impl_witness.d39, element0 [concrete = constants.%Convert.956]
  82. // CHECK:STDOUT: %bound_method.loc12_33.1: <bound method> = bound_method %int_0.loc12_16, %impl.elem0.loc12_33.1 [concrete = constants.%Convert.bound]
  83. // CHECK:STDOUT: %specific_fn.loc12_33.1: <specific function> = specific_function %impl.elem0.loc12_33.1, @Convert.2(constants.%int_32) [concrete = constants.%Convert.specific_fn]
  84. // CHECK:STDOUT: %bound_method.loc12_33.2: <bound method> = bound_method %int_0.loc12_16, %specific_fn.loc12_33.1 [concrete = constants.%bound_method]
  85. // CHECK:STDOUT: %int.convert_checked.loc12_33.1: init %i32 = call %bound_method.loc12_33.2(%int_0.loc12_16) [concrete = constants.%int_0.6a9]
  86. // CHECK:STDOUT: %.loc12_33.2: init %i32 = converted %int_0.loc12_16, %int.convert_checked.loc12_33.1 [concrete = constants.%int_0.6a9]
  87. // CHECK:STDOUT: %.loc12_33.3: ref %i32 = struct_access %return, element0
  88. // CHECK:STDOUT: %.loc12_33.4: init %i32 = initialize_from %.loc12_33.2 to %.loc12_33.3 [concrete = constants.%int_0.6a9]
  89. // CHECK:STDOUT: %.loc12_33.5: ref %i32 = struct_access %return, element1
  90. // CHECK:STDOUT: %.loc12_33.6: init %i32 = initialize_from %n.ref to %.loc12_33.5
  91. // CHECK:STDOUT: %impl.elem0.loc12_33.2: %.be7 = impl_witness_access constants.%impl_witness.d39, element0 [concrete = constants.%Convert.956]
  92. // CHECK:STDOUT: %bound_method.loc12_33.3: <bound method> = bound_method %int_0.loc12_32, %impl.elem0.loc12_33.2 [concrete = constants.%Convert.bound]
  93. // CHECK:STDOUT: %specific_fn.loc12_33.2: <specific function> = specific_function %impl.elem0.loc12_33.2, @Convert.2(constants.%int_32) [concrete = constants.%Convert.specific_fn]
  94. // CHECK:STDOUT: %bound_method.loc12_33.4: <bound method> = bound_method %int_0.loc12_32, %specific_fn.loc12_33.2 [concrete = constants.%bound_method]
  95. // CHECK:STDOUT: %int.convert_checked.loc12_33.2: init %i32 = call %bound_method.loc12_33.4(%int_0.loc12_32) [concrete = constants.%int_0.6a9]
  96. // CHECK:STDOUT: %.loc12_33.7: init %i32 = converted %int_0.loc12_32, %int.convert_checked.loc12_33.2 [concrete = constants.%int_0.6a9]
  97. // CHECK:STDOUT: %.loc12_33.8: ref %i32 = struct_access %return, element2
  98. // CHECK:STDOUT: %.loc12_33.9: init %i32 = initialize_from %.loc12_33.7 to %.loc12_33.8 [concrete = constants.%int_0.6a9]
  99. // CHECK:STDOUT: %.loc12_33.10: init %struct_type.a.b.c.0b6 = struct_init (%.loc12_33.4, %.loc12_33.6, %.loc12_33.9) to %return
  100. // CHECK:STDOUT: %.loc12_34: init %struct_type.a.b.c.0b6 = converted %.loc12_33.1, %.loc12_33.10
  101. // CHECK:STDOUT: return %.loc12_34 to %return
  102. // CHECK:STDOUT: }
  103. // CHECK:STDOUT: