self.carbon 6.2 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. // 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.as_type: type = facet_access_type %Self [symbolic]
  23. // CHECK:STDOUT: %pattern_type: type = pattern_type %Self.as_type [symbolic]
  24. // CHECK:STDOUT: %.4e5: Core.Form = init_form %Self.as_type [symbolic]
  25. // CHECK:STDOUT: %UseSelf.WithSelf.F.type: type = fn_type @UseSelf.WithSelf.F, @UseSelf.WithSelf(%Self) [symbolic]
  26. // CHECK:STDOUT: %UseSelf.WithSelf.F: %UseSelf.WithSelf.F.type = struct_value () [symbolic]
  27. // CHECK:STDOUT: %UseSelf.assoc_type: type = assoc_entity_type @UseSelf [concrete]
  28. // CHECK:STDOUT: %assoc0: %UseSelf.assoc_type = assoc_entity element0, @UseSelf.WithSelf.%UseSelf.WithSelf.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.WithSelf.decl = interface_with_self_decl @UseSelf [concrete]
  41. // CHECK:STDOUT:
  42. // CHECK:STDOUT: !with Self:
  43. // CHECK:STDOUT: %UseSelf.WithSelf.F.decl: @UseSelf.WithSelf.%UseSelf.WithSelf.F.type (%UseSelf.WithSelf.F.type) = fn_decl @UseSelf.WithSelf.F [symbolic = @UseSelf.WithSelf.%UseSelf.WithSelf.F (constants.%UseSelf.WithSelf.F)] {
  44. // CHECK:STDOUT: %self.param_patt: @UseSelf.WithSelf.F.%pattern_type (%pattern_type) = value_param_pattern [concrete]
  45. // CHECK:STDOUT: %self.patt: @UseSelf.WithSelf.F.%pattern_type (%pattern_type) = at_binding_pattern self, %self.param_patt [concrete]
  46. // CHECK:STDOUT: %return.param_patt: @UseSelf.WithSelf.F.%pattern_type (%pattern_type) = out_param_pattern [concrete]
  47. // CHECK:STDOUT: %return.patt: @UseSelf.WithSelf.F.%pattern_type (%pattern_type) = return_slot_pattern %return.param_patt, %.loc16_25.2 [concrete]
  48. // CHECK:STDOUT: } {
  49. // CHECK:STDOUT: %Self.ref.loc16_25: %UseSelf.type = name_ref Self, @UseSelf.%Self [symbolic = %Self (constants.%Self)]
  50. // CHECK:STDOUT: %Self.as_type.loc16_25: type = facet_access_type %Self.ref.loc16_25 [symbolic = %Self.as_type.loc16_14.1 (constants.%Self.as_type)]
  51. // CHECK:STDOUT: %.loc16_25.2: type = converted %Self.ref.loc16_25, %Self.as_type.loc16_25 [symbolic = %Self.as_type.loc16_14.1 (constants.%Self.as_type)]
  52. // CHECK:STDOUT: %.loc16_25.3: Core.Form = init_form %.loc16_25.2 [symbolic = %.loc16_25.1 (constants.%.4e5)]
  53. // CHECK:STDOUT: %self.param: @UseSelf.WithSelf.F.%Self.as_type.loc16_14.1 (%Self.as_type) = value_param call_param0
  54. // CHECK:STDOUT: %.loc16_14.1: type = splice_block %.loc16_14.2 [symbolic = %Self.as_type.loc16_14.1 (constants.%Self.as_type)] {
  55. // CHECK:STDOUT: %Self.ref.loc16_14: %UseSelf.type = name_ref Self, @UseSelf.%Self [symbolic = %Self (constants.%Self)]
  56. // CHECK:STDOUT: %Self.as_type.loc16_14.2: type = facet_access_type %Self.ref.loc16_14 [symbolic = %Self.as_type.loc16_14.1 (constants.%Self.as_type)]
  57. // CHECK:STDOUT: %.loc16_14.2: type = converted %Self.ref.loc16_14, %Self.as_type.loc16_14.2 [symbolic = %Self.as_type.loc16_14.1 (constants.%Self.as_type)]
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT: %self: @UseSelf.WithSelf.F.%Self.as_type.loc16_14.1 (%Self.as_type) = value_binding self, %self.param
  60. // CHECK:STDOUT: %return.param: ref @UseSelf.WithSelf.F.%Self.as_type.loc16_14.1 (%Self.as_type) = out_param call_param1
  61. // CHECK:STDOUT: %return: ref @UseSelf.WithSelf.F.%Self.as_type.loc16_14.1 (%Self.as_type) = return_slot %return.param
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT: %assoc0: %UseSelf.assoc_type = assoc_entity element0, %UseSelf.WithSelf.F.decl [concrete = constants.%assoc0]
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: !members:
  66. // CHECK:STDOUT: .Self = %Self
  67. // CHECK:STDOUT: .F = @UseSelf.WithSelf.%assoc0
  68. // CHECK:STDOUT: witness = (@UseSelf.WithSelf.%UseSelf.WithSelf.F.decl)
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: !requires:
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT:
  73. // CHECK:STDOUT: generic fn @UseSelf.WithSelf.F(@UseSelf.%Self: %UseSelf.type) {
  74. // CHECK:STDOUT: %Self: %UseSelf.type = symbolic_binding Self, 0 [symbolic = %Self (constants.%Self)]
  75. // CHECK:STDOUT: %Self.as_type.loc16_14.1: type = facet_access_type %Self [symbolic = %Self.as_type.loc16_14.1 (constants.%Self.as_type)]
  76. // CHECK:STDOUT: %pattern_type: type = pattern_type %Self.as_type.loc16_14.1 [symbolic = %pattern_type (constants.%pattern_type)]
  77. // CHECK:STDOUT: %.loc16_25.1: Core.Form = init_form %Self.as_type.loc16_14.1 [symbolic = %.loc16_25.1 (constants.%.4e5)]
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: fn(%self.param: @UseSelf.WithSelf.F.%Self.as_type.loc16_14.1 (%Self.as_type)) -> out %return.param: @UseSelf.WithSelf.F.%Self.as_type.loc16_14.1 (%Self.as_type);
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT:
  82. // CHECK:STDOUT: specific @UseSelf.WithSelf(constants.%Self) {}
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: specific @UseSelf.WithSelf.F(constants.%Self) {
  85. // CHECK:STDOUT: %Self => constants.%Self
  86. // CHECK:STDOUT: %Self.as_type.loc16_14.1 => constants.%Self.as_type
  87. // CHECK:STDOUT: %pattern_type => constants.%pattern_type
  88. // CHECK:STDOUT: %.loc16_25.1 => constants.%.4e5
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT: