generic_import.carbon 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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/generic_import.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/generic_import.carbon
  10. // --- a.carbon
  11. library "a";
  12. interface AddWith(T:! type) {
  13. fn F();
  14. }
  15. // --- b.carbon
  16. library "b";
  17. import library "a";
  18. class C {}
  19. impl C as AddWith(C) {
  20. fn F() {}
  21. }
  22. // CHECK:STDOUT: --- a.carbon
  23. // CHECK:STDOUT:
  24. // CHECK:STDOUT: constants {
  25. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
  26. // CHECK:STDOUT: %AddWith.type: type = generic_interface_type @AddWith [template]
  27. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  28. // CHECK:STDOUT: %AddWith: %AddWith.type = struct_value () [template]
  29. // CHECK:STDOUT: %.2: type = interface_type @AddWith, (%T) [symbolic]
  30. // CHECK:STDOUT: %Self: %.2 = bind_symbolic_name Self 1 [symbolic]
  31. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  32. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  33. // CHECK:STDOUT: %.3: type = assoc_entity_type @AddWith, %F.type [template]
  34. // CHECK:STDOUT: %.4: %.3 = assoc_entity element0, @AddWith.%F.decl [template]
  35. // CHECK:STDOUT: }
  36. // CHECK:STDOUT:
  37. // CHECK:STDOUT: file {
  38. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  39. // CHECK:STDOUT: .AddWith = %AddWith.decl
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT: %AddWith.decl: %AddWith.type = interface_decl @AddWith [template = constants.%AddWith] {
  42. // CHECK:STDOUT: %T.loc4_19.1: type = param T
  43. // CHECK:STDOUT: %T.loc4_19.2: type = bind_symbolic_name T 0, %T.loc4_19.1 [symbolic = constants.%T]
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT: }
  46. // CHECK:STDOUT:
  47. // CHECK:STDOUT: interface @AddWith
  48. // CHECK:STDOUT: generic [file.%T.loc4_19.2: type] {
  49. // CHECK:STDOUT: %Self: %.2 = bind_symbolic_name Self 1 [symbolic = constants.%Self]
  50. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {}
  51. // CHECK:STDOUT: %.loc5: %.3 = assoc_entity element0, %F.decl [template = constants.%.4]
  52. // CHECK:STDOUT:
  53. // CHECK:STDOUT: !members:
  54. // CHECK:STDOUT: .Self = %Self
  55. // CHECK:STDOUT: .F = %.loc5
  56. // CHECK:STDOUT: witness = (%F.decl)
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT:
  59. // CHECK:STDOUT: fn @F()
  60. // CHECK:STDOUT: generic [file.%T.loc4_19.2: type, @AddWith.%Self: %.2];
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: --- b.carbon
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: constants {
  65. // CHECK:STDOUT: %C: type = class_type @C [template]
  66. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  67. // CHECK:STDOUT: %AddWith.type: type = generic_interface_type @AddWith [template]
  68. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  69. // CHECK:STDOUT: %AddWith: %AddWith.type = struct_value () [template]
  70. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0, <unexpected instref inst+13> [symbolic]
  71. // CHECK:STDOUT: %.3: type = interface_type @AddWith, (%T) [symbolic]
  72. // CHECK:STDOUT: %Self: %.3 = bind_symbolic_name Self 1 [symbolic]
  73. // CHECK:STDOUT: %.4: type = interface_type @AddWith, (%C) [template]
  74. // CHECK:STDOUT: %F.type.1: type = fn_type @F.1 [template]
  75. // CHECK:STDOUT: %F.1: %F.type.1 = struct_value () [template]
  76. // CHECK:STDOUT: %F.type.2: type = fn_type @F.2 [template]
  77. // CHECK:STDOUT: %F.2: %F.type.2 = struct_value () [template]
  78. // CHECK:STDOUT: %.5: <witness> = interface_witness (%F.1) [template]
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT:
  81. // CHECK:STDOUT: file {
  82. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  83. // CHECK:STDOUT: .AddWith = %import_ref.1
  84. // CHECK:STDOUT: .C = %C.decl
  85. // CHECK:STDOUT: }
  86. // CHECK:STDOUT: %import_ref.1: %AddWith.type = import_ref ir1, inst+4, loaded [template = constants.%AddWith]
  87. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {}
  88. // CHECK:STDOUT: %import_ref.2 = import_ref ir1, inst+9, unloaded
  89. // CHECK:STDOUT: %import_ref.3 = import_ref ir1, inst+15, unloaded
  90. // CHECK:STDOUT: %import_ref.4: %F.type.2 = import_ref ir1, inst+11, loaded [template = constants.%F.2]
  91. // CHECK:STDOUT: %.loc7_20.1: type = value_of_initializer %.loc7_18 [template = constants.%.4]
  92. // CHECK:STDOUT: %.loc7_20.2: type = converted %.loc7_18, %.loc7_20.1 [template = constants.%.4]
  93. // CHECK:STDOUT: impl_decl @impl {
  94. // CHECK:STDOUT: %C.ref.loc7_6: type = name_ref C, %C.decl [template = constants.%C]
  95. // CHECK:STDOUT: %AddWith.ref: %AddWith.type = name_ref AddWith, %import_ref.1 [template = constants.%AddWith]
  96. // CHECK:STDOUT: %C.ref.loc7_19: type = name_ref C, %C.decl [template = constants.%C]
  97. // CHECK:STDOUT: %.loc7_18: init type = call %AddWith.ref(%C.ref.loc7_19) [template = constants.%.4]
  98. // CHECK:STDOUT: }
  99. // CHECK:STDOUT: }
  100. // CHECK:STDOUT:
  101. // CHECK:STDOUT: interface @AddWith {
  102. // CHECK:STDOUT: !members:
  103. // CHECK:STDOUT: .Self = file.%import_ref.2
  104. // CHECK:STDOUT: .F = file.%import_ref.3
  105. // CHECK:STDOUT: witness = (file.%import_ref.4)
  106. // CHECK:STDOUT: }
  107. // CHECK:STDOUT:
  108. // CHECK:STDOUT: impl @impl: %C as %.4 {
  109. // CHECK:STDOUT: %F.decl: %F.type.1 = fn_decl @F.1 [template = constants.%F.1] {}
  110. // CHECK:STDOUT: %.1: <witness> = interface_witness (%F.decl) [template = constants.%.5]
  111. // CHECK:STDOUT:
  112. // CHECK:STDOUT: !members:
  113. // CHECK:STDOUT: .F = %F.decl
  114. // CHECK:STDOUT: witness = %.1
  115. // CHECK:STDOUT: }
  116. // CHECK:STDOUT:
  117. // CHECK:STDOUT: class @C {
  118. // CHECK:STDOUT: !members:
  119. // CHECK:STDOUT: .Self = constants.%C
  120. // CHECK:STDOUT: }
  121. // CHECK:STDOUT:
  122. // CHECK:STDOUT: fn @F.1() {
  123. // CHECK:STDOUT: !entry:
  124. // CHECK:STDOUT: return
  125. // CHECK:STDOUT: }
  126. // CHECK:STDOUT:
  127. // CHECK:STDOUT: fn @F.2();
  128. // CHECK:STDOUT: