resolve_used.carbon 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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/function/generic/resolve_used.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/function/generic/resolve_used.carbon
  10. // CHECK:STDERR: {{.*}}/prelude/types/int.carbon:13:9: error: integer type width of 0 is not positive [IntWidthNotPositive]
  11. // CHECK:STDERR: adapt MakeInt(N);
  12. // CHECK:STDERR: ^~~~~~~~~~
  13. // --- fail_todo_call_monomorphization_error.carbon
  14. library "[[@TEST_NAME]]";
  15. fn ErrorIfNIsZero(N:! Core.IntLiteral()) {
  16. // Check that we resolve the definition of a used specific function by
  17. // ensuring we produce an error when doing so. Notionally this error is
  18. // produced as a result of instantiating the `Core.Int` template, although
  19. // that's not how we currently model `Core.Int`.
  20. // CHECK:STDERR: fail_todo_call_monomorphization_error.carbon:[[@LINE+3]]:10: note: in `i0` used here [ResolvingSpecificHere]
  21. // CHECK:STDERR: var v: Core.Int(N);
  22. // CHECK:STDERR: ^~~~~~~~~~~
  23. var v: Core.Int(N);
  24. }
  25. fn CallNegative() {
  26. // CHECK:STDERR: fail_todo_call_monomorphization_error.carbon:[[@LINE+4]]:3: note: in `ErrorIfNIsZero(0)` used here [ResolvingSpecificHere]
  27. // CHECK:STDERR: ErrorIfNIsZero(0);
  28. // CHECK:STDERR: ^~~~~~~~~~~~~~
  29. // CHECK:STDERR:
  30. ErrorIfNIsZero(0);
  31. }
  32. // CHECK:STDOUT: --- fail_todo_call_monomorphization_error.carbon
  33. // CHECK:STDOUT:
  34. // CHECK:STDOUT: constants {
  35. // CHECK:STDOUT: %IntLiteral.type: type = fn_type @IntLiteral [concrete]
  36. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  37. // CHECK:STDOUT: %IntLiteral: %IntLiteral.type = struct_value () [concrete]
  38. // CHECK:STDOUT: %N: Core.IntLiteral = bind_symbolic_name N, 0 [symbolic]
  39. // CHECK:STDOUT: %N.patt: Core.IntLiteral = symbolic_binding_pattern N, 0 [symbolic]
  40. // CHECK:STDOUT: %ErrorIfNIsZero.type: type = fn_type @ErrorIfNIsZero [concrete]
  41. // CHECK:STDOUT: %ErrorIfNIsZero: %ErrorIfNIsZero.type = struct_value () [concrete]
  42. // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
  43. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  44. // CHECK:STDOUT: %Int: type = class_type @Int, @Int(%N) [symbolic]
  45. // CHECK:STDOUT: %require_complete.b4f: <witness> = require_complete_type %Int [symbolic]
  46. // CHECK:STDOUT: %CallNegative.type: type = fn_type @CallNegative [concrete]
  47. // CHECK:STDOUT: %CallNegative: %CallNegative.type = struct_value () [concrete]
  48. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [concrete]
  49. // CHECK:STDOUT: %ErrorIfNIsZero.specific_fn: <specific function> = specific_function %ErrorIfNIsZero, @ErrorIfNIsZero(%int_0) [concrete]
  50. // CHECK:STDOUT: %i0: type = class_type @Int, @Int(%int_0) [concrete]
  51. // CHECK:STDOUT: %complete_type.d94: <witness> = complete_type_witness <error> [concrete]
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT:
  54. // CHECK:STDOUT: imports {
  55. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  56. // CHECK:STDOUT: .IntLiteral = %Core.IntLiteral
  57. // CHECK:STDOUT: .Int = %Core.Int
  58. // CHECK:STDOUT: import Core//prelude
  59. // CHECK:STDOUT: import Core//prelude/...
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT: %Core.IntLiteral: %IntLiteral.type = import_ref Core//prelude/types/int_literal, IntLiteral, loaded [concrete = constants.%IntLiteral]
  62. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/types/int, Int, loaded [concrete = constants.%Int.generic]
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: file {
  66. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  67. // CHECK:STDOUT: .Core = imports.%Core
  68. // CHECK:STDOUT: .ErrorIfNIsZero = %ErrorIfNIsZero.decl
  69. // CHECK:STDOUT: .CallNegative = %CallNegative.decl
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT: %Core.import = import Core
  72. // CHECK:STDOUT: %ErrorIfNIsZero.decl: %ErrorIfNIsZero.type = fn_decl @ErrorIfNIsZero [concrete = constants.%ErrorIfNIsZero] {
  73. // CHECK:STDOUT: %N.patt.loc4_19.1: Core.IntLiteral = symbolic_binding_pattern N, 0 [symbolic = %N.patt.loc4_19.2 (constants.%N.patt)]
  74. // CHECK:STDOUT: } {
  75. // CHECK:STDOUT: %.loc4_39.1: type = splice_block %.loc4_39.3 [concrete = Core.IntLiteral] {
  76. // CHECK:STDOUT: %Core.ref.loc4: <namespace> = name_ref Core, imports.%Core [concrete = imports.%Core]
  77. // CHECK:STDOUT: %IntLiteral.ref: %IntLiteral.type = name_ref IntLiteral, imports.%Core.IntLiteral [concrete = constants.%IntLiteral]
  78. // CHECK:STDOUT: %int_literal.make_type: init type = call %IntLiteral.ref() [concrete = Core.IntLiteral]
  79. // CHECK:STDOUT: %.loc4_39.2: type = value_of_initializer %int_literal.make_type [concrete = Core.IntLiteral]
  80. // CHECK:STDOUT: %.loc4_39.3: type = converted %int_literal.make_type, %.loc4_39.2 [concrete = Core.IntLiteral]
  81. // CHECK:STDOUT: }
  82. // CHECK:STDOUT: %N.loc4_19.1: Core.IntLiteral = bind_symbolic_name N, 0 [symbolic = %N.loc4_19.2 (constants.%N)]
  83. // CHECK:STDOUT: }
  84. // CHECK:STDOUT: %CallNegative.decl: %CallNegative.type = fn_decl @CallNegative [concrete = constants.%CallNegative] {} {}
  85. // CHECK:STDOUT: }
  86. // CHECK:STDOUT:
  87. // CHECK:STDOUT: generic fn @ErrorIfNIsZero(%N.loc4_19.1: Core.IntLiteral) {
  88. // CHECK:STDOUT: %N.loc4_19.2: Core.IntLiteral = bind_symbolic_name N, 0 [symbolic = %N.loc4_19.2 (constants.%N)]
  89. // CHECK:STDOUT: %N.patt.loc4_19.2: Core.IntLiteral = symbolic_binding_pattern N, 0 [symbolic = %N.patt.loc4_19.2 (constants.%N.patt)]
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: !definition:
  92. // CHECK:STDOUT: %Int.loc12_20.2: type = class_type @Int, @Int(%N.loc4_19.2) [symbolic = %Int.loc12_20.2 (constants.%Int)]
  93. // CHECK:STDOUT: %require_complete: <witness> = require_complete_type @ErrorIfNIsZero.%Int.loc12_20.2 (%Int) [symbolic = %require_complete (constants.%require_complete.b4f)]
  94. // CHECK:STDOUT:
  95. // CHECK:STDOUT: fn(%N.patt.loc4_19.1: Core.IntLiteral) {
  96. // CHECK:STDOUT: !entry:
  97. // CHECK:STDOUT: name_binding_decl {
  98. // CHECK:STDOUT: %v.patt: @ErrorIfNIsZero.%Int.loc12_20.2 (%Int) = binding_pattern v
  99. // CHECK:STDOUT: %.loc12_3: @ErrorIfNIsZero.%Int.loc12_20.2 (%Int) = var_pattern %v.patt
  100. // CHECK:STDOUT: }
  101. // CHECK:STDOUT: %v.var: ref @ErrorIfNIsZero.%Int.loc12_20.2 (%Int) = var v
  102. // CHECK:STDOUT: %.loc12_20: type = splice_block %Int.loc12_20.1 [symbolic = %Int.loc12_20.2 (constants.%Int)] {
  103. // CHECK:STDOUT: %Core.ref.loc12: <namespace> = name_ref Core, imports.%Core [concrete = imports.%Core]
  104. // CHECK:STDOUT: %Int.ref: %Int.type = name_ref Int, imports.%Core.Int [concrete = constants.%Int.generic]
  105. // CHECK:STDOUT: %N.ref: Core.IntLiteral = name_ref N, %N.loc4_19.1 [symbolic = %N.loc4_19.2 (constants.%N)]
  106. // CHECK:STDOUT: %Int.loc12_20.1: type = class_type @Int, @Int(constants.%N) [symbolic = %Int.loc12_20.2 (constants.%Int)]
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT: %v: ref @ErrorIfNIsZero.%Int.loc12_20.2 (%Int) = bind_name v, %v.var
  109. // CHECK:STDOUT: return
  110. // CHECK:STDOUT: }
  111. // CHECK:STDOUT: }
  112. // CHECK:STDOUT:
  113. // CHECK:STDOUT: fn @CallNegative() {
  114. // CHECK:STDOUT: !entry:
  115. // CHECK:STDOUT: %ErrorIfNIsZero.ref: %ErrorIfNIsZero.type = name_ref ErrorIfNIsZero, file.%ErrorIfNIsZero.decl [concrete = constants.%ErrorIfNIsZero]
  116. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [concrete = constants.%int_0]
  117. // CHECK:STDOUT: %ErrorIfNIsZero.specific_fn: <specific function> = specific_function %ErrorIfNIsZero.ref, @ErrorIfNIsZero(constants.%int_0) [concrete = constants.%ErrorIfNIsZero.specific_fn]
  118. // CHECK:STDOUT: %ErrorIfNIsZero.call: init %empty_tuple.type = call %ErrorIfNIsZero.specific_fn()
  119. // CHECK:STDOUT: return
  120. // CHECK:STDOUT: }
  121. // CHECK:STDOUT:
  122. // CHECK:STDOUT: specific @ErrorIfNIsZero(constants.%N) {
  123. // CHECK:STDOUT: %N.loc4_19.2 => constants.%N
  124. // CHECK:STDOUT: %N.patt.loc4_19.2 => constants.%N.patt
  125. // CHECK:STDOUT: }
  126. // CHECK:STDOUT:
  127. // CHECK:STDOUT: specific @ErrorIfNIsZero(constants.%int_0) {
  128. // CHECK:STDOUT: %N.loc4_19.2 => constants.%int_0
  129. // CHECK:STDOUT: %N.patt.loc4_19.2 => constants.%N.patt
  130. // CHECK:STDOUT:
  131. // CHECK:STDOUT: !definition:
  132. // CHECK:STDOUT: %Int.loc12_20.2 => constants.%i0
  133. // CHECK:STDOUT: %require_complete => constants.%complete_type.d94
  134. // CHECK:STDOUT: }
  135. // CHECK:STDOUT: