raw_core.carbon 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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/packages/raw_core.carbon
  11. // TIP: To dump output, run:
  12. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/packages/raw_core.carbon
  13. // --- package_raw_core.carbon
  14. package r#Core;
  15. fn F();
  16. // --- import_raw_core.carbon
  17. library "[[@TEST_NAME]]";
  18. import r#Core;
  19. fn G() { r#Core.F(); }
  20. fn H() { Core.Int(32); }
  21. // --- fail_raw_core_not_core.carbon
  22. library "[[@TEST_NAME]]";
  23. import r#Core;
  24. // CHECK:STDERR: fail_raw_core_not_core.carbon:[[@LINE+4]]:10: error: member name `F` not found in `Core` [MemberNameNotFoundInInstScope]
  25. // CHECK:STDERR: fn G() { Core.F(); }
  26. // CHECK:STDERR: ^~~~~~
  27. // CHECK:STDERR:
  28. fn G() { Core.F(); }
  29. // CHECK:STDERR: fail_raw_core_not_core.carbon:[[@LINE+4]]:10: error: member name `Int` not found in `r#Core` [MemberNameNotFoundInInstScope]
  30. // CHECK:STDERR: fn H() { r#Core.Int(32); }
  31. // CHECK:STDERR: ^~~~~~~~~~
  32. // CHECK:STDERR:
  33. fn H() { r#Core.Int(32); }
  34. // --- class_raw_core.carbon
  35. class r#Core {
  36. var n: Core.Int(32);
  37. }
  38. var c: r#Core = {.n = 0 as Core.Int(32)};
  39. // CHECK:STDOUT: --- package_raw_core.carbon
  40. // CHECK:STDOUT:
  41. // CHECK:STDOUT: constants {
  42. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  43. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT:
  46. // CHECK:STDOUT: imports {
  47. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  48. // CHECK:STDOUT: import Core//prelude
  49. // CHECK:STDOUT: import Core//prelude/...
  50. // CHECK:STDOUT: }
  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: .F = %F.decl
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT: %Core.import = import Core
  59. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {}
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: fn @F();
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: --- import_raw_core.carbon
  65. // CHECK:STDOUT:
  66. // CHECK:STDOUT: constants {
  67. // CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
  68. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  69. // CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
  70. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  71. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  72. // CHECK:STDOUT: %H.type: type = fn_type @H [concrete]
  73. // CHECK:STDOUT: %H: %H.type = struct_value () [concrete]
  74. // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
  75. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  76. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  77. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: imports {
  81. // CHECK:STDOUT: %Core.eced1c.1: <namespace> = namespace file.%Core.import.1, [concrete] {
  82. // CHECK:STDOUT: .Int = %Core.Int
  83. // CHECK:STDOUT: import Core//prelude
  84. // CHECK:STDOUT: import Core//prelude/...
  85. // CHECK:STDOUT: }
  86. // CHECK:STDOUT: %Core.eced1c.2: <namespace> = namespace file.%Core.import.loc4, [concrete] {
  87. // CHECK:STDOUT: .F = %Core.F
  88. // CHECK:STDOUT: import Core//default
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT: %Core.F: %F.type = import_ref Core//default, F, loaded [concrete = constants.%F]
  91. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/types/int, Int, loaded [concrete = constants.%Int.generic]
  92. // CHECK:STDOUT: }
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: file {
  95. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  96. // CHECK:STDOUT: .Core = imports.%Core.eced1c.1
  97. // CHECK:STDOUT: .r#Core = imports.%Core.eced1c.2
  98. // CHECK:STDOUT: .G = %G.decl
  99. // CHECK:STDOUT: .H = %H.decl
  100. // CHECK:STDOUT: }
  101. // CHECK:STDOUT: %Core.import.1 = import Core
  102. // CHECK:STDOUT: %Core.import.loc4 = import r#Core
  103. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [concrete = constants.%G] {} {}
  104. // CHECK:STDOUT: %H.decl: %H.type = fn_decl @H [concrete = constants.%H] {} {}
  105. // CHECK:STDOUT: }
  106. // CHECK:STDOUT:
  107. // CHECK:STDOUT: fn @G() {
  108. // CHECK:STDOUT: !entry:
  109. // CHECK:STDOUT: %Core.ref: <namespace> = name_ref r#Core, imports.%Core.eced1c.2 [concrete = imports.%Core.eced1c.2]
  110. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, imports.%Core.F [concrete = constants.%F]
  111. // CHECK:STDOUT: %F.call: init %empty_tuple.type = call %F.ref()
  112. // CHECK:STDOUT: return
  113. // CHECK:STDOUT: }
  114. // CHECK:STDOUT:
  115. // CHECK:STDOUT: fn @F [from "package_raw_core.carbon"];
  116. // CHECK:STDOUT:
  117. // CHECK:STDOUT: fn @H() {
  118. // CHECK:STDOUT: !entry:
  119. // CHECK:STDOUT: %Core.ref: <namespace> = name_ref Core, imports.%Core.eced1c.1 [concrete = imports.%Core.eced1c.1]
  120. // CHECK:STDOUT: %Int.ref: %Int.type = name_ref Int, imports.%Core.Int [concrete = constants.%Int.generic]
  121. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  122. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  123. // CHECK:STDOUT: return
  124. // CHECK:STDOUT: }
  125. // CHECK:STDOUT:
  126. // CHECK:STDOUT: --- fail_raw_core_not_core.carbon
  127. // CHECK:STDOUT:
  128. // CHECK:STDOUT: constants {
  129. // CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
  130. // CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
  131. // CHECK:STDOUT: %H.type: type = fn_type @H [concrete]
  132. // CHECK:STDOUT: %H: %H.type = struct_value () [concrete]
  133. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  134. // CHECK:STDOUT: }
  135. // CHECK:STDOUT:
  136. // CHECK:STDOUT: imports {
  137. // CHECK:STDOUT: %Core.eced1c.1: <namespace> = namespace file.%Core.import.1, [concrete] {
  138. // CHECK:STDOUT: .F = <poisoned>
  139. // CHECK:STDOUT: import Core//prelude
  140. // CHECK:STDOUT: import Core//prelude/...
  141. // CHECK:STDOUT: }
  142. // CHECK:STDOUT: %Core.eced1c.2: <namespace> = namespace file.%Core.import.loc4, [concrete] {
  143. // CHECK:STDOUT: .Int = <poisoned>
  144. // CHECK:STDOUT: import Core//default
  145. // CHECK:STDOUT: }
  146. // CHECK:STDOUT: }
  147. // CHECK:STDOUT:
  148. // CHECK:STDOUT: file {
  149. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  150. // CHECK:STDOUT: .Core = imports.%Core.eced1c.1
  151. // CHECK:STDOUT: .r#Core = imports.%Core.eced1c.2
  152. // CHECK:STDOUT: .G = %G.decl
  153. // CHECK:STDOUT: .H = %H.decl
  154. // CHECK:STDOUT: }
  155. // CHECK:STDOUT: %Core.import.1 = import Core
  156. // CHECK:STDOUT: %Core.import.loc4 = import r#Core
  157. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [concrete = constants.%G] {} {}
  158. // CHECK:STDOUT: %H.decl: %H.type = fn_decl @H [concrete = constants.%H] {} {}
  159. // CHECK:STDOUT: }
  160. // CHECK:STDOUT:
  161. // CHECK:STDOUT: fn @G() {
  162. // CHECK:STDOUT: !entry:
  163. // CHECK:STDOUT: %Core.ref: <namespace> = name_ref Core, imports.%Core.eced1c.1 [concrete = imports.%Core.eced1c.1]
  164. // CHECK:STDOUT: %F.ref: <error> = name_ref F, <error> [concrete = <error>]
  165. // CHECK:STDOUT: return
  166. // CHECK:STDOUT: }
  167. // CHECK:STDOUT:
  168. // CHECK:STDOUT: fn @H() {
  169. // CHECK:STDOUT: !entry:
  170. // CHECK:STDOUT: %Core.ref: <namespace> = name_ref r#Core, imports.%Core.eced1c.2 [concrete = imports.%Core.eced1c.2]
  171. // CHECK:STDOUT: %Int.ref: <error> = name_ref Int, <error> [concrete = <error>]
  172. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  173. // CHECK:STDOUT: return
  174. // CHECK:STDOUT: }
  175. // CHECK:STDOUT:
  176. // CHECK:STDOUT: --- class_raw_core.carbon
  177. // CHECK:STDOUT:
  178. // CHECK:STDOUT: constants {
  179. // CHECK:STDOUT: %Core: type = class_type @Core [concrete]
  180. // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
  181. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  182. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  183. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  184. // CHECK:STDOUT: %Core.elem: type = unbound_element_type %Core, %i32 [concrete]
  185. // CHECK:STDOUT: %struct_type.n: type = struct_type {.n: %i32} [concrete]
  186. // CHECK:STDOUT: %complete_type.54b: <witness> = complete_type_witness %struct_type.n [concrete]
  187. // CHECK:STDOUT: %pattern_type.c8a: type = pattern_type %Core [concrete]
  188. // CHECK:STDOUT: %int_0.5c6: Core.IntLiteral = int_value 0 [concrete]
  189. // CHECK:STDOUT: %As.type.90f: type = generic_interface_type @As [concrete]
  190. // CHECK:STDOUT: %As.generic: %As.type.90f = struct_value () [concrete]
  191. // CHECK:STDOUT: %As.type.fd4: type = facet_type <@As, @As(%i32)> [concrete]
  192. // CHECK:STDOUT: %Convert.type.99b: type = fn_type @Convert.1, @As(%i32) [concrete]
  193. // CHECK:STDOUT: %To.c80: Core.IntLiteral = bind_symbolic_name To, 0 [symbolic]
  194. // CHECK:STDOUT: %Convert.type.062: type = fn_type @Convert.6, @impl.686(%To.c80) [symbolic]
  195. // CHECK:STDOUT: %Convert.527: %Convert.type.062 = struct_value () [symbolic]
  196. // CHECK:STDOUT: %As.impl_witness.6b4: <witness> = impl_witness imports.%As.impl_witness_table.eb4, @impl.686(%int_32) [concrete]
  197. // CHECK:STDOUT: %Convert.type.4fd: type = fn_type @Convert.6, @impl.686(%int_32) [concrete]
  198. // CHECK:STDOUT: %Convert.197: %Convert.type.4fd = struct_value () [concrete]
  199. // CHECK:STDOUT: %As.facet: %As.type.fd4 = facet_value Core.IntLiteral, (%As.impl_witness.6b4) [concrete]
  200. // CHECK:STDOUT: %.982: type = fn_type_with_self_type %Convert.type.99b, %As.facet [concrete]
  201. // CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %int_0.5c6, %Convert.197 [concrete]
  202. // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.197, @Convert.6(%int_32) [concrete]
  203. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %int_0.5c6, %Convert.specific_fn [concrete]
  204. // CHECK:STDOUT: %int_0.6a9: %i32 = int_value 0 [concrete]
  205. // CHECK:STDOUT: %.96d: ref %i32 = class_element_access file.%c.var, element0 [concrete]
  206. // CHECK:STDOUT: %Core.val: %Core = struct_value (%int_0.6a9) [concrete]
  207. // CHECK:STDOUT: }
  208. // CHECK:STDOUT:
  209. // CHECK:STDOUT: imports {
  210. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  211. // CHECK:STDOUT: .Int = %Core.Int
  212. // CHECK:STDOUT: .As = %Core.As
  213. // CHECK:STDOUT: import Core//prelude
  214. // CHECK:STDOUT: import Core//prelude/...
  215. // CHECK:STDOUT: }
  216. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/types/int, Int, loaded [concrete = constants.%Int.generic]
  217. // CHECK:STDOUT: %Core.As: %As.type.90f = import_ref Core//prelude/operators/as, As, loaded [concrete = constants.%As.generic]
  218. // CHECK:STDOUT: %Core.import_ref.78a: @impl.686.%Convert.type (%Convert.type.062) = import_ref Core//prelude/types/int, loc28_39, loaded [symbolic = @impl.686.%Convert (constants.%Convert.527)]
  219. // CHECK:STDOUT: %As.impl_witness_table.eb4 = impl_witness_table (%Core.import_ref.78a), @impl.686 [concrete]
  220. // CHECK:STDOUT: }
  221. // CHECK:STDOUT:
  222. // CHECK:STDOUT: file {
  223. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  224. // CHECK:STDOUT: .Core = imports.%Core
  225. // CHECK:STDOUT: .r#Core = %Core.decl
  226. // CHECK:STDOUT: .c = %c
  227. // CHECK:STDOUT: }
  228. // CHECK:STDOUT: %Core.import = import Core
  229. // CHECK:STDOUT: %Core.decl: type = class_decl @Core [concrete = constants.%Core] {} {}
  230. // CHECK:STDOUT: name_binding_decl {
  231. // CHECK:STDOUT: %c.patt: %pattern_type.c8a = binding_pattern c [concrete]
  232. // CHECK:STDOUT: %c.var_patt: %pattern_type.c8a = var_pattern %c.patt [concrete]
  233. // CHECK:STDOUT: }
  234. // CHECK:STDOUT: %c.var: ref %Core = var %c.var_patt [concrete]
  235. // CHECK:STDOUT: %Core.ref: type = name_ref r#Core, %Core.decl [concrete = constants.%Core]
  236. // CHECK:STDOUT: %c: ref %Core = bind_name c, %c.var [concrete = %c.var]
  237. // CHECK:STDOUT: }
  238. // CHECK:STDOUT:
  239. // CHECK:STDOUT: class @Core {
  240. // CHECK:STDOUT: %Core.ref: <namespace> = name_ref Core, imports.%Core [concrete = imports.%Core]
  241. // CHECK:STDOUT: %Int.ref: %Int.type = name_ref Int, imports.%Core.Int [concrete = constants.%Int.generic]
  242. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  243. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  244. // CHECK:STDOUT: %.loc3: %Core.elem = field_decl n, element0 [concrete]
  245. // CHECK:STDOUT: %struct_type.n: type = struct_type {.n: %i32} [concrete = constants.%struct_type.n]
  246. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.n [concrete = constants.%complete_type.54b]
  247. // CHECK:STDOUT: complete_type_witness = %complete_type
  248. // CHECK:STDOUT:
  249. // CHECK:STDOUT: !members:
  250. // CHECK:STDOUT: .Self = constants.%Core
  251. // CHECK:STDOUT: .n = %.loc3
  252. // CHECK:STDOUT: }
  253. // CHECK:STDOUT:
  254. // CHECK:STDOUT: fn @__global_init() {
  255. // CHECK:STDOUT: !entry:
  256. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [concrete = constants.%int_0.5c6]
  257. // CHECK:STDOUT: %Core.ref: <namespace> = name_ref Core, imports.%Core [concrete = imports.%Core]
  258. // CHECK:STDOUT: %Int.ref: %Int.type = name_ref Int, imports.%Core.Int [concrete = constants.%Int.generic]
  259. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  260. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  261. // CHECK:STDOUT: %impl.elem0: %.982 = impl_witness_access constants.%As.impl_witness.6b4, element0 [concrete = constants.%Convert.197]
  262. // CHECK:STDOUT: %bound_method.loc6_25.1: <bound method> = bound_method %int_0, %impl.elem0 [concrete = constants.%Convert.bound]
  263. // CHECK:STDOUT: %specific_fn: <specific function> = specific_function %impl.elem0, @Convert.6(constants.%int_32) [concrete = constants.%Convert.specific_fn]
  264. // CHECK:STDOUT: %bound_method.loc6_25.2: <bound method> = bound_method %int_0, %specific_fn [concrete = constants.%bound_method]
  265. // CHECK:STDOUT: %int.convert_checked: init %i32 = call %bound_method.loc6_25.2(%int_0) [concrete = constants.%int_0.6a9]
  266. // CHECK:STDOUT: %.loc6_25.1: %i32 = value_of_initializer %int.convert_checked [concrete = constants.%int_0.6a9]
  267. // CHECK:STDOUT: %.loc6_25.2: %i32 = converted %int_0, %.loc6_25.1 [concrete = constants.%int_0.6a9]
  268. // CHECK:STDOUT: %.loc6_40.1: %struct_type.n = struct_literal (%.loc6_25.2)
  269. // CHECK:STDOUT: %.loc6_40.2: ref %i32 = class_element_access file.%c.var, element0 [concrete = constants.%.96d]
  270. // CHECK:STDOUT: %.loc6_40.3: init %i32 = initialize_from %.loc6_25.2 to %.loc6_40.2 [concrete = constants.%int_0.6a9]
  271. // CHECK:STDOUT: %.loc6_40.4: init %Core = class_init (%.loc6_40.3), file.%c.var [concrete = constants.%Core.val]
  272. // CHECK:STDOUT: %.loc6_1: init %Core = converted %.loc6_40.1, %.loc6_40.4 [concrete = constants.%Core.val]
  273. // CHECK:STDOUT: assign file.%c.var, %.loc6_1
  274. // CHECK:STDOUT: return
  275. // CHECK:STDOUT: }
  276. // CHECK:STDOUT: