var_init.carbon 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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/convert.carbon
  6. //
  7. // AUTOUPDATE
  8. // TIP: To test this file alone, run:
  9. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/as/var_init.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/as/var_init.carbon
  12. // --- var_init.carbon
  13. library "[[@TEST_NAME]]";
  14. class X {
  15. impl () as Core.ImplicitAs(X) {
  16. fn Convert[self: ()]() -> X { return {}; }
  17. }
  18. }
  19. fn Convert(t: ()) {
  20. //@dump-sem-ir-begin
  21. var x: X = ();
  22. //@dump-sem-ir-end
  23. }
  24. // CHECK:STDOUT: --- var_init.carbon
  25. // CHECK:STDOUT:
  26. // CHECK:STDOUT: constants {
  27. // CHECK:STDOUT: %X: type = class_type @X [concrete]
  28. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  29. // CHECK:STDOUT: %empty_tuple: %empty_tuple.type = tuple_value () [concrete]
  30. // CHECK:STDOUT: %ImplicitAs.type.179: type = facet_type <@ImplicitAs, @ImplicitAs(%X)> [concrete]
  31. // CHECK:STDOUT: %ImplicitAs.Convert.type.665: type = fn_type @ImplicitAs.Convert, @ImplicitAs(%X) [concrete]
  32. // CHECK:STDOUT: %ImplicitAs.impl_witness: <witness> = impl_witness @X.%ImplicitAs.impl_witness_table [concrete]
  33. // CHECK:STDOUT: %pattern_type.019: type = pattern_type %X [concrete]
  34. // CHECK:STDOUT: %empty_tuple.type.as.ImplicitAs.impl.Convert.type: type = fn_type @empty_tuple.type.as.ImplicitAs.impl.Convert [concrete]
  35. // CHECK:STDOUT: %empty_tuple.type.as.ImplicitAs.impl.Convert: %empty_tuple.type.as.ImplicitAs.impl.Convert.type = struct_value () [concrete]
  36. // CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.179 = facet_value %empty_tuple.type, (%ImplicitAs.impl_witness) [concrete]
  37. // CHECK:STDOUT: %.f5e: type = fn_type_with_self_type %ImplicitAs.Convert.type.665, %ImplicitAs.facet [concrete]
  38. // CHECK:STDOUT: %empty_tuple.type.as.ImplicitAs.impl.Convert.bound: <bound method> = bound_method %empty_tuple, %empty_tuple.type.as.ImplicitAs.impl.Convert [concrete]
  39. // CHECK:STDOUT: %type_where: type = facet_type <type where .Self impls <CanDestroy>> [concrete]
  40. // CHECK:STDOUT: %facet_value: %type_where = facet_value %X, () [concrete]
  41. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.type.bd5: type = fn_type @DestroyT.binding.as_type.as.Destroy.impl.Op, @DestroyT.binding.as_type.as.Destroy.impl(%facet_value) [concrete]
  42. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.1c8: %DestroyT.binding.as_type.as.Destroy.impl.Op.type.bd5 = struct_value () [concrete]
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT:
  45. // CHECK:STDOUT: imports {
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT:
  48. // CHECK:STDOUT: fn @Convert(%t.param: %empty_tuple.type) {
  49. // CHECK:STDOUT: !entry:
  50. // CHECK:STDOUT: name_binding_decl {
  51. // CHECK:STDOUT: %x.patt: %pattern_type.019 = ref_binding_pattern x [concrete]
  52. // CHECK:STDOUT: %x.var_patt: %pattern_type.019 = var_pattern %x.patt [concrete]
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT: %x.var: ref %X = var %x.var_patt
  55. // CHECK:STDOUT: %.loc12_15.1: %empty_tuple.type = tuple_literal () [concrete = constants.%empty_tuple]
  56. // CHECK:STDOUT: %impl.elem0: %.f5e = impl_witness_access constants.%ImplicitAs.impl_witness, element0 [concrete = constants.%empty_tuple.type.as.ImplicitAs.impl.Convert]
  57. // CHECK:STDOUT: %bound_method.loc12_3.1: <bound method> = bound_method %.loc12_15.1, %impl.elem0 [concrete = constants.%empty_tuple.type.as.ImplicitAs.impl.Convert.bound]
  58. // CHECK:STDOUT: %.loc12_3.1: ref %X = splice_block %x.var {}
  59. // CHECK:STDOUT: %empty_tuple: %empty_tuple.type = tuple_value () [concrete = constants.%empty_tuple]
  60. // CHECK:STDOUT: %.loc12_15.2: %empty_tuple.type = converted %.loc12_15.1, %empty_tuple [concrete = constants.%empty_tuple]
  61. // CHECK:STDOUT: %empty_tuple.type.as.ImplicitAs.impl.Convert.call: init %X = call %bound_method.loc12_3.1(%.loc12_15.2) to %.loc12_3.1
  62. // CHECK:STDOUT: %.loc12_3.2: init %X = converted %.loc12_15.1, %empty_tuple.type.as.ImplicitAs.impl.Convert.call
  63. // CHECK:STDOUT: assign %x.var, %.loc12_3.2
  64. // CHECK:STDOUT: %X.ref: type = name_ref X, file.%X.decl [concrete = constants.%X]
  65. // CHECK:STDOUT: %x: ref %X = ref_binding x, %x.var
  66. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.bound: <bound method> = bound_method %x.var, constants.%DestroyT.binding.as_type.as.Destroy.impl.Op.1c8
  67. // CHECK:STDOUT: <elided>
  68. // CHECK:STDOUT: %bound_method.loc12_3.2: <bound method> = bound_method %x.var, %DestroyT.binding.as_type.as.Destroy.impl.Op.specific_fn
  69. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.call: init %empty_tuple.type = call %bound_method.loc12_3.2(%x.var)
  70. // CHECK:STDOUT: <elided>
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT: