non_generic.carbon 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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/where_expr/non_generic.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/where_expr/non_generic.carbon
  10. interface I { let T:! type; }
  11. // Ensure that we don't crash when checking this `where` in a non-generic context.
  12. fn NotGenericF(U: I where .T == i32) {}
  13. // CHECK:STDOUT: --- non_generic.carbon
  14. // CHECK:STDOUT:
  15. // CHECK:STDOUT: constants {
  16. // CHECK:STDOUT: %I.type: type = facet_type <@I> [concrete]
  17. // CHECK:STDOUT: %Self: %I.type = bind_symbolic_name Self, 0 [symbolic]
  18. // CHECK:STDOUT: %I.assoc_type: type = assoc_entity_type @I [concrete]
  19. // CHECK:STDOUT: %assoc0: %I.assoc_type = assoc_entity element0, @I.%T [concrete]
  20. // CHECK:STDOUT: %.Self: %I.type = bind_symbolic_name .Self [symbolic_self]
  21. // CHECK:STDOUT: %.Self.as_type: type = facet_access_type %.Self [symbolic_self]
  22. // CHECK:STDOUT: %I.lookup_impl_witness: <witness> = lookup_impl_witness %.Self, @I [symbolic_self]
  23. // CHECK:STDOUT: %I.facet: %I.type = facet_value %.Self.as_type, (%I.lookup_impl_witness) [symbolic_self]
  24. // CHECK:STDOUT: %impl.elem0: type = impl_witness_access %I.lookup_impl_witness, element0 [symbolic_self]
  25. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  26. // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
  27. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  28. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  29. // CHECK:STDOUT: %I_where.type: type = facet_type <@I where TODO> [concrete]
  30. // CHECK:STDOUT: %pattern_type.f03: type = pattern_type %I_where.type [concrete]
  31. // CHECK:STDOUT: %NotGenericF.type: type = fn_type @NotGenericF [concrete]
  32. // CHECK:STDOUT: %NotGenericF: %NotGenericF.type = struct_value () [concrete]
  33. // CHECK:STDOUT: }
  34. // CHECK:STDOUT:
  35. // CHECK:STDOUT: imports {
  36. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  37. // CHECK:STDOUT: .Int = %Core.Int
  38. // CHECK:STDOUT: import Core//prelude
  39. // CHECK:STDOUT: import Core//prelude/...
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/types/int, Int, loaded [concrete = constants.%Int.generic]
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT:
  44. // CHECK:STDOUT: file {
  45. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  46. // CHECK:STDOUT: .Core = imports.%Core
  47. // CHECK:STDOUT: .I = %I.decl
  48. // CHECK:STDOUT: .NotGenericF = %NotGenericF.decl
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT: %Core.import = import Core
  51. // CHECK:STDOUT: %I.decl: type = interface_decl @I [concrete = constants.%I.type] {} {}
  52. // CHECK:STDOUT: %NotGenericF.decl: %NotGenericF.type = fn_decl @NotGenericF [concrete = constants.%NotGenericF] {
  53. // CHECK:STDOUT: %U.patt: %pattern_type.f03 = binding_pattern U [concrete]
  54. // CHECK:STDOUT: %U.param_patt: %pattern_type.f03 = value_param_pattern %U.patt, call_param0 [concrete]
  55. // CHECK:STDOUT: } {
  56. // CHECK:STDOUT: %U.param: %I_where.type = value_param call_param0
  57. // CHECK:STDOUT: %.loc14_21.1: type = splice_block %.loc14_21.2 [concrete = constants.%I_where.type] {
  58. // CHECK:STDOUT: %I.ref: type = name_ref I, file.%I.decl [concrete = constants.%I.type]
  59. // CHECK:STDOUT: %.Self: %I.type = bind_symbolic_name .Self [symbolic_self = constants.%.Self]
  60. // CHECK:STDOUT: %.Self.ref: %I.type = name_ref .Self, %.Self [symbolic_self = constants.%.Self]
  61. // CHECK:STDOUT: %T.ref: %I.assoc_type = name_ref T, @T.%assoc0 [concrete = constants.%assoc0]
  62. // CHECK:STDOUT: %.Self.as_type: type = facet_access_type %.Self.ref [symbolic_self = constants.%.Self.as_type]
  63. // CHECK:STDOUT: %.loc14_27: type = converted %.Self.ref, %.Self.as_type [symbolic_self = constants.%.Self.as_type]
  64. // CHECK:STDOUT: %impl.elem0: type = impl_witness_access constants.%I.lookup_impl_witness, element0 [symbolic_self = constants.%impl.elem0]
  65. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  66. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  67. // CHECK:STDOUT: %.loc14_21.2: type = where_expr %.Self [concrete = constants.%I_where.type] {
  68. // CHECK:STDOUT: requirement_equivalent %impl.elem0, %i32
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT: %U: %I_where.type = bind_name U, %U.param
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: interface @I {
  76. // CHECK:STDOUT: %Self: %I.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self]
  77. // CHECK:STDOUT: %T: type = assoc_const_decl @T [concrete] {
  78. // CHECK:STDOUT: %assoc0: %I.assoc_type = assoc_entity element0, @I.%T [concrete = constants.%assoc0]
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT:
  81. // CHECK:STDOUT: !members:
  82. // CHECK:STDOUT: .Self = %Self
  83. // CHECK:STDOUT: .T = @T.%assoc0
  84. // CHECK:STDOUT: witness = (%T)
  85. // CHECK:STDOUT: }
  86. // CHECK:STDOUT:
  87. // CHECK:STDOUT: generic assoc_const @T(@I.%Self: %I.type) {
  88. // CHECK:STDOUT: assoc_const T:! type;
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: fn @NotGenericF(%U.param: %I_where.type) {
  92. // CHECK:STDOUT: !entry:
  93. // CHECK:STDOUT: return
  94. // CHECK:STDOUT: }
  95. // CHECK:STDOUT:
  96. // CHECK:STDOUT: specific @T(constants.%Self) {}
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: specific @T(constants.%I.facet) {}
  99. // CHECK:STDOUT: