impl_as.carbon 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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: %.1: type = interface_type @Simple [template]
  25. // CHECK:STDOUT: %Self: %.1 = bind_symbolic_name Self 0 [symbolic]
  26. // CHECK:STDOUT: %F.type.1: type = fn_type @F.1 [template]
  27. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  28. // CHECK:STDOUT: %F.1: %F.type.1 = struct_value () [template]
  29. // CHECK:STDOUT: %.3: type = assoc_entity_type %.1, %F.type.1 [template]
  30. // CHECK:STDOUT: %.4: %.3 = assoc_entity element0, @Simple.%F.decl [template]
  31. // CHECK:STDOUT: %C: type = class_type @C [template]
  32. // CHECK:STDOUT: %F.type.2: type = fn_type @F.2 [template]
  33. // CHECK:STDOUT: %F.2: %F.type.2 = struct_value () [template]
  34. // CHECK:STDOUT: %.5: <witness> = interface_witness (%F.2) [template]
  35. // CHECK:STDOUT: %.6: type = struct_type {} [template]
  36. // CHECK:STDOUT: %.7: <witness> = complete_type_witness %.6 [template]
  37. // CHECK:STDOUT: %.8: type = ptr_type %.6 [template]
  38. // CHECK:STDOUT: %struct: %C = struct_value () [template]
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT:
  41. // CHECK:STDOUT: imports {
  42. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  43. // CHECK:STDOUT: import Core//prelude
  44. // CHECK:STDOUT: import Core//prelude/operators
  45. // CHECK:STDOUT: import Core//prelude/types
  46. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  47. // CHECK:STDOUT: import Core//prelude/operators/as
  48. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  49. // CHECK:STDOUT: import Core//prelude/operators/comparison
  50. // CHECK:STDOUT: import Core//prelude/types/bool
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT:
  54. // CHECK:STDOUT: file {
  55. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  56. // CHECK:STDOUT: .Core = imports.%Core
  57. // CHECK:STDOUT: .Simple = %Simple.decl
  58. // CHECK:STDOUT: .C = %C.decl
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT: %Core.import = import Core
  61. // CHECK:STDOUT: %Simple.decl: type = interface_decl @Simple [template = constants.%.1] {} {}
  62. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: interface @Simple {
  66. // CHECK:STDOUT: %Self: %.1 = bind_symbolic_name Self 0 [symbolic = constants.%Self]
  67. // CHECK:STDOUT: %F.decl: %F.type.1 = fn_decl @F.1 [template = constants.%F.1] {} {}
  68. // CHECK:STDOUT: %.loc12: %.3 = assoc_entity element0, %F.decl [template = constants.%.4]
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: !members:
  71. // CHECK:STDOUT: .Self = %Self
  72. // CHECK:STDOUT: .F = %.loc12
  73. // CHECK:STDOUT: witness = (%F.decl)
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: impl @impl: %C as %.1 {
  77. // CHECK:STDOUT: %F.decl: %F.type.2 = fn_decl @F.2 [template = constants.%F.2] {} {}
  78. // CHECK:STDOUT: %.loc16: <witness> = interface_witness (%F.decl) [template = constants.%.5]
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: !members:
  81. // CHECK:STDOUT: .F = %F.decl
  82. // CHECK:STDOUT: witness = %.loc16
  83. // CHECK:STDOUT: }
  84. // CHECK:STDOUT:
  85. // CHECK:STDOUT: class @C {
  86. // CHECK:STDOUT: impl_decl @impl {} {
  87. // CHECK:STDOUT: %Simple.ref: type = name_ref Simple, file.%Simple.decl [template = constants.%.1]
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT: %.loc22: <witness> = complete_type_witness %.6 [template = constants.%.7]
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: !members:
  92. // CHECK:STDOUT: .Self = constants.%C
  93. // CHECK:STDOUT: }
  94. // CHECK:STDOUT:
  95. // CHECK:STDOUT: generic fn @F.1(@Simple.%Self: %.1) {
  96. // CHECK:STDOUT:
  97. // CHECK:STDOUT: fn();
  98. // CHECK:STDOUT: }
  99. // CHECK:STDOUT:
  100. // CHECK:STDOUT: fn @F.2() {
  101. // CHECK:STDOUT: !entry:
  102. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  103. // CHECK:STDOUT: %c.var: ref %C = var c
  104. // CHECK:STDOUT: %c: ref %C = bind_name c, %c.var
  105. // CHECK:STDOUT: %.loc19_19.1: %.6 = struct_literal ()
  106. // CHECK:STDOUT: %.loc19_19.2: init %C = class_init (), %c.var [template = constants.%struct]
  107. // CHECK:STDOUT: %.loc19_20: init %C = converted %.loc19_19.1, %.loc19_19.2 [template = constants.%struct]
  108. // CHECK:STDOUT: assign %c.var, %.loc19_20
  109. // CHECK:STDOUT: return
  110. // CHECK:STDOUT: }
  111. // CHECK:STDOUT:
  112. // CHECK:STDOUT: specific @F.1(constants.%Self) {}
  113. // CHECK:STDOUT:
  114. // CHECK:STDOUT: specific @F.1(constants.%C) {}
  115. // CHECK:STDOUT: