reorder.carbon 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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: %Int32.type: type = fn_type @Int32 [template]
  23. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  24. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  25. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  26. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  27. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  28. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  29. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
  30. // CHECK:STDOUT: %.4: Core.IntLiteral = int_value 1 [template]
  31. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert.1, @ImplicitAs(i32) [template]
  32. // CHECK:STDOUT: %Convert.type.15: type = fn_type @Convert.11 [template]
  33. // CHECK:STDOUT: %Convert.15: %Convert.type.15 = struct_value () [template]
  34. // CHECK:STDOUT: %.28: <witness> = interface_witness (%Convert.15) [template]
  35. // CHECK:STDOUT: %.29: <bound method> = bound_method %.4, %Convert.15 [template]
  36. // CHECK:STDOUT: %.30: i32 = int_value 1 [template]
  37. // CHECK:STDOUT: }
  38. // CHECK:STDOUT:
  39. // CHECK:STDOUT: imports {
  40. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  41. // CHECK:STDOUT: .Int32 = %import_ref.1
  42. // CHECK:STDOUT: .ImplicitAs = %import_ref.2
  43. // CHECK:STDOUT: import Core//prelude
  44. // CHECK:STDOUT: import Core//prelude/...
  45. // CHECK:STDOUT: }
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT:
  48. // CHECK:STDOUT: file {
  49. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  50. // CHECK:STDOUT: .Core = imports.%Core
  51. // CHECK:STDOUT: .Class = %Class.decl
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT: %Core.import = import Core
  54. // CHECK:STDOUT: %Class.decl: type = class_decl @Class [template = constants.%Class] {} {}
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT:
  57. // CHECK:STDOUT: class @Class {
  58. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  59. // CHECK:STDOUT: %return.patt: i32 = return_slot_pattern
  60. // CHECK:STDOUT: %return.param_patt: i32 = out_param_pattern %return.patt, runtime_param0
  61. // CHECK:STDOUT: } {
  62. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  63. // CHECK:STDOUT: %.loc12_13.1: type = value_of_initializer %int.make_type_32 [template = i32]
  64. // CHECK:STDOUT: %.loc12_13.2: type = converted %int.make_type_32, %.loc12_13.1 [template = i32]
  65. // CHECK:STDOUT: %return.param: ref i32 = out_param runtime_param0
  66. // CHECK:STDOUT: %return: ref i32 = return_slot %return.param
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  69. // CHECK:STDOUT: %return.patt: i32 = return_slot_pattern
  70. // CHECK:STDOUT: %return.param_patt: i32 = out_param_pattern %return.patt, runtime_param0
  71. // CHECK:STDOUT: } {
  72. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  73. // CHECK:STDOUT: %.loc16_13.1: type = value_of_initializer %int.make_type_32 [template = i32]
  74. // CHECK:STDOUT: %.loc16_13.2: type = converted %int.make_type_32, %.loc16_13.1 [template = i32]
  75. // CHECK:STDOUT: %return.param: ref i32 = out_param runtime_param0
  76. // CHECK:STDOUT: %return: ref i32 = return_slot %return.param
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT: %.loc19: <witness> = complete_type_witness %.1 [template = constants.%.2]
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: !members:
  81. // CHECK:STDOUT: .Self = constants.%Class
  82. // CHECK:STDOUT: .G = %G.decl
  83. // CHECK:STDOUT: .F = %F.decl
  84. // CHECK:STDOUT: }
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: fn @G() -> i32 {
  87. // CHECK:STDOUT: !entry:
  88. // CHECK:STDOUT: %Class.ref: type = name_ref Class, file.%Class.decl [template = constants.%Class]
  89. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, @Class.%F.decl [template = constants.%F]
  90. // CHECK:STDOUT: %F.call: init i32 = call %F.ref()
  91. // CHECK:STDOUT: %.loc13_21.1: i32 = value_of_initializer %F.call
  92. // CHECK:STDOUT: %.loc13_21.2: i32 = converted %F.call, %.loc13_21.1
  93. // CHECK:STDOUT: return %.loc13_21.2
  94. // CHECK:STDOUT: }
  95. // CHECK:STDOUT:
  96. // CHECK:STDOUT: fn @F() -> i32 {
  97. // CHECK:STDOUT: !entry:
  98. // CHECK:STDOUT: %.loc17_12: Core.IntLiteral = int_value 1 [template = constants.%.4]
  99. // CHECK:STDOUT: %.loc17_13.1: %Convert.type.2 = interface_witness_access constants.%.28, element0 [template = constants.%Convert.15]
  100. // CHECK:STDOUT: %.loc17_13.2: <bound method> = bound_method %.loc17_12, %.loc17_13.1 [template = constants.%.29]
  101. // CHECK:STDOUT: %int.convert_checked: init i32 = call %.loc17_13.2(%.loc17_12) [template = constants.%.30]
  102. // CHECK:STDOUT: %.loc17_13.3: i32 = value_of_initializer %int.convert_checked [template = constants.%.30]
  103. // CHECK:STDOUT: %.loc17_13.4: i32 = converted %.loc17_12, %.loc17_13.3 [template = constants.%.30]
  104. // CHECK:STDOUT: return %.loc17_13.4
  105. // CHECK:STDOUT: }
  106. // CHECK:STDOUT: