default_fn.carbon 5.1 KB

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