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 {...@@ -68,14 +68,6 @@ pub const GlobalLinkage = enum {
68 link_once,68 link_once,
69};69};
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
79/// This data structure is used by the Zig language code generation and71/// This data structure is used by the Zig language code generation and
80/// therefore must be kept in sync with the compiler implementation.72/// therefore must be kept in sync with the compiler implementation.
81pub const SymbolVisibility = enum {73pub const SymbolVisibility = enum {
...@@ -691,7 +683,7 @@ pub const ExternOptions = struct {...@@ -691,7 +683,7 @@ pub const ExternOptions = struct {
691 library_name: ?[]const u8 = null,683 library_name: ?[]const u8 = null,
692 linkage: GlobalLinkage = .strong,684 linkage: GlobalLinkage = .strong,
693 is_thread_local: bool = false,685 is_thread_local: bool = false,
694 dll_storage_class: DllStorageClass = .default,686 is_dll_import: bool = false,
695};687};
696688
697/// This data structure is used by the Zig language code generation and689/// This data structure is used by the Zig language code generation and
src/Sema.zig+7-12
...@@ -26970,7 +26970,7 @@ fn resolveExternOptions(...@@ -26970,7 +26970,7 @@ fn resolveExternOptions(
26970 library_name: InternPool.OptionalNullTerminatedString = .none,26970 library_name: InternPool.OptionalNullTerminatedString = .none,
26971 linkage: std.builtin.GlobalLinkage = .strong,26971 linkage: std.builtin.GlobalLinkage = .strong,
26972 is_thread_local: bool = false,26972 is_thread_local: bool = false,
26973 dll_storage_class: std.builtin.DllStorageClass = .default,26973 is_dll_import: bool = false,
26974} {26974} {
26975 const pt = sema.pt;26975 const pt = sema.pt;
26976 const zcu = pt.zcu;26976 const zcu = pt.zcu;
...@@ -26984,7 +26984,7 @@ fn resolveExternOptions(...@@ -26984,7 +26984,7 @@ fn resolveExternOptions(
26984 const library_src = block.src(.{ .init_field_library = src.offset.node_offset_builtin_call_arg.builtin_call_node });26984 const library_src = block.src(.{ .init_field_library = src.offset.node_offset_builtin_call_arg.builtin_call_node });
26985 const linkage_src = block.src(.{ .init_field_linkage = src.offset.node_offset_builtin_call_arg.builtin_call_node });26985 const linkage_src = block.src(.{ .init_field_linkage = src.offset.node_offset_builtin_call_arg.builtin_call_node });
26986 const thread_local_src = block.src(.{ .init_field_thread_local = src.offset.node_offset_builtin_call_arg.builtin_call_node });26986 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
26989 const name_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "name", .no_embedded_nulls), name_src);26989 const name_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "name", .no_embedded_nulls), name_src);
26990 const name = try sema.toConstString(block, name_src, name_ref, .{26990 const name = try sema.toConstString(block, name_src, name_ref, .{
...@@ -27018,11 +27018,10 @@ fn resolveExternOptions(...@@ -27018,11 +27018,10 @@ fn resolveExternOptions(
27018 break :library_name library_name;27018 break :library_name library_name;
27019 } else null;27019 } 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);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 dll_storage_class_val = try sema.resolveConstDefinedValue(block, dll_storage_class_src, dll_storage_class_ref, .{27022 const is_dll_import_val = try sema.resolveConstDefinedValue(block, dll_import_src, is_dll_import_ref, .{
27023 .needed_comptime_reason = "dll_storage_class of the extern symbol must be comptime-known",27023 .needed_comptime_reason = "it must be comptime-known if the symbol is imported from a dll",
27024 });27024 });
27025 const dll_storage_class = zcu.toEnum(std.builtin.DllStorageClass, dll_storage_class_val);
2702627025
27027 if (name.len == 0) {27026 if (name.len == 0) {
27028 return sema.fail(block, name_src, "extern symbol name cannot be empty", .{});27027 return sema.fail(block, name_src, "extern symbol name cannot be empty", .{});
...@@ -27032,16 +27031,12 @@ fn resolveExternOptions(...@@ -27032,16 +27031,12 @@ fn resolveExternOptions(
27032 return sema.fail(block, linkage_src, "extern symbol must use strong or weak linkage", .{});27031 return sema.fail(block, linkage_src, "extern symbol must use strong or weak linkage", .{});
27033 }27032 }
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
27039 return .{27034 return .{
27040 .name = try ip.getOrPutString(gpa, pt.tid, name, .no_embedded_nulls),27035 .name = try ip.getOrPutString(gpa, pt.tid, name, .no_embedded_nulls),
27041 .library_name = try ip.getOrPutStringOpt(gpa, pt.tid, library_name, .no_embedded_nulls),27036 .library_name = try ip.getOrPutStringOpt(gpa, pt.tid, library_name, .no_embedded_nulls),
27042 .linkage = linkage,27037 .linkage = linkage,
27043 .is_thread_local = is_thread_local_val.toBool(),27038 .is_thread_local = is_thread_local_val.toBool(),
27044 .dll_storage_class = dll_storage_class,27039 .is_dll_import = is_dll_import_val.toBool(),
27045 };27040 };
27046}27041}
2704727042
...@@ -27087,7 +27082,7 @@ fn zirBuiltinExtern(...@@ -27087,7 +27082,7 @@ fn zirBuiltinExtern(
27087 .is_const = ptr_info.flags.is_const,27082 .is_const = ptr_info.flags.is_const,
27088 .is_threadlocal = options.is_thread_local,27083 .is_threadlocal = options.is_thread_local,
27089 .is_weak_linkage = options.linkage == .weak,27084 .is_weak_linkage = options.linkage == .weak,
27090 .is_dll_import = options.dll_storage_class == .import,27085 .is_dll_import = options.is_dll_import,
27091 .alignment = ptr_info.flags.alignment,27086 .alignment = ptr_info.flags.alignment,
27092 .@"addrspace" = ptr_info.flags.address_space,27087 .@"addrspace" = ptr_info.flags.address_space,
27093 // This instruction is just for source locations.27088 // This instruction is just for source locations.
src/Zcu.zig+3-3
...@@ -1522,7 +1522,7 @@ pub const SrcLoc = struct {...@@ -1522,7 +1522,7 @@ pub const SrcLoc = struct {
1522 .init_field_cache,1522 .init_field_cache,
1523 .init_field_library,1523 .init_field_library,
1524 .init_field_thread_local,1524 .init_field_thread_local,
1525 .init_field_dll_storage_class,1525 .init_field_dll_import,
1526 => |builtin_call_node| {1526 => |builtin_call_node| {
1527 const wanted = switch (src_loc.lazy) {1527 const wanted = switch (src_loc.lazy) {
1528 .init_field_name => "name",1528 .init_field_name => "name",
...@@ -1534,7 +1534,7 @@ pub const SrcLoc = struct {...@@ -1534,7 +1534,7 @@ pub const SrcLoc = struct {
1534 .init_field_cache => "cache",1534 .init_field_cache => "cache",
1535 .init_field_library => "library",1535 .init_field_library => "library",
1536 .init_field_thread_local => "thread_local",1536 .init_field_thread_local => "thread_local",
1537 .init_field_dll_storage_class => "dll_storage_class",1537 .init_field_dll_import => "dll_import",
1538 else => unreachable,1538 else => unreachable,
1539 };1539 };
1540 const tree = try src_loc.file_scope.getTree(gpa);1540 const tree = try src_loc.file_scope.getTree(gpa);
...@@ -1961,7 +1961,7 @@ pub const LazySrcLoc = struct {...@@ -1961,7 +1961,7 @@ pub const LazySrcLoc = struct {
1961 init_field_cache: i32,1961 init_field_cache: i32,
1962 init_field_library: i32,1962 init_field_library: i32,
1963 init_field_thread_local: i32,1963 init_field_thread_local: i32,
1964 init_field_dll_storage_class: i32,1964 init_field_dll_import: i32,
1965 /// The source location points to the value of an item in a specific1965 /// The source location points to the value of an item in a specific
1966 /// case of a `switch`.1966 /// case of a `switch`.
1967 switch_case_item: SwitchItem,1967 switch_case_item: SwitchItem,