partially_const.carbon 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 [template]
  17. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  18. // CHECK:STDOUT: %struct_type.a.b.c.1ce: type = struct_type {.a: %i32, .b: %i32, .c: %i32} [template]
  19. // CHECK:STDOUT: %Make.type: type = fn_type @Make [template]
  20. // CHECK:STDOUT: %Make: %Make.type = struct_value () [template]
  21. // CHECK:STDOUT: %int_0.5c6: Core.IntLiteral = int_value 0 [template]
  22. // CHECK:STDOUT: %struct_type.a.b.c.c6d: type = struct_type {.a: Core.IntLiteral, .b: %i32, .c: Core.IntLiteral} [template]
  23. // CHECK:STDOUT: %Convert.type.cd1: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  24. // CHECK:STDOUT: %impl_witness.5b0: <witness> = impl_witness (imports.%import_ref.723), @impl.1(%int_32) [template]
  25. // CHECK:STDOUT: %Convert.type.466: type = fn_type @Convert.2, @impl.1(%int_32) [template]
  26. // CHECK:STDOUT: %Convert.925: %Convert.type.466 = struct_value () [template]
  27. // CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %int_0.5c6, %Convert.925 [template]
  28. // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.bound, @Convert.2(%int_32) [template]
  29. // CHECK:STDOUT: %int_0.f61: %i32 = int_value 0 [template]
  30. // CHECK:STDOUT: }
  31. // CHECK:STDOUT:
  32. // CHECK:STDOUT: imports {
  33. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  34. // CHECK:STDOUT: .Int = %import_ref.187
  35. // CHECK:STDOUT: .ImplicitAs = %import_ref.a69
  36. // CHECK:STDOUT: import Core//prelude
  37. // CHECK:STDOUT: import Core//prelude/...
  38. // CHECK:STDOUT: }
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT:
  41. // CHECK:STDOUT: file {
  42. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  43. // CHECK:STDOUT: .Core = imports.%Core
  44. // CHECK:STDOUT: .Make = %Make.decl
  45. // CHECK:STDOUT: }
  46. // CHECK:STDOUT: %Core.import = import Core
  47. // CHECK:STDOUT: %Make.decl: %Make.type = fn_decl @Make [template = constants.%Make] {
  48. // CHECK:STDOUT: %n.patt: %i32 = binding_pattern n
  49. // CHECK:STDOUT: %n.param_patt: %i32 = value_param_pattern %n.patt, runtime_param0
  50. // CHECK:STDOUT: %return.patt: %struct_type.a.b.c.1ce = return_slot_pattern
  51. // CHECK:STDOUT: %return.param_patt: %struct_type.a.b.c.1ce = out_param_pattern %return.patt, runtime_param1
  52. // CHECK:STDOUT: } {
  53. // CHECK:STDOUT: %int_32.loc11_25: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  54. // CHECK:STDOUT: %i32.loc11_25: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  55. // CHECK:STDOUT: %int_32.loc11_34: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  56. // CHECK:STDOUT: %i32.loc11_34: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  57. // CHECK:STDOUT: %int_32.loc11_43: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  58. // CHECK:STDOUT: %i32.loc11_43: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  59. // CHECK:STDOUT: %struct_type.a.b.c: type = struct_type {.a: %i32, .b: %i32, .c: %i32} [template = constants.%struct_type.a.b.c.1ce]
  60. // CHECK:STDOUT: %n.param: %i32 = value_param runtime_param0
  61. // CHECK:STDOUT: %.loc11: type = splice_block %i32.loc11_12 [template = constants.%i32] {
  62. // CHECK:STDOUT: %int_32.loc11_12: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  63. // CHECK:STDOUT: %i32.loc11_12: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  64. // CHECK:STDOUT: }
  65. // CHECK:STDOUT: %n: %i32 = bind_name n, %n.param
  66. // CHECK:STDOUT: %return.param: ref %struct_type.a.b.c.1ce = out_param runtime_param1
  67. // CHECK:STDOUT: %return: ref %struct_type.a.b.c.1ce = return_slot %return.param
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: fn @Make(%n.param_patt: %i32) -> %return.param_patt: %struct_type.a.b.c.1ce {
  72. // CHECK:STDOUT: !entry:
  73. // CHECK:STDOUT: %int_0.loc12_16: Core.IntLiteral = int_value 0 [template = constants.%int_0.5c6]
  74. // CHECK:STDOUT: %n.ref: %i32 = name_ref n, %n
  75. // CHECK:STDOUT: %int_0.loc12_32: Core.IntLiteral = int_value 0 [template = constants.%int_0.5c6]
  76. // CHECK:STDOUT: %.loc12_33.1: %struct_type.a.b.c.c6d = struct_literal (%int_0.loc12_16, %n.ref, %int_0.loc12_32)
  77. // CHECK:STDOUT: %impl.elem0.loc12_33.1: %Convert.type.cd1 = impl_witness_access constants.%impl_witness.5b0, element0 [template = constants.%Convert.925]
  78. // CHECK:STDOUT: %Convert.bound.loc12_33.1: <bound method> = bound_method %int_0.loc12_16, %impl.elem0.loc12_33.1 [template = constants.%Convert.bound]
  79. // CHECK:STDOUT: %Convert.specific_fn.loc12_33.1: <specific function> = specific_function %Convert.bound.loc12_33.1, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn]
  80. // CHECK:STDOUT: %int.convert_checked.loc12_33.1: init %i32 = call %Convert.specific_fn.loc12_33.1(%int_0.loc12_16) [template = constants.%int_0.f61]
  81. // CHECK:STDOUT: %.loc12_33.2: init %i32 = converted %int_0.loc12_16, %int.convert_checked.loc12_33.1 [template = constants.%int_0.f61]
  82. // CHECK:STDOUT: %.loc12_33.3: ref %i32 = struct_access %return, element0
  83. // CHECK:STDOUT: %.loc12_33.4: init %i32 = initialize_from %.loc12_33.2 to %.loc12_33.3 [template = constants.%int_0.f61]
  84. // CHECK:STDOUT: %.loc12_33.5: ref %i32 = struct_access %return, element1
  85. // CHECK:STDOUT: %.loc12_33.6: init %i32 = initialize_from %n.ref to %.loc12_33.5
  86. // CHECK:STDOUT: %impl.elem0.loc12_33.2: %Convert.type.cd1 = impl_witness_access constants.%impl_witness.5b0, element0 [template = constants.%Convert.925]
  87. // CHECK:STDOUT: %Convert.bound.loc12_33.2: <bound method> = bound_method %int_0.loc12_32, %impl.elem0.loc12_33.2 [template = constants.%Convert.bound]
  88. // CHECK:STDOUT: %Convert.specific_fn.loc12_33.2: <specific function> = specific_function %Convert.bound.loc12_33.2, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn]
  89. // CHECK:STDOUT: %int.convert_checked.loc12_33.2: init %i32 = call %Convert.specific_fn.loc12_33.2(%int_0.loc12_32) [template = constants.%int_0.f61]
  90. // CHECK:STDOUT: %.loc12_33.7: init %i32 = converted %int_0.loc12_32, %int.convert_checked.loc12_33.2 [template = constants.%int_0.f61]
  91. // CHECK:STDOUT: %.loc12_33.8: ref %i32 = struct_access %return, element2
  92. // CHECK:STDOUT: %.loc12_33.9: init %i32 = initialize_from %.loc12_33.7 to %.loc12_33.8 [template = constants.%int_0.f61]
  93. // CHECK:STDOUT: %.loc12_33.10: init %struct_type.a.b.c.1ce = struct_init (%.loc12_33.4, %.loc12_33.6, %.loc12_33.9) to %return
  94. // CHECK:STDOUT: %.loc12_34: init %struct_type.a.b.c.1ce = converted %.loc12_33.1, %.loc12_33.10
  95. // CHECK:STDOUT: return %.loc12_34 to %return
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT: