authorgravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2024-10-20 18:20:08-04:00
committergravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2024-10-22 12:41:35-04:00
logb87fa93500380068b0fd1db6cd73623f3fbfa284
treec777094804204382d741b7e5e03c038d363651de
parenta4690ecb1fc8a9ac5f7dfccfdf9f67c7a74e1569

Change `ExternOptions.dll_storage_class` to `is_dll_import`

It wouldn't make sense to have passe `.export` here, and that was in fact a compile error - so simply make this a bool instead.

3 files changed, 11 insertions(+), 24 deletions(-)

lib/std/builtin.zig+1-9
......@@ -68,14 +68,6 @@ pub const GlobalLinkage = enum {
6868 link_once,
6969};
7070
71/// This data structure is used by the Zig language code generation and
72/// therefore must be kept in sync with the compiler implementation.
73pub const DllStorageClass = enum {
74 default,
75 import,
76 @"export",
77};
78
7971/// This data structure is used by the Zig language code generation and
8072/// therefore must be kept in sync with the compiler implementation.
8173pub const SymbolVisibility = enum {
......@@ -691,7 +683,7 @@ pub const ExternOptions = struct {
691683 library_name: ?[]const u8 = null,
692684 linkage: GlobalLinkage = .strong,
693685 is_thread_local: bool = false,
694 dll_storage_class: DllStorageClass = .default,
686 is_dll_import: bool = false,
695687};
696688
697689/// This data structure is used by the Zig language code generation and
src/Sema.zig+7-12
......@@ -26970,7 +26970,7 @@ fn resolveExternOptions(
2697026970 library_name: InternPool.OptionalNullTerminatedString = .none,
2697126971 linkage: std.builtin.GlobalLinkage = .strong,
2697226972 is_thread_local: bool = false,
26973 dll_storage_class: std.builtin.DllStorageClass = .default,
26973 is_dll_import: bool = false,
2697426974} {
2697526975 const pt = sema.pt;
2697626976 const zcu = pt.zcu;
......@@ -26984,7 +26984,7 @@ fn resolveExternOptions(
2698426984 const library_src = block.src(.{ .init_field_library = src.offset.node_offset_builtin_call_arg.builtin_call_node });
2698526985 const linkage_src = block.src(.{ .init_field_linkage = src.offset.node_offset_builtin_call_arg.builtin_call_node });
2698626986 const thread_local_src = block.src(.{ .init_field_thread_local = src.offset.node_offset_builtin_call_arg.builtin_call_node });
26987 const dll_storage_class_src = block.src(.{ .init_field_dll_storage_class = src.offset.node_offset_builtin_call_arg.builtin_call_node });
26987 const dll_import_src = block.src(.{ .init_field_dll_import = src.offset.node_offset_builtin_call_arg.builtin_call_node });
2698826988
2698926989 const name_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "name", .no_embedded_nulls), name_src);
2699026990 const name = try sema.toConstString(block, name_src, name_ref, .{
......@@ -27018,11 +27018,10 @@ fn resolveExternOptions(
2701827018 break :library_name library_name;
2701927019 } else null;
2702027020
27021 const dll_storage_class_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "dll_storage_class", .no_embedded_nulls), dll_storage_class_src);
27022 const dll_storage_class_val = try sema.resolveConstDefinedValue(block, dll_storage_class_src, dll_storage_class_ref, .{
27023 .needed_comptime_reason = "dll_storage_class of the extern symbol must be comptime-known",
27021 const is_dll_import_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "is_dll_import", .no_embedded_nulls), dll_import_src);
27022 const is_dll_import_val = try sema.resolveConstDefinedValue(block, dll_import_src, is_dll_import_ref, .{
27023 .needed_comptime_reason = "it must be comptime-known if the symbol is imported from a dll",
2702427024 });
27025 const dll_storage_class = zcu.toEnum(std.builtin.DllStorageClass, dll_storage_class_val);
2702627025
2702727026 if (name.len == 0) {
2702827027 return sema.fail(block, name_src, "extern symbol name cannot be empty", .{});
......@@ -27032,16 +27031,12 @@ fn resolveExternOptions(
2703227031 return sema.fail(block, linkage_src, "extern symbol must use strong or weak linkage", .{});
2703327032 }
2703427033
27035 if (dll_storage_class == .@"export") {
27036 return sema.fail(block, dll_storage_class_src, "extern symbol cannot have export dll storage class", .{});
27037 }
27038
2703927034 return .{
2704027035 .name = try ip.getOrPutString(gpa, pt.tid, name, .no_embedded_nulls),
2704127036 .library_name = try ip.getOrPutStringOpt(gpa, pt.tid, library_name, .no_embedded_nulls),
2704227037 .linkage = linkage,
2704327038 .is_thread_local = is_thread_local_val.toBool(),
27044 .dll_storage_class = dll_storage_class,
27039 .is_dll_import = is_dll_import_val.toBool(),
2704527040 };
2704627041}
2704727042
......@@ -27087,7 +27082,7 @@ fn zirBuiltinExtern(
2708727082 .is_const = ptr_info.flags.is_const,
2708827083 .is_threadlocal = options.is_thread_local,
2708927084 .is_weak_linkage = options.linkage == .weak,
27090 .is_dll_import = options.dll_storage_class == .import,
27085 .is_dll_import = options.is_dll_import,
2709127086 .alignment = ptr_info.flags.alignment,
2709227087 .@"addrspace" = ptr_info.flags.address_space,
2709327088 // This instruction is just for source locations.
src/Zcu.zig+3-3
......@@ -1522,7 +1522,7 @@ pub const SrcLoc = struct {
15221522 .init_field_cache,
15231523 .init_field_library,
15241524 .init_field_thread_local,
1525 .init_field_dll_storage_class,
1525 .init_field_dll_import,
15261526 => |builtin_call_node| {
15271527 const wanted = switch (src_loc.lazy) {
15281528 .init_field_name => "name",
......@@ -1534,7 +1534,7 @@ pub const SrcLoc = struct {
15341534 .init_field_cache => "cache",
15351535 .init_field_library => "library",
15361536 .init_field_thread_local => "thread_local",
1537 .init_field_dll_storage_class => "dll_storage_class",
1537 .init_field_dll_import => "dll_import",
15381538 else => unreachable,
15391539 };
15401540 const tree = try src_loc.file_scope.getTree(gpa);
......@@ -1961,7 +1961,7 @@ pub const LazySrcLoc = struct {
19611961 init_field_cache: i32,
19621962 init_field_library: i32,
19631963 init_field_thread_local: i32,
1964 init_field_dll_storage_class: i32,
1964 init_field_dll_import: i32,
19651965 /// The source location points to the value of an item in a specific
19661966 /// case of a `switch`.
19671967 switch_case_item: SwitchItem,