import_base.carbon 9.4 KB

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