complete_in_member_fn.carbon 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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/class/complete_in_member_fn.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/complete_in_member_fn.carbon
  10. class C {
  11. fn F(c: C) -> i32 { return c.a; }
  12. var a: i32;
  13. }
  14. // CHECK:STDOUT: --- complete_in_member_fn.carbon
  15. // CHECK:STDOUT:
  16. // CHECK:STDOUT: constants {
  17. // CHECK:STDOUT: %C: type = class_type @C [template]
  18. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  19. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  20. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  21. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  22. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  23. // CHECK:STDOUT: %.2: type = unbound_element_type %C, i32 [template]
  24. // CHECK:STDOUT: %.3: type = struct_type {.a: i32} [template]
  25. // CHECK:STDOUT: %.4: <witness> = complete_type_witness %.3 [template]
  26. // CHECK:STDOUT: %.5: type = ptr_type %.3 [template]
  27. // CHECK:STDOUT: }
  28. // CHECK:STDOUT:
  29. // CHECK:STDOUT: imports {
  30. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  31. // CHECK:STDOUT: .Int32 = %import_ref
  32. // CHECK:STDOUT: import Core//prelude
  33. // CHECK:STDOUT: import Core//prelude/...
  34. // CHECK:STDOUT: }
  35. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+15, loaded [template = constants.%Int32]
  36. // CHECK:STDOUT: }
  37. // CHECK:STDOUT:
  38. // CHECK:STDOUT: file {
  39. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  40. // CHECK:STDOUT: .Core = imports.%Core
  41. // CHECK:STDOUT: .C = %C.decl
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT: %Core.import = import Core
  44. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  45. // CHECK:STDOUT: }
  46. // CHECK:STDOUT:
  47. // CHECK:STDOUT: class @C {
  48. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  49. // CHECK:STDOUT: %c.patt: %C = binding_pattern c
  50. // CHECK:STDOUT: %c.param_patt: %C = value_param_pattern %c.patt, runtime_param0
  51. // CHECK:STDOUT: %return.patt: i32 = return_slot_pattern
  52. // CHECK:STDOUT: %return.param_patt: i32 = out_param_pattern %return.patt, runtime_param1
  53. // CHECK:STDOUT: } {
  54. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  55. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  56. // CHECK:STDOUT: %.loc12_17.1: type = value_of_initializer %int.make_type_32 [template = i32]
  57. // CHECK:STDOUT: %.loc12_17.2: type = converted %int.make_type_32, %.loc12_17.1 [template = i32]
  58. // CHECK:STDOUT: %c.param: %C = value_param runtime_param0
  59. // CHECK:STDOUT: %c: %C = bind_name c, %c.param
  60. // CHECK:STDOUT: %return.param: ref i32 = out_param runtime_param1
  61. // CHECK:STDOUT: %return: ref i32 = return_slot %return.param
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  64. // CHECK:STDOUT: %.loc14_10.1: type = value_of_initializer %int.make_type_32 [template = i32]
  65. // CHECK:STDOUT: %.loc14_10.2: type = converted %int.make_type_32, %.loc14_10.1 [template = i32]
  66. // CHECK:STDOUT: %.loc14_8: %.2 = field_decl a, element0 [template]
  67. // CHECK:STDOUT: %.loc15: <witness> = complete_type_witness %.3 [template = constants.%.4]
  68. // CHECK:STDOUT:
  69. // CHECK:STDOUT: !members:
  70. // CHECK:STDOUT: .Self = constants.%C
  71. // CHECK:STDOUT: .F = %F.decl
  72. // CHECK:STDOUT: .a = %.loc14_8
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  76. // CHECK:STDOUT:
  77. // CHECK:STDOUT: fn @F(%c.param_patt: %C) -> i32 {
  78. // CHECK:STDOUT: !entry:
  79. // CHECK:STDOUT: %c.ref: %C = name_ref c, %c
  80. // CHECK:STDOUT: %a.ref: %.2 = name_ref a, @C.%.loc14_8 [template = @C.%.loc14_8]
  81. // CHECK:STDOUT: %.loc12_31.1: ref i32 = class_element_access %c.ref, element0
  82. // CHECK:STDOUT: %.loc12_31.2: i32 = bind_value %.loc12_31.1
  83. // CHECK:STDOUT: return %.loc12_31.2
  84. // CHECK:STDOUT: }
  85. // CHECK:STDOUT: