generic.carbon 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 = symbolic_binding .Self [symbolic_self]
  27. // CHECK:STDOUT: %T: type = symbolic_binding 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: type = ptr_type %T [symbolic]
  34. // CHECK:STDOUT: %pattern_type.a60: type = pattern_type %ptr [symbolic]
  35. // CHECK:STDOUT: %pattern_type.e68: 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 = symbolic_binding DestroyT, 0 [symbolic]
  40. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.type.15c: 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.fd5: %DestroyT.binding.as_type.as.Destroy.impl.Op.type.15c = struct_value () [symbolic]
  42. // CHECK:STDOUT: %facet_value: %type_where = facet_value %ptr, () [symbolic]
  43. // CHECK:STDOUT: %Destroy.impl_witness.60c: <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.e46: 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.9ef: %DestroyT.binding.as_type.as.Destroy.impl.Op.type.e46 = struct_value () [symbolic]
  46. // CHECK:STDOUT: %Destroy.facet: %Destroy.type = facet_value %ptr, (%Destroy.impl_witness.60c) [symbolic]
  47. // CHECK:STDOUT: %.17f: type = fn_type_with_self_type %Destroy.Op.type, %Destroy.facet [symbolic]
  48. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.specific_fn: <specific function> = specific_function %DestroyT.binding.as_type.as.Destroy.impl.Op.9ef, @DestroyT.binding.as_type.as.Destroy.impl.Op(%facet_value) [symbolic]
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: imports {
  52. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  53. // CHECK:STDOUT: .Int = %Core.Int
  54. // CHECK:STDOUT: .Destroy = %Core.Destroy
  55. // CHECK:STDOUT: import Core//prelude
  56. // CHECK:STDOUT: import Core//prelude/...
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/parts/int, Int, loaded [concrete = constants.%Int.generic]
  59. // CHECK:STDOUT: %Core.Destroy: type = import_ref Core//prelude/parts/destroy, Destroy, loaded [concrete = constants.%Destroy.type]
  60. // CHECK:STDOUT: %Core.import_ref.5c4: @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.15c) = 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.fd5)]
  61. // CHECK:STDOUT: %Destroy.impl_witness_table = impl_witness_table (%Core.import_ref.5c4), @DestroyT.binding.as_type.as.Destroy.impl [concrete]
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: file {
  65. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  66. // CHECK:STDOUT: .Core = imports.%Core
  67. // CHECK:STDOUT: .F = %F.decl
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT: %Core.import = import Core
  70. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {}
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT:
  73. // CHECK:STDOUT: fn @F() {
  74. // CHECK:STDOUT: !entry:
  75. // CHECK:STDOUT: name_binding_decl {
  76. // CHECK:STDOUT: %T.patt: %pattern_type.98f = symbolic_binding_pattern T, 0 [concrete]
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  79. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  80. // CHECK:STDOUT: %.Self: %type = symbolic_binding .Self [symbolic_self = constants.%.Self]
  81. // CHECK:STDOUT: %T: type = symbolic_binding T, 0, %i32 [symbolic = constants.%T]
  82. // CHECK:STDOUT: name_binding_decl {
  83. // CHECK:STDOUT: %p.patt: %pattern_type.a60 = ref_binding_pattern p [concrete]
  84. // CHECK:STDOUT: %p.var_patt: %pattern_type.a60 = var_pattern %p.patt [concrete]
  85. // CHECK:STDOUT: }
  86. // CHECK:STDOUT: %p.var: ref %ptr = var %p.var_patt
  87. // CHECK:STDOUT: %.loc17: type = splice_block %ptr [symbolic = constants.%ptr] {
  88. // CHECK:STDOUT: %T.ref.loc17: type = name_ref T, %T [symbolic = constants.%T]
  89. // CHECK:STDOUT: %ptr: type = ptr_type %T.ref.loc17 [symbolic = constants.%ptr]
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT: %p: ref %ptr = ref_binding p, %p.var
  92. // CHECK:STDOUT: name_binding_decl {
  93. // CHECK:STDOUT: %a.patt: %pattern_type.e68 = value_binding_pattern a [concrete]
  94. // CHECK:STDOUT: }
  95. // CHECK:STDOUT: %p.ref: ref %ptr = name_ref p, %p
  96. // CHECK:STDOUT: %.loc18_15: %ptr = acquire_value %p.ref
  97. // CHECK:STDOUT: %.loc18_14.1: ref %T = deref %.loc18_15
  98. // CHECK:STDOUT: %T.ref.loc18: type = name_ref T, %T [symbolic = constants.%T]
  99. // CHECK:STDOUT: %.loc18_14.2: %T = acquire_value %.loc18_14.1
  100. // CHECK:STDOUT: %a: %T = value_binding a, %.loc18_14.2
  101. // CHECK:STDOUT: %impl.elem0: %.17f = impl_witness_access constants.%Destroy.impl_witness.60c, element0 [symbolic = constants.%DestroyT.binding.as_type.as.Destroy.impl.Op.9ef]
  102. // CHECK:STDOUT: %bound_method.loc17_3.1: <bound method> = bound_method %p.var, %impl.elem0
  103. // 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]
  104. // CHECK:STDOUT: %bound_method.loc17_3.2: <bound method> = bound_method %p.var, %specific_fn
  105. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.call: init %empty_tuple.type = call %bound_method.loc17_3.2(%p.var)
  106. // CHECK:STDOUT: return
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT: