resolve_used.carbon 8.4 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/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: %.1: type = int_type signed, %N [symbolic]
  38. // CHECK:STDOUT: %CallNegative.type: type = fn_type @CallNegative [template]
  39. // CHECK:STDOUT: %CallNegative: %CallNegative.type = struct_value () [template]
  40. // CHECK:STDOUT: %.2: i32 = int_value 0 [template]
  41. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert.1, @ImplicitAs(Core.IntLiteral) [template]
  42. // CHECK:STDOUT: %Convert.type.15: type = fn_type @Convert.11 [template]
  43. // CHECK:STDOUT: %Convert.15: %Convert.type.15 = struct_value () [template]
  44. // CHECK:STDOUT: %.25: <witness> = interface_witness (%Convert.15) [template]
  45. // CHECK:STDOUT: %.26: <bound method> = bound_method %.2, %Convert.15 [template]
  46. // CHECK:STDOUT: %.27: Core.IntLiteral = int_value 0 [template]
  47. // CHECK:STDOUT: %.28: <specific function> = specific_function %ErrorIfNIsZero, @ErrorIfNIsZero(%.27) [template]
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT:
  50. // CHECK:STDOUT: imports {
  51. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  52. // CHECK:STDOUT: .IntLiteral = %import_ref.1
  53. // CHECK:STDOUT: .Int = %import_ref.2
  54. // CHECK:STDOUT: .ImplicitAs = %import_ref.3
  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, inst+7, loaded [template = constants.%IntLiteral]
  59. // CHECK:STDOUT: %import_ref.2: %Int.type = import_ref Core//prelude/types, inst+30, loaded [template = constants.%Int]
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: file {
  63. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  64. // CHECK:STDOUT: .Core = imports.%Core
  65. // CHECK:STDOUT: .ErrorIfNIsZero = %ErrorIfNIsZero.decl
  66. // CHECK:STDOUT: .CallNegative = %CallNegative.decl
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT: %Core.import = import Core
  69. // CHECK:STDOUT: %ErrorIfNIsZero.decl: %ErrorIfNIsZero.type = fn_decl @ErrorIfNIsZero [template = constants.%ErrorIfNIsZero] {
  70. // CHECK:STDOUT: %N.patt.loc4_19.1: Core.IntLiteral = symbolic_binding_pattern N, 0 [symbolic = %N.patt.loc4_19.2 (constants.%N.patt)]
  71. // 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)]
  72. // CHECK:STDOUT: } {
  73. // CHECK:STDOUT: %Core.ref.loc4: <namespace> = name_ref Core, imports.%Core [template = imports.%Core]
  74. // CHECK:STDOUT: %IntLiteral.ref: %IntLiteral.type = name_ref IntLiteral, imports.%import_ref.1 [template = constants.%IntLiteral]
  75. // CHECK:STDOUT: %int_literal.make_type: init type = call %IntLiteral.ref() [template = Core.IntLiteral]
  76. // CHECK:STDOUT: %.loc4_39.1: type = value_of_initializer %int_literal.make_type [template = Core.IntLiteral]
  77. // CHECK:STDOUT: %.loc4_39.2: type = converted %int_literal.make_type, %.loc4_39.1 [template = Core.IntLiteral]
  78. // CHECK:STDOUT: %N.param: Core.IntLiteral = value_param runtime_param<invalid>
  79. // CHECK:STDOUT: %N.loc4_19.1: Core.IntLiteral = bind_symbolic_name N, 0, %N.param [symbolic = %N.loc4_19.2 (constants.%N)]
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT: %CallNegative.decl: %CallNegative.type = fn_decl @CallNegative [template = constants.%CallNegative] {} {}
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: generic fn @ErrorIfNIsZero(%N.loc4_19.1: Core.IntLiteral) {
  85. // CHECK:STDOUT: %N.loc4_19.2: Core.IntLiteral = bind_symbolic_name N, 0 [symbolic = %N.loc4_19.2 (constants.%N)]
  86. // CHECK:STDOUT: %N.patt.loc4_19.2: Core.IntLiteral = symbolic_binding_pattern N, 0 [symbolic = %N.patt.loc4_19.2 (constants.%N.patt)]
  87. // CHECK:STDOUT:
  88. // CHECK:STDOUT: !definition:
  89. // CHECK:STDOUT: %.loc12_18: type = int_type signed, %N.loc4_19.2 [symbolic = %.loc12_18 (constants.%.1)]
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: fn(%N.param_patt: Core.IntLiteral) {
  92. // CHECK:STDOUT: !entry:
  93. // CHECK:STDOUT: %Core.ref.loc12: <namespace> = name_ref Core, imports.%Core [template = imports.%Core]
  94. // CHECK:STDOUT: %Int.ref: %Int.type = name_ref Int, imports.%import_ref.2 [template = constants.%Int]
  95. // CHECK:STDOUT: %N.ref: Core.IntLiteral = name_ref N, %N.loc4_19.1 [symbolic = %N.loc4_19.2 (constants.%N)]
  96. // CHECK:STDOUT: %int.make_type_signed: init type = call %Int.ref(%N.ref) [symbolic = %.loc12_18 (constants.%.1)]
  97. // CHECK:STDOUT: %.loc12_20.1: type = value_of_initializer %int.make_type_signed [symbolic = %.loc12_18 (constants.%.1)]
  98. // CHECK:STDOUT: %.loc12_20.2: type = converted %int.make_type_signed, %.loc12_20.1 [symbolic = %.loc12_18 (constants.%.1)]
  99. // CHECK:STDOUT: %v.var: ref @ErrorIfNIsZero.%.loc12_18 (%.1) = var v
  100. // CHECK:STDOUT: %v: ref @ErrorIfNIsZero.%.loc12_18 (%.1) = bind_name v, %v.var
  101. // CHECK:STDOUT: return
  102. // CHECK:STDOUT: }
  103. // CHECK:STDOUT: }
  104. // CHECK:STDOUT:
  105. // CHECK:STDOUT: fn @CallNegative() {
  106. // CHECK:STDOUT: !entry:
  107. // CHECK:STDOUT: %ErrorIfNIsZero.ref: %ErrorIfNIsZero.type = name_ref ErrorIfNIsZero, file.%ErrorIfNIsZero.decl [template = constants.%ErrorIfNIsZero]
  108. // CHECK:STDOUT: %.loc16_18: i32 = int_value 0 [template = constants.%.2]
  109. // CHECK:STDOUT: %.loc16_17.1: %Convert.type.2 = interface_witness_access constants.%.25, element0 [template = constants.%Convert.15]
  110. // CHECK:STDOUT: %.loc16_17.2: <bound method> = bound_method %.loc16_18, %.loc16_17.1 [template = constants.%.26]
  111. // CHECK:STDOUT: %int.convert_checked: init Core.IntLiteral = call %.loc16_17.2(%.loc16_18) [template = constants.%.27]
  112. // CHECK:STDOUT: %.loc16_17.3: Core.IntLiteral = value_of_initializer %int.convert_checked [template = constants.%.27]
  113. // CHECK:STDOUT: %.loc16_17.4: Core.IntLiteral = converted %.loc16_18, %.loc16_17.3 [template = constants.%.27]
  114. // CHECK:STDOUT: %.loc16_3: <specific function> = specific_function %ErrorIfNIsZero.ref, @ErrorIfNIsZero(constants.%.27) [template = constants.%.28]
  115. // CHECK:STDOUT: %ErrorIfNIsZero.call: init %empty_tuple.type = call %.loc16_3()
  116. // CHECK:STDOUT: return
  117. // CHECK:STDOUT: }
  118. // CHECK:STDOUT:
  119. // CHECK:STDOUT: specific @ErrorIfNIsZero(constants.%N) {
  120. // CHECK:STDOUT: %N.loc4_19.2 => constants.%N
  121. // CHECK:STDOUT: %N.patt.loc4_19.2 => constants.%N
  122. // CHECK:STDOUT: }
  123. // CHECK:STDOUT:
  124. // CHECK:STDOUT: specific @ErrorIfNIsZero(constants.%.27) {
  125. // CHECK:STDOUT: %N.loc4_19.2 => constants.%.27
  126. // CHECK:STDOUT: %N.patt.loc4_19.2 => constants.%.27
  127. // CHECK:STDOUT:
  128. // CHECK:STDOUT: !definition:
  129. // CHECK:STDOUT: %.loc12_18 => <error>
  130. // CHECK:STDOUT: }
  131. // CHECK:STDOUT: