generic.carbon 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/int.carbon
  6. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  7. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  8. //
  9. // AUTOUPDATE
  10. // TIP: To test this file alone, run:
  11. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/let/generic.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/let/generic.carbon
  14. fn F() {
  15. let T:! type = i32;
  16. var p: T*;
  17. let a: T = *p;
  18. }
  19. // CHECK:STDOUT: --- generic.carbon
  20. // CHECK:STDOUT:
  21. // CHECK:STDOUT: constants {
  22. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  23. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  24. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  25. // CHECK:STDOUT: %type: type = facet_type <type> [concrete]
  26. // CHECK:STDOUT: %.Self: %type = bind_symbolic_name .Self [symbolic_self]
  27. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic]
  28. // CHECK:STDOUT: %pattern_type.98f: type = pattern_type type [concrete]
  29. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  30. // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
  31. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  32. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  33. // CHECK:STDOUT: %ptr.79f: type = ptr_type %T [symbolic]
  34. // CHECK:STDOUT: %pattern_type.afe: type = pattern_type %ptr.79f [symbolic]
  35. // CHECK:STDOUT: %pattern_type.7dc: type = pattern_type %T [symbolic]
  36. // CHECK:STDOUT: %Destroy.type: type = facet_type <@Destroy> [concrete]
  37. // CHECK:STDOUT: %Destroy.Op.type: type = fn_type @Destroy.Op [concrete]
  38. // CHECK:STDOUT: %type_where: type = facet_type <type where .Self impls <CanDestroy>> [concrete]
  39. // CHECK:STDOUT: %DestroyT: %type_where = bind_symbolic_name DestroyT, 0 [symbolic]
  40. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.type.b5d: type = fn_type @DestroyT.binding.as_type.as.Destroy.impl.Op, @DestroyT.binding.as_type.as.Destroy.impl(%DestroyT) [symbolic]
  41. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.544: %DestroyT.binding.as_type.as.Destroy.impl.Op.type.b5d = struct_value () [symbolic]
  42. // CHECK:STDOUT: %facet_value: %type_where = facet_value %ptr.79f, () [symbolic]
  43. // CHECK:STDOUT: %Destroy.impl_witness.5e2: <witness> = impl_witness imports.%Destroy.impl_witness_table, @DestroyT.binding.as_type.as.Destroy.impl(%facet_value) [symbolic]
  44. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.type.ca5: type = fn_type @DestroyT.binding.as_type.as.Destroy.impl.Op, @DestroyT.binding.as_type.as.Destroy.impl(%facet_value) [symbolic]
  45. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.7c0: %DestroyT.binding.as_type.as.Destroy.impl.Op.type.ca5 = struct_value () [symbolic]
  46. // CHECK:STDOUT: %ptr.a13: type = ptr_type %ptr.79f [symbolic]
  47. // CHECK:STDOUT: %Destroy.facet: %Destroy.type = facet_value %ptr.79f, (%Destroy.impl_witness.5e2) [symbolic]
  48. // CHECK:STDOUT: %.0f0: type = fn_type_with_self_type %Destroy.Op.type, %Destroy.facet [symbolic]
  49. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.specific_fn: <specific function> = specific_function %DestroyT.binding.as_type.as.Destroy.impl.Op.7c0, @DestroyT.binding.as_type.as.Destroy.impl.Op(%facet_value) [symbolic]
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT:
  52. // CHECK:STDOUT: imports {
  53. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  54. // CHECK:STDOUT: .Int = %Core.Int
  55. // CHECK:STDOUT: .Destroy = %Core.Destroy
  56. // CHECK:STDOUT: import Core//prelude
  57. // CHECK:STDOUT: import Core//prelude/...
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/parts/int, Int, loaded [concrete = constants.%Int.generic]
  60. // CHECK:STDOUT: %Core.Destroy: type = import_ref Core//prelude/parts/destroy, Destroy, loaded [concrete = constants.%Destroy.type]
  61. // CHECK:STDOUT: %Core.import_ref.950: @DestroyT.binding.as_type.as.Destroy.impl.%DestroyT.binding.as_type.as.Destroy.impl.Op.type (%DestroyT.binding.as_type.as.Destroy.impl.Op.type.b5d) = import_ref Core//prelude/parts/destroy, loc{{\d+_\d+}}, loaded [symbolic = @DestroyT.binding.as_type.as.Destroy.impl.%DestroyT.binding.as_type.as.Destroy.impl.Op (constants.%DestroyT.binding.as_type.as.Destroy.impl.Op.544)]
  62. // CHECK:STDOUT: %Destroy.impl_witness_table = impl_witness_table (%Core.import_ref.950), @DestroyT.binding.as_type.as.Destroy.impl [concrete]
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: file {
  66. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  67. // CHECK:STDOUT: .Core = imports.%Core
  68. // CHECK:STDOUT: .F = %F.decl
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT: %Core.import = import Core
  71. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {}
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: fn @F() {
  75. // CHECK:STDOUT: !entry:
  76. // CHECK:STDOUT: name_binding_decl {
  77. // CHECK:STDOUT: %T.patt: %pattern_type.98f = symbolic_binding_pattern T, 0 [concrete]
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  80. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  81. // CHECK:STDOUT: %.Self: %type = bind_symbolic_name .Self [symbolic_self = constants.%.Self]
  82. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0, %i32 [symbolic = constants.%T]
  83. // CHECK:STDOUT: name_binding_decl {
  84. // CHECK:STDOUT: %p.patt: %pattern_type.afe = binding_pattern p [concrete]
  85. // CHECK:STDOUT: %p.var_patt: %pattern_type.afe = var_pattern %p.patt [concrete]
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT: %p.var: ref %ptr.79f = var %p.var_patt
  88. // CHECK:STDOUT: %.loc17: type = splice_block %ptr [symbolic = constants.%ptr.79f] {
  89. // CHECK:STDOUT: %T.ref.loc17: type = name_ref T, %T [symbolic = constants.%T]
  90. // CHECK:STDOUT: %ptr: type = ptr_type %T.ref.loc17 [symbolic = constants.%ptr.79f]
  91. // CHECK:STDOUT: }
  92. // CHECK:STDOUT: %p: ref %ptr.79f = bind_name p, %p.var
  93. // CHECK:STDOUT: name_binding_decl {
  94. // CHECK:STDOUT: %a.patt: %pattern_type.7dc = binding_pattern a [concrete]
  95. // CHECK:STDOUT: }
  96. // CHECK:STDOUT: %p.ref: ref %ptr.79f = name_ref p, %p
  97. // CHECK:STDOUT: %.loc18_15: %ptr.79f = bind_value %p.ref
  98. // CHECK:STDOUT: %.loc18_14.1: ref %T = deref %.loc18_15
  99. // CHECK:STDOUT: %T.ref.loc18: type = name_ref T, %T [symbolic = constants.%T]
  100. // CHECK:STDOUT: %.loc18_14.2: %T = bind_value %.loc18_14.1
  101. // CHECK:STDOUT: %a: %T = bind_name a, %.loc18_14.2
  102. // CHECK:STDOUT: %impl.elem0: %.0f0 = impl_witness_access constants.%Destroy.impl_witness.5e2, element0 [symbolic = constants.%DestroyT.binding.as_type.as.Destroy.impl.Op.7c0]
  103. // CHECK:STDOUT: %bound_method.loc17_3.1: <bound method> = bound_method %p.var, %impl.elem0
  104. // CHECK:STDOUT: %specific_fn: <specific function> = specific_function %impl.elem0, @DestroyT.binding.as_type.as.Destroy.impl.Op(constants.%facet_value) [symbolic = constants.%DestroyT.binding.as_type.as.Destroy.impl.Op.specific_fn]
  105. // CHECK:STDOUT: %bound_method.loc17_3.2: <bound method> = bound_method %p.var, %specific_fn
  106. // CHECK:STDOUT: %addr: %ptr.a13 = addr_of %p.var
  107. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.call: init %empty_tuple.type = call %bound_method.loc17_3.2(%addr)
  108. // CHECK:STDOUT: return
  109. // CHECK:STDOUT: }
  110. // CHECK:STDOUT: