static_method.carbon 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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/static_method.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/static_method.carbon
  14. class Class {
  15. fn F() -> i32;
  16. }
  17. fn Run() -> i32 {
  18. var c: Class;
  19. return c.F();
  20. }
  21. // CHECK:STDOUT: --- static_method.carbon
  22. // CHECK:STDOUT:
  23. // CHECK:STDOUT: constants {
  24. // CHECK:STDOUT: %Class: type = class_type @Class [concrete]
  25. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  26. // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
  27. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [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: %.941: form = init_form %i32, call_param0 [concrete]
  31. // CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
  32. // CHECK:STDOUT: %Class.F.type: type = fn_type @Class.F [concrete]
  33. // CHECK:STDOUT: %Class.F: %Class.F.type = struct_value () [concrete]
  34. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  35. // CHECK:STDOUT: %complete_type.357: <witness> = complete_type_witness %empty_struct_type [concrete]
  36. // CHECK:STDOUT: %Run.type: type = fn_type @Run [concrete]
  37. // CHECK:STDOUT: %Run: %Run.type = struct_value () [concrete]
  38. // CHECK:STDOUT: %pattern_type.904: type = pattern_type %Class [concrete]
  39. // CHECK:STDOUT: %Destroy.type: type = facet_type <@Destroy> [concrete]
  40. // CHECK:STDOUT: %DestroyOp.type: type = fn_type @DestroyOp [concrete]
  41. // CHECK:STDOUT: %DestroyOp: %DestroyOp.type = struct_value () [concrete]
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT:
  44. // CHECK:STDOUT: imports {
  45. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  46. // CHECK:STDOUT: .Int = %Core.Int
  47. // CHECK:STDOUT: .Destroy = %Core.Destroy
  48. // CHECK:STDOUT: import Core//prelude
  49. // CHECK:STDOUT: import Core//prelude/...
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/parts/int, Int, loaded [concrete = constants.%Int.generic]
  52. // CHECK:STDOUT: %Core.Destroy: type = import_ref Core//prelude/parts/destroy, Destroy, loaded [concrete = constants.%Destroy.type]
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: file {
  56. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  57. // CHECK:STDOUT: .Core = imports.%Core
  58. // CHECK:STDOUT: .Class = %Class.decl
  59. // CHECK:STDOUT: .Run = %Run.decl
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT: %Core.import = import Core
  62. // CHECK:STDOUT: %Class.decl: type = class_decl @Class [concrete = constants.%Class] {} {}
  63. // CHECK:STDOUT: %Run.decl: %Run.type = fn_decl @Run [concrete = constants.%Run] {
  64. // CHECK:STDOUT: %return.patt: %pattern_type.7ce = return_slot_pattern [concrete]
  65. // CHECK:STDOUT: %return.param_patt: %pattern_type.7ce = out_param_pattern %return.patt, call_param0 [concrete]
  66. // CHECK:STDOUT: } {
  67. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  68. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  69. // CHECK:STDOUT: %.loc19: form = init_form %i32, call_param0 [concrete = constants.%.941]
  70. // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param0
  71. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  74. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT:
  77. // CHECK:STDOUT: class @Class {
  78. // CHECK:STDOUT: %Class.F.decl: %Class.F.type = fn_decl @Class.F [concrete = constants.%Class.F] {
  79. // CHECK:STDOUT: %return.patt: %pattern_type.7ce = return_slot_pattern [concrete]
  80. // CHECK:STDOUT: %return.param_patt: %pattern_type.7ce = out_param_pattern %return.patt, call_param0 [concrete]
  81. // CHECK:STDOUT: } {
  82. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  83. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  84. // CHECK:STDOUT: %.loc16: form = init_form %i32, call_param0 [concrete = constants.%.941]
  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: %complete_type: <witness> = complete_type_witness constants.%empty_struct_type [concrete = constants.%complete_type.357]
  89. // CHECK:STDOUT: complete_type_witness = %complete_type
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: !members:
  92. // CHECK:STDOUT: .Self = constants.%Class
  93. // CHECK:STDOUT: .F = %Class.F.decl
  94. // CHECK:STDOUT: }
  95. // CHECK:STDOUT:
  96. // CHECK:STDOUT: fn @Class.F() -> %i32;
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: fn @Run() -> %i32 {
  99. // CHECK:STDOUT: !entry:
  100. // CHECK:STDOUT: name_binding_decl {
  101. // CHECK:STDOUT: %c.patt: %pattern_type.904 = ref_binding_pattern c [concrete]
  102. // CHECK:STDOUT: %c.var_patt: %pattern_type.904 = var_pattern %c.patt [concrete]
  103. // CHECK:STDOUT: }
  104. // CHECK:STDOUT: %c.var: ref %Class = var %c.var_patt
  105. // CHECK:STDOUT: %Class.ref: type = name_ref Class, file.%Class.decl [concrete = constants.%Class]
  106. // CHECK:STDOUT: %c: ref %Class = ref_binding c, %c.var
  107. // CHECK:STDOUT: %c.ref: ref %Class = name_ref c, %c
  108. // CHECK:STDOUT: %F.ref: %Class.F.type = name_ref F, @Class.%Class.F.decl [concrete = constants.%Class.F]
  109. // CHECK:STDOUT: %Class.F.call: init %i32 = call %F.ref()
  110. // CHECK:STDOUT: %DestroyOp.bound: <bound method> = bound_method %c.var, constants.%DestroyOp
  111. // CHECK:STDOUT: %DestroyOp.call: init %empty_tuple.type = call %DestroyOp.bound(%c.var)
  112. // CHECK:STDOUT: return %Class.F.call to %return
  113. // CHECK:STDOUT: }
  114. // CHECK:STDOUT:
  115. // CHECK:STDOUT: fn @DestroyOp(%self.param: %Class) = "no_op";
  116. // CHECK:STDOUT: