Partial overlap with #30873.
Based these observations:
- The only fields of
ExternOptionsthat are relevant to SPIR-V arenameanddecoration. decorationmust be null on non-SPIR-V.
These should be different types.
--- a/lib/std/lang.zig
+++ b/lib/std/lang.zig
@@ -1160,35 +1160,45 @@ pub const ExportOptions = struct {
/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
-pub const ExternOptions = struct {
- name: []const u8,
- library_name: ?[]const u8 = null,
- linkage: GlobalLinkage = .strong,
- visibility: SymbolVisibility = .default,
- /// Setting this to `true` makes the `@extern` a runtime value.
- is_thread_local: bool = false,
- is_dll_import: bool = false,
- relocation: Relocation = .any,
- decoration: ?Decoration = null,
+pub const ExternOptions = switch (builtin.cpu.arch) {
+ .spirv32, .spirv64 => struct {
+ name: []const u8,
+ decoration: ?Decoration = null,
+
+ pub const Decoration = union(enum) {
+ storage: Storage,
+ descriptor: Descriptor,
+ };
- pub const Decoration = union(enum) {
- location: u32,
- flat: u32,
- descriptor: Descriptor,
+ pub const Storage = struct {
+ location: u32,
+ flat: bool = false,
+ name: ?[]const u8 = null,
+ };
pub const Descriptor = struct {
set: u32,
binding: u32,
};
- };
-
- pub const Relocation = enum(u1) {
- /// Any type of relocation is allowed.
- any,
- /// A program-counter-relative relocation is required.
- /// Using this value makes the `@extern` a runtime value.
- pcrel,
- };
+ },
+ else => struct {
+ name: []const u8,
+ library_name: ?[]const u8 = null,
+ linkage: GlobalLinkage = .strong,
+ visibility: SymbolVisibility = .default,
+ /// Setting this to `true` makes the `@extern` a runtime value.
+ is_thread_local: bool = false,
+ is_dll_import: bool = false,
+ relocation: Relocation = .any,
+
+ pub const Relocation = enum(u1) {
+ /// Any type of relocation is allowed.
+ any,
+ /// A program-counter-relative relocation is required.
+ /// Using this value makes the `@extern` a runtime value.
+ pcrel,
+ };
+ },
};
/// This data structure is used by the Zig language code generation and
Original version of this proposal was based on my incorrect understanding that name was unused on SPIR-V when in fact it appears to be always used, at least for debug information. Also incorrect understanding that decoration was mandatory, when in fact it can be null on SPIR-V too. Even so, this proposal is accepted.
Partial overlap with #30873.
Based these observations:
* The only fields of `ExternOptions` that are relevant to SPIR-V are `name` and `decoration`.
* `decoration` must be null on non-SPIR-V.
These should be different types.
```diff
--- a/lib/std/lang.zig
+++ b/lib/std/lang.zig
@@ -1160,35 +1160,45 @@ pub const ExportOptions = struct {
/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
-pub const ExternOptions = struct {
- name: []const u8,
- library_name: ?[]const u8 = null,
- linkage: GlobalLinkage = .strong,
- visibility: SymbolVisibility = .default,
- /// Setting this to `true` makes the `@extern` a runtime value.
- is_thread_local: bool = false,
- is_dll_import: bool = false,
- relocation: Relocation = .any,
- decoration: ?Decoration = null,
+pub const ExternOptions = switch (builtin.cpu.arch) {
+ .spirv32, .spirv64 => struct {
+ name: []const u8,
+ decoration: ?Decoration = null,
+
+ pub const Decoration = union(enum) {
+ storage: Storage,
+ descriptor: Descriptor,
+ };
- pub const Decoration = union(enum) {
- location: u32,
- flat: u32,
- descriptor: Descriptor,
+ pub const Storage = struct {
+ location: u32,
+ flat: bool = false,
+ name: ?[]const u8 = null,
+ };
pub const Descriptor = struct {
set: u32,
binding: u32,
};
- };
-
- pub const Relocation = enum(u1) {
- /// Any type of relocation is allowed.
- any,
- /// A program-counter-relative relocation is required.
- /// Using this value makes the `@extern` a runtime value.
- pcrel,
- };
+ },
+ else => struct {
+ name: []const u8,
+ library_name: ?[]const u8 = null,
+ linkage: GlobalLinkage = .strong,
+ visibility: SymbolVisibility = .default,
+ /// Setting this to `true` makes the `@extern` a runtime value.
+ is_thread_local: bool = false,
+ is_dll_import: bool = false,
+ relocation: Relocation = .any,
+
+ pub const Relocation = enum(u1) {
+ /// Any type of relocation is allowed.
+ any,
+ /// A program-counter-relative relocation is required.
+ /// Using this value makes the `@extern` a runtime value.
+ pcrel,
+ };
+ },
};
/// This data structure is used by the Zig language code generation and
```
Original version of this proposal was based on my incorrect understanding that `name` was unused on SPIR-V when in fact it appears to be always used, at least for debug information. Also incorrect understanding that `decoration` was mandatory, when in fact it can be null on SPIR-V too. Even so, this proposal is accepted.