Switch the prelude to using 'export import'. (#3976)

Note, I assume this doesn't affect all the TODOs (like for i32.carbon),
but does cut some things down (and requires updating some tests that
have prelude name conflicts, but I think they were intended to be
updated this way).
This commit is contained in:
Jon Ross-Perkins
2024-05-22 22:55:31 +00:00
committed by GitHub
parent d4025dc6c4
commit 3561ab5fae
35 changed files with 1370 additions and 3135 deletions
+39 -41
View File
@@ -6,47 +6,45 @@
// --- core.carbon
package Core;
package Core library "test";
import library "prelude";
fn Add(a: i32, b: i32) -> i32 = "int.sadd";
fn TestAdd(a: i32, b: i32) -> i32 = "int.sadd";
// --- use.carbon
import Core;
import Core library "test";
var arr: [i32; Core.Add(1, 2)] = (1, 2, 3);
var arr: [i32; Core.TestAdd(1, 2)] = (1, 2, 3);
// CHECK:STDOUT: --- core.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %Add: type = fn_type @Add [template]
// CHECK:STDOUT: %TestAdd: type = fn_type @TestAdd [template]
// CHECK:STDOUT: %.1: type = tuple_type () [template]
// CHECK:STDOUT: %struct: Add = struct_value () [template]
// CHECK:STDOUT: %struct: TestAdd = struct_value () [template]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: package: <namespace> = namespace [template] {
// CHECK:STDOUT: .Add = %Add.decl
// CHECK:STDOUT: .TestAdd = %TestAdd.decl
// CHECK:STDOUT: }
// CHECK:STDOUT: %Add.decl: Add = fn_decl @Add [template = constants.%struct] {
// CHECK:STDOUT: %a.loc6_8.1: i32 = param a
// CHECK:STDOUT: @Add.%a: i32 = bind_name a, %a.loc6_8.1
// CHECK:STDOUT: %b.loc6_16.1: i32 = param b
// CHECK:STDOUT: @Add.%b: i32 = bind_name b, %b.loc6_16.1
// CHECK:STDOUT: @Add.%return: ref i32 = var <return slot>
// CHECK:STDOUT: %TestAdd.decl: TestAdd = fn_decl @TestAdd [template = constants.%struct] {
// CHECK:STDOUT: %a.loc4_12.1: i32 = param a
// CHECK:STDOUT: @TestAdd.%a: i32 = bind_name a, %a.loc4_12.1
// CHECK:STDOUT: %b.loc4_20.1: i32 = param b
// CHECK:STDOUT: @TestAdd.%b: i32 = bind_name b, %b.loc4_20.1
// CHECK:STDOUT: @TestAdd.%return: ref i32 = var <return slot>
// CHECK:STDOUT: }
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @Add(%a: i32, %b: i32) -> i32 = "int.sadd";
// CHECK:STDOUT: fn @TestAdd(%a: i32, %b: i32) -> i32 = "int.sadd";
// CHECK:STDOUT:
// CHECK:STDOUT: --- use.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %Add: type = fn_type @Add [template]
// CHECK:STDOUT: %TestAdd: type = fn_type @TestAdd [template]
// CHECK:STDOUT: %.1: type = tuple_type () [template]
// CHECK:STDOUT: %struct: Add = struct_value () [template]
// CHECK:STDOUT: %struct: TestAdd = struct_value () [template]
// CHECK:STDOUT: %.2: i32 = int_literal 1 [template]
// CHECK:STDOUT: %.3: i32 = int_literal 2 [template]
// CHECK:STDOUT: %.4: i32 = int_literal 3 [template]
@@ -64,36 +62,36 @@ var arr: [i32; Core.Add(1, 2)] = (1, 2, 3);
// CHECK:STDOUT: }
// CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
// CHECK:STDOUT: %Core.ref: <namespace> = name_ref Core, %Core [template = %Core]
// CHECK:STDOUT: %import_ref: Add = import_ref ir2, inst+6, loaded [template = constants.%struct]
// CHECK:STDOUT: %Add.ref: Add = name_ref Add, %import_ref [template = constants.%struct]
// CHECK:STDOUT: %.loc4_25: i32 = int_literal 1 [template = constants.%.2]
// CHECK:STDOUT: %.loc4_28: i32 = int_literal 2 [template = constants.%.3]
// CHECK:STDOUT: %int.sadd: init i32 = call %Add.ref(%.loc4_25, %.loc4_28) [template = constants.%.4]
// CHECK:STDOUT: %.loc4_30: type = array_type %int.sadd, i32 [template = constants.%.5]
// CHECK:STDOUT: %import_ref: TestAdd = import_ref ir2, inst+6, loaded [template = constants.%struct]
// CHECK:STDOUT: %TestAdd.ref: TestAdd = name_ref TestAdd, %import_ref [template = constants.%struct]
// CHECK:STDOUT: %.loc4_29: i32 = int_literal 1 [template = constants.%.2]
// CHECK:STDOUT: %.loc4_32: i32 = int_literal 2 [template = constants.%.3]
// CHECK:STDOUT: %int.sadd: init i32 = call %TestAdd.ref(%.loc4_29, %.loc4_32) [template = constants.%.4]
// CHECK:STDOUT: %.loc4_34: type = array_type %int.sadd, i32 [template = constants.%.5]
// CHECK:STDOUT: %arr.var: ref [i32; 3] = var arr
// CHECK:STDOUT: %arr: ref [i32; 3] = bind_name arr, %arr.var
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @Add(%a: i32, %b: i32) -> i32 = "int.sadd";
// CHECK:STDOUT: fn @TestAdd(%a: i32, %b: i32) -> i32 = "int.sadd";
// CHECK:STDOUT:
// CHECK:STDOUT: fn @__global_init() {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %.loc4_35: i32 = int_literal 1 [template = constants.%.2]
// CHECK:STDOUT: %.loc4_38: i32 = int_literal 2 [template = constants.%.3]
// CHECK:STDOUT: %.loc4_41: i32 = int_literal 3 [template = constants.%.4]
// CHECK:STDOUT: %.loc4_42.1: (i32, i32, i32) = tuple_literal (%.loc4_35, %.loc4_38, %.loc4_41)
// CHECK:STDOUT: %.loc4_42.2: i32 = int_literal 0 [template = constants.%.8]
// CHECK:STDOUT: %.loc4_42.3: ref i32 = array_index file.%arr.var, %.loc4_42.2
// CHECK:STDOUT: %.loc4_42.4: init i32 = initialize_from %.loc4_35 to %.loc4_42.3 [template = constants.%.2]
// CHECK:STDOUT: %.loc4_42.5: i32 = int_literal 1 [template = constants.%.2]
// CHECK:STDOUT: %.loc4_42.6: ref i32 = array_index file.%arr.var, %.loc4_42.5
// CHECK:STDOUT: %.loc4_42.7: init i32 = initialize_from %.loc4_38 to %.loc4_42.6 [template = constants.%.3]
// CHECK:STDOUT: %.loc4_42.8: i32 = int_literal 2 [template = constants.%.3]
// CHECK:STDOUT: %.loc4_42.9: ref i32 = array_index file.%arr.var, %.loc4_42.8
// CHECK:STDOUT: %.loc4_42.10: init i32 = initialize_from %.loc4_41 to %.loc4_42.9 [template = constants.%.4]
// CHECK:STDOUT: %.loc4_42.11: init [i32; 3] = array_init (%.loc4_42.4, %.loc4_42.7, %.loc4_42.10) to file.%arr.var [template = constants.%array]
// CHECK:STDOUT: %.loc4_43: init [i32; 3] = converted %.loc4_42.1, %.loc4_42.11 [template = constants.%array]
// CHECK:STDOUT: assign file.%arr.var, %.loc4_43
// CHECK:STDOUT: %.loc4_39: i32 = int_literal 1 [template = constants.%.2]
// CHECK:STDOUT: %.loc4_42: i32 = int_literal 2 [template = constants.%.3]
// CHECK:STDOUT: %.loc4_45: i32 = int_literal 3 [template = constants.%.4]
// CHECK:STDOUT: %.loc4_46.1: (i32, i32, i32) = tuple_literal (%.loc4_39, %.loc4_42, %.loc4_45)
// CHECK:STDOUT: %.loc4_46.2: i32 = int_literal 0 [template = constants.%.8]
// CHECK:STDOUT: %.loc4_46.3: ref i32 = array_index file.%arr.var, %.loc4_46.2
// CHECK:STDOUT: %.loc4_46.4: init i32 = initialize_from %.loc4_39 to %.loc4_46.3 [template = constants.%.2]
// CHECK:STDOUT: %.loc4_46.5: i32 = int_literal 1 [template = constants.%.2]
// CHECK:STDOUT: %.loc4_46.6: ref i32 = array_index file.%arr.var, %.loc4_46.5
// CHECK:STDOUT: %.loc4_46.7: init i32 = initialize_from %.loc4_42 to %.loc4_46.6 [template = constants.%.3]
// CHECK:STDOUT: %.loc4_46.8: i32 = int_literal 2 [template = constants.%.3]
// CHECK:STDOUT: %.loc4_46.9: ref i32 = array_index file.%arr.var, %.loc4_46.8
// CHECK:STDOUT: %.loc4_46.10: init i32 = initialize_from %.loc4_45 to %.loc4_46.9 [template = constants.%.4]
// CHECK:STDOUT: %.loc4_46.11: init [i32; 3] = array_init (%.loc4_46.4, %.loc4_46.7, %.loc4_46.10) to file.%arr.var [template = constants.%array]
// CHECK:STDOUT: %.loc4_47: init [i32; 3] = converted %.loc4_46.1, %.loc4_46.11 [template = constants.%array]
// CHECK:STDOUT: assign file.%arr.var, %.loc4_47
// CHECK:STDOUT: return
// CHECK:STDOUT: }
// CHECK:STDOUT:
@@ -8,6 +8,8 @@
package Core;
fn Int32() -> type = "int.make_type_32";
interface Add {
fn Op[self: Self](other: Self) -> Self;
}
@@ -27,49 +29,57 @@ var arr: [i32; 1 + 2] = (3, 4, 3 + 4);
// CHECK:STDOUT: --- core.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %.1: type = interface_type @Add [template]
// CHECK:STDOUT: %Int32: type = fn_type @Int32 [template]
// CHECK:STDOUT: %.1: type = tuple_type () [template]
// CHECK:STDOUT: %struct.1: Int32 = struct_value () [template]
// CHECK:STDOUT: %.2: type = interface_type @Add [template]
// CHECK:STDOUT: %Self: Add = bind_symbolic_name Self 0 [symbolic]
// CHECK:STDOUT: %Op: type = fn_type @Op [template]
// CHECK:STDOUT: %.2: type = tuple_type () [template]
// CHECK:STDOUT: %struct: Op = struct_value () [template]
// CHECK:STDOUT: %struct.2: Op = struct_value () [template]
// CHECK:STDOUT: %.3: type = assoc_entity_type @Add, Op [template]
// CHECK:STDOUT: %.4: <associated Op in Add> = assoc_entity element0, @Add.%Op.decl [template]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: package: <namespace> = namespace [template] {
// CHECK:STDOUT: .Int32 = %Int32.decl
// CHECK:STDOUT: .Add = %Add.decl
// CHECK:STDOUT: }
// CHECK:STDOUT: %Add.decl: type = interface_decl @Add [template = constants.%.1] {}
// CHECK:STDOUT: %Int32.decl: Int32 = fn_decl @Int32 [template = constants.%struct.1] {
// CHECK:STDOUT: @Int32.%return: ref type = var <return slot>
// CHECK:STDOUT: }
// CHECK:STDOUT: %Add.decl: type = interface_decl @Add [template = constants.%.2] {}
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: interface @Add {
// CHECK:STDOUT: %Self: Add = bind_symbolic_name Self 0 [symbolic = constants.%Self]
// CHECK:STDOUT: %Op.decl: Op = fn_decl @Op [template = constants.%struct] {
// CHECK:STDOUT: %Self.ref.loc5_15: Add = name_ref Self, %Self [symbolic = constants.%Self]
// CHECK:STDOUT: %.loc5_15.1: type = facet_type_access %Self.ref.loc5_15 [symbolic = constants.%Self]
// CHECK:STDOUT: %.loc5_15.2: type = converted %Self.ref.loc5_15, %.loc5_15.1 [symbolic = constants.%Self]
// CHECK:STDOUT: %self.loc5_9.1: Self = param self
// CHECK:STDOUT: %self.loc5_9.2: Self = bind_name self, %self.loc5_9.1
// CHECK:STDOUT: %Self.ref.loc5_28: Add = name_ref Self, %Self [symbolic = constants.%Self]
// CHECK:STDOUT: %.loc5_28.1: type = facet_type_access %Self.ref.loc5_28 [symbolic = constants.%Self]
// CHECK:STDOUT: %.loc5_28.2: type = converted %Self.ref.loc5_28, %.loc5_28.1 [symbolic = constants.%Self]
// CHECK:STDOUT: %other.loc5_21.1: Self = param other
// CHECK:STDOUT: %other.loc5_21.2: Self = bind_name other, %other.loc5_21.1
// CHECK:STDOUT: %Self.ref.loc5_37: Add = name_ref Self, %Self [symbolic = constants.%Self]
// CHECK:STDOUT: %.loc5_37.1: type = facet_type_access %Self.ref.loc5_37 [symbolic = constants.%Self]
// CHECK:STDOUT: %.loc5_37.2: type = converted %Self.ref.loc5_37, %.loc5_37.1 [symbolic = constants.%Self]
// CHECK:STDOUT: %Op.decl: Op = fn_decl @Op [template = constants.%struct.2] {
// CHECK:STDOUT: %Self.ref.loc7_15: Add = name_ref Self, %Self [symbolic = constants.%Self]
// CHECK:STDOUT: %.loc7_15.1: type = facet_type_access %Self.ref.loc7_15 [symbolic = constants.%Self]
// CHECK:STDOUT: %.loc7_15.2: type = converted %Self.ref.loc7_15, %.loc7_15.1 [symbolic = constants.%Self]
// CHECK:STDOUT: %self.loc7_9.1: Self = param self
// CHECK:STDOUT: %self.loc7_9.2: Self = bind_name self, %self.loc7_9.1
// CHECK:STDOUT: %Self.ref.loc7_28: Add = name_ref Self, %Self [symbolic = constants.%Self]
// CHECK:STDOUT: %.loc7_28.1: type = facet_type_access %Self.ref.loc7_28 [symbolic = constants.%Self]
// CHECK:STDOUT: %.loc7_28.2: type = converted %Self.ref.loc7_28, %.loc7_28.1 [symbolic = constants.%Self]
// CHECK:STDOUT: %other.loc7_21.1: Self = param other
// CHECK:STDOUT: %other.loc7_21.2: Self = bind_name other, %other.loc7_21.1
// CHECK:STDOUT: %Self.ref.loc7_37: Add = name_ref Self, %Self [symbolic = constants.%Self]
// CHECK:STDOUT: %.loc7_37.1: type = facet_type_access %Self.ref.loc7_37 [symbolic = constants.%Self]
// CHECK:STDOUT: %.loc7_37.2: type = converted %Self.ref.loc7_37, %.loc7_37.1 [symbolic = constants.%Self]
// CHECK:STDOUT: %return.var: ref Self = var <return slot>
// CHECK:STDOUT: }
// CHECK:STDOUT: %.loc5_41: <associated Op in Add> = assoc_entity element0, %Op.decl [template = constants.%.4]
// CHECK:STDOUT: %.loc7_41: <associated Op in Add> = assoc_entity element0, %Op.decl [template = constants.%.4]
// CHECK:STDOUT:
// CHECK:STDOUT: !members:
// CHECK:STDOUT: .Self = %Self
// CHECK:STDOUT: .Op = %.loc5_41
// CHECK:STDOUT: .Op = %.loc7_41
// CHECK:STDOUT: witness = (%Op.decl)
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @Op[@Add.%self.loc5_9.2: Self](@Add.%other.loc5_21.2: Self) -> Self;
// CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
// CHECK:STDOUT:
// CHECK:STDOUT: fn @Op[@Add.%self.loc7_9.2: Self](@Add.%other.loc7_21.2: Self) -> Self;
// CHECK:STDOUT:
// CHECK:STDOUT: --- user.carbon
// CHECK:STDOUT:
@@ -104,31 +114,31 @@ var arr: [i32; 1 + 2] = (3, 4, 3 + 4);
// CHECK:STDOUT: .arr = %arr
// CHECK:STDOUT: }
// CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
// CHECK:STDOUT: %import_ref.1: type = import_ref ir2, inst+1, loaded [template = constants.%.1]
// CHECK:STDOUT: %import_ref.2: <associated Op in Add> = import_ref ir2, inst+24, loaded [template = constants.%.7]
// CHECK:STDOUT: %import_ref.3 = import_ref ir2, inst+3, unloaded
// CHECK:STDOUT: %import_ref.4: Op = import_ref ir2, inst+19, loaded [template = constants.%struct.2]
// CHECK:STDOUT: %import_ref.1: type = import_ref ir1, inst+6, loaded [template = constants.%.1]
// CHECK:STDOUT: %import_ref.2 = import_ref ir1, inst+8, unloaded
// CHECK:STDOUT: %import_ref.3: <associated Op in Add> = import_ref ir1, inst+28, loaded [template = constants.%.7]
// CHECK:STDOUT: %import_ref.4: Op = import_ref ir1, inst+24, loaded [template = constants.%struct.2]
// CHECK:STDOUT: impl_decl @impl {
// CHECK:STDOUT: %Core.ref: <namespace> = name_ref Core, %Core [template = %Core]
// CHECK:STDOUT: %Add.ref: type = name_ref Add, %import_ref.1 [template = constants.%.1]
// CHECK:STDOUT: }
// CHECK:STDOUT: %.loc10_16: i32 = int_literal 1 [template = constants.%.4]
// CHECK:STDOUT: %.loc10_20: i32 = int_literal 2 [template = constants.%.5]
// CHECK:STDOUT: %import_ref.5: type = import_ref ir2, inst+1, loaded [template = constants.%.1]
// CHECK:STDOUT: %import_ref.6 = import_ref ir2, inst+19, unloaded
// CHECK:STDOUT: %import_ref.5: type = import_ref ir1, inst+6, loaded [template = constants.%.1]
// CHECK:STDOUT: %import_ref.6 = import_ref ir1, inst+24, unloaded
// CHECK:STDOUT: %.1: Op = interface_witness_access @impl.%.1, element0 [template = constants.%struct.1]
// CHECK:STDOUT: %.loc10_18: <bound method> = bound_method %.loc10_16, %.1 [template = constants.%.8]
// CHECK:STDOUT: %int.sadd: init i32 = call %.loc10_18(%.loc10_16, %.loc10_20) [template = constants.%.9]
// CHECK:STDOUT: %.loc10_21: type = array_type %int.sadd, i32 [template = constants.%.10]
// CHECK:STDOUT: %arr.var: ref [i32; 3] = var arr
// CHECK:STDOUT: %arr: ref [i32; 3] = bind_name arr, %arr.var
// CHECK:STDOUT: %import_ref.7: type = import_ref ir2, inst+1, loaded [template = constants.%.1]
// CHECK:STDOUT: %import_ref.7: type = import_ref ir1, inst+6, loaded [template = constants.%.1]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: interface @Add {
// CHECK:STDOUT: !members:
// CHECK:STDOUT: .Op = file.%import_ref.2
// CHECK:STDOUT: .Self = file.%import_ref.3
// CHECK:STDOUT: .Self = file.%import_ref.2
// CHECK:STDOUT: .Op = file.%import_ref.3
// CHECK:STDOUT: witness = (file.%import_ref.4)
// CHECK:STDOUT: }
// CHECK:STDOUT: