resolve_used.carbon 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. // TODO: This declaration should be accepted, and the `var v` below should be
  13. // rejected during monomorphization, once integer literals have the type
  14. // `Core.IntLiteral(N)` as described in the design.
  15. // CHECK:STDERR: fail_todo_call_monomorphization_error.carbon:[[@LINE+3]]:41: error: name `IntLiteral` not found [NameNotFound]
  16. // CHECK:STDERR: fn ErrorIfNIsZero[N:! Core.BigInt()](n: Core.IntLiteral(N)) {
  17. // CHECK:STDERR: ^~~~~~~~~~~~~~~
  18. fn ErrorIfNIsZero[N:! Core.BigInt()](n: Core.IntLiteral(N)) {
  19. // Check that we resolve the definition of a used specific function by
  20. // ensuring we produce an error when doing so. Notionally this error is
  21. // produced as a result of instantiating the `Core.Int` template, although
  22. // that's not how we currently model `Core.Int`.
  23. var v: Core.Int(N);
  24. }
  25. fn CallNegative() {
  26. ErrorIfNIsZero(0);
  27. }
  28. // CHECK:STDOUT: --- fail_todo_call_monomorphization_error.carbon
  29. // CHECK:STDOUT:
  30. // CHECK:STDOUT: constants {
  31. // CHECK:STDOUT: %BigInt.type: type = fn_type @BigInt [template]
  32. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  33. // CHECK:STDOUT: %BigInt: %BigInt.type = struct_value () [template]
  34. // CHECK:STDOUT: %N: Core.BigInt = bind_symbolic_name N, 0 [symbolic]
  35. // CHECK:STDOUT: %N.patt: Core.BigInt = symbolic_binding_pattern N, 0 [symbolic]
  36. // CHECK:STDOUT: %ErrorIfNIsZero.type: type = fn_type @ErrorIfNIsZero [template]
  37. // CHECK:STDOUT: %ErrorIfNIsZero: %ErrorIfNIsZero.type = struct_value () [template]
  38. // CHECK:STDOUT: %Int.type: type = fn_type @Int [template]
  39. // CHECK:STDOUT: %Int: %Int.type = struct_value () [template]
  40. // CHECK:STDOUT: %.2: type = int_type signed, %N [symbolic]
  41. // CHECK:STDOUT: %CallNegative.type: type = fn_type @CallNegative [template]
  42. // CHECK:STDOUT: %CallNegative: %CallNegative.type = struct_value () [template]
  43. // CHECK:STDOUT: %.3: i32 = int_literal 0 [template]
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT:
  46. // CHECK:STDOUT: imports {
  47. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  48. // CHECK:STDOUT: .BigInt = %import_ref.1
  49. // CHECK:STDOUT: .Int = %import_ref.2
  50. // CHECK:STDOUT: import Core//prelude
  51. // CHECK:STDOUT: import Core//prelude/operators
  52. // CHECK:STDOUT: import Core//prelude/types
  53. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  54. // CHECK:STDOUT: import Core//prelude/operators/as
  55. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  56. // CHECK:STDOUT: import Core//prelude/operators/comparison
  57. // CHECK:STDOUT: import Core//prelude/types/bool
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT: %import_ref.1: %BigInt.type = import_ref Core//prelude/types, inst+7, loaded [template = constants.%BigInt]
  60. // CHECK:STDOUT: %import_ref.2: %Int.type = import_ref Core//prelude/types, inst+30, loaded [template = constants.%Int]
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT:
  63. // CHECK:STDOUT: file {
  64. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  65. // CHECK:STDOUT: .Core = imports.%Core
  66. // CHECK:STDOUT: .ErrorIfNIsZero = %ErrorIfNIsZero.decl
  67. // CHECK:STDOUT: .CallNegative = %CallNegative.decl
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT: %Core.import = import Core
  70. // CHECK:STDOUT: %ErrorIfNIsZero.decl: %ErrorIfNIsZero.type = fn_decl @ErrorIfNIsZero [template = constants.%ErrorIfNIsZero] {
  71. // CHECK:STDOUT: %N.patt.loc10_19.1: Core.BigInt = symbolic_binding_pattern N, 0 [symbolic = %N.patt.loc10_19.2 (constants.%N.patt)]
  72. // CHECK:STDOUT: %N.param_patt: Core.BigInt = value_param_pattern %N.patt.loc10_19.1, runtime_param<invalid> [symbolic = %N.patt.loc10_19.2 (constants.%N.patt)]
  73. // CHECK:STDOUT: %n.patt: <error> = binding_pattern n
  74. // CHECK:STDOUT: %n.param_patt: <error> = value_param_pattern %n.patt, runtime_param0
  75. // CHECK:STDOUT: } {
  76. // CHECK:STDOUT: %Core.ref.loc10_23: <namespace> = name_ref Core, imports.%Core [template = imports.%Core]
  77. // CHECK:STDOUT: %BigInt.ref: %BigInt.type = name_ref BigInt, imports.%import_ref.1 [template = constants.%BigInt]
  78. // CHECK:STDOUT: %big_int.make_type: init type = call %BigInt.ref() [template = Core.BigInt]
  79. // CHECK:STDOUT: %.loc10_35.1: type = value_of_initializer %big_int.make_type [template = Core.BigInt]
  80. // CHECK:STDOUT: %.loc10_35.2: type = converted %big_int.make_type, %.loc10_35.1 [template = Core.BigInt]
  81. // CHECK:STDOUT: %Core.ref.loc10_41: <namespace> = name_ref Core, imports.%Core [template = imports.%Core]
  82. // CHECK:STDOUT: %IntLiteral.ref: <error> = name_ref IntLiteral, <error> [template = <error>]
  83. // CHECK:STDOUT: %N.ref.loc10: Core.BigInt = name_ref N, %N.loc10_19.1 [symbolic = %N.loc10_19.2 (constants.%N)]
  84. // CHECK:STDOUT: %N.param: Core.BigInt = value_param runtime_param<invalid>
  85. // CHECK:STDOUT: %N.loc10_19.1: Core.BigInt = bind_symbolic_name N, 0, %N.param [symbolic = %N.loc10_19.2 (constants.%N)]
  86. // CHECK:STDOUT: %n.param: <error> = value_param runtime_param0
  87. // CHECK:STDOUT: %n: <error> = bind_name n, %n.param
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT: %CallNegative.decl: %CallNegative.type = fn_decl @CallNegative [template = constants.%CallNegative] {} {}
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: fn @BigInt() -> type = "big_int.make_type";
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: generic fn @ErrorIfNIsZero(%N.loc10_19.1: Core.BigInt) {
  95. // CHECK:STDOUT: %N.loc10_19.2: Core.BigInt = bind_symbolic_name N, 0 [symbolic = %N.loc10_19.2 (constants.%N)]
  96. // CHECK:STDOUT: %N.patt.loc10_19.2: Core.BigInt = symbolic_binding_pattern N, 0 [symbolic = %N.patt.loc10_19.2 (constants.%N.patt)]
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: !definition:
  99. // CHECK:STDOUT: %.loc15_18: type = int_type signed, %N.loc10_19.2 [symbolic = %.loc15_18 (constants.%.2)]
  100. // CHECK:STDOUT:
  101. // CHECK:STDOUT: fn[%N.param_patt: Core.BigInt](%n.param_patt: <error>) {
  102. // CHECK:STDOUT: !entry:
  103. // CHECK:STDOUT: %Core.ref.loc15: <namespace> = name_ref Core, imports.%Core [template = imports.%Core]
  104. // CHECK:STDOUT: %Int.ref: %Int.type = name_ref Int, imports.%import_ref.2 [template = constants.%Int]
  105. // CHECK:STDOUT: %N.ref.loc15: Core.BigInt = name_ref N, %N.loc10_19.1 [symbolic = %N.loc10_19.2 (constants.%N)]
  106. // CHECK:STDOUT: %int.make_type_signed: init type = call %Int.ref(%N.ref.loc15) [symbolic = %.loc15_18 (constants.%.2)]
  107. // CHECK:STDOUT: %.loc15_20.1: type = value_of_initializer %int.make_type_signed [symbolic = %.loc15_18 (constants.%.2)]
  108. // CHECK:STDOUT: %.loc15_20.2: type = converted %int.make_type_signed, %.loc15_20.1 [symbolic = %.loc15_18 (constants.%.2)]
  109. // CHECK:STDOUT: %v.var: ref @ErrorIfNIsZero.%.loc15_18 (%.2) = var v
  110. // CHECK:STDOUT: %v: ref @ErrorIfNIsZero.%.loc15_18 (%.2) = bind_name v, %v.var
  111. // CHECK:STDOUT: return
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT: }
  114. // CHECK:STDOUT:
  115. // CHECK:STDOUT: fn @Int(%size.param_patt: Core.BigInt) -> type = "int.make_type_signed";
  116. // CHECK:STDOUT:
  117. // CHECK:STDOUT: fn @CallNegative() {
  118. // CHECK:STDOUT: !entry:
  119. // CHECK:STDOUT: %ErrorIfNIsZero.ref: %ErrorIfNIsZero.type = name_ref ErrorIfNIsZero, file.%ErrorIfNIsZero.decl [template = constants.%ErrorIfNIsZero]
  120. // CHECK:STDOUT: %.loc19: i32 = int_literal 0 [template = constants.%.3]
  121. // CHECK:STDOUT: return
  122. // CHECK:STDOUT: }
  123. // CHECK:STDOUT:
  124. // CHECK:STDOUT: specific @ErrorIfNIsZero(constants.%N) {
  125. // CHECK:STDOUT: %N.loc10_19.2 => constants.%N
  126. // CHECK:STDOUT: %N.patt.loc10_19.2 => constants.%N
  127. // CHECK:STDOUT: }
  128. // CHECK:STDOUT: