@zigc/lib 0.17.0-dev.9 → 0.17.0-dev.93

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 (107) 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/search.zig +1 -27
  5. package/c/stdlib/drand48.zig +0 -57
  6. package/c/stdlib.zig +0 -100
  7. package/c/string.zig +0 -7
  8. package/c/strings.zig +0 -38
  9. package/c/unistd.zig +27 -26
  10. package/c.zig +1 -2
  11. package/compiler/aro/aro/CodeGen.zig +3 -2
  12. package/compiler/aro/aro/Compilation.zig +15 -12
  13. package/compiler/aro/aro/Driver.zig +9 -6
  14. package/compiler/aro/aro/Parser.zig +18 -12
  15. package/compiler/aro/aro/Pragma.zig +3 -2
  16. package/compiler/aro/aro/Preprocessor.zig +9 -6
  17. package/compiler/aro/aro/pragmas/message.zig +3 -2
  18. package/compiler/aro/aro/text_literal.zig +3 -2
  19. package/compiler/aro/assembly_backend/x86_64.zig +3 -2
  20. package/compiler/build_runner.zig +0 -2
  21. package/compiler/test_runner.zig +1 -1
  22. package/compiler/translate-c/Translator.zig +4 -0
  23. package/compiler_rt/cos.zig +0 -2
  24. package/compiler_rt/divmodei4.zig +40 -17
  25. package/compiler_rt/exp.zig +1 -6
  26. package/compiler_rt/exp2.zig +1 -6
  27. package/compiler_rt/exp_f128.zig +377 -0
  28. package/compiler_rt/fabs.zig +0 -2
  29. package/compiler_rt/fma.zig +0 -2
  30. package/compiler_rt/fmax.zig +0 -2
  31. package/compiler_rt/fmin.zig +0 -2
  32. package/compiler_rt/fmod.zig +0 -2
  33. package/compiler_rt/limb64.zig +876 -15
  34. package/compiler_rt/log.zig +0 -2
  35. package/compiler_rt/log10.zig +0 -2
  36. package/compiler_rt/log2.zig +0 -2
  37. package/compiler_rt/mulXi3.zig +1 -1
  38. package/compiler_rt/round.zig +0 -2
  39. package/compiler_rt/sin.zig +0 -2
  40. package/compiler_rt/sincos.zig +0 -2
  41. package/compiler_rt/sqrt.zig +0 -2
  42. package/compiler_rt/ssp.zig +1 -1
  43. package/compiler_rt/tan.zig +0 -2
  44. package/compiler_rt/trunc.zig +0 -2
  45. package/compiler_rt/udivmodei4.zig +28 -0
  46. package/fuzzer.zig +2 -0
  47. package/libc/musl/arch/mipsn32/syscall_arch.h +35 -32
  48. package/package.json +1 -1
  49. package/std/Build/Step/Compile.zig +0 -1
  50. package/std/Build.zig +0 -3
  51. package/std/Io/Dispatch.zig +3 -13
  52. package/std/Io/Semaphore.zig +112 -17
  53. package/std/Io/Threaded.zig +167 -33
  54. package/std/Io/Uring.zig +12 -14
  55. package/std/Io/Writer.zig +46 -42
  56. package/std/Io/net.zig +11 -11
  57. package/std/Io.zig +89 -25
  58. package/std/Target.zig +50 -5
  59. package/std/builtin.zig +4 -0
  60. package/std/c/haiku.zig +3 -0
  61. package/std/c/serenity.zig +1 -6
  62. package/std/c.zig +59 -6
  63. package/std/debug.zig +4 -3
  64. package/std/fmt.zig +7 -2
  65. package/std/fs/path.zig +6 -4
  66. package/std/heap/BufferFirstAllocator.zig +165 -0
  67. package/std/heap.zig +2 -126
  68. package/std/http/Client.zig +21 -24
  69. package/std/os/linux/aarch64.zig +41 -12
  70. package/std/os/linux/arc.zig +41 -12
  71. package/std/os/linux/arm.zig +41 -12
  72. package/std/os/linux/hexagon.zig +33 -11
  73. package/std/os/linux/loongarch32.zig +41 -13
  74. package/std/os/linux/loongarch64.zig +41 -12
  75. package/std/os/linux/m68k.zig +41 -13
  76. package/std/os/linux/mips.zig +67 -36
  77. package/std/os/linux/mips64.zig +60 -29
  78. package/std/os/linux/mipsn32.zig +60 -29
  79. package/std/os/linux/or1k.zig +41 -12
  80. package/std/os/linux/powerpc.zig +41 -12
  81. package/std/os/linux/powerpc64.zig +41 -12
  82. package/std/os/linux/riscv32.zig +41 -12
  83. package/std/os/linux/riscv64.zig +41 -12
  84. package/std/os/linux/s390x.zig +44 -7
  85. package/std/os/linux/sparc64.zig +83 -52
  86. package/std/os/linux/thumb.zig +52 -36
  87. package/std/os/linux/x32.zig +41 -12
  88. package/std/os/linux/x86.zig +42 -13
  89. package/std/os/linux/x86_64.zig +41 -12
  90. package/std/os/linux.zig +398 -434
  91. package/std/os.zig +41 -0
  92. package/std/sort.zig +3 -3
  93. package/std/zig/AstGen.zig +22 -92
  94. package/std/zig/AstRlAnnotate.zig +0 -11
  95. package/std/zig/BuiltinFn.zig +0 -32
  96. package/std/zig/LibCInstallation.zig +1 -0
  97. package/std/zig/Zir.zig +50 -63
  98. package/std/zig/ZonGen.zig +5 -4
  99. package/std/zig/llvm/Builder.zig +12 -12
  100. package/std/zig.zig +0 -10
  101. package/zig.h +340 -1
  102. package/libc/mingw/math/fdiml.c +0 -24
  103. package/libc/musl/src/linux/tee.c +0 -8
  104. package/libc/musl/src/math/fdimf.c +0 -10
  105. package/libc/musl/src/math/fdiml.c +0 -18
  106. package/libc/musl/src/unistd/dup2.c +0 -20
  107. package/libc/musl/src/unistd/dup3.c +0 -26
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/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
  /// ```
@@ -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,
@@ -8405,9 +8405,10 @@ fn tunnelThroughClosure(
8405
8405
 
8406
8406
  // Otherwise we need a tunnel. First, figure out the path of namespaces we
8407
8407
  // 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);
8408
+ // use an BFA to optimize for the common case.
8409
+ var bfa_buf: [2]usize = undefined;
8410
+ var bfa: std.heap.BufferFirstAllocator = .init(@ptrCast(&bfa_buf), astgen.arena);
8411
+ var intermediate_tunnels = try bfa.allocator().alloc(*Scope.Namespace, num_tunnels - 1);
8411
8412
 
8412
8413
  const root_ns = ns: {
8413
8414
  var i: usize = num_tunnels - 1;
@@ -8955,7 +8956,6 @@ fn typeOf(
8955
8956
  var typeof_scope = gz.makeSubBlock(scope);
8956
8957
  typeof_scope.is_comptime = false;
8957
8958
  typeof_scope.is_typeof = true;
8958
- typeof_scope.c_import = false;
8959
8959
  defer typeof_scope.unstack();
8960
8960
 
8961
8961
  const ty_expr = try reachableExpr(&typeof_scope, &typeof_scope.base, .{ .rl = .none }, args[0], node);
@@ -9055,8 +9055,7 @@ fn builtinCall(
9055
9055
  const builtin_name = tree.tokenSlice(builtin_token);
9056
9056
 
9057
9057
  // 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.
9058
+ // on the function. For example, `@as` and others participate in result location semantics.
9060
9059
  // Also, some builtins have a variable number of parameters.
9061
9060
 
9062
9061
  const info = BuiltinFn.list.get(builtin_name) orelse {
@@ -9175,7 +9174,6 @@ fn builtinCall(
9175
9174
  .bit_cast => return bitCast( gz, scope, ri, node, params[0]),
9176
9175
  .TypeOf => return typeOf( gz, scope, ri, node, params),
9177
9176
  .union_init => return unionInit(gz, scope, ri, node, params),
9178
- .c_import => return cImport( gz, scope, node, params[0]),
9179
9177
  .min => return minMax( gz, scope, ri, node, params, .min),
9180
9178
  .max => return minMax( gz, scope, ri, node, params, .max),
9181
9179
  // zig fmt: on
@@ -9484,9 +9482,6 @@ fn builtinCall(
9484
9482
  .bit_offset_of => return offsetOf(gz, scope, ri, node, params[0], params[1], .bit_offset_of),
9485
9483
  .offset_of => return offsetOf(gz, scope, ri, node, params[0], params[1], .offset_of),
9486
9484
 
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
9485
  .cmpxchg_strong => return cmpxchg(gz, scope, ri, node, params, 1),
9491
9486
  .cmpxchg_weak => return cmpxchg(gz, scope, ri, node, params, 0),
9492
9487
  // zig fmt: on
@@ -9509,17 +9504,6 @@ fn builtinCall(
9509
9504
  });
9510
9505
  return rvalue(gz, ri, result, node);
9511
9506
  },
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
9507
  .splat => {
9524
9508
  const result_type = try ri.rl.resultTypeForCast(gz, node, builtin_name);
9525
9509
  const elem_type = try gz.addUnNode(.splat_op_result_ty, result_type, node);
@@ -9951,30 +9935,6 @@ fn divBuiltin(
9951
9935
  return rvalue(gz, ri, result, node);
9952
9936
  }
9953
9937
 
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
9938
  fn offsetOf(
9979
9939
  gz: *GenZir,
9980
9940
  scope: *Scope,
@@ -10024,35 +9984,6 @@ fn shiftOp(
10024
9984
  return rvalue(gz, ri, result, node);
10025
9985
  }
10026
9986
 
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
9987
  fn overflowArithmetic(
10057
9988
  gz: *GenZir,
10058
9989
  scope: *Scope,
@@ -11339,7 +11270,6 @@ const GenZir = struct {
11339
11270
  /// This is set to true for a `GenZir` of a `block_inline`, indicating that
11340
11271
  /// exits from this block should use `break_inline` rather than `break`.
11341
11272
  is_inline: bool = false,
11342
- c_import: bool = false,
11343
11273
  /// The containing decl AST node.
11344
11274
  decl_node_index: Ast.Node.Index,
11345
11275
  /// The containing decl line index, absolute.
@@ -11427,7 +11357,6 @@ const GenZir = struct {
11427
11357
  return .{
11428
11358
  .is_comptime = gz.is_comptime,
11429
11359
  .is_typeof = gz.is_typeof,
11430
- .c_import = gz.c_import,
11431
11360
  .decl_node_index = gz.decl_node_index,
11432
11361
  .decl_line = gz.decl_line,
11433
11362
  .parent = scope,
@@ -12999,17 +12928,18 @@ fn scanContainer(
12999
12928
  next: ?*@This(),
13000
12929
  };
13001
12930
 
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();
12931
+ // The maps below are allocated into this BFA to avoid using the GPA for small namespaces.
12932
+ var bfa_buf: [512]u8 = undefined;
12933
+ var bfa_state: std.heap.BufferFirstAllocator = .init(&bfa_buf, astgen.gpa);
12934
+ const bfa = bfa_state.allocator();
13005
12935
 
13006
12936
  var names: std.AutoArrayHashMapUnmanaged(Zir.NullTerminatedString, NameEntry) = .empty;
13007
12937
  var test_names: std.AutoArrayHashMapUnmanaged(Zir.NullTerminatedString, NameEntry) = .empty;
13008
12938
  var decltest_names: std.AutoArrayHashMapUnmanaged(Zir.NullTerminatedString, NameEntry) = .empty;
13009
12939
  defer {
13010
- names.deinit(sfba);
13011
- test_names.deinit(sfba);
13012
- decltest_names.deinit(sfba);
12940
+ names.deinit(bfa);
12941
+ test_names.deinit(bfa);
12942
+ decltest_names.deinit(bfa);
13013
12943
  }
13014
12944
 
13015
12945
  var any_duplicates = false;
@@ -13081,7 +13011,7 @@ fn scanContainer(
13081
13011
  else => {}, // unnamed test
13082
13012
  .string_literal => {
13083
13013
  const name = try astgen.strLitAsString(test_name_token);
13084
- const gop = try test_names.getOrPut(sfba, name.index);
13014
+ const gop = try test_names.getOrPut(bfa, name.index);
13085
13015
  if (gop.found_existing) {
13086
13016
  var e = gop.value_ptr;
13087
13017
  while (e.next) |n| e = n;
@@ -13094,7 +13024,7 @@ fn scanContainer(
13094
13024
  },
13095
13025
  .identifier => {
13096
13026
  const name = try astgen.identAsString(test_name_token);
13097
- const gop = try decltest_names.getOrPut(sfba, name);
13027
+ const gop = try decltest_names.getOrPut(bfa, name);
13098
13028
  if (gop.found_existing) {
13099
13029
  var e = gop.value_ptr;
13100
13030
  while (e.next) |n| e = n;
@@ -13121,7 +13051,7 @@ fn scanContainer(
13121
13051
  }
13122
13052
 
13123
13053
  {
13124
- const gop = try names.getOrPut(sfba, name_str_index);
13054
+ const gop = try names.getOrPut(bfa, name_str_index);
13125
13055
  const new_ent: NameEntry = .{
13126
13056
  .tok = name_token,
13127
13057
  .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
  .{
@@ -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,
package/std/zig/Zir.zig CHANGED
@@ -1016,9 +1016,6 @@ pub const Inst = struct {
1016
1016
  /// Implements the `@max` builtin for 2 args.
1017
1017
  /// Uses the `pl_node` union field with payload `Bin`
1018
1018
  max,
1019
- /// Implements the `@cImport` builtin.
1020
- /// Uses the `pl_node` union field with payload `Block`.
1021
- c_import,
1022
1019
 
1023
1020
  /// Allocates stack local memory.
1024
1021
  /// Uses the `un_node` union field. The operand is the type of the allocated object.
@@ -1297,7 +1294,6 @@ pub const Inst = struct {
1297
1294
  .memset,
1298
1295
  .memmove,
1299
1296
  .min,
1300
- .c_import,
1301
1297
  .@"resume",
1302
1298
  .ret_err_value_code,
1303
1299
  .extended,
@@ -1577,7 +1573,6 @@ pub const Inst = struct {
1577
1573
  .builtin_call,
1578
1574
  .max,
1579
1575
  .min,
1580
- .c_import,
1581
1576
  .@"resume",
1582
1577
  .ret_err_value_code,
1583
1578
  .@"break",
@@ -1857,7 +1852,6 @@ pub const Inst = struct {
1857
1852
  .memset = .pl_node,
1858
1853
  .memmove = .pl_node,
1859
1854
  .min = .pl_node,
1860
- .c_import = .pl_node,
1861
1855
 
1862
1856
  .alloc = .un_node,
1863
1857
  .alloc_mut = .un_node,
@@ -2018,12 +2012,6 @@ pub const Inst = struct {
2018
2012
  /// `small` is unused.
2019
2013
  round_op_ty,
2020
2014
  /// `operand` is payload index to `UnNode`.
2021
- c_undef,
2022
- /// `operand` is payload index to `UnNode`.
2023
- c_include,
2024
- /// `operand` is payload index to `BinNode`.
2025
- c_define,
2026
- /// `operand` is payload index to `UnNode`.
2027
2015
  wasm_memory_size,
2028
2016
  /// `operand` is payload index to `BinNode`.
2029
2017
  wasm_memory_grow,
@@ -4033,30 +4021,30 @@ pub const DeclContents = struct {
4033
4021
  /// This is a simple optional because ZIR guarantees that a `func`/`func_inferred`/`func_fancy` instruction
4034
4022
  /// can only occur once per `declaration`.
4035
4023
  func_decl: ?Inst.Index,
4036
- explicit_types: std.ArrayList(Inst.Index),
4024
+ type_decls: std.ArrayList(Inst.Index),
4037
4025
  other: std.ArrayList(Inst.Index),
4038
4026
 
4039
4027
  pub const init: DeclContents = .{
4040
4028
  .func_decl = null,
4041
- .explicit_types = .empty,
4029
+ .type_decls = .empty,
4042
4030
  .other = .empty,
4043
4031
  };
4044
4032
 
4045
4033
  pub fn clear(contents: *DeclContents) void {
4046
4034
  contents.func_decl = null;
4047
- contents.explicit_types.clearRetainingCapacity();
4035
+ contents.type_decls.clearRetainingCapacity();
4048
4036
  contents.other.clearRetainingCapacity();
4049
4037
  }
4050
4038
 
4051
4039
  pub fn deinit(contents: *DeclContents, gpa: Allocator) void {
4052
- contents.explicit_types.deinit(gpa);
4040
+ contents.type_decls.deinit(gpa);
4053
4041
  contents.other.deinit(gpa);
4054
4042
  }
4055
4043
  };
4056
4044
 
4057
4045
  /// Find all tracked ZIR instructions, recursively, within a `declaration` instruction. Does not recurse through
4058
4046
  /// nested declarations; to find all declarations, call this function recursively on the type declarations discovered
4059
- /// in `contents.explicit_types`.
4047
+ /// in `contents.type_decls`.
4060
4048
  ///
4061
4049
  /// This populates an `ArrayList` because an iterator would need to allocate memory anyway.
4062
4050
  pub fn findTrackable(zir: Zir, gpa: Allocator, contents: *DeclContents, decl_inst: Zir.Inst.Index) !void {
@@ -4076,15 +4064,49 @@ pub fn findTrackable(zir: Zir, gpa: Allocator, contents: *DeclContents, decl_ins
4076
4064
  if (decl.value_body) |b| try zir.findTrackableBody(gpa, contents, &found_defers, b);
4077
4065
  }
4078
4066
 
4079
- /// Like `findTrackable`, but only considers the `main_struct_inst` instruction. This may return more than
4080
- /// just that instruction because it will also traverse fields.
4081
- pub fn findTrackableRoot(zir: Zir, gpa: Allocator, contents: *DeclContents) !void {
4067
+ /// `findTrackable` does not recurse into field expressions in a type. Instead, this function will
4068
+ /// scan specifically field expressions in a given type declaration for trackable ZIR instructions.
4069
+ pub fn findTrackableFields(
4070
+ zir: *const Zir,
4071
+ gpa: Allocator,
4072
+ contents: *DeclContents,
4073
+ type_decl_inst: Zir.Inst.Index,
4074
+ ) Allocator.Error!void {
4082
4075
  contents.clear();
4083
4076
 
4084
4077
  var found_defers: std.AutoHashMapUnmanaged(u32, void) = .empty;
4085
4078
  defer found_defers.deinit(gpa);
4086
4079
 
4087
- try zir.findTrackableInner(gpa, contents, &found_defers, .main_struct_inst);
4080
+ assert(zir.instructions.items(.tag)[@intFromEnum(type_decl_inst)] == .extended);
4081
+ switch (zir.instructions.items(.data)[@intFromEnum(type_decl_inst)].extended.opcode) {
4082
+ .struct_decl => {
4083
+ const struct_decl = zir.getStructDecl(type_decl_inst);
4084
+ var it = struct_decl.iterateFields();
4085
+ while (it.next()) |field| {
4086
+ try zir.findTrackableBody(gpa, contents, &found_defers, field.type_body);
4087
+ if (field.align_body) |b| try zir.findTrackableBody(gpa, contents, &found_defers, b);
4088
+ if (field.default_body) |b| try zir.findTrackableBody(gpa, contents, &found_defers, b);
4089
+ }
4090
+ },
4091
+ .union_decl => {
4092
+ const union_decl = zir.getUnionDecl(type_decl_inst);
4093
+ var it = union_decl.iterateFields();
4094
+ while (it.next()) |field| {
4095
+ if (field.type_body) |b| try zir.findTrackableBody(gpa, contents, &found_defers, b);
4096
+ if (field.align_body) |b| try zir.findTrackableBody(gpa, contents, &found_defers, b);
4097
+ if (field.value_body) |b| try zir.findTrackableBody(gpa, contents, &found_defers, b);
4098
+ }
4099
+ },
4100
+ .enum_decl => {
4101
+ const enum_decl = zir.getEnumDecl(type_decl_inst);
4102
+ var it = enum_decl.iterateFields();
4103
+ while (it.next()) |field| {
4104
+ if (field.value_body) |b| try zir.findTrackableBody(gpa, contents, &found_defers, b);
4105
+ }
4106
+ },
4107
+ .opaque_decl => {},
4108
+ else => unreachable,
4109
+ }
4088
4110
  }
4089
4111
 
4090
4112
  fn findTrackableInner(
@@ -4360,9 +4382,6 @@ fn findTrackableInner(
4360
4382
  .mul_with_overflow,
4361
4383
  .shl_with_overflow,
4362
4384
  .round_op,
4363
- .c_undef,
4364
- .c_include,
4365
- .c_define,
4366
4385
  .wasm_memory_size,
4367
4386
  .wasm_memory_grow,
4368
4387
  .prefetch,
@@ -4411,49 +4430,18 @@ fn findTrackableInner(
4411
4430
  try zir.findTrackableBody(gpa, contents, defers, body);
4412
4431
  },
4413
4432
 
4414
- // Reifications and opaque declarations need tracking, but have no bodies.
4433
+ // Reifications need tracking.
4415
4434
  .reify_enum,
4416
4435
  .reify_struct,
4417
4436
  .reify_union,
4418
- .opaque_decl,
4419
4437
  => return contents.other.append(gpa, inst),
4420
4438
 
4421
- // Struct declarations need tracking and have bodies.
4422
- .struct_decl => {
4423
- try contents.explicit_types.append(gpa, inst);
4424
-
4425
- const struct_decl = zir.getStructDecl(inst);
4426
- var it = struct_decl.iterateFields();
4427
- while (it.next()) |field| {
4428
- try zir.findTrackableBody(gpa, contents, defers, field.type_body);
4429
- if (field.align_body) |b| try zir.findTrackableBody(gpa, contents, defers, b);
4430
- if (field.default_body) |b| try zir.findTrackableBody(gpa, contents, defers, b);
4431
- }
4432
- },
4433
-
4434
- // Union declarations need tracking and have bodies.
4435
- .union_decl => {
4436
- try contents.explicit_types.append(gpa, inst);
4437
-
4438
- const union_decl = zir.getUnionDecl(inst);
4439
- var it = union_decl.iterateFields();
4440
- while (it.next()) |field| {
4441
- if (field.type_body) |b| try zir.findTrackableBody(gpa, contents, defers, b);
4442
- if (field.align_body) |b| try zir.findTrackableBody(gpa, contents, defers, b);
4443
- if (field.value_body) |b| try zir.findTrackableBody(gpa, contents, defers, b);
4444
- }
4445
- },
4446
-
4447
- // Enum declarations need tracking and have bodies.
4448
- .enum_decl => {
4449
- try contents.explicit_types.append(gpa, inst);
4450
-
4451
- const enum_decl = zir.getEnumDecl(inst);
4452
- var it = enum_decl.iterateFields();
4453
- while (it.next()) |field| {
4454
- if (field.value_body) |b| try zir.findTrackableBody(gpa, contents, defers, b);
4455
- }
4456
- },
4439
+ // Type declarations need tracking.
4440
+ .struct_decl,
4441
+ .union_decl,
4442
+ .enum_decl,
4443
+ .opaque_decl,
4444
+ => return contents.type_decls.append(gpa, inst),
4457
4445
  }
4458
4446
  },
4459
4447
 
@@ -4532,7 +4520,6 @@ fn findTrackableInner(
4532
4520
 
4533
4521
  .block,
4534
4522
  .block_inline,
4535
- .c_import,
4536
4523
  .typeof_builtin,
4537
4524
  .loop,
4538
4525
  => {
@@ -427,10 +427,11 @@ fn expr(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) Allocator
427
427
  });
428
428
 
429
429
  // For short initializers, track the names on the stack rather than going through gpa.
430
- var sfba_state = std.heap.stackFallback(256, gpa);
431
- const sfba = sfba_state.get();
430
+ var bfa_buf: [256]u8 = undefined;
431
+ var bfa_state: std.heap.BufferFirstAllocator = .init(&bfa_buf, gpa);
432
+ const bfa = bfa_state.allocator();
432
433
  var field_names: std.AutoHashMapUnmanaged(Zoir.NullTerminatedString, Ast.TokenIndex) = .empty;
433
- defer field_names.deinit(sfba);
434
+ defer field_names.deinit(bfa);
434
435
 
435
436
  var reported_any_duplicate = false;
436
437
 
@@ -438,7 +439,7 @@ fn expr(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) Allocator
438
439
  const name_token = tree.firstToken(elem_node) - 2;
439
440
  if (zg.identAsString(name_token)) |name_str| {
440
441
  zg.extra.items[extra_name_idx] = @intFromEnum(name_str);
441
- const gop = try field_names.getOrPut(sfba, name_str);
442
+ const gop = try field_names.getOrPut(bfa, name_str);
442
443
  if (gop.found_existing and !reported_any_duplicate) {
443
444
  reported_any_duplicate = true;
444
445
  const earlier_token = gop.value_ptr.*;