@zigc/lib 0.16.0 → 0.17.0-dev.131

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.
Files changed (155) hide show
  1. package/c/fcntl.zig +6 -1
  2. package/c/inttypes.zig +0 -10
  3. package/c/math.zig +46 -122
  4. package/c/pthread.zig +57 -0
  5. package/c/search.zig +1 -27
  6. package/c/stdlib/drand48.zig +0 -57
  7. package/c/stdlib.zig +0 -100
  8. package/c/string.zig +20 -7
  9. package/c/strings.zig +0 -38
  10. package/c/unistd.zig +27 -26
  11. package/c/wchar.zig +10 -0
  12. package/c.zig +2 -2
  13. package/compiler/aro/aro/CodeGen.zig +5 -6
  14. package/compiler/aro/aro/Compilation.zig +17 -14
  15. package/compiler/aro/aro/Driver.zig +14 -13
  16. package/compiler/aro/aro/Parser.zig +20 -15
  17. package/compiler/aro/aro/Pragma.zig +3 -2
  18. package/compiler/aro/aro/Preprocessor.zig +9 -6
  19. package/compiler/aro/aro/pragmas/message.zig +3 -2
  20. package/compiler/aro/aro/text_literal.zig +3 -2
  21. package/compiler/aro/assembly_backend/x86_64.zig +4 -4
  22. package/compiler/build_runner.zig +0 -2
  23. package/compiler/reduce/Walk.zig +7 -7
  24. package/compiler/test_runner.zig +2 -2
  25. package/compiler/translate-c/Translator.zig +6 -2
  26. package/compiler/translate-c/main.zig +1 -1
  27. package/compiler_rt/cos.zig +0 -2
  28. package/compiler_rt/divmodei4.zig +40 -17
  29. package/compiler_rt/exp.zig +1 -6
  30. package/compiler_rt/exp2.zig +1 -6
  31. package/compiler_rt/exp_f128.zig +377 -0
  32. package/compiler_rt/fabs.zig +0 -2
  33. package/compiler_rt/fma.zig +0 -2
  34. package/compiler_rt/fmax.zig +0 -2
  35. package/compiler_rt/fmin.zig +0 -2
  36. package/compiler_rt/fmod.zig +0 -2
  37. package/compiler_rt/limb64.zig +876 -15
  38. package/compiler_rt/log.zig +0 -2
  39. package/compiler_rt/log10.zig +0 -2
  40. package/compiler_rt/log2.zig +0 -2
  41. package/compiler_rt/mulXi3.zig +1 -1
  42. package/compiler_rt/round.zig +0 -2
  43. package/compiler_rt/sin.zig +0 -2
  44. package/compiler_rt/sincos.zig +0 -2
  45. package/compiler_rt/sqrt.zig +0 -2
  46. package/compiler_rt/ssp.zig +1 -1
  47. package/compiler_rt/tan.zig +0 -2
  48. package/compiler_rt/trunc.zig +0 -2
  49. package/compiler_rt/udivmodei4.zig +28 -0
  50. package/fuzzer.zig +2 -0
  51. package/libc/musl/arch/mipsn32/syscall_arch.h +35 -32
  52. package/package.json +1 -1
  53. package/std/Build/Cache.zig +6 -6
  54. package/std/Build/Step/Compile.zig +0 -1
  55. package/std/Build/Step/Run.zig +2 -2
  56. package/std/Build/Step.zig +2 -4
  57. package/std/Build/WebServer.zig +2 -2
  58. package/std/Build.zig +0 -3
  59. package/std/Io/Dir.zig +7 -2
  60. package/std/Io/Dispatch.zig +3 -13
  61. package/std/Io/File/Writer.zig +8 -6
  62. package/std/Io/Reader.zig +8 -9
  63. package/std/Io/Semaphore.zig +112 -17
  64. package/std/Io/Terminal.zig +1 -1
  65. package/std/Io/Threaded.zig +171 -37
  66. package/std/Io/Uring.zig +13 -15
  67. package/std/Io/Writer.zig +46 -42
  68. package/std/Io/net.zig +11 -11
  69. package/std/Io.zig +90 -26
  70. package/std/SemanticVersion.zig +1 -1
  71. package/std/Target/Query.zig +2 -2
  72. package/std/Target.zig +50 -5
  73. package/std/array_hash_map.zig +9 -18
  74. package/std/builtin.zig +4 -0
  75. package/std/c/haiku.zig +3 -0
  76. package/std/c/serenity.zig +1 -6
  77. package/std/c.zig +89 -7
  78. package/std/compress/flate/Decompress.zig +2 -3
  79. package/std/compress/zstd/Decompress.zig +2 -4
  80. package/std/crypto/Certificate.zig +13 -1
  81. package/std/crypto/ascon.zig +75 -33
  82. package/std/crypto/codecs/asn1/Oid.zig +12 -1
  83. package/std/crypto/codecs/base64_hex_ct.zig +2 -4
  84. package/std/crypto/ml_kem.zig +2 -9
  85. package/std/crypto/tls/Client.zig +79 -4
  86. package/std/crypto/tls.zig +1 -1
  87. package/std/crypto.zig +1 -0
  88. package/std/debug/Pdb.zig +1 -1
  89. package/std/debug.zig +4 -3
  90. package/std/fmt.zig +8 -3
  91. package/std/fs/path.zig +6 -4
  92. package/std/heap/BufferFirstAllocator.zig +165 -0
  93. package/std/heap.zig +2 -126
  94. package/std/http/Client.zig +21 -24
  95. package/std/http.zig +3 -4
  96. package/std/json/Scanner.zig +2 -2
  97. package/std/os/emscripten.zig +1 -1
  98. package/std/os/linux/IoUring.zig +2 -0
  99. package/std/os/linux/aarch64.zig +41 -12
  100. package/std/os/linux/arc.zig +173 -0
  101. package/std/os/linux/arm.zig +41 -12
  102. package/std/os/linux/hexagon.zig +33 -11
  103. package/std/os/linux/loongarch32.zig +41 -13
  104. package/std/os/linux/loongarch64.zig +41 -12
  105. package/std/os/linux/m68k.zig +41 -13
  106. package/std/os/linux/mips.zig +67 -36
  107. package/std/os/linux/mips64.zig +60 -29
  108. package/std/os/linux/mipsn32.zig +60 -29
  109. package/std/os/linux/or1k.zig +41 -12
  110. package/std/os/linux/powerpc.zig +41 -12
  111. package/std/os/linux/powerpc64.zig +41 -12
  112. package/std/os/linux/riscv32.zig +41 -12
  113. package/std/os/linux/riscv64.zig +41 -12
  114. package/std/os/linux/s390x.zig +44 -7
  115. package/std/os/linux/sparc64.zig +83 -52
  116. package/std/os/linux/thumb.zig +52 -36
  117. package/std/os/linux/x32.zig +41 -12
  118. package/std/os/linux/x86.zig +42 -13
  119. package/std/os/linux/x86_64.zig +41 -12
  120. package/std/os/linux.zig +412 -436
  121. package/std/os/uefi/tables/boot_services.zig +9 -8
  122. package/std/os.zig +41 -0
  123. package/std/process.zig +1 -1
  124. package/std/sort.zig +3 -3
  125. package/std/zig/Ast/Render.zig +3 -3
  126. package/std/zig/AstGen.zig +44 -98
  127. package/std/zig/AstRlAnnotate.zig +0 -11
  128. package/std/zig/BuiltinFn.zig +0 -32
  129. package/std/zig/LibCInstallation.zig +4 -3
  130. package/std/zig/Parse.zig +7 -7
  131. package/std/zig/WindowsSdk.zig +13 -13
  132. package/std/zig/Zir.zig +50 -63
  133. package/std/zig/ZonGen.zig +6 -5
  134. package/std/zig/llvm/Builder.zig +12 -12
  135. package/std/zig.zig +1 -10
  136. package/std/zip.zig +5 -5
  137. package/zig.h +340 -1
  138. package/libc/mingw/math/fdiml.c +0 -24
  139. package/libc/mingw/winpthreads/spinlock.c +0 -82
  140. package/libc/musl/src/linux/tee.c +0 -8
  141. package/libc/musl/src/math/fdimf.c +0 -10
  142. package/libc/musl/src/math/fdiml.c +0 -18
  143. package/libc/musl/src/string/strdup.c +0 -10
  144. package/libc/musl/src/string/strndup.c +0 -12
  145. package/libc/musl/src/string/wcsdup.c +0 -10
  146. package/libc/musl/src/thread/pthread_spin_destroy.c +0 -6
  147. package/libc/musl/src/thread/pthread_spin_init.c +0 -6
  148. package/libc/musl/src/thread/pthread_spin_lock.c +0 -8
  149. package/libc/musl/src/thread/pthread_spin_trylock.c +0 -7
  150. package/libc/musl/src/thread/pthread_spin_unlock.c +0 -7
  151. package/libc/musl/src/unistd/dup2.c +0 -20
  152. package/libc/musl/src/unistd/dup3.c +0 -26
  153. package/libc/wasi/thread-stub/pthread_spin_lock.c +0 -8
  154. package/libc/wasi/thread-stub/pthread_spin_trylock.c +0 -8
  155. package/libc/wasi/thread-stub/pthread_spin_unlock.c +0 -7
@@ -158,12 +158,10 @@ pub const BootServices = extern struct {
158
158
  _locateProtocol: *const fn (protocol: *const Guid, registration: ?EventRegistration, interface: *?*const anyopaque) callconv(cc) Status,
159
159
 
160
160
  /// Installs one or more protocol interfaces into the boot services environment
161
- // TODO: use callconv(cc) instead once that works
162
- _installMultipleProtocolInterfaces: *const fn (handle: *Handle, ...) callconv(.c) Status,
161
+ _installMultipleProtocolInterfaces: *const fn (handle: *?Handle, ...) callconv(cc) Status,
163
162
 
164
163
  /// Removes one or more protocol interfaces into the boot services environment
165
- // TODO: use callconv(cc) instead once that works
166
- _uninstallMultipleProtocolInterfaces: *const fn (handle: *Handle, ...) callconv(.c) Status,
164
+ _uninstallMultipleProtocolInterfaces: *const fn (handle: Handle, ...) callconv(cc) Status,
167
165
 
168
166
  /// Computes and returns a 32-bit CRC for a data buffer.
169
167
  _calculateCrc32: *const fn (data: [*]const u8, data_size: usize, *u32) callconv(cc) Status,
@@ -1238,8 +1236,9 @@ fn protocolInterfaces(
1238
1236
  @TypeOf(interfaces),
1239
1237
  ) = undefined;
1240
1238
  result[0] = handle_arg;
1239
+ result[result.len - 1] = null;
1241
1240
 
1242
- var idx: usize = 1;
1241
+ comptime var idx: usize = 1;
1243
1242
  inline for (interfaces) |interface| {
1244
1243
  const InterfacePtr = @TypeOf(interface);
1245
1244
  const Interface = switch (@typeInfo(InterfacePtr)) {
@@ -1272,13 +1271,15 @@ fn ProtocolInterfaces(HandleType: type, Interfaces: type) type {
1272
1271
  @compileError("expected tuple of protocol interfaces, got " ++ @typeName(Interfaces));
1273
1272
  const interfaces_info = interfaces_type_info.@"struct";
1274
1273
 
1275
- var tuple_types: [interfaces_info.fields.len * 2 + 1]type = undefined;
1274
+ var tuple_types: [interfaces_info.fields.len * 2 + 2]type = undefined;
1276
1275
  tuple_types[0] = HandleType;
1276
+ tuple_types[tuple_types.len - 1] = ?*const Guid;
1277
+
1277
1278
  var idx = 1;
1278
- while (idx < tuple_types.len) : (idx += 2) {
1279
+ while (idx < tuple_types.len - 1) : (idx += 2) {
1279
1280
  tuple_types[idx] = *const Guid;
1280
1281
  tuple_types[idx + 1] = *const anyopaque;
1281
1282
  }
1282
1283
 
1283
- return std.meta.Tuple(tuple_types[0..]);
1284
+ return @Tuple(tuple_types[0..]);
1284
1285
  }
package/std/os.zig CHANGED
@@ -1,4 +1,5 @@
1
1
  const builtin = @import("builtin");
2
+ const std = @import("std.zig");
2
3
  const native_os = builtin.os.tag;
3
4
 
4
5
  pub const linux = @import("os/linux.zig");
@@ -8,6 +9,46 @@ pub const wasi = @import("os/wasi.zig");
8
9
  pub const emscripten = @import("os/emscripten.zig");
9
10
  pub const windows = @import("os/windows.zig");
10
11
 
12
+ /// Returns whether the Zig standard library requires libc in order to interface
13
+ /// with the operating system on the given target.
14
+ pub fn targetRequiresLibC(target: *const std.Target) bool {
15
+ if (target.requiresLibC()) return true;
16
+ return switch (target.os.tag) {
17
+ .linux => switch (target.cpu.arch) {
18
+ // https://codeberg.org/ziglang/zig/issues/30940
19
+ .alpha,
20
+ // https://codeberg.org/ziglang/zig/issues/30942
21
+ .csky,
22
+ // https://codeberg.org/ziglang/zig/issues/30943
23
+ .hppa,
24
+ .hppa64,
25
+ // https://codeberg.org/ziglang/zig/issues/30944
26
+ .microblaze,
27
+ .microblazeel,
28
+ // https://codeberg.org/ziglang/zig/issues/30946
29
+ .sh,
30
+ .sheb,
31
+ // https://codeberg.org/ziglang/zig/issues/30945
32
+ .sparc,
33
+ // https://codeberg.org/ziglang/zig/issues/30947
34
+ .xtensa,
35
+ .xtensaeb,
36
+ => true,
37
+ else => false,
38
+ },
39
+ .freebsd => true, // https://codeberg.org/ziglang/zig/issues/30981
40
+ .netbsd => true, // https://codeberg.org/ziglang/zig/issues/30980
41
+ .openbsd => true, // https://codeberg.org/ziglang/zig/issues/30982
42
+ else => false,
43
+ };
44
+ }
45
+
46
+ /// Returns whether the Zig standard library requires libc in order to interface
47
+ /// with the operating system on the current target.
48
+ pub fn requiresLibC() bool {
49
+ return targetRequiresLibC(&builtin.target);
50
+ }
51
+
11
52
  test {
12
53
  _ = linux;
13
54
  if (native_os == .uefi) _ = uefi;
package/std/process.zig CHANGED
@@ -130,7 +130,7 @@ pub fn posixGetUserInfo(io: Io, name: []const u8) !UserInfo {
130
130
  return posixGetUserInfoPasswdStream(name, &file_reader.interface) catch |err| switch (err) {
131
131
  error.ReadFailed => return file_reader.err.?,
132
132
  error.EndOfStream => return error.UserNotFound,
133
- error.CorruptPasswordFile => return error.CorruptPasswordFile,
133
+ error.CorruptPasswordFile => |e| return e,
134
134
  };
135
135
  }
136
136
 
package/std/sort.zig CHANGED
@@ -749,9 +749,9 @@ test partitionPoint {
749
749
 
750
750
  /// Returns a tuple of the lower and upper indices in `items` between which all
751
751
  /// elements return `.eq` when given to `compareFn`.
752
- /// - If no element in `items` returns `.eq`, both indices are the
753
- /// index of the first element in `items` returning `.gt`.
754
- /// - If no element in `items` returns `.gt`, both indices equal `items.len`.
752
+ /// If no element in `items` returns `.eq`, both indices are the index of the
753
+ /// first element in `items` which returns `.gt`, or if no element returns `.gt`,
754
+ /// both indices are `items.len`.
755
755
  ///
756
756
  /// `items` must be sorted in ascending order with respect to `compareFn`:
757
757
  /// ```
@@ -998,8 +998,8 @@ fn rendersMultiline(r: *const Render, node: Ast.Node.Index) error{OutOfMemory}!b
998
998
  .fixups = r.fixups,
999
999
  };
1000
1000
 
1001
- renderExpression(&sub_r, node, .none) catch |e| return switch (e) {
1002
- error.OutOfMemory => return error.OutOfMemory,
1001
+ renderExpression(&sub_r, node, .none) catch |err| return switch (err) {
1002
+ error.OutOfMemory => |e| return e,
1003
1003
  error.WriteFailed => return true,
1004
1004
  };
1005
1005
  if (sub_ais.disabled_offset != null) return true;
@@ -1685,7 +1685,7 @@ fn renderBuiltinCall(
1685
1685
  assert(tree.tokenTag(str_lit_token) == .string_literal);
1686
1686
  const token_bytes = tree.tokenSlice(str_lit_token);
1687
1687
  const imported_string = std.zig.string_literal.parseAlloc(r.gpa, token_bytes) catch |err| switch (err) {
1688
- error.OutOfMemory => return error.OutOfMemory,
1688
+ error.OutOfMemory => |e| return e,
1689
1689
  error.InvalidLiteral => break :f,
1690
1690
  };
1691
1691
  defer r.gpa.free(imported_string);
@@ -199,7 +199,7 @@ pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir {
199
199
  assert(struct_decl_ref.toIndex().? == .main_struct_inst);
200
200
  break :fatal false;
201
201
  } else |err| switch (err) {
202
- error.OutOfMemory => return error.OutOfMemory,
202
+ error.OutOfMemory => |e| return e,
203
203
  error.AnalysisFail => break :fatal true, // Handled via compile_errors below.
204
204
  }
205
205
  } else fatal: {
@@ -1776,11 +1776,12 @@ fn structInitExpr(
1776
1776
  }
1777
1777
 
1778
1778
  {
1779
- var sfba = std.heap.stackFallback(256, astgen.arena);
1780
- const sfba_allocator = sfba.get();
1779
+ var bfa_buf: [256]u8 = undefined;
1780
+ var bfa_state: std.heap.BufferFirstAllocator = .init(&bfa_buf, astgen.arena);
1781
+ const bfa = bfa_state.allocator();
1781
1782
 
1782
1783
  var duplicate_names: std.array_hash_map.Auto(Zir.NullTerminatedString, ArrayList(Ast.TokenIndex)) = .empty;
1783
- try duplicate_names.ensureTotalCapacity(sfba_allocator, @intCast(struct_init.ast.fields.len));
1784
+ try duplicate_names.ensureTotalCapacity(bfa, @intCast(struct_init.ast.fields.len));
1784
1785
 
1785
1786
  // When there aren't errors, use this to avoid a second iteration.
1786
1787
  var any_duplicate = false;
@@ -1789,14 +1790,14 @@ fn structInitExpr(
1789
1790
  const name_token = tree.firstToken(field) - 2;
1790
1791
  const name_index = try astgen.identAsString(name_token);
1791
1792
 
1792
- const gop = try duplicate_names.getOrPut(sfba_allocator, name_index);
1793
+ const gop = try duplicate_names.getOrPut(bfa, name_index);
1793
1794
 
1794
1795
  if (gop.found_existing) {
1795
- try gop.value_ptr.append(sfba_allocator, name_token);
1796
+ try gop.value_ptr.append(bfa, name_token);
1796
1797
  any_duplicate = true;
1797
1798
  } else {
1798
1799
  gop.value_ptr.* = .empty;
1799
- try gop.value_ptr.append(sfba_allocator, name_token);
1800
+ try gop.value_ptr.append(bfa, name_token);
1800
1801
  }
1801
1802
  }
1802
1803
 
@@ -2870,7 +2871,6 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As
2870
2871
  .mul_add,
2871
2872
  .max,
2872
2873
  .min,
2873
- .c_import,
2874
2874
  .@"resume",
2875
2875
  .ret_err_value_code,
2876
2876
  .ret_ptr,
@@ -5681,7 +5681,7 @@ fn containerMember(
5681
5681
 
5682
5682
  const prev_decl_index = wip_decls.index;
5683
5683
  astgen.fnDecl(gz, scope, wip_decls, member_node, body, full) catch |err| switch (err) {
5684
- error.OutOfMemory => return error.OutOfMemory,
5684
+ error.OutOfMemory => |e| return e,
5685
5685
  error.AnalysisFail => {
5686
5686
  wip_decls.index = prev_decl_index;
5687
5687
  try addFailedDeclaration(
@@ -5704,7 +5704,7 @@ fn containerMember(
5704
5704
  const full = tree.fullVarDecl(member_node).?;
5705
5705
  const prev_decl_index = wip_decls.index;
5706
5706
  astgen.globalVarDecl(gz, scope, wip_decls, member_node, full) catch |err| switch (err) {
5707
- error.OutOfMemory => return error.OutOfMemory,
5707
+ error.OutOfMemory => |e| return e,
5708
5708
  error.AnalysisFail => {
5709
5709
  wip_decls.index = prev_decl_index;
5710
5710
  try addFailedDeclaration(
@@ -5722,7 +5722,7 @@ fn containerMember(
5722
5722
  .@"comptime" => {
5723
5723
  const prev_decl_index = wip_decls.index;
5724
5724
  astgen.comptimeDecl(gz, scope, wip_decls, member_node) catch |err| switch (err) {
5725
- error.OutOfMemory => return error.OutOfMemory,
5725
+ error.OutOfMemory => |e| return e,
5726
5726
  error.AnalysisFail => {
5727
5727
  wip_decls.index = prev_decl_index;
5728
5728
  try addFailedDeclaration(
@@ -5742,7 +5742,7 @@ fn containerMember(
5742
5742
  // Since it doesn't strictly matter *what* this is, let's save ourselves the trouble
5743
5743
  // of duplicating the test name logic, and just assume this is an unnamed test.
5744
5744
  astgen.testDecl(gz, scope, wip_decls, member_node) catch |err| switch (err) {
5745
- error.OutOfMemory => return error.OutOfMemory,
5745
+ error.OutOfMemory => |e| return e,
5746
5746
  error.AnalysisFail => {
5747
5747
  wip_decls.index = prev_decl_index;
5748
5748
  try addFailedDeclaration(
@@ -6656,9 +6656,16 @@ fn whileExpr(
6656
6656
  .operand = undefined,
6657
6657
  } },
6658
6658
  });
6659
+ if (!continue_scope.is_comptime) {
6660
+ _ = try continue_scope.addRestoreErrRetIndex(.{ .block = continue_block }, .always, then_node);
6661
+ }
6659
6662
  _ = try continue_scope.addBreak(break_tag, continue_block, .void_value);
6660
6663
  }
6661
6664
  try continue_scope.setBlockBody(continue_block);
6665
+ if (!then_scope.is_comptime) {
6666
+ const cont_node = while_full.ast.cont_expr.unwrap() orelse then_node;
6667
+ _ = try then_scope.addRestoreErrRetIndex(.{ .block = cond_block }, .always, cont_node);
6668
+ }
6662
6669
  _ = try then_scope.addBreak(break_tag, cond_block, .void_value);
6663
6670
 
6664
6671
  var else_scope = parent_gz.makeSubBlock(&cond_scope.base);
@@ -6703,6 +6710,9 @@ fn whileExpr(
6703
6710
 
6704
6711
  try checkUsed(parent_gz, &else_scope.base, sub_scope);
6705
6712
  if (!else_scope.endsWithNoReturn()) {
6713
+ if (!else_scope.is_comptime) {
6714
+ _ = try else_scope.addRestoreErrRetIndex(.{ .block = loop_block }, .always, else_node);
6715
+ }
6706
6716
  _ = try else_scope.addBreakWithSrcNode(break_tag, loop_block, else_result, else_node);
6707
6717
  }
6708
6718
  } else {
@@ -6973,6 +6983,9 @@ fn forExpr(
6973
6983
  });
6974
6984
 
6975
6985
  const break_tag: Zir.Inst.Tag = if (is_inline) .break_inline else .@"break";
6986
+ if (!then_scope.is_comptime) {
6987
+ _ = try then_scope.addRestoreErrRetIndex(.{ .block = cond_block }, .always, then_node);
6988
+ }
6976
6989
  _ = try then_scope.addBreak(break_tag, cond_block, .void_value);
6977
6990
 
6978
6991
  var else_scope = parent_gz.makeSubBlock(&cond_scope.base);
@@ -6990,6 +7003,9 @@ fn forExpr(
6990
7003
  _ = try addEnsureResult(&else_scope, else_result, else_node);
6991
7004
  }
6992
7005
  if (!else_scope.endsWithNoReturn()) {
7006
+ if (!else_scope.is_comptime) {
7007
+ _ = try else_scope.addRestoreErrRetIndex(.{ .block = loop_block }, .always, else_node);
7008
+ }
6993
7009
  _ = try else_scope.addBreakWithSrcNode(break_tag, loop_block, else_result, else_node);
6994
7010
  }
6995
7011
  } else {
@@ -8405,9 +8421,10 @@ fn tunnelThroughClosure(
8405
8421
 
8406
8422
  // Otherwise we need a tunnel. First, figure out the path of namespaces we
8407
8423
  // are tunneling through. This is usually only going to be one or two, so
8408
- // use an SFBA to optimize for the common case.
8409
- var sfba = std.heap.stackFallback(@sizeOf(usize) * 2, astgen.arena);
8410
- var intermediate_tunnels = try sfba.get().alloc(*Scope.Namespace, num_tunnels - 1);
8424
+ // use an BFA to optimize for the common case.
8425
+ var bfa_buf: [2]usize = undefined;
8426
+ var bfa: std.heap.BufferFirstAllocator = .init(@ptrCast(&bfa_buf), astgen.arena);
8427
+ var intermediate_tunnels = try bfa.allocator().alloc(*Scope.Namespace, num_tunnels - 1);
8411
8428
 
8412
8429
  const root_ns = ns: {
8413
8430
  var i: usize = num_tunnels - 1;
@@ -8562,7 +8579,7 @@ fn numberLiteral(gz: *GenZir, ri: ResultInfo, node: Ast.Node.Index, source_node:
8562
8579
  big_int.setString(@intFromEnum(base), bytes[prefix_offset..]) catch |err| switch (err) {
8563
8580
  error.InvalidCharacter => unreachable, // caught in `parseNumberLiteral`
8564
8581
  error.InvalidBase => unreachable, // we only pass 16, 8, 2, see above
8565
- error.OutOfMemory => return error.OutOfMemory,
8582
+ error.OutOfMemory => |e| return e,
8566
8583
  };
8567
8584
 
8568
8585
  const limbs = big_int.limbs[0..big_int.len()];
@@ -8955,7 +8972,6 @@ fn typeOf(
8955
8972
  var typeof_scope = gz.makeSubBlock(scope);
8956
8973
  typeof_scope.is_comptime = false;
8957
8974
  typeof_scope.is_typeof = true;
8958
- typeof_scope.c_import = false;
8959
8975
  defer typeof_scope.unstack();
8960
8976
 
8961
8977
  const ty_expr = try reachableExpr(&typeof_scope, &typeof_scope.base, .{ .rl = .none }, args[0], node);
@@ -9055,8 +9071,7 @@ fn builtinCall(
9055
9071
  const builtin_name = tree.tokenSlice(builtin_token);
9056
9072
 
9057
9073
  // We handle the different builtins manually because they have different semantics depending
9058
- // on the function. For example, `@as` and others participate in result location semantics,
9059
- // and `@cImport` creates a special scope that collects a .c source code text buffer.
9074
+ // on the function. For example, `@as` and others participate in result location semantics.
9060
9075
  // Also, some builtins have a variable number of parameters.
9061
9076
 
9062
9077
  const info = BuiltinFn.list.get(builtin_name) orelse {
@@ -9175,7 +9190,6 @@ fn builtinCall(
9175
9190
  .bit_cast => return bitCast( gz, scope, ri, node, params[0]),
9176
9191
  .TypeOf => return typeOf( gz, scope, ri, node, params),
9177
9192
  .union_init => return unionInit(gz, scope, ri, node, params),
9178
- .c_import => return cImport( gz, scope, node, params[0]),
9179
9193
  .min => return minMax( gz, scope, ri, node, params, .min),
9180
9194
  .max => return minMax( gz, scope, ri, node, params, .max),
9181
9195
  // zig fmt: on
@@ -9484,9 +9498,6 @@ fn builtinCall(
9484
9498
  .bit_offset_of => return offsetOf(gz, scope, ri, node, params[0], params[1], .bit_offset_of),
9485
9499
  .offset_of => return offsetOf(gz, scope, ri, node, params[0], params[1], .offset_of),
9486
9500
 
9487
- .c_undef => return simpleCBuiltin(gz, scope, ri, node, params[0], .c_undef),
9488
- .c_include => return simpleCBuiltin(gz, scope, ri, node, params[0], .c_include),
9489
-
9490
9501
  .cmpxchg_strong => return cmpxchg(gz, scope, ri, node, params, 1),
9491
9502
  .cmpxchg_weak => return cmpxchg(gz, scope, ri, node, params, 0),
9492
9503
  // zig fmt: on
@@ -9509,17 +9520,6 @@ fn builtinCall(
9509
9520
  });
9510
9521
  return rvalue(gz, ri, result, node);
9511
9522
  },
9512
- .c_define => {
9513
- if (!gz.c_import) return gz.astgen.failNode(node, "C define valid only inside C import block", .{});
9514
- const name = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = .slice_const_u8_type } }, params[0], .operand_cDefine_macro_name);
9515
- const value = try comptimeExpr(gz, scope, .{ .rl = .none }, params[1], .operand_cDefine_macro_value);
9516
- const result = try gz.addExtendedPayload(.c_define, Zir.Inst.BinNode{
9517
- .node = gz.nodeIndexToRelative(node),
9518
- .lhs = name,
9519
- .rhs = value,
9520
- });
9521
- return rvalue(gz, ri, result, node);
9522
- },
9523
9523
  .splat => {
9524
9524
  const result_type = try ri.rl.resultTypeForCast(gz, node, builtin_name);
9525
9525
  const elem_type = try gz.addUnNode(.splat_op_result_ty, result_type, node);
@@ -9951,30 +9951,6 @@ fn divBuiltin(
9951
9951
  return rvalue(gz, ri, result, node);
9952
9952
  }
9953
9953
 
9954
- fn simpleCBuiltin(
9955
- gz: *GenZir,
9956
- scope: *Scope,
9957
- ri: ResultInfo,
9958
- node: Ast.Node.Index,
9959
- operand_node: Ast.Node.Index,
9960
- tag: Zir.Inst.Extended,
9961
- ) InnerError!Zir.Inst.Ref {
9962
- const name: []const u8 = if (tag == .c_undef) "C undef" else "C include";
9963
- if (!gz.c_import) return gz.astgen.failNode(node, "{s} valid only inside C import block", .{name});
9964
- const operand = try comptimeExpr(
9965
- gz,
9966
- scope,
9967
- .{ .rl = .{ .coerced_ty = .slice_const_u8_type } },
9968
- operand_node,
9969
- if (tag == .c_undef) .operand_cUndef_macro_name else .operand_cInclude_file_name,
9970
- );
9971
- _ = try gz.addExtendedPayload(tag, Zir.Inst.UnNode{
9972
- .node = gz.nodeIndexToRelative(node),
9973
- .operand = operand,
9974
- });
9975
- return rvalue(gz, ri, .void_value, node);
9976
- }
9977
-
9978
9954
  fn offsetOf(
9979
9955
  gz: *GenZir,
9980
9956
  scope: *Scope,
@@ -10024,35 +10000,6 @@ fn shiftOp(
10024
10000
  return rvalue(gz, ri, result, node);
10025
10001
  }
10026
10002
 
10027
- fn cImport(
10028
- gz: *GenZir,
10029
- scope: *Scope,
10030
- node: Ast.Node.Index,
10031
- body_node: Ast.Node.Index,
10032
- ) InnerError!Zir.Inst.Ref {
10033
- const astgen = gz.astgen;
10034
- const gpa = astgen.gpa;
10035
-
10036
- if (gz.c_import) return gz.astgen.failNode(node, "cannot nest @cImport", .{});
10037
-
10038
- var block_scope = gz.makeSubBlock(scope);
10039
- block_scope.is_comptime = true;
10040
- block_scope.c_import = true;
10041
- defer block_scope.unstack();
10042
-
10043
- const block_inst = try gz.makeBlockInst(.c_import, node);
10044
- const block_result = try fullBodyExpr(&block_scope, &block_scope.base, .{ .rl = .none }, body_node, .normal);
10045
- _ = try gz.addUnNode(.ensure_result_used, block_result, node);
10046
- if (!gz.refIsNoReturn(block_result)) {
10047
- _ = try block_scope.addBreak(.break_inline, block_inst, .void_value);
10048
- }
10049
- try block_scope.setBlockBody(block_inst);
10050
- // block_scope unstacked now, can add new instructions to gz
10051
- try gz.instructions.append(gpa, block_inst);
10052
-
10053
- return block_inst.toRef();
10054
- }
10055
-
10056
10003
  fn overflowArithmetic(
10057
10004
  gz: *GenZir,
10058
10005
  scope: *Scope,
@@ -11339,7 +11286,6 @@ const GenZir = struct {
11339
11286
  /// This is set to true for a `GenZir` of a `block_inline`, indicating that
11340
11287
  /// exits from this block should use `break_inline` rather than `break`.
11341
11288
  is_inline: bool = false,
11342
- c_import: bool = false,
11343
11289
  /// The containing decl AST node.
11344
11290
  decl_node_index: Ast.Node.Index,
11345
11291
  /// The containing decl line index, absolute.
@@ -11427,7 +11373,6 @@ const GenZir = struct {
11427
11373
  return .{
11428
11374
  .is_comptime = gz.is_comptime,
11429
11375
  .is_typeof = gz.is_typeof,
11430
- .c_import = gz.c_import,
11431
11376
  .decl_node_index = gz.decl_node_index,
11432
11377
  .decl_line = gz.decl_line,
11433
11378
  .parent = scope,
@@ -12999,17 +12944,18 @@ fn scanContainer(
12999
12944
  next: ?*@This(),
13000
12945
  };
13001
12946
 
13002
- // The maps below are allocated into this SFBA to avoid using the GPA for small namespaces.
13003
- var sfba_state = std.heap.stackFallback(512, astgen.gpa);
13004
- const sfba = sfba_state.get();
12947
+ // The maps below are allocated into this BFA to avoid using the GPA for small namespaces.
12948
+ var bfa_buf: [512]u8 = undefined;
12949
+ var bfa_state: std.heap.BufferFirstAllocator = .init(&bfa_buf, astgen.gpa);
12950
+ const bfa = bfa_state.allocator();
13005
12951
 
13006
12952
  var names: std.AutoArrayHashMapUnmanaged(Zir.NullTerminatedString, NameEntry) = .empty;
13007
12953
  var test_names: std.AutoArrayHashMapUnmanaged(Zir.NullTerminatedString, NameEntry) = .empty;
13008
12954
  var decltest_names: std.AutoArrayHashMapUnmanaged(Zir.NullTerminatedString, NameEntry) = .empty;
13009
12955
  defer {
13010
- names.deinit(sfba);
13011
- test_names.deinit(sfba);
13012
- decltest_names.deinit(sfba);
12956
+ names.deinit(bfa);
12957
+ test_names.deinit(bfa);
12958
+ decltest_names.deinit(bfa);
13013
12959
  }
13014
12960
 
13015
12961
  var any_duplicates = false;
@@ -13081,7 +13027,7 @@ fn scanContainer(
13081
13027
  else => {}, // unnamed test
13082
13028
  .string_literal => {
13083
13029
  const name = try astgen.strLitAsString(test_name_token);
13084
- const gop = try test_names.getOrPut(sfba, name.index);
13030
+ const gop = try test_names.getOrPut(bfa, name.index);
13085
13031
  if (gop.found_existing) {
13086
13032
  var e = gop.value_ptr;
13087
13033
  while (e.next) |n| e = n;
@@ -13094,7 +13040,7 @@ fn scanContainer(
13094
13040
  },
13095
13041
  .identifier => {
13096
13042
  const name = try astgen.identAsString(test_name_token);
13097
- const gop = try decltest_names.getOrPut(sfba, name);
13043
+ const gop = try decltest_names.getOrPut(bfa, name);
13098
13044
  if (gop.found_existing) {
13099
13045
  var e = gop.value_ptr;
13100
13046
  while (e.next) |n| e = n;
@@ -13121,7 +13067,7 @@ fn scanContainer(
13121
13067
  }
13122
13068
 
13123
13069
  {
13124
- const gop = try names.getOrPut(sfba, name_str_index);
13070
+ const gop = try names.getOrPut(bfa, name_str_index);
13125
13071
  const new_ent: NameEntry = .{
13126
13072
  .tok = name_token,
13127
13073
  .next = null,
@@ -842,10 +842,6 @@ fn builtinCall(astrl: *AstRlAnnotate, block: ?*Block, ri: ResultInfo, node: Ast.
842
842
  _ = try astrl.expr(args[2], block, ResultInfo.type_only);
843
843
  return false;
844
844
  },
845
- .c_import => {
846
- _ = try astrl.expr(args[0], block, ResultInfo.none);
847
- return false;
848
- },
849
845
  .min, .max => {
850
846
  for (args) |arg_node| {
851
847
  _ = try astrl.expr(arg_node, block, ResultInfo.none);
@@ -907,8 +903,6 @@ fn builtinCall(astrl: *AstRlAnnotate, block: ?*Block, ri: ResultInfo, node: Ast.
907
903
  .error_name,
908
904
  .set_runtime_safety,
909
905
  .Tuple,
910
- .c_undef,
911
- .c_include,
912
906
  .wasm_memory_size,
913
907
  .splat,
914
908
  .set_float_mode,
@@ -986,11 +980,6 @@ fn builtinCall(astrl: *AstRlAnnotate, block: ?*Block, ri: ResultInfo, node: Ast.
986
980
  _ = try astrl.expr(args[1], block, ResultInfo.type_only);
987
981
  return false;
988
982
  },
989
- .c_define => {
990
- _ = try astrl.expr(args[0], block, ResultInfo.type_only);
991
- _ = try astrl.expr(args[1], block, ResultInfo.none);
992
- return false;
993
- },
994
983
  .reduce => {
995
984
  _ = try astrl.expr(args[0], block, ResultInfo.type_only);
996
985
  _ = try astrl.expr(args[1], block, ResultInfo.none);
@@ -20,9 +20,6 @@ pub const Tag = enum {
20
20
  bit_reverse,
21
21
  offset_of,
22
22
  call,
23
- c_define,
24
- c_import,
25
- c_include,
26
23
  clz,
27
24
  cmpxchg_strong,
28
25
  cmpxchg_weak,
@@ -30,7 +27,6 @@ pub const Tag = enum {
30
27
  compile_log,
31
28
  const_cast,
32
29
  ctz,
33
- c_undef,
34
30
  c_va_arg,
35
31
  c_va_copy,
36
32
  c_va_end,
@@ -306,27 +302,6 @@ pub const list = list: {
306
302
  .param_count = 3,
307
303
  },
308
304
  },
309
- .{
310
- "@cDefine",
311
- .{
312
- .tag = .c_define,
313
- .param_count = 2,
314
- },
315
- },
316
- .{
317
- "@cImport",
318
- .{
319
- .tag = .c_import,
320
- .param_count = 1,
321
- },
322
- },
323
- .{
324
- "@cInclude",
325
- .{
326
- .tag = .c_include,
327
- .param_count = 1,
328
- },
329
- },
330
305
  .{
331
306
  "@clz",
332
307
  .{
@@ -376,13 +351,6 @@ pub const list = list: {
376
351
  .param_count = 1,
377
352
  },
378
353
  },
379
- .{
380
- "@cUndef",
381
- .{
382
- .tag = .c_undef,
383
- .param_count = 1,
384
- },
385
- },
386
354
  .{
387
355
  "@cVaArg",
388
356
  .{
@@ -196,7 +196,7 @@ pub fn findNative(gpa: Allocator, io: Io, args: FindNativeOptions) FindError!Lib
196
196
  const sdk = std.zig.WindowsSdk.find(gpa, io, args.target.cpu.arch, args.environ_map) catch |err| switch (err) {
197
197
  error.NotFound => return error.WindowsSdkNotFound,
198
198
  error.PathTooLong => return error.WindowsSdkNotFound,
199
- error.OutOfMemory => return error.OutOfMemory,
199
+ error.OutOfMemory => |e| return e,
200
200
  };
201
201
  defer sdk.free(gpa);
202
202
 
@@ -278,7 +278,7 @@ fn findNativeIncludeDirPosix(self: *LibCInstallation, gpa: Allocator, io: Io, ar
278
278
  // So we use the expandArg0 variant of ChildProcess to give them a helping hand.
279
279
  .expand_arg0 = .expand,
280
280
  }) catch |err| switch (err) {
281
- error.OutOfMemory => return error.OutOfMemory,
281
+ error.OutOfMemory => |e| return e,
282
282
  else => {
283
283
  printVerboseInvocation(argv.items, null, args.verbose, null);
284
284
  return error.UnableToSpawnCCompiler;
@@ -459,6 +459,7 @@ fn findNativeCrtDirPosix(self: *LibCInstallation, gpa: Allocator, io: Io, args:
459
459
 
460
460
  fn findNativeGccDirHaiku(self: *LibCInstallation, gpa: Allocator, io: Io, args: FindNativeOptions) FindError!void {
461
461
  self.gcc_dir = try ccPrintFileName(gpa, io, .{
462
+ .environ_map = args.environ_map,
462
463
  .search_basename = "crtbeginS.o",
463
464
  .want_dirname = .only_dir,
464
465
  .verbose = args.verbose,
@@ -595,7 +596,7 @@ fn ccPrintFileName(gpa: Allocator, io: Io, args: CCPrintFileNameOptions) ![]u8 {
595
596
  // So we use the expandArg0 variant of ChildProcess to give them a helping hand.
596
597
  .expand_arg0 = .expand,
597
598
  }) catch |err| switch (err) {
598
- error.OutOfMemory => return error.OutOfMemory,
599
+ error.OutOfMemory => |e| return e,
599
600
  else => return error.UnableToSpawnCCompiler,
600
601
  };
601
602
  defer {
package/std/zig/Parse.zig CHANGED
@@ -278,7 +278,7 @@ fn parseContainerMembers(p: *Parse) Allocator.Error!Members {
278
278
  }
279
279
  const comptime_token = p.nextToken();
280
280
  const opt_block = p.parseBlock() catch |err| switch (err) {
281
- error.OutOfMemory => return error.OutOfMemory,
281
+ error.OutOfMemory => |e| return e,
282
282
  error.ParseError => blk: {
283
283
  p.findNextContainerMember();
284
284
  break :blk null;
@@ -301,7 +301,7 @@ fn parseContainerMembers(p: *Parse) Allocator.Error!Members {
301
301
  const identifier = p.tok_i;
302
302
  defer last_field = identifier;
303
303
  const container_field = p.expectContainerField() catch |err| switch (err) {
304
- error.OutOfMemory => return error.OutOfMemory,
304
+ error.OutOfMemory => |e| return e,
305
305
  error.ParseError => {
306
306
  p.findNextContainerMember();
307
307
  continue;
@@ -398,7 +398,7 @@ fn parseContainerMembers(p: *Parse) Allocator.Error!Members {
398
398
  },
399
399
  else => {
400
400
  const c_container = p.parseCStyleContainer() catch |err| switch (err) {
401
- error.OutOfMemory => return error.OutOfMemory,
401
+ error.OutOfMemory => |e| return e,
402
402
  error.ParseError => false,
403
403
  };
404
404
  if (c_container) continue;
@@ -406,7 +406,7 @@ fn parseContainerMembers(p: *Parse) Allocator.Error!Members {
406
406
  const identifier = p.tok_i;
407
407
  defer last_field = identifier;
408
408
  const container_field = p.expectContainerField() catch |err| switch (err) {
409
- error.OutOfMemory => return error.OutOfMemory,
409
+ error.OutOfMemory => |e| return e,
410
410
  error.ParseError => {
411
411
  p.findNextContainerMember();
412
412
  continue;
@@ -589,7 +589,7 @@ fn expectTestDeclRecoverable(p: *Parse) error{OutOfMemory}!?Node.Index {
589
589
  if (p.expectTestDecl()) |node| {
590
590
  return node;
591
591
  } else |err| switch (err) {
592
- error.OutOfMemory => return error.OutOfMemory,
592
+ error.OutOfMemory => |e| return e,
593
593
  error.ParseError => {
594
594
  p.findNextContainerMember();
595
595
  return null;
@@ -668,7 +668,7 @@ fn expectTopLevelDecl(p: *Parse) !?Node.Index {
668
668
 
669
669
  fn expectTopLevelDeclRecoverable(p: *Parse) error{OutOfMemory}!?Node.Index {
670
670
  return p.expectTopLevelDecl() catch |err| switch (err) {
671
- error.OutOfMemory => return error.OutOfMemory,
671
+ error.OutOfMemory => |e| return e,
672
672
  error.ParseError => {
673
673
  p.findNextContainerMember();
674
674
  return null;
@@ -1145,7 +1145,7 @@ fn expectVarDeclExprStatement(p: *Parse, comptime_token: ?TokenIndex) !Node.Inde
1145
1145
  fn expectStatementRecoverable(p: *Parse) Error!?Node.Index {
1146
1146
  while (true) {
1147
1147
  return p.expectStatement(true) catch |err| switch (err) {
1148
- error.OutOfMemory => return error.OutOfMemory,
1148
+ error.OutOfMemory => |e| return e,
1149
1149
  error.ParseError => {
1150
1150
  p.findNextStmt(); // Try to skip to the next statement.
1151
1151
  switch (p.tokenTag(p.tok_i)) {