import_base.carbon 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. // --- a.carbon
  7. library "a" api;
  8. base class Base {
  9. fn F[self: Self]();
  10. fn Unused[self: Self]();
  11. var x: i32;
  12. var unused: i32;
  13. }
  14. class Child {
  15. extend base: Base;
  16. }
  17. // --- b.carbon
  18. library "b" api;
  19. import library "a";
  20. fn Run() {
  21. var a: Child = {.base = {.x = 0, .unused = 1}};
  22. a.x = 2;
  23. a.F();
  24. }
  25. // CHECK:STDOUT: --- a.carbon
  26. // CHECK:STDOUT:
  27. // CHECK:STDOUT: constants {
  28. // CHECK:STDOUT: %Base: type = class_type @Base [template]
  29. // CHECK:STDOUT: %.1: type = unbound_element_type Base, i32 [template]
  30. // CHECK:STDOUT: %.2: type = struct_type {.x: i32, .unused: i32} [template]
  31. // CHECK:STDOUT: %Child: type = class_type @Child [template]
  32. // CHECK:STDOUT: %.3: type = ptr_type {.x: i32, .unused: i32} [template]
  33. // CHECK:STDOUT: %.4: type = unbound_element_type Child, Base [template]
  34. // CHECK:STDOUT: %.5: type = struct_type {.base: Base} [template]
  35. // CHECK:STDOUT: }
  36. // CHECK:STDOUT:
  37. // CHECK:STDOUT: file {
  38. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  39. // CHECK:STDOUT: .Core = %Core
  40. // CHECK:STDOUT: .Base = %Base.decl
  41. // CHECK:STDOUT: .Child = %Child.decl
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  44. // CHECK:STDOUT: %Base.decl: type = class_decl @Base [template = constants.%Base] {}
  45. // CHECK:STDOUT: %Child.decl: type = class_decl @Child [template = constants.%Child] {}
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT:
  48. // CHECK:STDOUT: class @Base {
  49. // CHECK:STDOUT: %F: <function> = fn_decl @F [template] {
  50. // CHECK:STDOUT: %Self.ref.loc5: type = name_ref Self, constants.%Base [template = constants.%Base]
  51. // CHECK:STDOUT: %self.loc5_8.1: Base = param self
  52. // CHECK:STDOUT: %self.loc5_8.2: Base = bind_name self, %self.loc5_8.1
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT: %Unused: <function> = fn_decl @Unused [template] {
  55. // CHECK:STDOUT: %Self.ref.loc6: type = name_ref Self, constants.%Base [template = constants.%Base]
  56. // CHECK:STDOUT: %self.loc6_13.1: Base = param self
  57. // CHECK:STDOUT: %self.loc6_13.2: Base = bind_name self, %self.loc6_13.1
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT: %.loc8: <unbound element of class Base> = field_decl x, element0 [template]
  60. // CHECK:STDOUT: %.loc9: <unbound element of class Base> = field_decl unused, element1 [template]
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: !members:
  63. // CHECK:STDOUT: .Self = constants.%Base
  64. // CHECK:STDOUT: .F = %F
  65. // CHECK:STDOUT: .Unused = %Unused
  66. // CHECK:STDOUT: .x = %.loc8
  67. // CHECK:STDOUT: .unused = %.loc9
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: class @Child {
  71. // CHECK:STDOUT: %Base.ref: type = name_ref Base, file.%Base.decl [template = constants.%Base]
  72. // CHECK:STDOUT: %.loc13: <unbound element of class Child> = base_decl Base, element0 [template]
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: !members:
  75. // CHECK:STDOUT: .Self = constants.%Child
  76. // CHECK:STDOUT: .base = %.loc13
  77. // CHECK:STDOUT: extend name_scope2
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: fn @F[@Base.%self.loc5_8.2: Base]();
  81. // CHECK:STDOUT:
  82. // CHECK:STDOUT: fn @Unused[@Base.%self.loc6_13.2: Base]();
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: --- b.carbon
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: constants {
  87. // CHECK:STDOUT: %Child: type = class_type @Child [template]
  88. // CHECK:STDOUT: %Base: type = class_type @Base [template]
  89. // CHECK:STDOUT: %.1: type = struct_type {.x: i32, .unused: i32} [template]
  90. // CHECK:STDOUT: %.2: type = unbound_element_type Child, Base [template]
  91. // CHECK:STDOUT: %.3: type = struct_type {.base: Base} [template]
  92. // CHECK:STDOUT: %.4: type = ptr_type {.x: i32, .unused: i32} [template]
  93. // CHECK:STDOUT: %.5: type = struct_type {.base: {.x: i32, .unused: i32}*} [template]
  94. // CHECK:STDOUT: %.6: type = ptr_type {.base: Base} [template]
  95. // CHECK:STDOUT: %.7: i32 = int_literal 0 [template]
  96. // CHECK:STDOUT: %.8: i32 = int_literal 1 [template]
  97. // CHECK:STDOUT: %.9: type = struct_type {.base: {.x: i32, .unused: i32}} [template]
  98. // CHECK:STDOUT: %.10: Base = struct_value (%.7, %.8) [template]
  99. // CHECK:STDOUT: %.11: Child = struct_value (%.10) [template]
  100. // CHECK:STDOUT: %.12: type = unbound_element_type Base, i32 [template]
  101. // CHECK:STDOUT: %.13: i32 = int_literal 2 [template]
  102. // CHECK:STDOUT: %.14: type = tuple_type () [template]
  103. // CHECK:STDOUT: }
  104. // CHECK:STDOUT:
  105. // CHECK:STDOUT: file {
  106. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  107. // CHECK:STDOUT: .Base = %import_ref.1
  108. // CHECK:STDOUT: .Child = %import_ref.2
  109. // CHECK:STDOUT: .Core = %Core
  110. // CHECK:STDOUT: .Run = %Run
  111. // CHECK:STDOUT: }
  112. // CHECK:STDOUT: %import_ref.1 = import_ref ir2, inst+2, unloaded
  113. // CHECK:STDOUT: %import_ref.2: type = import_ref ir2, inst+20, loc_16 [template = constants.%Child]
  114. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  115. // CHECK:STDOUT: %Run: <function> = fn_decl @Run [template] {}
  116. // CHECK:STDOUT: %import_ref.3: <function> = import_ref ir2, inst+7, loc_44 [template = imports.%F]
  117. // CHECK:STDOUT: %import_ref.4 = import_ref ir2, inst+3, unloaded
  118. // CHECK:STDOUT: %import_ref.5: <unbound element of class Base> = import_ref ir2, inst+13, loc_38 [template = imports.%.1]
  119. // CHECK:STDOUT: %import_ref.6 = import_ref ir2, inst+11, unloaded
  120. // CHECK:STDOUT: %import_ref.7 = import_ref ir2, inst+16, unloaded
  121. // CHECK:STDOUT: %import_ref.8 = import_ref ir2, inst+21, unloaded
  122. // CHECK:STDOUT: %import_ref.9 = import_ref ir2, inst+25, unloaded
  123. // CHECK:STDOUT: }
  124. // CHECK:STDOUT:
  125. // CHECK:STDOUT: class @Child {
  126. // CHECK:STDOUT: !members:
  127. // CHECK:STDOUT: .Self = file.%import_ref.8
  128. // CHECK:STDOUT: .base = file.%import_ref.9
  129. // CHECK:STDOUT: extend name_scope2
  130. // CHECK:STDOUT: }
  131. // CHECK:STDOUT:
  132. // CHECK:STDOUT: class @Base {
  133. // CHECK:STDOUT: !members:
  134. // CHECK:STDOUT: .F = file.%import_ref.3
  135. // CHECK:STDOUT: .Self = file.%import_ref.4
  136. // CHECK:STDOUT: .x = file.%import_ref.5
  137. // CHECK:STDOUT: .Unused = file.%import_ref.6
  138. // CHECK:STDOUT: .unused = file.%import_ref.7
  139. // CHECK:STDOUT: }
  140. // CHECK:STDOUT:
  141. // CHECK:STDOUT: fn @Run() {
  142. // CHECK:STDOUT: !entry:
  143. // CHECK:STDOUT: %Child.decl: invalid = class_decl @Child [template = constants.%Child] {}
  144. // CHECK:STDOUT: %Base.decl: invalid = class_decl @Base [template = constants.%Base] {}
  145. // CHECK:STDOUT: %Child.ref: type = name_ref Child, file.%import_ref.2 [template = constants.%Child]
  146. // CHECK:STDOUT: %a.var: ref Child = var a
  147. // CHECK:STDOUT: %a: ref Child = bind_name a, %a.var
  148. // CHECK:STDOUT: %.loc7_33: i32 = int_literal 0 [template = constants.%.7]
  149. // CHECK:STDOUT: %.loc7_46: i32 = int_literal 1 [template = constants.%.8]
  150. // CHECK:STDOUT: %.loc7_47.1: {.x: i32, .unused: i32} = struct_literal (%.loc7_33, %.loc7_46)
  151. // CHECK:STDOUT: %.loc7_48.1: {.base: {.x: i32, .unused: i32}} = struct_literal (%.loc7_47.1)
  152. // CHECK:STDOUT: %.loc7_48.2: ref Base = class_element_access %a.var, element0
  153. // CHECK:STDOUT: %.loc7_47.2: ref i32 = class_element_access %.loc7_48.2, element0
  154. // CHECK:STDOUT: %.loc7_47.3: init i32 = initialize_from %.loc7_33 to %.loc7_47.2 [template = constants.%.7]
  155. // CHECK:STDOUT: %.loc7_47.4: ref i32 = class_element_access %.loc7_48.2, element1
  156. // CHECK:STDOUT: %.loc7_47.5: init i32 = initialize_from %.loc7_46 to %.loc7_47.4 [template = constants.%.8]
  157. // CHECK:STDOUT: %.loc7_47.6: init Base = class_init (%.loc7_47.3, %.loc7_47.5), %.loc7_48.2 [template = constants.%.10]
  158. // CHECK:STDOUT: %.loc7_47.7: init Base = converted %.loc7_47.1, %.loc7_47.6 [template = constants.%.10]
  159. // CHECK:STDOUT: %.loc7_48.3: init Child = class_init (%.loc7_47.7), %a.var [template = constants.%.11]
  160. // CHECK:STDOUT: %.loc7_48.4: init Child = converted %.loc7_48.1, %.loc7_48.3 [template = constants.%.11]
  161. // CHECK:STDOUT: assign %a.var, %.loc7_48.4
  162. // CHECK:STDOUT: %a.ref.loc8: ref Child = name_ref a, %a
  163. // CHECK:STDOUT: %x.ref: <unbound element of class Base> = name_ref x, file.%import_ref.5 [template = imports.%.1]
  164. // CHECK:STDOUT: %.loc8_4.1: ref Base = class_element_access %a.ref.loc8, element0
  165. // CHECK:STDOUT: %.loc8_3: ref Base = converted %a.ref.loc8, %.loc8_4.1
  166. // CHECK:STDOUT: %.loc8_4.2: ref i32 = class_element_access %.loc8_3, element0
  167. // CHECK:STDOUT: %.loc8_9: i32 = int_literal 2 [template = constants.%.13]
  168. // CHECK:STDOUT: assign %.loc8_4.2, %.loc8_9
  169. // CHECK:STDOUT: %a.ref.loc9: ref Child = name_ref a, %a
  170. // CHECK:STDOUT: %F.ref: <function> = name_ref F, file.%import_ref.3 [template = imports.%F]
  171. // CHECK:STDOUT: %.loc9_4: <bound method> = bound_method %a.ref.loc9, %F.ref
  172. // CHECK:STDOUT: %.loc9_6.1: ref Base = class_element_access %a.ref.loc9, element0
  173. // CHECK:STDOUT: %.loc9_3.1: ref Base = converted %a.ref.loc9, %.loc9_6.1
  174. // CHECK:STDOUT: %.loc9_3.2: Base = bind_value %.loc9_3.1
  175. // CHECK:STDOUT: %.loc9_6.2: init () = call %.loc9_4(%.loc9_3.2)
  176. // CHECK:STDOUT: return
  177. // CHECK:STDOUT: }
  178. // CHECK:STDOUT:
  179. // CHECK:STDOUT: fn @F[%self: Base]();
  180. // CHECK:STDOUT: