raw_self.carbon 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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/raw_self.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/raw_self.carbon
  10. class Class {
  11. fn F[addr self: Self*](r#self: i32);
  12. fn G[self: Self](r#self: i32) -> (i32, i32);
  13. var n: i32;
  14. }
  15. fn Class.F[addr self: Self*](r#self: i32) {
  16. (*self).n = r#self;
  17. }
  18. fn Class.G[self: Self](r#self: i32) -> (i32, i32) {
  19. return (self.n, r#self);
  20. }
  21. // CHECK:STDOUT: --- raw_self.carbon
  22. // CHECK:STDOUT:
  23. // CHECK:STDOUT: constants {
  24. // CHECK:STDOUT: %Class: type = class_type @Class [template]
  25. // CHECK:STDOUT: %.1: type = ptr_type %Class [template]
  26. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  27. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  28. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  29. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  30. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  31. // CHECK:STDOUT: %.3: type = tuple_type (type, type) [template]
  32. // CHECK:STDOUT: %.4: type = tuple_type (i32, i32) [template]
  33. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  34. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  35. // CHECK:STDOUT: %.5: type = unbound_element_type %Class, i32 [template]
  36. // CHECK:STDOUT: %.6: type = struct_type {.n: i32} [template]
  37. // CHECK:STDOUT: %.7: <witness> = complete_type_witness %.6 [template]
  38. // CHECK:STDOUT: %.8: type = ptr_type %.6 [template]
  39. // CHECK:STDOUT: %.9: type = ptr_type %.4 [template]
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT:
  42. // CHECK:STDOUT: imports {
  43. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  44. // CHECK:STDOUT: .Int32 = %import_ref
  45. // CHECK:STDOUT: import Core//prelude
  46. // CHECK:STDOUT: import Core//prelude/operators
  47. // CHECK:STDOUT: import Core//prelude/types
  48. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  49. // CHECK:STDOUT: import Core//prelude/operators/as
  50. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  51. // CHECK:STDOUT: import Core//prelude/operators/comparison
  52. // CHECK:STDOUT: import Core//prelude/types/bool
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT:
  57. // CHECK:STDOUT: file {
  58. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  59. // CHECK:STDOUT: .Core = imports.%Core
  60. // CHECK:STDOUT: .Class = %Class.decl
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT: %Core.import = import Core
  63. // CHECK:STDOUT: %Class.decl: type = class_decl @Class [template = constants.%Class] {} {}
  64. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  65. // CHECK:STDOUT: %self.patt.loc17_17: %.1 = binding_pattern self
  66. // CHECK:STDOUT: %self.patt.loc17_30: i32 = binding_pattern r#self
  67. // CHECK:STDOUT: } {
  68. // CHECK:STDOUT: %Self.ref.loc17: type = name_ref Self, constants.%Class [template = constants.%Class]
  69. // CHECK:STDOUT: %.loc17_27: type = ptr_type %Class [template = constants.%.1]
  70. // CHECK:STDOUT: %self.param.loc17_17: %.1 = param self, runtime_param0
  71. // CHECK:STDOUT: %self.loc17_17: %.1 = bind_name self, %self.param.loc17_17
  72. // CHECK:STDOUT: %.loc17_12: %.1 = addr_pattern %self.loc17_17
  73. // CHECK:STDOUT: %int.make_type_32.loc17: init type = call constants.%Int32() [template = i32]
  74. // CHECK:STDOUT: %.loc17_38.1: type = value_of_initializer %int.make_type_32.loc17 [template = i32]
  75. // CHECK:STDOUT: %.loc17_38.2: type = converted %int.make_type_32.loc17, %.loc17_38.1 [template = i32]
  76. // CHECK:STDOUT: %self.param.loc17_30: i32 = param r#self, runtime_param1
  77. // CHECK:STDOUT: %self.loc17_30: i32 = bind_name r#self, %self.param.loc17_30
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  80. // CHECK:STDOUT: %self.patt.loc21_12: %Class = binding_pattern self
  81. // CHECK:STDOUT: %self.patt.loc21_24: i32 = binding_pattern r#self
  82. // CHECK:STDOUT: } {
  83. // CHECK:STDOUT: %Self.ref.loc21: type = name_ref Self, constants.%Class [template = constants.%Class]
  84. // CHECK:STDOUT: %self.param.loc21_12: %Class = param self, runtime_param0
  85. // CHECK:STDOUT: %self.loc21_12: %Class = bind_name self, %self.param.loc21_12
  86. // CHECK:STDOUT: %int.make_type_32.loc21_32: init type = call constants.%Int32() [template = i32]
  87. // CHECK:STDOUT: %.loc21_32.1: type = value_of_initializer %int.make_type_32.loc21_32 [template = i32]
  88. // CHECK:STDOUT: %.loc21_32.2: type = converted %int.make_type_32.loc21_32, %.loc21_32.1 [template = i32]
  89. // CHECK:STDOUT: %self.param.loc21_24: i32 = param r#self, runtime_param1
  90. // CHECK:STDOUT: %self.loc21_24: i32 = bind_name r#self, %self.param.loc21_24
  91. // CHECK:STDOUT: %int.make_type_32.loc21_41: init type = call constants.%Int32() [template = i32]
  92. // CHECK:STDOUT: %int.make_type_32.loc21_46: init type = call constants.%Int32() [template = i32]
  93. // CHECK:STDOUT: %.loc21_49.1: %.3 = tuple_literal (%int.make_type_32.loc21_41, %int.make_type_32.loc21_46)
  94. // CHECK:STDOUT: %.loc21_49.2: type = value_of_initializer %int.make_type_32.loc21_41 [template = i32]
  95. // CHECK:STDOUT: %.loc21_49.3: type = converted %int.make_type_32.loc21_41, %.loc21_49.2 [template = i32]
  96. // CHECK:STDOUT: %.loc21_49.4: type = value_of_initializer %int.make_type_32.loc21_46 [template = i32]
  97. // CHECK:STDOUT: %.loc21_49.5: type = converted %int.make_type_32.loc21_46, %.loc21_49.4 [template = i32]
  98. // CHECK:STDOUT: %.loc21_49.6: type = converted %.loc21_49.1, constants.%.4 [template = constants.%.4]
  99. // CHECK:STDOUT: %return: ref %.4 = var <return slot>
  100. // CHECK:STDOUT: }
  101. // CHECK:STDOUT: }
  102. // CHECK:STDOUT:
  103. // CHECK:STDOUT: class @Class {
  104. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  105. // CHECK:STDOUT: %self.patt.loc17_17: %.1 = binding_pattern self
  106. // CHECK:STDOUT: %self.patt.loc17_30: i32 = binding_pattern r#self
  107. // CHECK:STDOUT: } {
  108. // CHECK:STDOUT: %Self.ref.loc12: type = name_ref Self, constants.%Class [template = constants.%Class]
  109. // CHECK:STDOUT: %.loc12_23: type = ptr_type %Class [template = constants.%.1]
  110. // CHECK:STDOUT: %self.param.loc12_13: %.1 = param self, runtime_param0
  111. // CHECK:STDOUT: %self.loc12_13: %.1 = bind_name self, %self.param.loc12_13
  112. // CHECK:STDOUT: %.loc12_8: %.1 = addr_pattern %self.loc12_13
  113. // CHECK:STDOUT: %int.make_type_32.loc12: init type = call constants.%Int32() [template = i32]
  114. // CHECK:STDOUT: %.loc12_34.1: type = value_of_initializer %int.make_type_32.loc12 [template = i32]
  115. // CHECK:STDOUT: %.loc12_34.2: type = converted %int.make_type_32.loc12, %.loc12_34.1 [template = i32]
  116. // CHECK:STDOUT: %self.param.loc12_26: i32 = param r#self, runtime_param1
  117. // CHECK:STDOUT: %self.loc12_26: i32 = bind_name r#self, %self.param.loc12_26
  118. // CHECK:STDOUT: }
  119. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  120. // CHECK:STDOUT: %self.patt.loc21_12: %Class = binding_pattern self
  121. // CHECK:STDOUT: %self.patt.loc21_24: i32 = binding_pattern r#self
  122. // CHECK:STDOUT: } {
  123. // CHECK:STDOUT: %Self.ref.loc13: type = name_ref Self, constants.%Class [template = constants.%Class]
  124. // CHECK:STDOUT: %self.param.loc13_8: %Class = param self, runtime_param0
  125. // CHECK:STDOUT: %self.loc13_8: %Class = bind_name self, %self.param.loc13_8
  126. // CHECK:STDOUT: %int.make_type_32.loc13_28: init type = call constants.%Int32() [template = i32]
  127. // CHECK:STDOUT: %.loc13_28.1: type = value_of_initializer %int.make_type_32.loc13_28 [template = i32]
  128. // CHECK:STDOUT: %.loc13_28.2: type = converted %int.make_type_32.loc13_28, %.loc13_28.1 [template = i32]
  129. // CHECK:STDOUT: %self.param.loc13_20: i32 = param r#self, runtime_param1
  130. // CHECK:STDOUT: %self.loc13_20: i32 = bind_name r#self, %self.param.loc13_20
  131. // CHECK:STDOUT: %int.make_type_32.loc13_37: init type = call constants.%Int32() [template = i32]
  132. // CHECK:STDOUT: %int.make_type_32.loc13_42: init type = call constants.%Int32() [template = i32]
  133. // CHECK:STDOUT: %.loc13_45.1: %.3 = tuple_literal (%int.make_type_32.loc13_37, %int.make_type_32.loc13_42)
  134. // CHECK:STDOUT: %.loc13_45.2: type = value_of_initializer %int.make_type_32.loc13_37 [template = i32]
  135. // CHECK:STDOUT: %.loc13_45.3: type = converted %int.make_type_32.loc13_37, %.loc13_45.2 [template = i32]
  136. // CHECK:STDOUT: %.loc13_45.4: type = value_of_initializer %int.make_type_32.loc13_42 [template = i32]
  137. // CHECK:STDOUT: %.loc13_45.5: type = converted %int.make_type_32.loc13_42, %.loc13_45.4 [template = i32]
  138. // CHECK:STDOUT: %.loc13_45.6: type = converted %.loc13_45.1, constants.%.4 [template = constants.%.4]
  139. // CHECK:STDOUT: %return.var.loc13: ref %.4 = var <return slot>
  140. // CHECK:STDOUT: }
  141. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  142. // CHECK:STDOUT: %.loc14_10.1: type = value_of_initializer %int.make_type_32 [template = i32]
  143. // CHECK:STDOUT: %.loc14_10.2: type = converted %int.make_type_32, %.loc14_10.1 [template = i32]
  144. // CHECK:STDOUT: %.loc14_8: %.5 = field_decl n, element0 [template]
  145. // CHECK:STDOUT: %.loc15: <witness> = complete_type_witness %.6 [template = constants.%.7]
  146. // CHECK:STDOUT:
  147. // CHECK:STDOUT: !members:
  148. // CHECK:STDOUT: .Self = constants.%Class
  149. // CHECK:STDOUT: .F = %F.decl
  150. // CHECK:STDOUT: .G = %G.decl
  151. // CHECK:STDOUT: .n = %.loc14_8
  152. // CHECK:STDOUT: }
  153. // CHECK:STDOUT:
  154. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  155. // CHECK:STDOUT:
  156. // CHECK:STDOUT: fn @F[addr %self.loc17_17: %.1](%self.loc17_30: i32) {
  157. // CHECK:STDOUT: !entry:
  158. // CHECK:STDOUT: %self.ref.loc18_5: %.1 = name_ref self, %self.loc17_17
  159. // CHECK:STDOUT: %.loc18_4: ref %Class = deref %self.ref.loc18_5
  160. // CHECK:STDOUT: %n.ref: %.5 = name_ref n, @Class.%.loc14_8 [template = @Class.%.loc14_8]
  161. // CHECK:STDOUT: %.loc18_10: ref i32 = class_element_access %.loc18_4, element0
  162. // CHECK:STDOUT: %self.ref.loc18_15: i32 = name_ref r#self, %self.loc17_30
  163. // CHECK:STDOUT: assign %.loc18_10, %self.ref.loc18_15
  164. // CHECK:STDOUT: return
  165. // CHECK:STDOUT: }
  166. // CHECK:STDOUT:
  167. // CHECK:STDOUT: fn @G[%self.loc21_12: %Class](%self.loc21_24: i32) -> %return: %.4 {
  168. // CHECK:STDOUT: !entry:
  169. // CHECK:STDOUT: %self.ref.loc22_11: %Class = name_ref self, %self.loc21_12
  170. // CHECK:STDOUT: %n.ref: %.5 = name_ref n, @Class.%.loc14_8 [template = @Class.%.loc14_8]
  171. // CHECK:STDOUT: %.loc22_15.1: ref i32 = class_element_access %self.ref.loc22_11, element0
  172. // CHECK:STDOUT: %.loc22_15.2: i32 = bind_value %.loc22_15.1
  173. // CHECK:STDOUT: %self.ref.loc22_19: i32 = name_ref r#self, %self.loc21_24
  174. // CHECK:STDOUT: %.loc22_25.1: %.4 = tuple_literal (%.loc22_15.2, %self.ref.loc22_19)
  175. // CHECK:STDOUT: %.loc22_25.2: ref i32 = tuple_access %return, element0
  176. // CHECK:STDOUT: %.loc22_25.3: init i32 = initialize_from %.loc22_15.2 to %.loc22_25.2
  177. // CHECK:STDOUT: %.loc22_25.4: ref i32 = tuple_access %return, element1
  178. // CHECK:STDOUT: %.loc22_25.5: init i32 = initialize_from %self.ref.loc22_19 to %.loc22_25.4
  179. // CHECK:STDOUT: %.loc22_25.6: init %.4 = tuple_init (%.loc22_25.3, %.loc22_25.5) to %return
  180. // CHECK:STDOUT: %.loc22_26: init %.4 = converted %.loc22_25.1, %.loc22_25.6
  181. // CHECK:STDOUT: return %.loc22_26 to %return
  182. // CHECK:STDOUT: }
  183. // CHECK:STDOUT: