self.carbon 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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/none.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/interface/self.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interface/self.carbon
  14. interface UseSelf {
  15. fn F[self: Self]() -> Self;
  16. }
  17. // CHECK:STDOUT: --- self.carbon
  18. // CHECK:STDOUT:
  19. // CHECK:STDOUT: constants {
  20. // CHECK:STDOUT: %UseSelf.type: type = facet_type <@UseSelf> [concrete]
  21. // CHECK:STDOUT: %Self: %UseSelf.type = symbolic_binding Self, 0 [symbolic]
  22. // CHECK:STDOUT: %Self.binding.as_type: type = symbolic_binding_type Self, 0, %Self [symbolic]
  23. // CHECK:STDOUT: %pattern_type: type = pattern_type %Self.binding.as_type [symbolic]
  24. // CHECK:STDOUT: %.52b: Core.Form = init_form %Self.binding.as_type, call_param1 [symbolic]
  25. // CHECK:STDOUT: %UseSelf.F.type: type = fn_type @UseSelf.F [concrete]
  26. // CHECK:STDOUT: %UseSelf.F: %UseSelf.F.type = struct_value () [concrete]
  27. // CHECK:STDOUT: %UseSelf.assoc_type: type = assoc_entity_type @UseSelf [concrete]
  28. // CHECK:STDOUT: %assoc0: %UseSelf.assoc_type = assoc_entity element0, @UseSelf.%UseSelf.F.decl [concrete]
  29. // CHECK:STDOUT: }
  30. // CHECK:STDOUT:
  31. // CHECK:STDOUT: file {
  32. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  33. // CHECK:STDOUT: .UseSelf = %UseSelf.decl
  34. // CHECK:STDOUT: }
  35. // CHECK:STDOUT: %UseSelf.decl: type = interface_decl @UseSelf [concrete = constants.%UseSelf.type] {} {}
  36. // CHECK:STDOUT: }
  37. // CHECK:STDOUT:
  38. // CHECK:STDOUT: interface @UseSelf {
  39. // CHECK:STDOUT: %Self: %UseSelf.type = symbolic_binding Self, 0 [symbolic = constants.%Self]
  40. // CHECK:STDOUT: %UseSelf.F.decl: %UseSelf.F.type = fn_decl @UseSelf.F [concrete = constants.%UseSelf.F] {
  41. // CHECK:STDOUT: %self.patt: @UseSelf.F.%pattern_type (%pattern_type) = value_binding_pattern self [concrete]
  42. // CHECK:STDOUT: %self.param_patt: @UseSelf.F.%pattern_type (%pattern_type) = value_param_pattern %self.patt, call_param0 [concrete]
  43. // CHECK:STDOUT: %return.patt: @UseSelf.F.%pattern_type (%pattern_type) = return_slot_pattern [concrete]
  44. // CHECK:STDOUT: %return.param_patt: @UseSelf.F.%pattern_type (%pattern_type) = out_param_pattern %return.patt, call_param1 [concrete]
  45. // CHECK:STDOUT: } {
  46. // CHECK:STDOUT: %Self.ref.loc16_25: %UseSelf.type = name_ref Self, @UseSelf.%Self [symbolic = %Self (constants.%Self)]
  47. // CHECK:STDOUT: %Self.as_type.loc16_25: type = facet_access_type %Self.ref.loc16_25 [symbolic = %Self.binding.as_type (constants.%Self.binding.as_type)]
  48. // CHECK:STDOUT: %.loc16_25.2: type = converted %Self.ref.loc16_25, %Self.as_type.loc16_25 [symbolic = %Self.binding.as_type (constants.%Self.binding.as_type)]
  49. // CHECK:STDOUT: %.loc16_25.3: Core.Form = init_form %.loc16_25.2, call_param1 [symbolic = %.loc16_25.1 (constants.%.52b)]
  50. // CHECK:STDOUT: %self.param: @UseSelf.F.%Self.binding.as_type (%Self.binding.as_type) = value_param call_param0
  51. // CHECK:STDOUT: %.loc16_14.1: type = splice_block %.loc16_14.2 [symbolic = %Self.binding.as_type (constants.%Self.binding.as_type)] {
  52. // CHECK:STDOUT: %Self.ref.loc16_14: %UseSelf.type = name_ref Self, @UseSelf.%Self [symbolic = %Self (constants.%Self)]
  53. // CHECK:STDOUT: %Self.as_type.loc16_14: type = facet_access_type %Self.ref.loc16_14 [symbolic = %Self.binding.as_type (constants.%Self.binding.as_type)]
  54. // CHECK:STDOUT: %.loc16_14.2: type = converted %Self.ref.loc16_14, %Self.as_type.loc16_14 [symbolic = %Self.binding.as_type (constants.%Self.binding.as_type)]
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT: %self: @UseSelf.F.%Self.binding.as_type (%Self.binding.as_type) = value_binding self, %self.param
  57. // CHECK:STDOUT: %return.param: ref @UseSelf.F.%Self.binding.as_type (%Self.binding.as_type) = out_param call_param1
  58. // CHECK:STDOUT: %return: ref @UseSelf.F.%Self.binding.as_type (%Self.binding.as_type) = return_slot %return.param
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT: %assoc0: %UseSelf.assoc_type = assoc_entity element0, %UseSelf.F.decl [concrete = constants.%assoc0]
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: !members:
  63. // CHECK:STDOUT: .Self = %Self
  64. // CHECK:STDOUT: .F = %assoc0
  65. // CHECK:STDOUT: witness = (%UseSelf.F.decl)
  66. // CHECK:STDOUT:
  67. // CHECK:STDOUT: !requires:
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: generic fn @UseSelf.F(@UseSelf.%Self: %UseSelf.type) {
  71. // CHECK:STDOUT: %Self: %UseSelf.type = symbolic_binding Self, 0 [symbolic = %Self (constants.%Self)]
  72. // CHECK:STDOUT: %Self.binding.as_type: type = symbolic_binding_type Self, 0, %Self [symbolic = %Self.binding.as_type (constants.%Self.binding.as_type)]
  73. // CHECK:STDOUT: %pattern_type: type = pattern_type %Self.binding.as_type [symbolic = %pattern_type (constants.%pattern_type)]
  74. // CHECK:STDOUT: %.loc16_25.1: Core.Form = init_form %Self.binding.as_type, call_param1 [symbolic = %.loc16_25.1 (constants.%.52b)]
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: fn(%self.param: @UseSelf.F.%Self.binding.as_type (%Self.binding.as_type)) -> out %return.param: @UseSelf.F.%Self.binding.as_type (%Self.binding.as_type);
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: specific @UseSelf.F(constants.%Self) {
  80. // CHECK:STDOUT: %Self => constants.%Self
  81. // CHECK:STDOUT: %Self.binding.as_type => constants.%Self.binding.as_type
  82. // CHECK:STDOUT: %pattern_type => constants.%pattern_type
  83. // CHECK:STDOUT: %.loc16_25.1 => constants.%.52b
  84. // CHECK:STDOUT: }
  85. // CHECK:STDOUT: