reorder.carbon 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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/class/reorder.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/reorder.carbon
  14. class Class {
  15. fn G() -> i32 {
  16. return Class.F();
  17. }
  18. fn F() -> i32 {
  19. return 1;
  20. }
  21. }
  22. // CHECK:STDOUT: --- reorder.carbon
  23. // CHECK:STDOUT:
  24. // CHECK:STDOUT: constants {
  25. // CHECK:STDOUT: %Class: type = class_type @Class [concrete]
  26. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  27. // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
  28. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  29. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  30. // CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
  31. // CHECK:STDOUT: %Class.G.type: type = fn_type @Class.G [concrete]
  32. // CHECK:STDOUT: %Class.G: %Class.G.type = struct_value () [concrete]
  33. // CHECK:STDOUT: %Class.F.type: type = fn_type @Class.F [concrete]
  34. // CHECK:STDOUT: %Class.F: %Class.F.type = struct_value () [concrete]
  35. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  36. // CHECK:STDOUT: %complete_type.357: <witness> = complete_type_witness %empty_struct_type [concrete]
  37. // CHECK:STDOUT: %int_1.5b8: Core.IntLiteral = int_value 1 [concrete]
  38. // CHECK:STDOUT: %ImplicitAs.type.cc7: type = generic_interface_type @ImplicitAs [concrete]
  39. // CHECK:STDOUT: %ImplicitAs.generic: %ImplicitAs.type.cc7 = struct_value () [concrete]
  40. // CHECK:STDOUT: %ImplicitAs.type.d14: type = facet_type <@ImplicitAs, @ImplicitAs(%i32)> [concrete]
  41. // CHECK:STDOUT: %ImplicitAs.Convert.type.1b6: type = fn_type @ImplicitAs.Convert, @ImplicitAs(%i32) [concrete]
  42. // CHECK:STDOUT: %To: Core.IntLiteral = symbolic_binding To, 0 [symbolic]
  43. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.f51: type = fn_type @Core.IntLiteral.as.ImplicitAs.impl.Convert, @Core.IntLiteral.as.ImplicitAs.impl(%To) [symbolic]
  44. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.2a1: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.f51 = struct_value () [symbolic]
  45. // CHECK:STDOUT: %ImplicitAs.impl_witness.bc9: <witness> = impl_witness imports.%ImplicitAs.impl_witness_table.132, @Core.IntLiteral.as.ImplicitAs.impl(%int_32) [concrete]
  46. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.51e: type = fn_type @Core.IntLiteral.as.ImplicitAs.impl.Convert, @Core.IntLiteral.as.ImplicitAs.impl(%int_32) [concrete]
  47. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.e9b: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.51e = struct_value () [concrete]
  48. // CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.d14 = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.bc9) [concrete]
  49. // CHECK:STDOUT: %.322: type = fn_type_with_self_type %ImplicitAs.Convert.type.1b6, %ImplicitAs.facet [concrete]
  50. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.bound: <bound method> = bound_method %int_1.5b8, %Core.IntLiteral.as.ImplicitAs.impl.Convert.e9b [concrete]
  51. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn: <specific function> = specific_function %Core.IntLiteral.as.ImplicitAs.impl.Convert.e9b, @Core.IntLiteral.as.ImplicitAs.impl.Convert(%int_32) [concrete]
  52. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %int_1.5b8, %Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn [concrete]
  53. // CHECK:STDOUT: %int_1.5d2: %i32 = int_value 1 [concrete]
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT:
  56. // CHECK:STDOUT: imports {
  57. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  58. // CHECK:STDOUT: .Int = %Core.Int
  59. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  60. // CHECK:STDOUT: import Core//prelude
  61. // CHECK:STDOUT: import Core//prelude/...
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/parts/int, Int, loaded [concrete = constants.%Int.generic]
  64. // CHECK:STDOUT: %Core.ImplicitAs: %ImplicitAs.type.cc7 = import_ref Core//prelude/parts/as, ImplicitAs, loaded [concrete = constants.%ImplicitAs.generic]
  65. // CHECK:STDOUT: %Core.import_ref.e24: @Core.IntLiteral.as.ImplicitAs.impl.%Core.IntLiteral.as.ImplicitAs.impl.Convert.type (%Core.IntLiteral.as.ImplicitAs.impl.Convert.type.f51) = import_ref Core//prelude/parts/int, loc{{\d+_\d+}}, loaded [symbolic = @Core.IntLiteral.as.ImplicitAs.impl.%Core.IntLiteral.as.ImplicitAs.impl.Convert (constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.2a1)]
  66. // CHECK:STDOUT: %ImplicitAs.impl_witness_table.132 = impl_witness_table (%Core.import_ref.e24), @Core.IntLiteral.as.ImplicitAs.impl [concrete]
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT:
  69. // CHECK:STDOUT: file {
  70. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  71. // CHECK:STDOUT: .Core = imports.%Core
  72. // CHECK:STDOUT: .Class = %Class.decl
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT: %Core.import = import Core
  75. // CHECK:STDOUT: %Class.decl: type = class_decl @Class [concrete = constants.%Class] {} {}
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT:
  78. // CHECK:STDOUT: class @Class {
  79. // CHECK:STDOUT: %Class.G.decl: %Class.G.type = fn_decl @Class.G [concrete = constants.%Class.G] {
  80. // CHECK:STDOUT: %return.patt: %pattern_type.7ce = return_slot_pattern [concrete]
  81. // CHECK:STDOUT: %return.param_patt: %pattern_type.7ce = out_param_pattern %return.patt, call_param0 [concrete]
  82. // CHECK:STDOUT: } {
  83. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  84. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  85. // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param0
  86. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT: %Class.F.decl: %Class.F.type = fn_decl @Class.F [concrete = constants.%Class.F] {
  89. // CHECK:STDOUT: %return.patt: %pattern_type.7ce = return_slot_pattern [concrete]
  90. // CHECK:STDOUT: %return.param_patt: %pattern_type.7ce = out_param_pattern %return.patt, call_param0 [concrete]
  91. // CHECK:STDOUT: } {
  92. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  93. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  94. // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param0
  95. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%empty_struct_type [concrete = constants.%complete_type.357]
  98. // CHECK:STDOUT: complete_type_witness = %complete_type
  99. // CHECK:STDOUT:
  100. // CHECK:STDOUT: !members:
  101. // CHECK:STDOUT: .Self = constants.%Class
  102. // CHECK:STDOUT: .G = %Class.G.decl
  103. // CHECK:STDOUT: .F = %Class.F.decl
  104. // CHECK:STDOUT: .Class = <poisoned>
  105. // CHECK:STDOUT: }
  106. // CHECK:STDOUT:
  107. // CHECK:STDOUT: fn @Class.G() -> %i32 {
  108. // CHECK:STDOUT: !entry:
  109. // CHECK:STDOUT: %Class.ref: type = name_ref Class, file.%Class.decl [concrete = constants.%Class]
  110. // CHECK:STDOUT: %F.ref: %Class.F.type = name_ref F, @Class.%Class.F.decl [concrete = constants.%Class.F]
  111. // CHECK:STDOUT: %Class.F.call: init %i32 = call %F.ref()
  112. // CHECK:STDOUT: return %Class.F.call to %return
  113. // CHECK:STDOUT: }
  114. // CHECK:STDOUT:
  115. // CHECK:STDOUT: fn @Class.F() -> %i32 {
  116. // CHECK:STDOUT: !entry:
  117. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8]
  118. // CHECK:STDOUT: %impl.elem0: %.322 = impl_witness_access constants.%ImplicitAs.impl_witness.bc9, element0 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.e9b]
  119. // CHECK:STDOUT: %bound_method.loc21_13.1: <bound method> = bound_method %int_1, %impl.elem0 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.bound]
  120. // CHECK:STDOUT: %specific_fn: <specific function> = specific_function %impl.elem0, @Core.IntLiteral.as.ImplicitAs.impl.Convert(constants.%int_32) [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn]
  121. // CHECK:STDOUT: %bound_method.loc21_13.2: <bound method> = bound_method %int_1, %specific_fn [concrete = constants.%bound_method]
  122. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.call: init %i32 = call %bound_method.loc21_13.2(%int_1) [concrete = constants.%int_1.5d2]
  123. // CHECK:STDOUT: %.loc21: init %i32 = converted %int_1, %Core.IntLiteral.as.ImplicitAs.impl.Convert.call [concrete = constants.%int_1.5d2]
  124. // CHECK:STDOUT: return %.loc21 to %return
  125. // CHECK:STDOUT: }
  126. // CHECK:STDOUT: