complete_in_member_fn.carbon 4.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  6. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  7. //
  8. // AUTOUPDATE
  9. // TIP: To test this file alone, run:
  10. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/class/complete_in_member_fn.carbon
  11. // TIP: To dump output, run:
  12. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/complete_in_member_fn.carbon
  13. class C {
  14. fn F(c: C) -> i32 { return c.a; }
  15. var a: i32;
  16. }
  17. // CHECK:STDOUT: --- complete_in_member_fn.carbon
  18. // CHECK:STDOUT:
  19. // CHECK:STDOUT: constants {
  20. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  21. // CHECK:STDOUT: %pattern_type.c48: type = pattern_type %C [concrete]
  22. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  23. // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
  24. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  25. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  26. // CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
  27. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  28. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  29. // CHECK:STDOUT: %C.elem: type = unbound_element_type %C, %i32 [concrete]
  30. // CHECK:STDOUT: %struct_type.a: type = struct_type {.a: %i32} [concrete]
  31. // CHECK:STDOUT: %complete_type.fd7: <witness> = complete_type_witness %struct_type.a [concrete]
  32. // CHECK:STDOUT: }
  33. // CHECK:STDOUT:
  34. // CHECK:STDOUT: imports {
  35. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  36. // CHECK:STDOUT: .Int = %Core.Int
  37. // CHECK:STDOUT: import Core//prelude
  38. // CHECK:STDOUT: import Core//prelude/...
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/types/int, Int, loaded [concrete = constants.%Int.generic]
  41. // CHECK:STDOUT: }
  42. // CHECK:STDOUT:
  43. // CHECK:STDOUT: file {
  44. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  45. // CHECK:STDOUT: .Core = imports.%Core
  46. // CHECK:STDOUT: .C = %C.decl
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT: %Core.import = import Core
  49. // CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT:
  52. // CHECK:STDOUT: class @C {
  53. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {
  54. // CHECK:STDOUT: %c.patt: %pattern_type.c48 = binding_pattern c [concrete]
  55. // CHECK:STDOUT: %c.param_patt: %pattern_type.c48 = value_param_pattern %c.patt, call_param0 [concrete]
  56. // CHECK:STDOUT: %return.patt: %pattern_type.7ce = return_slot_pattern [concrete]
  57. // CHECK:STDOUT: %return.param_patt: %pattern_type.7ce = out_param_pattern %return.patt, call_param1 [concrete]
  58. // CHECK:STDOUT: } {
  59. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  60. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  61. // CHECK:STDOUT: %c.param: %C = value_param call_param0
  62. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
  63. // CHECK:STDOUT: %c: %C = bind_name c, %c.param
  64. // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param1
  65. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  68. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  69. // CHECK:STDOUT: %.loc17: %C.elem = field_decl a, element0 [concrete]
  70. // CHECK:STDOUT: %struct_type.a: type = struct_type {.a: %i32} [concrete = constants.%struct_type.a]
  71. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.a [concrete = constants.%complete_type.fd7]
  72. // CHECK:STDOUT: complete_type_witness = %complete_type
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: !members:
  75. // CHECK:STDOUT: .Self = constants.%C
  76. // CHECK:STDOUT: .C = <poisoned>
  77. // CHECK:STDOUT: .F = %F.decl
  78. // CHECK:STDOUT: .a = %.loc17
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT:
  81. // CHECK:STDOUT: fn @F(%c.param: %C) -> %i32 {
  82. // CHECK:STDOUT: !entry:
  83. // CHECK:STDOUT: %c.ref: %C = name_ref c, %c
  84. // CHECK:STDOUT: %a.ref: %C.elem = name_ref a, @C.%.loc17 [concrete = @C.%.loc17]
  85. // CHECK:STDOUT: %.loc15_31.1: ref %i32 = class_element_access %c.ref, element0
  86. // CHECK:STDOUT: %.loc15_31.2: %i32 = bind_value %.loc15_31.1
  87. // CHECK:STDOUT: return %.loc15_31.2
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT: