reorder.carbon 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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/class/reorder.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/reorder.carbon
  10. class Class {
  11. fn G() -> i32 {
  12. return Class.F();
  13. }
  14. fn F() -> i32 {
  15. return 1;
  16. }
  17. }
  18. // CHECK:STDOUT: --- reorder.carbon
  19. // CHECK:STDOUT:
  20. // CHECK:STDOUT: constants {
  21. // CHECK:STDOUT: %Class: type = class_type @Class [template]
  22. // CHECK:STDOUT: %.1: Core.IntLiteral = int_value 32 [template]
  23. // CHECK:STDOUT: %Int.type: type = fn_type @Int [template]
  24. // CHECK:STDOUT: %Int: %Int.type = struct_value () [template]
  25. // CHECK:STDOUT: %i32: type = int_type signed, %.1 [template]
  26. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  27. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  28. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  29. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  30. // CHECK:STDOUT: %.2: type = struct_type {} [template]
  31. // CHECK:STDOUT: %.3: <witness> = complete_type_witness %.2 [template]
  32. // CHECK:STDOUT: %.5: Core.IntLiteral = int_value 1 [template]
  33. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  34. // CHECK:STDOUT: %Convert.type.14: type = fn_type @Convert.2, @impl.1(%.1) [template]
  35. // CHECK:STDOUT: %Convert.14: %Convert.type.14 = struct_value () [template]
  36. // CHECK:STDOUT: %.25: <witness> = interface_witness (%Convert.14) [template]
  37. // CHECK:STDOUT: %.26: <bound method> = bound_method %.5, %Convert.14 [template]
  38. // CHECK:STDOUT: %.27: <specific function> = specific_function %.26, @Convert.2(%.1) [template]
  39. // CHECK:STDOUT: %.28: %i32 = int_value 1 [template]
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT:
  42. // CHECK:STDOUT: imports {
  43. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  44. // CHECK:STDOUT: .Int = %import_ref.1
  45. // CHECK:STDOUT: .ImplicitAs = %import_ref.2
  46. // CHECK:STDOUT: import Core//prelude
  47. // CHECK:STDOUT: import Core//prelude/...
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: file {
  52. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  53. // CHECK:STDOUT: .Core = imports.%Core
  54. // CHECK:STDOUT: .Class = %Class.decl
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT: %Core.import = import Core
  57. // CHECK:STDOUT: %Class.decl: type = class_decl @Class [template = constants.%Class] {} {}
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT:
  60. // CHECK:STDOUT: class @Class {
  61. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  62. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  63. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param0
  64. // CHECK:STDOUT: } {
  65. // CHECK:STDOUT: %.loc12_13.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  66. // CHECK:STDOUT: %int.make_type_signed: init type = call constants.%Int(%.loc12_13.1) [template = constants.%i32]
  67. // CHECK:STDOUT: %.loc12_13.2: type = value_of_initializer %int.make_type_signed [template = constants.%i32]
  68. // CHECK:STDOUT: %.loc12_13.3: type = converted %int.make_type_signed, %.loc12_13.2 [template = constants.%i32]
  69. // CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param0
  70. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  73. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  74. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param0
  75. // CHECK:STDOUT: } {
  76. // CHECK:STDOUT: %.loc16_13.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  77. // CHECK:STDOUT: %int.make_type_signed: init type = call constants.%Int(%.loc16_13.1) [template = constants.%i32]
  78. // CHECK:STDOUT: %.loc16_13.2: type = value_of_initializer %int.make_type_signed [template = constants.%i32]
  79. // CHECK:STDOUT: %.loc16_13.3: type = converted %int.make_type_signed, %.loc16_13.2 [template = constants.%i32]
  80. // CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param0
  81. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT: %.loc19: <witness> = complete_type_witness %.2 [template = constants.%.3]
  84. // CHECK:STDOUT:
  85. // CHECK:STDOUT: !members:
  86. // CHECK:STDOUT: .Self = constants.%Class
  87. // CHECK:STDOUT: .G = %G.decl
  88. // CHECK:STDOUT: .F = %F.decl
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: fn @G() -> %i32 {
  92. // CHECK:STDOUT: !entry:
  93. // CHECK:STDOUT: %Class.ref: type = name_ref Class, file.%Class.decl [template = constants.%Class]
  94. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, @Class.%F.decl [template = constants.%F]
  95. // CHECK:STDOUT: %F.call: init %i32 = call %F.ref()
  96. // CHECK:STDOUT: %.loc13_21.1: %i32 = value_of_initializer %F.call
  97. // CHECK:STDOUT: %.loc13_21.2: %i32 = converted %F.call, %.loc13_21.1
  98. // CHECK:STDOUT: return %.loc13_21.2
  99. // CHECK:STDOUT: }
  100. // CHECK:STDOUT:
  101. // CHECK:STDOUT: fn @F() -> %i32 {
  102. // CHECK:STDOUT: !entry:
  103. // CHECK:STDOUT: %.loc17_12: Core.IntLiteral = int_value 1 [template = constants.%.5]
  104. // CHECK:STDOUT: %.loc17_13.1: %Convert.type.2 = interface_witness_access constants.%.25, element0 [template = constants.%Convert.14]
  105. // CHECK:STDOUT: %.loc17_13.2: <bound method> = bound_method %.loc17_12, %.loc17_13.1 [template = constants.%.26]
  106. // CHECK:STDOUT: %.loc17_13.3: <specific function> = specific_function %.loc17_13.2, @Convert.2(constants.%.1) [template = constants.%.27]
  107. // CHECK:STDOUT: %int.convert_checked: init %i32 = call %.loc17_13.3(%.loc17_12) [template = constants.%.28]
  108. // CHECK:STDOUT: %.loc17_13.4: %i32 = value_of_initializer %int.convert_checked [template = constants.%.28]
  109. // CHECK:STDOUT: %.loc17_13.5: %i32 = converted %.loc17_12, %.loc17_13.4 [template = constants.%.28]
  110. // CHECK:STDOUT: return %.loc17_13.5
  111. // CHECK:STDOUT: }
  112. // CHECK:STDOUT: