complete_in_member_fn.carbon 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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/class/complete_in_member_fn.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/complete_in_member_fn.carbon
  14. class C {
  15. fn F(c: C) -> i32 { return c.a; }
  16. var a: i32;
  17. }
  18. // CHECK:STDOUT: --- complete_in_member_fn.carbon
  19. // CHECK:STDOUT:
  20. // CHECK:STDOUT: constants {
  21. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  22. // CHECK:STDOUT: %pattern_type.c48: type = pattern_type %C [concrete]
  23. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  24. // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
  25. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  26. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  27. // CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
  28. // CHECK:STDOUT: %C.F.type: type = fn_type @C.F [concrete]
  29. // CHECK:STDOUT: %C.F: %C.F.type = struct_value () [concrete]
  30. // CHECK:STDOUT: %C.elem: type = unbound_element_type %C, %i32 [concrete]
  31. // CHECK:STDOUT: %Destroy.type: type = facet_type <@Destroy> [concrete]
  32. // CHECK:STDOUT: %pattern_type.f6d: type = pattern_type auto [concrete]
  33. // CHECK:STDOUT: %Destroy.impl_witness: <witness> = impl_witness @C.%Destroy.impl_witness_table [concrete]
  34. // CHECK:STDOUT: %ptr.019: type = ptr_type %C [concrete]
  35. // CHECK:STDOUT: %pattern_type.44a: type = pattern_type %ptr.019 [concrete]
  36. // CHECK:STDOUT: %C.as.Destroy.impl.Op.type: type = fn_type @C.as.Destroy.impl.Op [concrete]
  37. // CHECK:STDOUT: %C.as.Destroy.impl.Op: %C.as.Destroy.impl.Op.type = struct_value () [concrete]
  38. // CHECK:STDOUT: %struct_type.a: type = struct_type {.a: %i32} [concrete]
  39. // CHECK:STDOUT: %complete_type.fd7: <witness> = complete_type_witness %struct_type.a [concrete]
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT:
  42. // CHECK:STDOUT: imports {
  43. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  44. // CHECK:STDOUT: .Int = %Core.Int
  45. // CHECK:STDOUT: .Destroy = %Core.Destroy
  46. // CHECK:STDOUT: import Core//prelude
  47. // CHECK:STDOUT: import Core//prelude/...
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/parts/int, Int, loaded [concrete = constants.%Int.generic]
  50. // CHECK:STDOUT: %Core.Destroy: type = import_ref Core//prelude/parts/destroy, Destroy, loaded [concrete = constants.%Destroy.type]
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT:
  53. // CHECK:STDOUT: file {
  54. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  55. // CHECK:STDOUT: .Core = imports.%Core
  56. // CHECK:STDOUT: .C = %C.decl
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT: %Core.import = import Core
  59. // CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: impl @C.as.Destroy.impl: @C.%Self.ref as constants.%Destroy.type {
  63. // CHECK:STDOUT: %C.as.Destroy.impl.Op.decl: %C.as.Destroy.impl.Op.type = fn_decl @C.as.Destroy.impl.Op [concrete = constants.%C.as.Destroy.impl.Op] {
  64. // CHECK:STDOUT: %self.patt: %pattern_type.44a = binding_pattern self [concrete]
  65. // CHECK:STDOUT: %self.param_patt: %pattern_type.44a = value_param_pattern %self.patt, call_param0 [concrete]
  66. // CHECK:STDOUT: %.loc15: %pattern_type.f6d = addr_pattern %self.param_patt [concrete]
  67. // CHECK:STDOUT: } {
  68. // CHECK:STDOUT: %self.param: %ptr.019 = value_param call_param0
  69. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%C [concrete = constants.%C]
  70. // CHECK:STDOUT: %self: %ptr.019 = bind_name self, %self.param
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT:
  73. // CHECK:STDOUT: !members:
  74. // CHECK:STDOUT: .Op = %C.as.Destroy.impl.Op.decl
  75. // CHECK:STDOUT: witness = @C.%Destroy.impl_witness
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT:
  78. // CHECK:STDOUT: class @C {
  79. // CHECK:STDOUT: %C.F.decl: %C.F.type = fn_decl @C.F [concrete = constants.%C.F] {
  80. // CHECK:STDOUT: %c.patt: %pattern_type.c48 = binding_pattern c [concrete]
  81. // CHECK:STDOUT: %c.param_patt: %pattern_type.c48 = value_param_pattern %c.patt, call_param0 [concrete]
  82. // CHECK:STDOUT: %return.patt: %pattern_type.7ce = return_slot_pattern [concrete]
  83. // CHECK:STDOUT: %return.param_patt: %pattern_type.7ce = out_param_pattern %return.patt, call_param1 [concrete]
  84. // CHECK:STDOUT: } {
  85. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  86. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  87. // CHECK:STDOUT: %c.param: %C = value_param call_param0
  88. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
  89. // CHECK:STDOUT: %c: %C = bind_name c, %c.param
  90. // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param1
  91. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  92. // CHECK:STDOUT: }
  93. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  94. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  95. // CHECK:STDOUT: %.loc18: %C.elem = field_decl a, element0 [concrete]
  96. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%C [concrete = constants.%C]
  97. // CHECK:STDOUT: impl_decl @C.as.Destroy.impl [concrete] {} {}
  98. // CHECK:STDOUT: %Destroy.impl_witness_table = impl_witness_table (@C.as.Destroy.impl.%C.as.Destroy.impl.Op.decl), @C.as.Destroy.impl [concrete]
  99. // CHECK:STDOUT: %Destroy.impl_witness: <witness> = impl_witness %Destroy.impl_witness_table [concrete = constants.%Destroy.impl_witness]
  100. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%struct_type.a [concrete = constants.%complete_type.fd7]
  101. // CHECK:STDOUT: complete_type_witness = %complete_type
  102. // CHECK:STDOUT:
  103. // CHECK:STDOUT: !members:
  104. // CHECK:STDOUT: .Self = constants.%C
  105. // CHECK:STDOUT: .C = <poisoned>
  106. // CHECK:STDOUT: .F = %C.F.decl
  107. // CHECK:STDOUT: .a = %.loc18
  108. // CHECK:STDOUT: }
  109. // CHECK:STDOUT:
  110. // CHECK:STDOUT: fn @C.F(%c.param: %C) -> %i32 {
  111. // CHECK:STDOUT: !entry:
  112. // CHECK:STDOUT: %c.ref: %C = name_ref c, %c
  113. // CHECK:STDOUT: %a.ref: %C.elem = name_ref a, @C.%.loc18 [concrete = @C.%.loc18]
  114. // CHECK:STDOUT: %.loc16_31.1: ref %i32 = class_element_access %c.ref, element0
  115. // CHECK:STDOUT: %.loc16_31.2: %i32 = bind_value %.loc16_31.1
  116. // CHECK:STDOUT: return %.loc16_31.2
  117. // CHECK:STDOUT: }
  118. // CHECK:STDOUT:
  119. // CHECK:STDOUT: fn @C.as.Destroy.impl.Op(%self.param: %ptr.019) = "no_op";
  120. // CHECK:STDOUT: