impl_as.carbon 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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/impl/impl_as.carbon
  11. // TIP: To dump output, run:
  12. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/impl/impl_as.carbon
  13. interface Simple {
  14. fn F();
  15. }
  16. class C {
  17. impl as Simple {
  18. fn F() {
  19. // C is a complete type here.
  20. var c: C = {};
  21. }
  22. }
  23. }
  24. // CHECK:STDOUT: --- impl_as.carbon
  25. // CHECK:STDOUT:
  26. // CHECK:STDOUT: constants {
  27. // CHECK:STDOUT: %Simple.type: type = facet_type <@Simple> [concrete]
  28. // CHECK:STDOUT: %Self: %Simple.type = bind_symbolic_name Self, 0 [symbolic]
  29. // CHECK:STDOUT: %F.type.e2e: type = fn_type @F.1 [concrete]
  30. // CHECK:STDOUT: %F.df8: %F.type.e2e = struct_value () [concrete]
  31. // CHECK:STDOUT: %Simple.assoc_type: type = assoc_entity_type @Simple [concrete]
  32. // CHECK:STDOUT: %assoc0: %Simple.assoc_type = assoc_entity element0, @Simple.%F.decl [concrete]
  33. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  34. // CHECK:STDOUT: %Simple.impl_witness: <witness> = impl_witness @C.%Simple.impl_witness_table [concrete]
  35. // CHECK:STDOUT: %F.type.e4b: type = fn_type @F.2 [concrete]
  36. // CHECK:STDOUT: %F.c94: %F.type.e4b = struct_value () [concrete]
  37. // CHECK:STDOUT: %Simple.facet: %Simple.type = facet_value %C, (%Simple.impl_witness) [concrete]
  38. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  39. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  40. // CHECK:STDOUT: %pattern_type: type = pattern_type %C [concrete]
  41. // CHECK:STDOUT: %C.val: %C = struct_value () [concrete]
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT:
  44. // CHECK:STDOUT: imports {
  45. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  46. // CHECK:STDOUT: import Core//prelude
  47. // CHECK:STDOUT: import Core//prelude/...
  48. // CHECK:STDOUT: }
  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: .Simple = %Simple.decl
  55. // CHECK:STDOUT: .C = %C.decl
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT: %Core.import = import Core
  58. // CHECK:STDOUT: %Simple.decl: type = interface_decl @Simple [concrete = constants.%Simple.type] {} {}
  59. // CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: interface @Simple {
  63. // CHECK:STDOUT: %Self: %Simple.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self]
  64. // CHECK:STDOUT: %F.decl: %F.type.e2e = fn_decl @F.1 [concrete = constants.%F.df8] {} {}
  65. // CHECK:STDOUT: %assoc0: %Simple.assoc_type = assoc_entity element0, %F.decl [concrete = constants.%assoc0]
  66. // CHECK:STDOUT:
  67. // CHECK:STDOUT: !members:
  68. // CHECK:STDOUT: .Self = %Self
  69. // CHECK:STDOUT: .F = %assoc0
  70. // CHECK:STDOUT: witness = (%F.decl)
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT:
  73. // CHECK:STDOUT: impl @impl: %Self.ref as %Simple.ref {
  74. // CHECK:STDOUT: %F.decl: %F.type.e4b = fn_decl @F.2 [concrete = constants.%F.c94] {} {}
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: !members:
  77. // CHECK:STDOUT: .F = %F.decl
  78. // CHECK:STDOUT: .C = <poisoned>
  79. // CHECK:STDOUT: witness = @C.%Simple.impl_witness
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT:
  82. // CHECK:STDOUT: class @C {
  83. // CHECK:STDOUT: impl_decl @impl [concrete] {} {
  84. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%C [concrete = constants.%C]
  85. // CHECK:STDOUT: %Simple.ref: type = name_ref Simple, file.%Simple.decl [concrete = constants.%Simple.type]
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT: %Simple.impl_witness_table = impl_witness_table (@impl.%F.decl), @impl [concrete]
  88. // CHECK:STDOUT: %Simple.impl_witness: <witness> = impl_witness %Simple.impl_witness_table [concrete = constants.%Simple.impl_witness]
  89. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
  90. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type]
  91. // CHECK:STDOUT: complete_type_witness = %complete_type
  92. // CHECK:STDOUT:
  93. // CHECK:STDOUT: !members:
  94. // CHECK:STDOUT: .Self = constants.%C
  95. // CHECK:STDOUT: .Simple = <poisoned>
  96. // CHECK:STDOUT: .C = <poisoned>
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT:
  99. // CHECK:STDOUT: generic fn @F.1(@Simple.%Self: %Simple.type) {
  100. // CHECK:STDOUT: fn();
  101. // CHECK:STDOUT: }
  102. // CHECK:STDOUT:
  103. // CHECK:STDOUT: fn @F.2() {
  104. // CHECK:STDOUT: !entry:
  105. // CHECK:STDOUT: name_binding_decl {
  106. // CHECK:STDOUT: %c.patt: %pattern_type = binding_pattern c [concrete]
  107. // CHECK:STDOUT: %c.var_patt: %pattern_type = var_pattern %c.patt [concrete]
  108. // CHECK:STDOUT: }
  109. // CHECK:STDOUT: %c.var: ref %C = var %c.var_patt
  110. // CHECK:STDOUT: %.loc22_19.1: %empty_struct_type = struct_literal ()
  111. // CHECK:STDOUT: %.loc22_19.2: init %C = class_init (), %c.var [concrete = constants.%C.val]
  112. // CHECK:STDOUT: %.loc22_7: init %C = converted %.loc22_19.1, %.loc22_19.2 [concrete = constants.%C.val]
  113. // CHECK:STDOUT: assign %c.var, %.loc22_7
  114. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
  115. // CHECK:STDOUT: %c: ref %C = bind_name c, %c.var
  116. // CHECK:STDOUT: return
  117. // CHECK:STDOUT: }
  118. // CHECK:STDOUT:
  119. // CHECK:STDOUT: specific @F.1(constants.%Self) {}
  120. // CHECK:STDOUT:
  121. // CHECK:STDOUT: specific @F.1(constants.%Simple.facet) {}
  122. // CHECK:STDOUT: