impl_as.carbon 5.1 KB

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