resolve_used.carbon 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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+3]]:10: error: integer type width of 0 is not positive [IntWidthNotPositive]
  18. // CHECK:STDERR: var v: Core.Int(N);
  19. // CHECK:STDERR: ^~~~~~~~~~~
  20. var v: Core.Int(N);
  21. }
  22. fn CallNegative() {
  23. ErrorIfNIsZero(0);
  24. }
  25. // CHECK:STDOUT: --- fail_todo_call_monomorphization_error.carbon
  26. // CHECK:STDOUT:
  27. // CHECK:STDOUT: constants {
  28. // CHECK:STDOUT: %IntLiteral.type: type = fn_type @IntLiteral [template]
  29. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [template]
  30. // CHECK:STDOUT: %IntLiteral: %IntLiteral.type = struct_value () [template]
  31. // CHECK:STDOUT: %N: Core.IntLiteral = bind_symbolic_name N, 0 [symbolic]
  32. // CHECK:STDOUT: %N.patt: Core.IntLiteral = symbolic_binding_pattern N, 0 [symbolic]
  33. // CHECK:STDOUT: %ErrorIfNIsZero.type: type = fn_type @ErrorIfNIsZero [template]
  34. // CHECK:STDOUT: %ErrorIfNIsZero: %ErrorIfNIsZero.type = struct_value () [template]
  35. // CHECK:STDOUT: %Int.type: type = fn_type @Int [template]
  36. // CHECK:STDOUT: %Int: %Int.type = struct_value () [template]
  37. // CHECK:STDOUT: %iN: type = int_type signed, %N [symbolic]
  38. // CHECK:STDOUT: %require_complete: <witness> = require_complete_type %iN [symbolic]
  39. // CHECK:STDOUT: %CallNegative.type: type = fn_type @CallNegative [template]
  40. // CHECK:STDOUT: %CallNegative: %CallNegative.type = struct_value () [template]
  41. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [template]
  42. // CHECK:STDOUT: %ErrorIfNIsZero.specific_fn: <specific function> = specific_function %ErrorIfNIsZero, @ErrorIfNIsZero(%int_0) [template]
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT:
  45. // CHECK:STDOUT: imports {
  46. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  47. // CHECK:STDOUT: .IntLiteral = %import_ref.1
  48. // CHECK:STDOUT: .Int = %import_ref.2
  49. // CHECK:STDOUT: import Core//prelude
  50. // CHECK:STDOUT: import Core//prelude/...
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT: %import_ref.1: %IntLiteral.type = import_ref Core//prelude/types, IntLiteral, loaded [template = constants.%IntLiteral]
  53. // CHECK:STDOUT: %import_ref.2: %Int.type = import_ref Core//prelude/types, Int, loaded [template = constants.%Int]
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT:
  56. // CHECK:STDOUT: file {
  57. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  58. // CHECK:STDOUT: .Core = imports.%Core
  59. // CHECK:STDOUT: .ErrorIfNIsZero = %ErrorIfNIsZero.decl
  60. // CHECK:STDOUT: .CallNegative = %CallNegative.decl
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT: %Core.import = import Core
  63. // CHECK:STDOUT: %ErrorIfNIsZero.decl: %ErrorIfNIsZero.type = fn_decl @ErrorIfNIsZero [template = constants.%ErrorIfNIsZero] {
  64. // CHECK:STDOUT: %N.patt.loc4_19.1: Core.IntLiteral = symbolic_binding_pattern N, 0 [symbolic = %N.patt.loc4_19.2 (constants.%N.patt)]
  65. // 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)]
  66. // CHECK:STDOUT: } {
  67. // CHECK:STDOUT: %Core.ref.loc4: <namespace> = name_ref Core, imports.%Core [template = imports.%Core]
  68. // CHECK:STDOUT: %IntLiteral.ref: %IntLiteral.type = name_ref IntLiteral, imports.%import_ref.1 [template = constants.%IntLiteral]
  69. // CHECK:STDOUT: %int_literal.make_type: init type = call %IntLiteral.ref() [template = Core.IntLiteral]
  70. // CHECK:STDOUT: %.loc4_39.1: type = value_of_initializer %int_literal.make_type [template = Core.IntLiteral]
  71. // CHECK:STDOUT: %.loc4_39.2: type = converted %int_literal.make_type, %.loc4_39.1 [template = Core.IntLiteral]
  72. // CHECK:STDOUT: %N.param: Core.IntLiteral = value_param runtime_param<invalid>
  73. // CHECK:STDOUT: %N.loc4_19.1: Core.IntLiteral = bind_symbolic_name N, 0, %N.param [symbolic = %N.loc4_19.2 (constants.%N)]
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT: %CallNegative.decl: %CallNegative.type = fn_decl @CallNegative [template = constants.%CallNegative] {} {}
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT:
  78. // CHECK:STDOUT: generic fn @ErrorIfNIsZero(%N.loc4_19.1: Core.IntLiteral) {
  79. // CHECK:STDOUT: %N.loc4_19.2: Core.IntLiteral = bind_symbolic_name N, 0 [symbolic = %N.loc4_19.2 (constants.%N)]
  80. // CHECK:STDOUT: %N.patt.loc4_19.2: Core.IntLiteral = symbolic_binding_pattern N, 0 [symbolic = %N.patt.loc4_19.2 (constants.%N.patt)]
  81. // CHECK:STDOUT:
  82. // CHECK:STDOUT: !definition:
  83. // CHECK:STDOUT: %iN: type = int_type signed, %N.loc4_19.2 [symbolic = %iN (constants.%iN)]
  84. // CHECK:STDOUT: %require_complete: <witness> = require_complete_type @ErrorIfNIsZero.%iN (%iN) [symbolic = %require_complete (constants.%require_complete)]
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: fn(%N.param_patt: Core.IntLiteral) {
  87. // CHECK:STDOUT: !entry:
  88. // CHECK:STDOUT: %Core.ref.loc12: <namespace> = name_ref Core, imports.%Core [template = imports.%Core]
  89. // CHECK:STDOUT: %Int.ref: %Int.type = name_ref Int, imports.%import_ref.2 [template = constants.%Int]
  90. // CHECK:STDOUT: %N.ref: Core.IntLiteral = name_ref N, %N.loc4_19.1 [symbolic = %N.loc4_19.2 (constants.%N)]
  91. // CHECK:STDOUT: %int.make_type_signed: init type = call %Int.ref(%N.ref) [symbolic = %iN (constants.%iN)]
  92. // CHECK:STDOUT: %.loc12_20.1: type = value_of_initializer %int.make_type_signed [symbolic = %iN (constants.%iN)]
  93. // CHECK:STDOUT: %.loc12_20.2: type = converted %int.make_type_signed, %.loc12_20.1 [symbolic = %iN (constants.%iN)]
  94. // CHECK:STDOUT: %v.var: ref @ErrorIfNIsZero.%iN (%iN) = var v
  95. // CHECK:STDOUT: %v: ref @ErrorIfNIsZero.%iN (%iN) = bind_name v, %v.var
  96. // CHECK:STDOUT: return
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT: }
  99. // CHECK:STDOUT:
  100. // CHECK:STDOUT: fn @CallNegative() {
  101. // CHECK:STDOUT: !entry:
  102. // CHECK:STDOUT: %ErrorIfNIsZero.ref: %ErrorIfNIsZero.type = name_ref ErrorIfNIsZero, file.%ErrorIfNIsZero.decl [template = constants.%ErrorIfNIsZero]
  103. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [template = constants.%int_0]
  104. // CHECK:STDOUT: %ErrorIfNIsZero.specific_fn: <specific function> = specific_function %ErrorIfNIsZero.ref, @ErrorIfNIsZero(constants.%int_0) [template = constants.%ErrorIfNIsZero.specific_fn]
  105. // CHECK:STDOUT: %ErrorIfNIsZero.call: init %empty_tuple.type = call %ErrorIfNIsZero.specific_fn()
  106. // CHECK:STDOUT: return
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT:
  109. // CHECK:STDOUT: specific @ErrorIfNIsZero(constants.%N) {
  110. // CHECK:STDOUT: %N.loc4_19.2 => constants.%N
  111. // CHECK:STDOUT: %N.patt.loc4_19.2 => constants.%N
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT:
  114. // CHECK:STDOUT: specific @ErrorIfNIsZero(constants.%int_0) {
  115. // CHECK:STDOUT: %N.loc4_19.2 => constants.%int_0
  116. // CHECK:STDOUT: %N.patt.loc4_19.2 => constants.%int_0
  117. // CHECK:STDOUT:
  118. // CHECK:STDOUT: !definition:
  119. // CHECK:STDOUT: %iN => <error>
  120. // CHECK:STDOUT: %require_complete => <error>
  121. // CHECK:STDOUT: }
  122. // CHECK:STDOUT: