assoc_const_in_generic.carbon 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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/assoc_const_in_generic.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/assoc_const_in_generic.carbon
  10. interface I(T:! type) {
  11. fn F(U:! type) -> U;
  12. }
  13. fn G(T:! type) {
  14. // This should not result in a `fn_decl` instruction being added to the eval
  15. // block for the generic G. This used to crash when printing formatted SemIR
  16. // because the same instruction ended up in multiple scopes.
  17. I(T).F;
  18. }
  19. fn H() {
  20. G({});
  21. }
  22. // CHECK:STDOUT: --- assoc_const_in_generic.carbon
  23. // CHECK:STDOUT:
  24. // CHECK:STDOUT: constants {
  25. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
  26. // CHECK:STDOUT: %I.type: type = generic_interface_type @I [template]
  27. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  28. // CHECK:STDOUT: %I: %I.type = struct_value () [template]
  29. // CHECK:STDOUT: %.2: type = interface_type @I, @I(%T) [symbolic]
  30. // CHECK:STDOUT: %Self: %.2 = bind_symbolic_name Self 1 [symbolic]
  31. // CHECK:STDOUT: %U: type = bind_symbolic_name U 2 [symbolic]
  32. // CHECK:STDOUT: %F.type: type = fn_type @F, @I(%T) [symbolic]
  33. // CHECK:STDOUT: %F: %F.type = struct_value () [symbolic]
  34. // CHECK:STDOUT: %.3: type = assoc_entity_type %.2, %F.type [symbolic]
  35. // CHECK:STDOUT: %.4: %.3 = assoc_entity element0, @I.%F.decl [symbolic]
  36. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  37. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  38. // CHECK:STDOUT: %H.type: type = fn_type @H [template]
  39. // CHECK:STDOUT: %H: %H.type = struct_value () [template]
  40. // CHECK:STDOUT: %.5: type = struct_type {} [template]
  41. // CHECK:STDOUT: }
  42. // CHECK:STDOUT:
  43. // CHECK:STDOUT: file {
  44. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  45. // CHECK:STDOUT: .I = %I.decl
  46. // CHECK:STDOUT: .G = %G.decl
  47. // CHECK:STDOUT: .H = %H.decl
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT: %I.decl: %I.type = interface_decl @I [template = constants.%I] {
  50. // CHECK:STDOUT: %T.patt: type = symbolic_binding_pattern T 0
  51. // CHECK:STDOUT: } {
  52. // CHECK:STDOUT: %T.param: type = param T, runtime_param<invalid>
  53. // CHECK:STDOUT: %T.loc11: type = bind_symbolic_name T 0, %T.param [symbolic = %T.1 (constants.%T)]
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  56. // CHECK:STDOUT: %T.patt: type = symbolic_binding_pattern T 0
  57. // CHECK:STDOUT: } {
  58. // CHECK:STDOUT: %T.param: type = param T, runtime_param<invalid>
  59. // CHECK:STDOUT: %T.loc15: type = bind_symbolic_name T 0, %T.param [symbolic = %T.1 (constants.%T)]
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT: %H.decl: %H.type = fn_decl @H [template = constants.%H] {} {}
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: generic interface @I(%T.loc11: type) {
  65. // CHECK:STDOUT: %T.1: type = bind_symbolic_name T 0 [symbolic = %T.1 (constants.%T)]
  66. // CHECK:STDOUT:
  67. // CHECK:STDOUT: !definition:
  68. // CHECK:STDOUT: %.1: type = interface_type @I, @I(%T.1) [symbolic = %.1 (constants.%.2)]
  69. // CHECK:STDOUT: %Self.2: %.2 = bind_symbolic_name Self 1 [symbolic = %Self.2 (constants.%Self)]
  70. // CHECK:STDOUT: %F.type: type = fn_type @F, @I(%T.1) [symbolic = %F.type (constants.%F.type)]
  71. // CHECK:STDOUT: %F: @I.%F.type (%F.type) = struct_value () [symbolic = %F (constants.%F)]
  72. // CHECK:STDOUT: %.2: type = assoc_entity_type @I.%.1 (%.2), @I.%F.type (%F.type) [symbolic = %.2 (constants.%.3)]
  73. // CHECK:STDOUT: %.3: @I.%.2 (%.3) = assoc_entity element0, %F.decl [symbolic = %.3 (constants.%.4)]
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: interface {
  76. // CHECK:STDOUT: %Self.1: @I.%.1 (%.2) = bind_symbolic_name Self 1 [symbolic = %Self.2 (constants.%Self)]
  77. // CHECK:STDOUT: %F.decl: @I.%F.type (%F.type) = fn_decl @F [symbolic = @I.%F (constants.%F)] {
  78. // CHECK:STDOUT: %U.patt: type = symbolic_binding_pattern U 2
  79. // CHECK:STDOUT: } {
  80. // CHECK:STDOUT: %U.param: type = param U, runtime_param<invalid>
  81. // CHECK:STDOUT: %U.loc12: type = bind_symbolic_name U 2, %U.param [symbolic = %U.1 (constants.%U)]
  82. // CHECK:STDOUT: %U.ref: type = name_ref U, %U.loc12 [symbolic = %U.1 (constants.%U)]
  83. // CHECK:STDOUT: %return: ref @F.%U.1 (%U) = var <return slot>
  84. // CHECK:STDOUT: }
  85. // CHECK:STDOUT: %.loc12: @I.%.2 (%.3) = assoc_entity element0, %F.decl [symbolic = %.3 (constants.%.4)]
  86. // CHECK:STDOUT:
  87. // CHECK:STDOUT: !members:
  88. // CHECK:STDOUT: .Self = %Self.1
  89. // CHECK:STDOUT: .F = %.loc12
  90. // CHECK:STDOUT: witness = (%F.decl)
  91. // CHECK:STDOUT: }
  92. // CHECK:STDOUT: }
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: generic fn @F(@I.%T.loc11: type, @I.%Self.1: @I.%.1 (%.2), %U.loc12: type) {
  95. // CHECK:STDOUT: %U.1: type = bind_symbolic_name U 2 [symbolic = %U.1 (constants.%U)]
  96. // CHECK:STDOUT:
  97. // CHECK:STDOUT: fn(%U.loc12: type) -> @F.%U.1 (%U);
  98. // CHECK:STDOUT: }
  99. // CHECK:STDOUT:
  100. // CHECK:STDOUT: generic fn @G(%T.loc15: type) {
  101. // CHECK:STDOUT: %T.1: type = bind_symbolic_name T 0 [symbolic = %T.1 (constants.%T)]
  102. // CHECK:STDOUT:
  103. // CHECK:STDOUT: !definition:
  104. // CHECK:STDOUT: %.1: type = interface_type @I, @I(%T.1) [symbolic = %.1 (constants.%.2)]
  105. // CHECK:STDOUT: %F.type: type = fn_type @F, @I(%T.1) [symbolic = %F.type (constants.%F.type)]
  106. // CHECK:STDOUT: %.2: type = assoc_entity_type @G.%.1 (%.2), @G.%F.type (%F.type) [symbolic = %.2 (constants.%.3)]
  107. // CHECK:STDOUT: %.3: @G.%.2 (%.3) = assoc_entity element0, @I.%F.decl [symbolic = %.3 (constants.%.4)]
  108. // CHECK:STDOUT:
  109. // CHECK:STDOUT: fn(%T.loc15: type) {
  110. // CHECK:STDOUT: !entry:
  111. // CHECK:STDOUT: %I.ref: %I.type = name_ref I, file.%I.decl [template = constants.%I]
  112. // CHECK:STDOUT: %T.ref: type = name_ref T, %T.loc15 [symbolic = %T.1 (constants.%T)]
  113. // CHECK:STDOUT: %.loc19_4: type = interface_type @I, @I(constants.%T) [symbolic = %.1 (constants.%.2)]
  114. // CHECK:STDOUT: %.loc19_7: @G.%.2 (%.3) = specific_constant @I.%.loc12, @I(constants.%T) [symbolic = %.3 (constants.%.4)]
  115. // CHECK:STDOUT: %F.ref: @G.%.2 (%.3) = name_ref F, %.loc19_7 [symbolic = %.3 (constants.%.4)]
  116. // CHECK:STDOUT: return
  117. // CHECK:STDOUT: }
  118. // CHECK:STDOUT: }
  119. // CHECK:STDOUT:
  120. // CHECK:STDOUT: fn @H() {
  121. // CHECK:STDOUT: !entry:
  122. // CHECK:STDOUT: %G.ref: %G.type = name_ref G, file.%G.decl [template = constants.%G]
  123. // CHECK:STDOUT: %.loc23_6: %.5 = struct_literal ()
  124. // CHECK:STDOUT: %.loc23_4: type = converted %.loc23_6, constants.%.5 [template = constants.%.5]
  125. // CHECK:STDOUT: %G.call: init %.1 = call %G.ref()
  126. // CHECK:STDOUT: return
  127. // CHECK:STDOUT: }
  128. // CHECK:STDOUT:
  129. // CHECK:STDOUT: specific @I(constants.%T) {
  130. // CHECK:STDOUT: %T.1 => constants.%T
  131. // CHECK:STDOUT:
  132. // CHECK:STDOUT: !definition:
  133. // CHECK:STDOUT: %.1 => constants.%.2
  134. // CHECK:STDOUT: %Self.2 => constants.%Self
  135. // CHECK:STDOUT: %F.type => constants.%F.type
  136. // CHECK:STDOUT: %F => constants.%F
  137. // CHECK:STDOUT: %.2 => constants.%.3
  138. // CHECK:STDOUT: %.3 => constants.%.4
  139. // CHECK:STDOUT: }
  140. // CHECK:STDOUT:
  141. // CHECK:STDOUT: specific @F(constants.%T, constants.%Self, constants.%U) {
  142. // CHECK:STDOUT: %U.1 => constants.%U
  143. // CHECK:STDOUT: }
  144. // CHECK:STDOUT:
  145. // CHECK:STDOUT: specific @I(@I.%T.1) {
  146. // CHECK:STDOUT: %T.1 => constants.%T
  147. // CHECK:STDOUT: }
  148. // CHECK:STDOUT:
  149. // CHECK:STDOUT: specific @G(constants.%T) {
  150. // CHECK:STDOUT: %T.1 => constants.%T
  151. // CHECK:STDOUT: }
  152. // CHECK:STDOUT:
  153. // CHECK:STDOUT: specific @I(@G.%T.1) {
  154. // CHECK:STDOUT: %T.1 => constants.%T
  155. // CHECK:STDOUT: }
  156. // CHECK:STDOUT:
  157. // CHECK:STDOUT: specific @G(constants.%.5) {
  158. // CHECK:STDOUT: %T.1 => constants.%.5
  159. // CHECK:STDOUT: }
  160. // CHECK:STDOUT: