resolve_used.carbon 7.5 KB

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