@zigc/lib 0.17.0-dev.813 → 0.17.0-dev.836

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -285,10 +285,10 @@ fn updateStats() error{OutOfMemory}!void {
285
285
  , .{
286
286
  hdr.n_runs,
287
287
  hdr.unique_runs,
288
- @as(f64, @floatFromInt(hdr.unique_runs)) / @as(f64, @floatFromInt(hdr.n_runs)),
288
+ @as(f64, @floatFromInt(hdr.unique_runs)) / @as(f64, @floatFromInt(hdr.n_runs)) * 100,
289
289
  covered_src_locs,
290
290
  total_src_locs,
291
- @as(f64, @floatFromInt(covered_src_locs)) / @as(f64, @floatFromInt(total_src_locs)),
291
+ @as(f64, @floatFromInt(covered_src_locs)) / @as(f64, @floatFromInt(total_src_locs)) * 100,
292
292
  avg_speed,
293
293
  });
294
294
  defer gpa.free(html);
package/c/math.zig CHANGED
@@ -37,6 +37,7 @@ comptime {
37
37
  symbol(&hypotf, "hypotf");
38
38
  symbol(&hypotl, "hypotl");
39
39
  symbol(&lrintl, "lrintl");
40
+ symbol(&lroundl, "lroundl");
40
41
  symbol(&modfl, "modfl");
41
42
  symbol(&rintl, "rintl");
42
43
  }
@@ -76,6 +77,8 @@ comptime {
76
77
  symbol(&log1pf, "log1pf");
77
78
  symbol(&lrint, "lrint");
78
79
  symbol(&lrintf, "lrintf");
80
+ symbol(&lround, "lround");
81
+ symbol(&lroundf, "lroundf");
79
82
  symbol(&modf, "modf");
80
83
  symbol(&nan, "nan");
81
84
  symbol(&nanf, "nanf");
@@ -278,6 +281,18 @@ fn lrintl(x: c_longdouble) callconv(.c) c_long {
278
281
  return @trunc(rintl(x));
279
282
  }
280
283
 
284
+ fn lround(x: f64) callconv(.c) c_long {
285
+ return @round(x);
286
+ }
287
+
288
+ fn lroundf(x: f32) callconv(.c) c_long {
289
+ return @round(x);
290
+ }
291
+
292
+ fn lroundl(x: c_longdouble) callconv(.c) c_long {
293
+ return @round(x);
294
+ }
295
+
281
296
  fn modfGeneric(comptime T: type, x: T, iptr: *T) T {
282
297
  if (math.isNegativeInf(x)) {
283
298
  iptr.* = -math.inf(T);
@@ -861,7 +861,7 @@ fn lowerZigArgs(
861
861
  "--error-limit", try allocPrint(arena, "{d}", .{err_limit}),
862
862
  };
863
863
 
864
- try addFlag(gpa, zig_args, "incremental", graph.incremental);
864
+ try addFlag(gpa, zig_args, "incremental", conf_comp.flags4.incremental.toBool() orelse graph.incremental);
865
865
 
866
866
  try zig_args.append(gpa, "--listen=-");
867
867
 
@@ -984,6 +984,11 @@ fn addFlag(gpa: Allocator, args: *std.ArrayList([]const u8), comptime name: []co
984
984
  try args.append(gpa, if (cond) "-f" ++ name else "-fno-" ++ name);
985
985
  }
986
986
 
987
+ fn addArchFlag(gpa: Allocator, args: *std.ArrayList([]const u8), comptime name: []const u8, opt: ?bool) !void {
988
+ const cond = opt orelse return;
989
+ try args.append(gpa, if (cond) "-m" ++ name else "-mno-" ++ name);
990
+ }
991
+
987
992
  fn checkCompileErrors(arena: Allocator, maker: *Maker, step_index: Configuration.Step.Index) Step.ExtendedMakeError!void {
988
993
  const step = maker.stepByIndex(step_index);
989
994
  const conf = &maker.scanned_config.configuration;
@@ -1249,9 +1254,9 @@ fn appendModuleFlags(
1249
1254
  try addFlag(gpa, zig_args, "fuzz", m.flags.fuzz.toBool());
1250
1255
  try addFlag(gpa, zig_args, "valgrind", m.flags2.valgrind.toBool());
1251
1256
  try addFlag(gpa, zig_args, "PIC", m.flags2.pic.toBool());
1252
- try addFlag(gpa, zig_args, "red-zone", m.flags2.red_zone.toBool());
1253
1257
  try addFlag(gpa, zig_args, "no-builtin", m.flags2.no_builtin.toBool());
1254
1258
 
1259
+ try addArchFlag(gpa, zig_args, "red-zone", m.flags2.red_zone.toBool());
1255
1260
  {
1256
1261
  try zig_args.ensureUnusedCapacity(gpa, 6);
1257
1262
 
@@ -797,6 +797,7 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {
797
797
  .generated_llvm_bc = c.generated_llvm_bc != .none,
798
798
  .generated_llvm_ir = c.generated_llvm_ir != .none,
799
799
  .generated_h = c.generated_h != .none,
800
+ .incremental = .init(c.incremental),
800
801
  },
801
802
  .root_module = try s.addModule(c.root_module),
802
803
  .root_name = try wc.addString(c.name),
@@ -4,7 +4,7 @@
4
4
 
5
5
  const std = @import("std");
6
6
  const compiler_rt = @import("../compiler_rt.zig");
7
- const symbol = @import("../compiler_rt.zig").symbol;
7
+ const symbol = compiler_rt.symbol;
8
8
 
9
9
  const normalize = compiler_rt.normalize;
10
10
  const wideMultiply = compiler_rt.wideMultiply;
@@ -189,14 +189,13 @@ inline fn div(a: f64, b: f64) f64 {
189
189
 
190
190
  const writtenExponent = quotientExponent +% exponentBias;
191
191
 
192
+ const round = @intFromBool((residual << 1) >= bSignificand);
193
+
192
194
  if (writtenExponent >= maxExponent) {
193
195
  // If we have overflowed the exponent, return infinity.
194
196
  return @bitCast(infRep | quotientSign);
195
197
  } else if (writtenExponent < 1) {
196
198
  if (writtenExponent == 0) {
197
- // Check whether the rounded result is normal.
198
- const round = @intFromBool((residual << 1) > bSignificand);
199
- // Clear the implicit bit.
200
199
  var absResult = quotient & significandMask;
201
200
  // Round.
202
201
  absResult += round;
@@ -205,11 +204,16 @@ inline fn div(a: f64, b: f64) f64 {
205
204
  return @bitCast(absResult | quotientSign);
206
205
  }
207
206
  }
208
- // Flush denormals to zero. In the future, it would be nice to add
209
- // code to round them correctly.
210
- return @bitCast(quotientSign);
207
+
208
+ const roundedQuotient = quotient +% round;
209
+ const shiftAmount: u32 = @intCast(1 - writtenExponent);
210
+ if (shiftAmount > significandBits + 1) {
211
+ return @bitCast(quotientSign);
212
+ }
213
+
214
+ const denormQuotient = roundedQuotient >> @as(std.math.Log2Int(Z), @intCast(shiftAmount));
215
+ return @bitCast((denormQuotient & significandMask) | quotientSign);
211
216
  } else {
212
- const round = @intFromBool((residual << 1) > bSignificand);
213
217
  // Clear the implicit bit
214
218
  var absResult = quotient & significandMask;
215
219
  // Insert the exponent
@@ -5,7 +5,7 @@
5
5
  const std = @import("std");
6
6
 
7
7
  const compiler_rt = @import("../compiler_rt.zig");
8
- const symbol = @import("../compiler_rt.zig").symbol;
8
+ const symbol = compiler_rt.symbol;
9
9
  const normalize = compiler_rt.normalize;
10
10
 
11
11
  comptime {
@@ -170,14 +170,14 @@ inline fn div(a: f32, b: f32) f32 {
170
170
 
171
171
  const writtenExponent = quotientExponent +% exponentBias;
172
172
 
173
+ const round = @intFromBool((residual << 1) >= bSignificand);
174
+
173
175
  if (writtenExponent >= maxExponent) {
174
176
  // If we have overflowed the exponent, return infinity.
175
177
  return @bitCast(infRep | quotientSign);
176
178
  } else if (writtenExponent < 1) {
177
179
  if (writtenExponent == 0) {
178
180
  // Check whether the rounded result is normal.
179
- const round = @intFromBool((residual << 1) > bSignificand);
180
- // Clear the implicit bit.
181
181
  var absResult = quotient & significandMask;
182
182
  // Round.
183
183
  absResult += round;
@@ -186,11 +186,16 @@ inline fn div(a: f32, b: f32) f32 {
186
186
  return @bitCast(absResult | quotientSign);
187
187
  }
188
188
  }
189
- // Flush denormals to zero. In the future, it would be nice to add
190
- // code to round them correctly.
191
- return @bitCast(quotientSign);
189
+
190
+ const roundedQuotient = quotient +% round;
191
+ const shiftAmount: u32 = @intCast(1 - writtenExponent);
192
+ if (shiftAmount > significandBits + 1) {
193
+ return @bitCast(quotientSign);
194
+ }
195
+
196
+ const denormQuotient = roundedQuotient >> @as(std.math.Log2Int(Z), @intCast(shiftAmount));
197
+ return @bitCast((denormQuotient & significandMask) | quotientSign);
192
198
  } else {
193
- const round = @intFromBool((residual << 1) > bSignificand);
194
199
  // Clear the implicit bit
195
200
  var absResult = quotient & significandMask;
196
201
  // Insert the exponent
@@ -707,7 +707,7 @@ def root_InternPool_Index_SummaryProvider(value, _=None):
707
707
  return re.sub(
708
708
  expr_path_re,
709
709
  lambda matchobj: getattr(unwrapped.GetValueForExpressionPath(matchobj[1]), matchobj[2]).strip(matchobj[3] or ''),
710
- summary.summary.removeprefix('.').removeprefix('@"').removesuffix('"').replace(r'\"', '"'),
710
+ summary.value.removeprefix('.').removeprefix('@"').removesuffix('"').replace(r'\"', '"'),
711
711
  )
712
712
 
713
713
  class root_InternPool_Index_SynthProvider:
@@ -773,7 +773,7 @@ class root_InternPool_Index_Unwrapped_SynthProvider:
773
773
  trailing_type = encoding_trailing.GetValueAsType()
774
774
  trailing_bytes, trailing_data = bytearray(trailing_type.size), lldb.SBData()
775
775
  def eval_config(config_name):
776
- expr = encoding_config.GetChildMemberWithName(config_name).summary.removeprefix('.').removeprefix('@"').removesuffix('"').replace(r'\"', '"')
776
+ expr = encoding_config.GetChildMemberWithName(config_name).value.removeprefix('.').removeprefix('@"').removesuffix('"').replace(r'\"', '"')
777
777
  if 'payload.' in expr:
778
778
  return self.payload.EvaluateExpression(expr.replace('payload.', '@this().'))
779
779
  elif expr.startswith('trailing.'):
@@ -848,7 +848,8 @@ def root_InternPool_String_SummaryProvider(value, _=None):
848
848
  if local_value is None:
849
849
  wrapped = 0
850
850
  local_value = locals_value.child[0]
851
- string = local_value.GetChildMemberWithName('shared').GetChildMemberWithName('strings').GetChildMemberWithName('view').GetChildMemberWithName('0').child[wrapped & (1 << tid_shift_32) - 1].address_of
851
+ shared = local_value.GetChildMemberWithName('shared')
852
+ string = shared.GetChildMemberWithName('string_bytes').GetChildMemberWithName('view').GetChildMemberWithName('0').child[shared.GetChildMemberWithName('strings').GetChildMemberWithName('view').GetChildMemberWithName('0').child[wrapped & (1 << tid_shift_32) - 1].unsigned].address_of
852
853
  string.format = lldb.eFormatCString
853
854
  return string.value
854
855
 
@@ -878,13 +879,13 @@ class root_InternPool_Nav_Index_SynthProvider:
878
879
  wrapped = self.value.unsigned
879
880
  if wrapped == (1 << 32) - 1: return
880
881
  ip = self.value.CreateValueFromType(self.value.type).GetChildMemberWithName('debug_state').GetChildMemberWithName('intern_pool').GetNonSyntheticValue().GetChildMemberWithName('?')
881
- tid_shift_32 = ip.GetChildMemberWithName('tid_shift_32').unsigned
882
+ tid_shift_30 = ip.GetChildMemberWithName('tid_shift_30').unsigned
882
883
  locals_value = ip.GetChildMemberWithName('locals').GetSyntheticValue()
883
- local_value = locals_value.child[wrapped >> tid_shift_32]
884
+ local_value = locals_value.child[wrapped >> tid_shift_30]
884
885
  if local_value is None:
885
886
  wrapped = 0
886
887
  local_value = locals_value.child[0]
887
- self.nav = local_value.GetChildMemberWithName('shared').GetChildMemberWithName('navs').GetChildMemberWithName('view').child[wrapped & (1 << tid_shift_32) - 1]
888
+ self.nav = local_value.GetChildMemberWithName('shared').GetChildMemberWithName('navs').GetChildMemberWithName('view').child[wrapped & (1 << tid_shift_30) - 1]
888
889
  def has_children(self): return False if self.nav is None else self.nav.GetNumChildren(1) > 0
889
890
  def num_children(self): return 0 if self.nav is None else self.nav.GetNumChildren()
890
891
  def get_child_index(self, name): return -1 if self.nav is None else self.nav.GetIndexOfChildWithName(name)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zigc/lib",
3
- "version": "0.17.0-dev.813",
3
+ "version": "0.17.0-dev.836",
4
4
  "description": "Zig standard library and libc headers (shared across all platforms)",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1016,7 +1016,8 @@ pub const Step = extern struct {
1016
1016
  generated_llvm_bc: bool,
1017
1017
  generated_llvm_ir: bool,
1018
1018
  generated_h: bool,
1019
- _: u9 = 0,
1019
+ incremental: DefaultingBool,
1020
+ _: u7 = 0,
1020
1021
  };
1021
1022
 
1022
1023
  pub fn isDynamicLibrary(compile: *const Compile) bool {
@@ -234,6 +234,12 @@ is_linking_libcpp: bool = false,
234
234
  /// builtin fuzzer, see the `fuzz` flag in `Module`.
235
235
  sanitize_coverage_trace_pc_guard: ?bool = null,
236
236
 
237
+ /// Enable or disable incremental compilation.
238
+ ///
239
+ /// Incremental compilation reduces compile time by mutating an existing build artifact. Non-
240
+ /// incremental compilation is slower but preserves previous build artifacts.
241
+ incremental: ?bool = null,
242
+
237
243
  emit_directory: Configuration.OptionalGeneratedFileIndex = .none,
238
244
  generated_docs: Configuration.OptionalGeneratedFileIndex = .none,
239
245
  generated_asm: Configuration.OptionalGeneratedFileIndex = .none,
package/std/Build.zig CHANGED
@@ -1839,7 +1839,7 @@ fn tryFindProgram(b: *Build, full_path: []const u8) ?[]const u8 {
1839
1839
  while (it.next()) |ext| {
1840
1840
  if (!supportedWindowsProgramExtension(ext)) continue;
1841
1841
 
1842
- const extended_path = try mem.concat(arena, &.{ full_path, ext });
1842
+ const extended_path = try mem.concat(arena, u8, &.{ full_path, ext });
1843
1843
 
1844
1844
  if (Io.Dir.cwd().access(io, extended_path, .{ .execute = true })) |_| {
1845
1845
  return extended_path;
package/std/Target.zig CHANGED
@@ -2341,7 +2341,8 @@ pub fn supportsAddressSpace(
2341
2341
  .lut => arch == .propeller and std.Target.propeller.featureSetHas(target.cpu.features, .p2),
2342
2342
 
2343
2343
  .global, .local, .shared => is_gpu,
2344
- .constant => is_gpu and (context == null or context == .constant),
2344
+ .constant => (is_gpu and (context == null or context == .constant)) or
2345
+ (is_spirv and (context == null or context == .constant or context == .pointer)),
2345
2346
  .param => is_nvptx,
2346
2347
  .input, .output, .uniform, .push_constant, .storage_buffer, .physical_storage_buffer => is_spirv,
2347
2348
  };
@@ -121,17 +121,6 @@ fn testExpectDecompressError(err: anyerror, compressed: []const u8) !void {
121
121
  try std.testing.expectError(err, zstd_stream.err orelse {});
122
122
  }
123
123
 
124
- test Decompress {
125
- const uncompressed = @embedFile("testdata/rfc8478.txt");
126
- const compressed3 = @embedFile("testdata/rfc8478.txt.zst.3");
127
- const compressed19 = @embedFile("testdata/rfc8478.txt.zst.19");
128
-
129
- try testExpectDecompress(uncompressed, compressed3);
130
- try testExpectDecompress(uncompressed, compressed19);
131
- try std.testing.expectEqual(uncompressed.len, testDiscard(std.testing.allocator, compressed3));
132
- try std.testing.expectEqual(uncompressed.len, testDiscard(std.testing.allocator, compressed19));
133
- }
134
-
135
124
  test "partial magic number" {
136
125
  const input_raw =
137
126
  "\x28\xb5\x2f"; // 3 bytes of the 4-byte zstandard frame magic number
@@ -76,6 +76,7 @@ pub fn hash(hasher: anytype, key: anytype, comptime strat: HashStrategy) void {
76
76
  switch (@typeInfo(Key)) {
77
77
  .noreturn,
78
78
  .@"opaque",
79
+ .spirv,
79
80
  .undefined,
80
81
  .null,
81
82
  .comptime_float,
package/std/lang.zig CHANGED
@@ -578,6 +578,7 @@ pub const Type = union(enum) {
578
578
  @"anyframe": AnyFrame,
579
579
  vector: Vector,
580
580
  enum_literal,
581
+ spirv: Spirv,
581
582
 
582
583
  /// This data structure is used by the Zig language code generation and
583
584
  /// therefore must be kept in sync with the compiler implementation.
@@ -781,6 +782,59 @@ pub const Type = union(enum) {
781
782
  };
782
783
  };
783
784
 
785
+ /// This data structure is used by the Zig language code generation and
786
+ /// therefore must be kept in sync with the compiler implementation.
787
+ pub const Spirv = union(enum(u2)) {
788
+ sampler,
789
+ image: Image,
790
+ sampled_image: type,
791
+ runtime_array: type,
792
+
793
+ pub const Image = struct {
794
+ usage: Usage,
795
+ format: Format,
796
+ dim: Dimensionality,
797
+ depth: Depth,
798
+ access: Access,
799
+ arrayed: bool,
800
+ multisampled: bool,
801
+
802
+ pub const Usage = union(enum(u2)) {
803
+ unknown: type,
804
+ sampled: type,
805
+ storage,
806
+ };
807
+
808
+ pub const Format = enum(u4) {
809
+ unknown,
810
+ rgba32f,
811
+ rgba32i,
812
+ rgba32u,
813
+ rgba16f,
814
+ rgba16i,
815
+ rgba16u,
816
+ rgba8unorm,
817
+ rgba8snorm,
818
+ rgba8i,
819
+ rgba8u,
820
+ r32f,
821
+ r32i,
822
+ r32u,
823
+ };
824
+
825
+ pub const Dimensionality = enum(u2) {
826
+ @"1d",
827
+ @"2d",
828
+ @"3d",
829
+ cube,
830
+ };
831
+
832
+ pub const Depth = enum(u2) { unknown, depth, not_depth };
833
+
834
+ pub const Access = enum(u2) { unknown, read_only, write_only, read_write };
835
+ };
836
+ };
837
+
784
838
  /// This data structure is used by the Zig language code generation and
785
839
  /// therefore must be kept in sync with the compiler implementation.
786
840
  pub const Opaque = struct {
package/std/mem.zig CHANGED
@@ -352,6 +352,7 @@ pub fn zeroes(comptime T: type) T {
352
352
  .noreturn,
353
353
  .undefined,
354
354
  .@"opaque",
355
+ .spirv,
355
356
  .frame,
356
357
  .@"anyframe",
357
358
  => {
package/std/meta.zig CHANGED
@@ -14,31 +14,14 @@ test {
14
14
  _ = TrailerFlags;
15
15
  }
16
16
 
17
- /// Returns the variant of an enum type, `T`, which is named `str`, or `null` if no such variant exists.
17
+ /// Returns the variant of an enum type corresponding to the provided tag name,
18
+ /// or `null` if no such variant exists.
18
19
  pub fn stringToEnum(comptime T: type, tag_name: []const u8) ?T {
19
- // Using StaticStringMap here is more performant, but it will start to take too
20
- // long to compile if the enum is large enough, due to the current limits of comptime
21
- // performance when doing things like constructing lookup maps at comptime.
22
- // TODO The '100' here is arbitrary and should be increased when possible:
23
- // - https://github.com/ziglang/zig/issues/4055
24
- // - https://github.com/ziglang/zig/issues/3863
25
- if (@typeInfo(T).@"enum".field_names.len <= 100) {
26
- return std.StaticStringMap(T).initEnum().get(tag_name);
27
- } else {
28
- inline for (@typeInfo(T).@"enum".field_names) |name| {
29
- if (mem.eql(u8, tag_name, name)) {
30
- return @field(T, name);
31
- }
32
- }
33
- return null;
34
- }
20
+ return std.StaticStringMap(T).initEnum().get(tag_name);
35
21
  }
36
22
 
37
23
  test stringToEnum {
38
- const E1 = enum {
39
- A,
40
- B,
41
- };
24
+ const E1 = enum { A, B };
42
25
  try testing.expect(E1.A == stringToEnum(E1, "A").?);
43
26
  try testing.expect(E1.B == stringToEnum(E1, "B").?);
44
27
  try testing.expect(null == stringToEnum(E1, "C"));
package/std/start.zig CHANGED
@@ -19,7 +19,9 @@ comptime {
19
19
  // decls there get run.
20
20
  _ = root;
21
21
 
22
- if (builtin.output_mode == .Lib and builtin.link_mode == .dynamic) {
22
+ if (builtin.zig_backend == .stage2_spirv) {
23
+ // Do nothing
24
+ } else if (builtin.output_mode == .Lib and builtin.link_mode == .dynamic) {
23
25
  const dll_main_crt_startup = if (builtin.abi.isGnu()) "DllMainCRTStartup" else "_DllMainCRTStartup";
24
26
  if (native_os == .windows and !builtin.link_libc and !@hasDecl(root, dll_main_crt_startup)) {
25
27
  @export(&DllMainCRTStartup, .{ .name = dll_main_crt_startup });
@@ -241,7 +241,10 @@ pub fn StaticStringMapWithEql(
241
241
  return self.kvs.values[self.getIndex(str) orelse return null];
242
242
  }
243
243
 
244
- fn getIndex(self: Self, str: []const u8) ?usize {
244
+ /// Returns the index corresponding to the `str` within the
245
+ /// generated `kvs`, or `null` if `str` was not found.
246
+ /// The returned index is unrelated to the input `kvs_list`.
247
+ pub fn getIndex(self: Self, str: []const u8) ?usize {
245
248
  const kvs = self.kvs.*;
246
249
  if (kvs.len == 0)
247
250
  return null;
@@ -279,6 +282,14 @@ pub fn StaticStringMapWithEql(
279
282
  };
280
283
  }
281
284
 
285
+ /// Returns the index within the generated `kvs` corresponding to the
286
+ /// key-value pair where key is the longest prefix of `str`, or `null`
287
+ /// if no such key-value pair was found. The returned index is unrelated
288
+ /// to the input `kvs_list`.
289
+ ///
290
+ /// This is effectively an O(N) algorithm which loops from `max_len` to
291
+ /// `min_len` and calls `getIndex()` to check all keys with the given
292
+ /// len.
282
293
  pub fn getLongestPrefixIndex(self: Self, str: []const u8) ?usize {
283
294
  if (self.kvs.len == 0)
284
295
  return null;
@@ -294,11 +305,15 @@ pub fn StaticStringMapWithEql(
294
305
  return null;
295
306
  }
296
307
 
308
+ /// Returns the slice of keys from the generated `kvs`, which may
309
+ /// be in a different order than the input `kvs_list`.
297
310
  pub fn keys(self: Self) []const []const u8 {
298
311
  const kvs = self.kvs.*;
299
312
  return kvs.keys[0..kvs.len];
300
313
  }
301
314
 
315
+ /// Returns the slice of values from the generated `kvs`, which may
316
+ /// be in a different order than the input `kvs_list`.
302
317
  pub fn values(self: Self) []const V {
303
318
  const kvs = self.kvs.*;
304
319
  return kvs.values[0..kvs.len];
@@ -504,6 +519,20 @@ test "comptime-only value" {
504
519
  try testing.expect(map.get("d") == null);
505
520
  }
506
521
 
522
+ test "getIndex" {
523
+ const slice = [_]TestKV{
524
+ .{ "longer", .A },
525
+ .{ "short", .B },
526
+ };
527
+ const map = TestMap.initComptime(slice);
528
+
529
+ // This index can be different than the index of the "short" KV in `slice`
530
+ const short_index = map.getIndex("short").?;
531
+ try testing.expectEqualStrings("short", map.keys()[short_index]);
532
+ try testing.expectEqual(.B, map.values()[short_index]);
533
+ try testing.expectEqual(null, map.getIndex("missing"));
534
+ }
535
+
507
536
  test "getLongestPrefix" {
508
537
  const slice = [_]TestKV{
509
538
  .{ "a", .A },
package/std/testing.zig CHANGED
@@ -79,6 +79,7 @@ fn expectEqualInner(comptime T: type, expected: T, actual: T) !void {
79
79
  switch (@typeInfo(@TypeOf(actual))) {
80
80
  .noreturn,
81
81
  .@"opaque",
82
+ .spirv,
82
83
  .frame,
83
84
  .@"anyframe",
84
85
  => @compileError("value of type " ++ @typeName(@TypeOf(actual)) ++ " encountered"),
@@ -737,6 +738,7 @@ fn expectEqualDeepInner(comptime T: type, expected: T, actual: T) error{TestExpe
737
738
  switch (@typeInfo(@TypeOf(actual))) {
738
739
  .noreturn,
739
740
  .@"opaque",
741
+ .spirv,
740
742
  .frame,
741
743
  .@"anyframe",
742
744
  => @compileError("value of type " ++ @typeName(@TypeOf(actual)) ++ " encountered"),
@@ -9327,6 +9327,16 @@ fn builtinCall(
9327
9327
  });
9328
9328
  return rvalue(gz, ri, result, node);
9329
9329
  },
9330
+ .SpirvType => {
9331
+ const spirv_type_options_ty = try gz.addStdLangValue(node, .spirv_type_options);
9332
+ const operand = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = spirv_type_options_ty } }, params[0], .type);
9333
+ const result = try gz.addExtendedPayload(.reify_spirv_type, Zir.Inst.ReifySpirvType{
9334
+ .src_line = gz.astgen.source_line,
9335
+ .node = node,
9336
+ .operand = operand,
9337
+ });
9338
+ return rvalue(gz, ri, result, node);
9339
+ },
9330
9340
 
9331
9341
  .panic => {
9332
9342
  try emitDbgNode(gz, node);
@@ -1079,6 +1079,10 @@ fn builtinCall(astrl: *AstRlAnnotate, block: ?*Block, ri: ResultInfo, node: Ast.
1079
1079
  _ = try astrl.expr(args[3], block, ResultInfo.type_only);
1080
1080
  return false;
1081
1081
  },
1082
+ .SpirvType => {
1083
+ _ = try astrl.expr(args[0], block, ResultInfo.type_only);
1084
+ return false;
1085
+ },
1082
1086
  .Vector => {
1083
1087
  _ = try astrl.expr(args[0], block, ResultInfo.type_only);
1084
1088
  _ = try astrl.expr(args[1], block, ResultInfo.type_only);
@@ -238,9 +238,6 @@ fn pegToken(a: *AstSmith, tag: Token.Tag) SourceError!void {
238
238
 
239
239
  switch (lexeme[0]) {
240
240
  '_', 'a'...'z', 'A'...'Z', '0'...'9' => try a.preservePegEndOfWord(),
241
- '*' => if (a.tokens_len > 0 and a.source_buf[a.source_len - 1] == '*') {
242
- try a.addSourceByte(' ');
243
- },
244
241
  '.' => if (a.tokens_len > 0 and switch (a.source_buf[a.source_len - 1]) {
245
242
  '.' => true,
246
243
  '0'...'9', 'a'...'z', 'A'...'Z' => a.token_tag_buf[a.tokens_len - 1] == .number_literal,
@@ -1810,7 +1807,7 @@ fn pegPrefixTypeOp(a: *AstSmith) SourceError!void {
1810
1807
  }
1811
1808
 
1812
1809
  /// SuffixOp
1813
- /// <- LBRACKET Expr (DOT2 (Expr? (COLON Expr)?)?)? RBRACKET
1810
+ /// <- LBRACKET Expr (DOT2 Expr? (COLON Expr)?)? RBRACKET
1814
1811
  /// / DOT IDENTIFIER
1815
1812
  /// / DOTASTERISK
1816
1813
  /// / DOTQUESTIONMARK
@@ -1820,12 +1817,14 @@ fn pegSuffixOp(a: *AstSmith) SourceError!void {
1820
1817
  try a.pegToken(.l_bracket);
1821
1818
  try a.pegExpr();
1822
1819
 
1823
- const components = a.smith.value(u2);
1824
- if (components >= 1) try a.pegToken(.ellipsis2);
1825
- if (components >= 2) try a.pegExpr();
1826
- if (components >= 3) {
1827
- try a.pegToken(.colon);
1828
- try a.pegExpr();
1820
+ if (a.smith.value(bool)) {
1821
+ try a.pegToken(.ellipsis2);
1822
+ if (a.smith.value(bool))
1823
+ try a.pegExpr();
1824
+ if (a.smith.value(bool)) {
1825
+ try a.pegToken(.colon);
1826
+ try a.pegExpr();
1827
+ }
1829
1828
  }
1830
1829
 
1831
1830
  try a.pegToken(.r_bracket);
@@ -114,6 +114,7 @@ pub const Tag = enum {
114
114
  Struct,
115
115
  Union,
116
116
  Enum,
117
+ SpirvType,
117
118
  type_info,
118
119
  type_name,
119
120
  TypeOf,
@@ -971,6 +972,13 @@ pub const list = list: {
971
972
  .param_count = 4,
972
973
  },
973
974
  },
975
+ .{
976
+ "@SpirvType",
977
+ .{
978
+ .tag = .SpirvType,
979
+ .param_count = 1,
980
+ },
981
+ },
974
982
  .{
975
983
  "@typeInfo",
976
984
  .{
package/std/zig/Parse.zig CHANGED
@@ -3137,7 +3137,7 @@ fn parsePtrModifiers(p: *Parse) !PtrModifiers {
3137
3137
  }
3138
3138
 
3139
3139
  /// SuffixOp
3140
- /// <- LBRACKET Expr (DOT2 (Expr? (COLON Expr)?)?)? RBRACKET
3140
+ /// <- LBRACKET Expr (DOT2 Expr? (COLON Expr)?)? RBRACKET
3141
3141
  /// / DOT IDENTIFIER
3142
3142
  /// / DOTASTERISK
3143
3143
  /// / DOTQUESTIONMARK
package/std/zig/Zir.zig CHANGED
@@ -2055,6 +2055,9 @@ pub const Inst = struct {
2055
2055
  /// `operand` is payload index to `ReifyEnum`.
2056
2056
  /// `small` contains `NameStrategy`.
2057
2057
  reify_enum,
2058
+ /// Implements builtin `@SpirvType`.
2059
+ /// `operand` is payload index to `ReifyFn`.
2060
+ reify_spirv_type,
2058
2061
  /// Implements the `@cmpxchgStrong` and `@cmpxchgWeak` builtins.
2059
2062
  /// `small` 0=>weak 1=>strong
2060
2063
  /// `operand` is payload index to `Cmpxchg`.
@@ -3269,6 +3272,14 @@ pub const Inst = struct {
3269
3272
  field_values: Ref,
3270
3273
  };
3271
3274
 
3275
+ pub const ReifySpirvType = struct {
3276
+ src_line: u32,
3277
+ /// This node is absolute, because `reify` instructions are tracked across updates, and
3278
+ /// this simplifies the logic for getting source locations for types.
3279
+ node: Ast.Node.Index,
3280
+ operand: Ref,
3281
+ };
3282
+
3272
3283
  /// Trailing:
3273
3284
  /// 0. multi_cases_len: u32, // If has_multi_cases is set.
3274
3285
  /// 1. payload_capture_placeholder: Inst.Index, // If payload_capture_inst_is_placeholder is set.
@@ -3584,6 +3595,7 @@ pub const Inst = struct {
3584
3595
  fn_attributes,
3585
3596
  container_layout,
3586
3597
  enum_mode,
3598
+ spirv_type_options,
3587
3599
  // Values
3588
3600
  calling_convention_c,
3589
3601
  calling_convention_inline,
@@ -4389,6 +4401,7 @@ fn findTrackableInner(
4389
4401
  .reify_enum,
4390
4402
  .reify_struct,
4391
4403
  .reify_union,
4404
+ .reify_spirv_type,
4392
4405
  => return contents.other.append(gpa, inst),
4393
4406
 
4394
4407
  // Type declarations need tracking.
@@ -5181,6 +5194,7 @@ pub fn assertTrackable(zir: Zir, inst_idx: Zir.Inst.Index) void {
5181
5194
  .reify_enum,
5182
5195
  .reify_struct,
5183
5196
  .reify_union,
5197
+ .reify_spirv_type,
5184
5198
  => {}, // tracked in order, as the owner instructions of explicit container types
5185
5199
  else => unreachable, // assertion failure; not trackable
5186
5200
  },
package/std/zip.zig CHANGED
@@ -164,50 +164,6 @@ pub const EndRecord = extern struct {
164
164
  }
165
165
  };
166
166
 
167
- pub const Decompress = struct {
168
- interface: Reader,
169
- state: union {
170
- inflate: flate.Decompress,
171
- store: *Reader,
172
- },
173
-
174
- pub fn init(reader: *Reader, method: CompressionMethod, buffer: []u8) Reader {
175
- return switch (method) {
176
- .store => .{
177
- .state = .{ .store = reader },
178
- .interface = .{
179
- .context = undefined,
180
- .vtable = &.{ .stream = streamStore },
181
- .buffer = buffer,
182
- .end = 0,
183
- .seek = 0,
184
- },
185
- },
186
- .deflate => .{
187
- .state = .{ .inflate = .init(reader, .raw) },
188
- .interface = .{
189
- .context = undefined,
190
- .vtable = &.{ .stream = streamDeflate },
191
- .buffer = buffer,
192
- .end = 0,
193
- .seek = 0,
194
- },
195
- },
196
- else => unreachable,
197
- };
198
- }
199
-
200
- fn streamStore(r: *Reader, w: *Writer, limit: std.Io.Limit) Reader.StreamError!usize {
201
- const d: *Decompress = @fieldParentPtr("interface", r);
202
- return d.store.read(w, limit);
203
- }
204
-
205
- fn streamDeflate(r: *Reader, w: *Writer, limit: std.Io.Limit) Reader.StreamError!usize {
206
- const d: *Decompress = @fieldParentPtr("interface", r);
207
- return flate.Decompress.read(&d.inflate, w, limit);
208
- }
209
- };
210
-
211
167
  fn isBadFilename(filename: []const u8) bool {
212
168
  if (filename.len == 0 or filename[0] == '/')
213
169
  return true;
@@ -854,6 +854,7 @@ fn canSerializeTypeInner(
854
854
  .frame,
855
855
  .@"anyframe",
856
856
  .@"opaque",
857
+ .spirv,
857
858
  => false,
858
859
 
859
860
  .@"enum" => |@"enum"| @"enum".mode == .exhaustive,
package/std/zon/parse.zig CHANGED
@@ -1173,7 +1173,9 @@ const Parser = struct {
1173
1173
  };
1174
1174
 
1175
1175
  fn intFromFloatExact(T: type, value: anytype) ?T {
1176
- if (value > std.math.maxInt(T) or value < std.math.minInt(T)) {
1176
+ const max: @TypeOf(value) = @floatFromInt(std.math.maxInt(T));
1177
+ const min: @TypeOf(value) = @floatFromInt(std.math.minInt(T));
1178
+ if (value > max or value < min) {
1177
1179
  return null;
1178
1180
  }
1179
1181
 
@@ -1213,6 +1215,7 @@ fn canParseTypeInner(
1213
1215
  .frame,
1214
1216
  .@"anyframe",
1215
1217
  .@"opaque",
1218
+ .spirv,
1216
1219
  .comptime_int,
1217
1220
  .comptime_float,
1218
1221
  .enum_literal,
@@ -2447,6 +2450,7 @@ test "std.zon intFromFloatExact" {
2447
2450
  try std.testing.expectEqual(@as(u8, 10), intFromFloatExact(u8, @as(f32, 10.0)).?);
2448
2451
  try std.testing.expectEqual(@as(i8, -123), intFromFloatExact(i8, @as(f64, @as(f64, -123.0))).?);
2449
2452
  try std.testing.expectEqual(@as(i16, 45), intFromFloatExact(i16, @as(f128, @as(f128, 45.0))).?);
2453
+ try std.testing.expectEqual(@as(u128, 67), intFromFloatExact(u128, @as(f128, @as(f128, 67.0))).?);
2450
2454
 
2451
2455
  // Out of range
2452
2456
  try std.testing.expectEqual(@as(?u4, null), intFromFloatExact(u4, @as(f32, 16.0)));
@@ -2489,6 +2493,10 @@ test "std.zon parse int" {
2489
2493
  @as(u65, 36893488147419103231),
2490
2494
  try fromSlice(u65, gpa, "368934_881_474191032_31", null, .{}),
2491
2495
  );
2496
+ try std.testing.expectEqual(
2497
+ @as(u128, 340282366920938463463374607431768211455),
2498
+ try fromSlice(u128, gpa, "340282366920938463463374607431768211455", null, .{}),
2499
+ );
2492
2500
 
2493
2501
  // Test big integer limits
2494
2502
  try std.testing.expectEqual(
@@ -1,37 +0,0 @@
1
- /**
2
- * This file has no copyright assigned and is placed in the Public Domain.
3
- * This file is part of the mingw-w64 runtime package.
4
- * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5
- */
6
- #include <math.h>
7
- #include <limits.h>
8
- #include <errno.h>
9
-
10
- long
11
- lroundl (long double x)
12
- {
13
- long double res;
14
-
15
- if (x >= 0.0L)
16
- {
17
- res = ceill (x);
18
- if (res - x > 0.5L)
19
- res -= 1.0;
20
- }
21
- else
22
- {
23
- res = ceill (-x);
24
- if (res + x > 0.5L)
25
- res -= 1.0L;
26
- res = -res;
27
- }
28
- if (!isfinite (res)
29
- || res > (long double)LONG_MAX
30
- || res < (long double)LONG_MIN)
31
- {
32
- errno = ERANGE;
33
- /* Undefined behaviour, so we could return anything. */
34
- /* return res > 0.0L ? LONG_MAX : LONG_MIN; */
35
- }
36
- return (long) res;
37
- }
@@ -1,8 +0,0 @@
1
- #include <math.h>
2
-
3
- long lround(double x)
4
- {
5
- long n;
6
- __asm__ ("fcvtas %x0, %d1" : "=r"(n) : "w"(x));
7
- return n;
8
- }
@@ -1,8 +0,0 @@
1
- #include <math.h>
2
-
3
- long lroundf(float x)
4
- {
5
- long n;
6
- __asm__ ("fcvtas %x0, %s1" : "=r"(n) : "w"(x));
7
- return n;
8
- }
@@ -1,6 +0,0 @@
1
- #include <math.h>
2
-
3
- long lround(double x)
4
- {
5
- return round(x);
6
- }
@@ -1,6 +0,0 @@
1
- #include <math.h>
2
-
3
- long lroundf(float x)
4
- {
5
- return roundf(x);
6
- }
@@ -1,6 +0,0 @@
1
- #include <math.h>
2
-
3
- long lroundl(long double x)
4
- {
5
- return roundl(x);
6
- }
@@ -1,18 +0,0 @@
1
- #include <math.h>
2
-
3
- #ifdef __VSX__
4
-
5
- long lround(double x)
6
- {
7
- long n;
8
- __asm__ (
9
- "xsrdpi %1, %1\n"
10
- "fctid %0, %1\n" : "=d"(n), "+d"(x));
11
- return n;
12
- }
13
-
14
- #else
15
-
16
- #include "../lround.c"
17
-
18
- #endif
@@ -1,18 +0,0 @@
1
- #include <math.h>
2
-
3
- #ifdef __VSX__
4
-
5
- long lroundf(float x)
6
- {
7
- long n;
8
- __asm__ (
9
- "xsrdpi %1, %1\n"
10
- "fctid %0, %1\n" : "=d"(n), "+f"(x));
11
- return n;
12
- }
13
-
14
- #else
15
-
16
- #include "../lroundf.c"
17
-
18
- #endif