simple_init.carbon 5.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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/global/simple_init.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/global/simple_init.carbon
  10. var a: i32 = 0;
  11. // CHECK:STDOUT: --- simple_init.carbon
  12. // CHECK:STDOUT:
  13. // CHECK:STDOUT: constants {
  14. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  15. // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
  16. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  17. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  18. // CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
  19. // CHECK:STDOUT: %int_0.5c6: Core.IntLiteral = int_value 0 [concrete]
  20. // CHECK:STDOUT: %ImplicitAs.type.cc7: type = generic_interface_type @ImplicitAs [concrete]
  21. // CHECK:STDOUT: %ImplicitAs.generic: %ImplicitAs.type.cc7 = struct_value () [concrete]
  22. // CHECK:STDOUT: %ImplicitAs.type.205: type = facet_type <@ImplicitAs, @ImplicitAs(%i32)> [concrete]
  23. // CHECK:STDOUT: %Convert.type.1b6: type = fn_type @Convert.1, @ImplicitAs(%i32) [concrete]
  24. // CHECK:STDOUT: %To.c80: Core.IntLiteral = bind_symbolic_name To, 0 [symbolic]
  25. // CHECK:STDOUT: %Convert.type.0f9: type = fn_type @Convert.2, @impl.4f9(%To.c80) [symbolic]
  26. // CHECK:STDOUT: %Convert.f06: %Convert.type.0f9 = struct_value () [symbolic]
  27. // CHECK:STDOUT: %ImplicitAs.impl_witness.c75: <witness> = impl_witness imports.%ImplicitAs.impl_witness_table.a2f, @impl.4f9(%int_32) [concrete]
  28. // CHECK:STDOUT: %Convert.type.035: type = fn_type @Convert.2, @impl.4f9(%int_32) [concrete]
  29. // CHECK:STDOUT: %Convert.956: %Convert.type.035 = struct_value () [concrete]
  30. // CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.205 = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.c75) [concrete]
  31. // CHECK:STDOUT: %.9c3: type = fn_type_with_self_type %Convert.type.1b6, %ImplicitAs.facet [concrete]
  32. // CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %int_0.5c6, %Convert.956 [concrete]
  33. // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.956, @Convert.2(%int_32) [concrete]
  34. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %int_0.5c6, %Convert.specific_fn [concrete]
  35. // CHECK:STDOUT: %int_0.6a9: %i32 = int_value 0 [concrete]
  36. // CHECK:STDOUT: }
  37. // CHECK:STDOUT:
  38. // CHECK:STDOUT: imports {
  39. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  40. // CHECK:STDOUT: .Int = %Core.Int
  41. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  42. // CHECK:STDOUT: import Core//prelude
  43. // CHECK:STDOUT: import Core//prelude/...
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/types/int, Int, loaded [concrete = constants.%Int.generic]
  46. // CHECK:STDOUT: %Core.ImplicitAs: %ImplicitAs.type.cc7 = import_ref Core//prelude/operators/as, ImplicitAs, loaded [concrete = constants.%ImplicitAs.generic]
  47. // CHECK:STDOUT: %Core.import_ref.a5b: @impl.4f9.%Convert.type (%Convert.type.0f9) = import_ref Core//prelude/types/int, loc19_39, loaded [symbolic = @impl.4f9.%Convert (constants.%Convert.f06)]
  48. // CHECK:STDOUT: %ImplicitAs.impl_witness_table.a2f = impl_witness_table (%Core.import_ref.a5b), @impl.4f9 [concrete]
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: file {
  52. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  53. // CHECK:STDOUT: .Core = imports.%Core
  54. // CHECK:STDOUT: .a = %a
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT: %Core.import = import Core
  57. // CHECK:STDOUT: name_binding_decl {
  58. // CHECK:STDOUT: %a.patt: %pattern_type.7ce = binding_pattern a [concrete]
  59. // CHECK:STDOUT: %a.var_patt: %pattern_type.7ce = var_pattern %a.patt [concrete]
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT: %a.var: ref %i32 = var %a.var_patt [concrete]
  62. // CHECK:STDOUT: %.loc10: type = splice_block %i32 [concrete = constants.%i32] {
  63. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  64. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT: %a: ref %i32 = bind_name a, %a.var
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT:
  69. // CHECK:STDOUT: fn @__global_init() {
  70. // CHECK:STDOUT: !entry:
  71. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [concrete = constants.%int_0.5c6]
  72. // CHECK:STDOUT: %impl.elem0: %.9c3 = impl_witness_access constants.%ImplicitAs.impl_witness.c75, element0 [concrete = constants.%Convert.956]
  73. // CHECK:STDOUT: %bound_method.loc10_1.1: <bound method> = bound_method %int_0, %impl.elem0 [concrete = constants.%Convert.bound]
  74. // CHECK:STDOUT: %specific_fn: <specific function> = specific_function %impl.elem0, @Convert.2(constants.%int_32) [concrete = constants.%Convert.specific_fn]
  75. // CHECK:STDOUT: %bound_method.loc10_1.2: <bound method> = bound_method %int_0, %specific_fn [concrete = constants.%bound_method]
  76. // CHECK:STDOUT: %int.convert_checked: init %i32 = call %bound_method.loc10_1.2(%int_0) [concrete = constants.%int_0.6a9]
  77. // CHECK:STDOUT: %.loc10: init %i32 = converted %int_0, %int.convert_checked [concrete = constants.%int_0.6a9]
  78. // CHECK:STDOUT: assign file.%a.var, %.loc10
  79. // CHECK:STDOUT: return
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT: