authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-14 10:27:44-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-14 10:27:44-05:00
loga8b36fbe34e4acfea1fcb348fbed321b05611fd3
tree23f489f85c427a003577f5c40b74201ba8c85ddb
parentcdc5070f216a924d24588b8d0fe06400e036e6bf
parent40b9db7cad6f876bb3e8fa32d7b32bbd4bc983ea
signaturelock-open Commit is signed but in an unrecognized format.

Merge remote-tracking branch 'origin/master' into llvm10


68 files changed, 3303 insertions(+), 1752 deletions(-)

CMakeLists.txt+3-13
......@@ -5,18 +5,6 @@ if(NOT CMAKE_BUILD_TYPE)
55 "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE)
66endif()
77
8set(_list "None;Debug;Release;RelWithDebInfo;MinSizeRel")
9list(FIND _list ${CMAKE_BUILD_TYPE} _index)
10if(${_index} EQUAL -1)
11 string(REPLACE ";" ", " _list_pretty "${_list}")
12 message("::")
13 message(":: ERROR: Invalid build type: ${CMAKE_BUILD_TYPE}")
14 message("::")
15 message(":: valid types: { ${_list_pretty} }")
16 message("::")
17 message(FATAL_ERROR)
18endif()
19
208if(NOT CMAKE_INSTALL_PREFIX)
219 set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}" CACHE STRING
2210 "Directory to install zig to" FORCE)
......@@ -256,7 +244,7 @@ set(ZIG_MAIN_SRC "${CMAKE_SOURCE_DIR}/src/main.cpp")
256244set(ZIG0_SHIM_SRC "${CMAKE_SOURCE_DIR}/src/userland.cpp")
257245
258246if(ZIG_ENABLE_MEM_PROFILE)
259 set(ZIG_SOURCES_MEM_PROFILE "${CMAKE_SOURCE_DIR}/src/memory_profiling.cpp")
247 set(ZIG_SOURCES_MEM_PROFILE "${CMAKE_SOURCE_DIR}/src/mem_profile.cpp")
260248endif()
261249
262250set(ZIG_SOURCES
......@@ -272,10 +260,12 @@ set(ZIG_SOURCES
272260 "${CMAKE_SOURCE_DIR}/src/errmsg.cpp"
273261 "${CMAKE_SOURCE_DIR}/src/error.cpp"
274262 "${CMAKE_SOURCE_DIR}/src/glibc.cpp"
263 "${CMAKE_SOURCE_DIR}/src/heap.cpp"
275264 "${CMAKE_SOURCE_DIR}/src/ir.cpp"
276265 "${CMAKE_SOURCE_DIR}/src/ir_print.cpp"
277266 "${CMAKE_SOURCE_DIR}/src/libc_installation.cpp"
278267 "${CMAKE_SOURCE_DIR}/src/link.cpp"
268 "${CMAKE_SOURCE_DIR}/src/mem.cpp"
279269 "${CMAKE_SOURCE_DIR}/src/os.cpp"
280270 "${CMAKE_SOURCE_DIR}/src/parser.cpp"
281271 "${CMAKE_SOURCE_DIR}/src/range_set.cpp"
lib/std/array_list.zig+3-11
......@@ -244,10 +244,7 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type {
244244}
245245
246246test "std.ArrayList.init" {
247 var bytes: [1024]u8 = undefined;
248 const allocator = &std.heap.FixedBufferAllocator.init(bytes[0..]).allocator;
249
250 var list = ArrayList(i32).init(allocator);
247 var list = ArrayList(i32).init(testing.allocator);
251248 defer list.deinit();
252249
253250 testing.expect(list.len == 0);
......@@ -255,19 +252,14 @@ test "std.ArrayList.init" {
255252}
256253
257254test "std.ArrayList.initCapacity" {
258 var bytes: [1024]u8 = undefined;
259 const allocator = &std.heap.FixedBufferAllocator.init(bytes[0..]).allocator;
260 var list = try ArrayList(i8).initCapacity(allocator, 200);
255 var list = try ArrayList(i8).initCapacity(testing.allocator, 200);
261256 defer list.deinit();
262257 testing.expect(list.len == 0);
263258 testing.expect(list.capacity() >= 200);
264259}
265260
266261test "std.ArrayList.basic" {
267 var bytes: [1024]u8 = undefined;
268 const allocator = &std.heap.FixedBufferAllocator.init(bytes[0..]).allocator;
269
270 var list = ArrayList(i32).init(allocator);
262 var list = ArrayList(i32).init(testing.allocator);
271263 defer list.deinit();
272264
273265 // setting on empty list is out of bounds
lib/std/ascii.zig+2-3
......@@ -236,9 +236,8 @@ pub fn allocLowerString(allocator: *std.mem.Allocator, ascii_string: []const u8)
236236}
237237
238238test "allocLowerString" {
239 var buf: [100]u8 = undefined;
240 const allocator = &std.heap.FixedBufferAllocator.init(&buf).allocator;
241 const result = try allocLowerString(allocator, "aBcDeFgHiJkLmNOPqrst0234+💩!");
239 const result = try allocLowerString(std.testing.allocator, "aBcDeFgHiJkLmNOPqrst0234+💩!");
240 defer std.testing.allocator.free(result);
242241 std.testing.expect(std.mem.eql(u8, "abcdefghijklmnopqrst0234+💩!", result));
243242}
244243
lib/std/c/tokenizer.zig+13-3
......@@ -651,6 +651,7 @@ pub const Tokenizer = struct {
651651 state = .StringLiteral;
652652 },
653653 else => {
654 self.index -= 1;
654655 state = .Identifier;
655656 },
656657 },
......@@ -660,6 +661,7 @@ pub const Tokenizer = struct {
660661 state = .StringLiteral;
661662 },
662663 else => {
664 self.index -= 1;
663665 state = .Identifier;
664666 },
665667 },
......@@ -673,6 +675,7 @@ pub const Tokenizer = struct {
673675 state = .StringLiteral;
674676 },
675677 else => {
678 self.index -= 1;
676679 state = .Identifier;
677680 },
678681 },
......@@ -686,6 +689,7 @@ pub const Tokenizer = struct {
686689 state = .StringLiteral;
687690 },
688691 else => {
692 self.index -= 1;
689693 state = .Identifier;
690694 },
691695 },
......@@ -1079,6 +1083,9 @@ pub const Tokenizer = struct {
10791083 'x', 'X' => {
10801084 state = .IntegerLiteralHex;
10811085 },
1086 '.' => {
1087 state = .FloatFraction;
1088 },
10821089 else => {
10831090 state = .IntegerSuffix;
10841091 self.index -= 1;
......@@ -1261,13 +1268,16 @@ pub const Tokenizer = struct {
12611268 .UnicodeEscape,
12621269 .MultiLineComment,
12631270 .MultiLineCommentAsterisk,
1264 .FloatFraction,
1265 .FloatFractionHex,
12661271 .FloatExponent,
1267 .FloatExponentDigits,
12681272 .MacroString,
12691273 => result.id = .Invalid,
12701274
1275 .FloatExponentDigits => result.id = if (counter == 0) .Invalid else .{ .FloatLiteral = .None },
1276
1277 .FloatFraction,
1278 .FloatFractionHex,
1279 => result.id = .{ .FloatLiteral = .None },
1280
12711281 .IntegerLiteralOct,
12721282 .IntegerLiteralBinary,
12731283 .IntegerLiteralHex,
lib/std/cstr.zig+2-3
......@@ -41,9 +41,8 @@ pub fn addNullByte(allocator: *mem.Allocator, slice: []const u8) ![:0]u8 {
4141}
4242
4343test "addNullByte" {
44 var buf: [30]u8 = undefined;
45 const allocator = &std.heap.FixedBufferAllocator.init(&buf).allocator;
46 const slice = try addNullByte(allocator, "hello"[0..4]);
44 const slice = try addNullByte(std.testing.allocator, "hello"[0..4]);
45 defer std.testing.allocator.free(slice);
4746 testing.expect(slice.len == 4);
4847 testing.expect(slice[4] == 0);
4948}
lib/std/fmt.zig+50-6
......@@ -69,12 +69,12 @@ fn peekIsAlign(comptime fmt: []const u8) bool {
6969///
7070/// If a formatted user type contains a function of the type
7171/// ```
72/// fn format(value: ?, comptime fmt: []const u8, options: std.fmt.FormatOptions, context: var, comptime Errors: type, output: fn (@TypeOf(context), []const u8) Errors!void) Errors!void
72/// fn format(value: ?, comptime fmt: []const u8, options: std.fmt.FormatOptions, context: var, comptime Errors: type, comptime output: fn (@TypeOf(context), []const u8) Errors!void) Errors!void
7373/// ```
7474/// with `?` being the type formatted, this function will be called instead of the default implementation.
7575/// This allows user types to be formatted in a logical manner instead of dumping all fields of the type.
7676///
77/// A user type may be a `struct`, `union` or `enum` type.
77/// A user type may be a `struct`, `vector`, `union` or `enum` type.
7878pub fn format(
7979 context: var,
8080 comptime Errors: type,
......@@ -373,11 +373,11 @@ pub fn formatType(
373373 try output(context, @typeName(T));
374374 if (enumInfo.is_exhaustive) {
375375 try output(context, ".");
376 return formatType(@tagName(value), "", options, context, Errors, output, max_depth);
376 try output(context, @tagName(value));
377377 } else {
378378 // TODO: when @tagName works on exhaustive enums print known enum strings
379379 try output(context, "(");
380 try formatType(@enumToInt(value), "", options, context, Errors, output, max_depth);
380 try formatType(@enumToInt(value), fmt, options, context, Errors, output, max_depth);
381381 try output(context, ")");
382382 }
383383 },
......@@ -397,7 +397,7 @@ pub fn formatType(
397397 try output(context, " = ");
398398 inline for (info.fields) |u_field| {
399399 if (@enumToInt(@as(UnionTagType, value)) == u_field.enum_field.?.value) {
400 try formatType(@field(value, u_field.name), "", options, context, Errors, output, max_depth - 1);
400 try formatType(@field(value, u_field.name), fmt, options, context, Errors, output, max_depth - 1);
401401 }
402402 }
403403 try output(context, " }");
......@@ -424,7 +424,7 @@ pub fn formatType(
424424 }
425425 try output(context, @memberName(T, field_i));
426426 try output(context, " = ");
427 try formatType(@field(value, @memberName(T, field_i)), "", options, context, Errors, output, max_depth - 1);
427 try formatType(@field(value, @memberName(T, field_i)), fmt, options, context, Errors, output, max_depth - 1);
428428 }
429429 try output(context, " }");
430430 },
......@@ -474,6 +474,18 @@ pub fn formatType(
474474 });
475475 return formatType(@as(Slice, &value), fmt, options, context, Errors, output, max_depth);
476476 },
477 .Vector => {
478 const len = @typeInfo(T).Vector.len;
479 try output(context, "{ ");
480 var i: usize = 0;
481 while (i < len) : (i += 1) {
482 try formatValue(value[i], fmt, options, context, Errors, output);
483 if (i < len - 1) {
484 try output(context, ", ");
485 }
486 }
487 try output(context, " }");
488 },
477489 .Fn => {
478490 return format(context, Errors, output, "{}@{x}", .{ @typeName(T), @ptrToInt(value) });
479491 },
......@@ -500,6 +512,7 @@ fn formatValue(
500512 switch (@typeId(T)) {
501513 .Float => return formatFloatValue(value, fmt, options, context, Errors, output),
502514 .Int, .ComptimeInt => return formatIntValue(value, fmt, options, context, Errors, output),
515 .Bool => return output(context, if (value) "true" else "false"),
503516 else => comptime unreachable,
504517 }
505518}
......@@ -1343,6 +1356,20 @@ test "enum" {
13431356 try testFmt("enum: Enum.Two\n", "enum: {}\n", .{&value});
13441357}
13451358
1359test "non-exhaustive enum" {
1360 const Enum = enum(u16) {
1361 One = 0x000f,
1362 Two = 0xbeef,
1363 _,
1364 };
1365 try testFmt("enum: Enum(15)\n", "enum: {}\n", .{Enum.One});
1366 try testFmt("enum: Enum(48879)\n", "enum: {}\n", .{Enum.Two});
1367 try testFmt("enum: Enum(4660)\n", "enum: {}\n", .{@intToEnum(Enum, 0x1234)});
1368 try testFmt("enum: Enum(f)\n", "enum: {x}\n", .{Enum.One});
1369 try testFmt("enum: Enum(beef)\n", "enum: {x}\n", .{Enum.Two});
1370 try testFmt("enum: Enum(1234)\n", "enum: {x}\n", .{@intToEnum(Enum, 0x1234)});
1371}
1372
13461373test "float.scientific" {
13471374 try testFmt("f32: 1.34000003e+00", "f32: {e}", .{@as(f32, 1.34)});
13481375 try testFmt("f32: 1.23400001e+01", "f32: {e}", .{@as(f32, 12.34)});
......@@ -1699,3 +1726,20 @@ test "positional with specifier" {
16991726test "positional/alignment/width/precision" {
17001727 try testFmt("10.0", "{0d: >3.1}", .{@as(f64, 9.999)});
17011728}
1729
1730test "vector" {
1731 // https://github.com/ziglang/zig/issues/3317
1732 if (builtin.arch == .mipsel) return error.SkipZigTest;
1733
1734 const vbool: @Vector(4, bool) = [_]bool{ true, false, true, false };
1735 const vi64: @Vector(4, i64) = [_]i64{ -2, -1, 0, 1 };
1736 const vu64: @Vector(4, u64) = [_]u64{ 1000, 2000, 3000, 4000 };
1737
1738 try testFmt("{ true, false, true, false }", "{}", .{vbool});
1739 try testFmt("{ -2, -1, 0, 1 }", "{}", .{vi64});
1740 try testFmt("{ - 2, - 1, + 0, + 1 }", "{d:5}", .{vi64});
1741 try testFmt("{ 1000, 2000, 3000, 4000 }", "{}", .{vu64});
1742 try testFmt("{ 3e8, 7d0, bb8, fa0 }", "{x}", .{vu64});
1743 try testFmt("{ 1kB, 2kB, 3kB, 4kB }", "{B}", .{vu64});
1744 try testFmt("{ 1000B, 1.953125KiB, 2.9296875KiB, 3.90625KiB }", "{Bi}", .{vu64});
1745}
lib/std/fs/get_app_data_dir.zig+2-4
......@@ -56,9 +56,7 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD
5656}
5757
5858test "getAppDataDir" {
59 var buf: [512]u8 = undefined;
60 const allocator = &std.heap.FixedBufferAllocator.init(buf[0..]).allocator;
61
6259 // We can't actually validate the result
63 _ = getAppDataDir(allocator, "zig") catch return;
60 const dir = getAppDataDir(std.testing.allocator, "zig") catch return;
61 defer std.testing.allocator.free(dir);
6462}
lib/std/fs/path.zig+4-6
......@@ -89,16 +89,14 @@ pub fn joinPosix(allocator: *Allocator, paths: []const []const u8) ![]u8 {
8989}
9090
9191fn testJoinWindows(paths: []const []const u8, expected: []const u8) void {
92 var buf: [1024]u8 = undefined;
93 const a = &std.heap.FixedBufferAllocator.init(&buf).allocator;
94 const actual = joinWindows(a, paths) catch @panic("fail");
92 const actual = joinWindows(testing.allocator, paths) catch @panic("fail");
93 defer testing.allocator.free(actual);
9594 testing.expectEqualSlices(u8, expected, actual);
9695}
9796
9897fn testJoinPosix(paths: []const []const u8, expected: []const u8) void {
99 var buf: [1024]u8 = undefined;
100 const a = &std.heap.FixedBufferAllocator.init(&buf).allocator;
101 const actual = joinPosix(a, paths) catch @panic("fail");
98 const actual = joinPosix(testing.allocator, paths) catch @panic("fail");
99 defer testing.allocator.free(actual);
102100 testing.expectEqualSlices(u8, expected, actual);
103101}
104102
lib/std/heap.zig+1-1
......@@ -533,7 +533,7 @@ pub const ArenaAllocator = struct {
533533 };
534534 }
535535
536 pub fn deinit(self: *ArenaAllocator) void {
536 pub fn deinit(self: ArenaAllocator) void {
537537 var it = self.buffer_list.first;
538538 while (it) |node| {
539539 // this has to occur before the free because the free frees node
lib/std/http/headers.zig+22-26
......@@ -83,12 +83,8 @@ const HeaderEntry = struct {
8383 }
8484};
8585
86var test_memory: [32 * 1024]u8 = undefined;
87var test_fba_state = std.heap.FixedBufferAllocator.init(&test_memory);
88const test_allocator = &test_fba_state.allocator;
89
9086test "HeaderEntry" {
91 var e = try HeaderEntry.init(test_allocator, "foo", "bar", null);
87 var e = try HeaderEntry.init(testing.allocator, "foo", "bar", null);
9288 defer e.deinit();
9389 testing.expectEqualSlices(u8, "foo", e.name);
9490 testing.expectEqualSlices(u8, "bar", e.value);
......@@ -368,7 +364,7 @@ pub const Headers = struct {
368364};
369365
370366test "Headers.iterator" {
371 var h = Headers.init(test_allocator);
367 var h = Headers.init(testing.allocator);
372368 defer h.deinit();
373369 try h.append("foo", "bar", null);
374370 try h.append("cookie", "somevalue", null);
......@@ -390,7 +386,7 @@ test "Headers.iterator" {
390386}
391387
392388test "Headers.contains" {
393 var h = Headers.init(test_allocator);
389 var h = Headers.init(testing.allocator);
394390 defer h.deinit();
395391 try h.append("foo", "bar", null);
396392 try h.append("cookie", "somevalue", null);
......@@ -400,7 +396,7 @@ test "Headers.contains" {
400396}
401397
402398test "Headers.delete" {
403 var h = Headers.init(test_allocator);
399 var h = Headers.init(testing.allocator);
404400 defer h.deinit();
405401 try h.append("foo", "bar", null);
406402 try h.append("baz", "qux", null);
......@@ -428,7 +424,7 @@ test "Headers.delete" {
428424}
429425
430426test "Headers.orderedRemove" {
431 var h = Headers.init(test_allocator);
427 var h = Headers.init(testing.allocator);
432428 defer h.deinit();
433429 try h.append("foo", "bar", null);
434430 try h.append("baz", "qux", null);
......@@ -451,7 +447,7 @@ test "Headers.orderedRemove" {
451447}
452448
453449test "Headers.swapRemove" {
454 var h = Headers.init(test_allocator);
450 var h = Headers.init(testing.allocator);
455451 defer h.deinit();
456452 try h.append("foo", "bar", null);
457453 try h.append("baz", "qux", null);
......@@ -474,7 +470,7 @@ test "Headers.swapRemove" {
474470}
475471
476472test "Headers.at" {
477 var h = Headers.init(test_allocator);
473 var h = Headers.init(testing.allocator);
478474 defer h.deinit();
479475 try h.append("foo", "bar", null);
480476 try h.append("cookie", "somevalue", null);
......@@ -494,7 +490,7 @@ test "Headers.at" {
494490}
495491
496492test "Headers.getIndices" {
497 var h = Headers.init(test_allocator);
493 var h = Headers.init(testing.allocator);
498494 defer h.deinit();
499495 try h.append("foo", "bar", null);
500496 try h.append("set-cookie", "x=1", null);
......@@ -506,27 +502,27 @@ test "Headers.getIndices" {
506502}
507503
508504test "Headers.get" {
509 var h = Headers.init(test_allocator);
505 var h = Headers.init(testing.allocator);
510506 defer h.deinit();
511507 try h.append("foo", "bar", null);
512508 try h.append("set-cookie", "x=1", null);
513509 try h.append("set-cookie", "y=2", null);
514510
515511 {
516 const v = try h.get(test_allocator, "not-present");
512 const v = try h.get(testing.allocator, "not-present");
517513 testing.expect(null == v);
518514 }
519515 {
520 const v = (try h.get(test_allocator, "foo")).?;
521 defer test_allocator.free(v);
516 const v = (try h.get(testing.allocator, "foo")).?;
517 defer testing.allocator.free(v);
522518 const e = v[0];
523519 testing.expectEqualSlices(u8, "foo", e.name);
524520 testing.expectEqualSlices(u8, "bar", e.value);
525521 testing.expectEqual(false, e.never_index);
526522 }
527523 {
528 const v = (try h.get(test_allocator, "set-cookie")).?;
529 defer test_allocator.free(v);
524 const v = (try h.get(testing.allocator, "set-cookie")).?;
525 defer testing.allocator.free(v);
530526 {
531527 const e = v[0];
532528 testing.expectEqualSlices(u8, "set-cookie", e.name);
......@@ -543,30 +539,30 @@ test "Headers.get" {
543539}
544540
545541test "Headers.getCommaSeparated" {
546 var h = Headers.init(test_allocator);
542 var h = Headers.init(testing.allocator);
547543 defer h.deinit();
548544 try h.append("foo", "bar", null);
549545 try h.append("set-cookie", "x=1", null);
550546 try h.append("set-cookie", "y=2", null);
551547
552548 {
553 const v = try h.getCommaSeparated(test_allocator, "not-present");
549 const v = try h.getCommaSeparated(testing.allocator, "not-present");
554550 testing.expect(null == v);
555551 }
556552 {
557 const v = (try h.getCommaSeparated(test_allocator, "foo")).?;
558 defer test_allocator.free(v);
553 const v = (try h.getCommaSeparated(testing.allocator, "foo")).?;
554 defer testing.allocator.free(v);
559555 testing.expectEqualSlices(u8, "bar", v);
560556 }
561557 {
562 const v = (try h.getCommaSeparated(test_allocator, "set-cookie")).?;
563 defer test_allocator.free(v);
558 const v = (try h.getCommaSeparated(testing.allocator, "set-cookie")).?;
559 defer testing.allocator.free(v);
564560 testing.expectEqualSlices(u8, "x=1,y=2", v);
565561 }
566562}
567563
568564test "Headers.sort" {
569 var h = Headers.init(test_allocator);
565 var h = Headers.init(testing.allocator);
570566 defer h.deinit();
571567 try h.append("foo", "bar", null);
572568 try h.append("cookie", "somevalue", null);
......@@ -587,7 +583,7 @@ test "Headers.sort" {
587583}
588584
589585test "Headers.format" {
590 var h = Headers.init(test_allocator);
586 var h = Headers.init(testing.allocator);
591587 defer h.deinit();
592588 try h.append("foo", "bar", null);
593589 try h.append("cookie", "somevalue", null);
lib/std/io.zig+4-8
......@@ -223,15 +223,13 @@ test "io.BufferedInStream" {
223223 }
224224 };
225225
226 var buf: [100]u8 = undefined;
227 const allocator = &std.heap.FixedBufferAllocator.init(buf[0..]).allocator;
228
229226 const str = "This is a test";
230227 var one_byte_stream = OneByteReadInStream.init(str);
231228 var buf_in_stream = BufferedInStream(OneByteReadInStream.Error).init(&one_byte_stream.stream);
232229 const stream = &buf_in_stream.stream;
233230
234 const res = try stream.readAllAlloc(allocator, str.len + 1);
231 const res = try stream.readAllAlloc(testing.allocator, str.len + 1);
232 defer testing.allocator.free(res);
235233 testing.expectEqualSlices(u8, str, res);
236234}
237235
......@@ -874,10 +872,8 @@ pub fn readLineFrom(stream: var, buf: *std.Buffer) ![]u8 {
874872}
875873
876874test "io.readLineFrom" {
877 var bytes: [128]u8 = undefined;
878 const allocator = &std.heap.FixedBufferAllocator.init(bytes[0..]).allocator;
879
880 var buf = try std.Buffer.initSize(allocator, 0);
875 var buf = try std.Buffer.initSize(testing.allocator, 0);
876 defer buf.deinit();
881877 var mem_stream = SliceInStream.init(
882878 \\Line 1
883879 \\Line 22
lib/std/io/test.zig+4-9
......@@ -11,9 +11,6 @@ const fs = std.fs;
1111const File = std.fs.File;
1212
1313test "write a file, read it, then delete it" {
14 var raw_bytes: [200 * 1024]u8 = undefined;
15 var allocator = &std.heap.FixedBufferAllocator.init(raw_bytes[0..]).allocator;
16
1714 const cwd = fs.cwd();
1815
1916 var data: [1024]u8 = undefined;
......@@ -53,8 +50,8 @@ test "write a file, read it, then delete it" {
5350 var file_in_stream = file.inStream();
5451 var buf_stream = io.BufferedInStream(File.ReadError).init(&file_in_stream.stream);
5552 const st = &buf_stream.stream;
56 const contents = try st.readAllAlloc(allocator, 2 * 1024);
57 defer allocator.free(contents);
53 const contents = try st.readAllAlloc(std.testing.allocator, 2 * 1024);
54 defer std.testing.allocator.free(contents);
5855
5956 expect(mem.eql(u8, contents[0.."begin".len], "begin"));
6057 expect(mem.eql(u8, contents["begin".len .. contents.len - "end".len], &data));
......@@ -64,10 +61,8 @@ test "write a file, read it, then delete it" {
6461}
6562
6663test "BufferOutStream" {
67 var bytes: [100]u8 = undefined;
68 var allocator = &std.heap.FixedBufferAllocator.init(bytes[0..]).allocator;
69
70 var buffer = try std.Buffer.initSize(allocator, 0);
64 var buffer = try std.Buffer.initSize(std.testing.allocator, 0);
65 defer buffer.deinit();
7166 var buf_stream = &std.io.BufferOutStream.init(&buffer).stream;
7267
7368 const x: i32 = 42;
lib/std/json.zig+20-22
......@@ -1495,10 +1495,7 @@ fn unescapeString(output: []u8, input: []const u8) !void {
14951495}
14961496
14971497test "json.parser.dynamic" {
1498 var memory: [1024 * 16]u8 = undefined;
1499 var buf_alloc = std.heap.FixedBufferAllocator.init(&memory);
1500
1501 var p = Parser.init(&buf_alloc.allocator, false);
1498 var p = Parser.init(testing.allocator, false);
15021499 defer p.deinit();
15031500
15041501 const s =
......@@ -1588,10 +1585,10 @@ test "write json then parse it" {
15881585
15891586 try jw.endObject();
15901587
1591 var mem_buffer: [1024 * 20]u8 = undefined;
1592 const allocator = &std.heap.FixedBufferAllocator.init(&mem_buffer).allocator;
1593 var parser = Parser.init(allocator, false);
1594 const tree = try parser.parse(slice_out_stream.getWritten());
1588 var parser = Parser.init(testing.allocator, false);
1589 defer parser.deinit();
1590 var tree = try parser.parse(slice_out_stream.getWritten());
1591 defer tree.deinit();
15951592
15961593 testing.expect(tree.root.Object.get("f").?.value.Bool == false);
15971594 testing.expect(tree.root.Object.get("t").?.value.Bool == true);
......@@ -1601,21 +1598,21 @@ test "write json then parse it" {
16011598 testing.expect(mem.eql(u8, tree.root.Object.get("str").?.value.String, "hello"));
16021599}
16031600
1604fn test_parse(memory: []u8, json_str: []const u8) !Value {
1605 // buf_alloc goes out of scope, but we don't use it after parsing
1606 var buf_alloc = std.heap.FixedBufferAllocator.init(memory);
1607 var p = Parser.init(&buf_alloc.allocator, false);
1601fn test_parse(arena_allocator: *std.mem.Allocator, json_str: []const u8) !Value {
1602 var p = Parser.init(arena_allocator, false);
16081603 return (try p.parse(json_str)).root;
16091604}
16101605
16111606test "parsing empty string gives appropriate error" {
1612 var memory: [1024 * 4]u8 = undefined;
1613 testing.expectError(error.UnexpectedEndOfJson, test_parse(&memory, ""));
1607 var arena_allocator = std.heap.ArenaAllocator.init(std.testing.allocator);
1608 defer arena_allocator.deinit();
1609 testing.expectError(error.UnexpectedEndOfJson, test_parse(&arena_allocator.allocator, ""));
16141610}
16151611
16161612test "integer after float has proper type" {
1617 var memory: [1024 * 8]u8 = undefined;
1618 const json = try test_parse(&memory,
1613 var arena_allocator = std.heap.ArenaAllocator.init(std.testing.allocator);
1614 defer arena_allocator.deinit();
1615 const json = try test_parse(&arena_allocator.allocator,
16191616 \\{
16201617 \\ "float": 3.14,
16211618 \\ "ints": [1, 2, 3]
......@@ -1625,7 +1622,8 @@ test "integer after float has proper type" {
16251622}
16261623
16271624test "escaped characters" {
1628 var memory: [1024 * 16]u8 = undefined;
1625 var arena_allocator = std.heap.ArenaAllocator.init(std.testing.allocator);
1626 defer arena_allocator.deinit();
16291627 const input =
16301628 \\{
16311629 \\ "backslash": "\\",
......@@ -1641,7 +1639,7 @@ test "escaped characters" {
16411639 \\}
16421640 ;
16431641
1644 const obj = (try test_parse(&memory, input)).Object;
1642 const obj = (try test_parse(&arena_allocator.allocator, input)).Object;
16451643
16461644 testing.expectEqualSlices(u8, obj.get("backslash").?.value.String, "\\");
16471645 testing.expectEqualSlices(u8, obj.get("forwardslash").?.value.String, "/");
......@@ -1665,13 +1663,13 @@ test "string copy option" {
16651663 \\}
16661664 ;
16671665
1668 var mem_buffer: [1024 * 16]u8 = undefined;
1669 var buf_alloc = std.heap.FixedBufferAllocator.init(&mem_buffer);
1666 var arena_allocator = std.heap.ArenaAllocator.init(std.testing.allocator);
1667 defer arena_allocator.deinit();
16701668
1671 const tree_nocopy = try Parser.init(&buf_alloc.allocator, false).parse(input);
1669 const tree_nocopy = try Parser.init(&arena_allocator.allocator, false).parse(input);
16721670 const obj_nocopy = tree_nocopy.root.Object;
16731671
1674 const tree_copy = try Parser.init(&buf_alloc.allocator, true).parse(input);
1672 const tree_copy = try Parser.init(&arena_allocator.allocator, true).parse(input);
16751673 const obj_copy = tree_copy.root.Object;
16761674
16771675 for ([_][]const u8{ "noescape", "simple", "unicode", "surrogatepair" }) |field_name| {
lib/std/json/test.zig+14-17
......@@ -8,19 +8,18 @@ const std = @import("../std.zig");
88fn ok(comptime s: []const u8) void {
99 std.testing.expect(std.json.validate(s));
1010
11 var mem_buffer: [1024 * 20]u8 = undefined;
12 const allocator = &std.heap.FixedBufferAllocator.init(&mem_buffer).allocator;
13 var p = std.json.Parser.init(allocator, false);
11 var p = std.json.Parser.init(std.testing.allocator, false);
12 defer p.deinit();
1413
15 _ = p.parse(s) catch unreachable;
14 var tree = p.parse(s) catch unreachable;
15 defer tree.deinit();
1616}
1717
1818fn err(comptime s: []const u8) void {
1919 std.testing.expect(!std.json.validate(s));
2020
21 var mem_buffer: [1024 * 20]u8 = undefined;
22 const allocator = &std.heap.FixedBufferAllocator.init(&mem_buffer).allocator;
23 var p = std.json.Parser.init(allocator, false);
21 var p = std.json.Parser.init(std.testing.allocator, false);
22 defer p.deinit();
2423
2524 if (p.parse(s)) |_| {
2625 unreachable;
......@@ -30,9 +29,8 @@ fn err(comptime s: []const u8) void {
3029fn utf8Error(comptime s: []const u8) void {
3130 std.testing.expect(!std.json.validate(s));
3231
33 var mem_buffer: [1024 * 20]u8 = undefined;
34 const allocator = &std.heap.FixedBufferAllocator.init(&mem_buffer).allocator;
35 var p = std.json.Parser.init(allocator, false);
32 var p = std.json.Parser.init(std.testing.allocator, false);
33 defer p.deinit();
3634
3735 if (p.parse(s)) |_| {
3836 unreachable;
......@@ -44,19 +42,18 @@ fn utf8Error(comptime s: []const u8) void {
4442fn any(comptime s: []const u8) void {
4543 _ = std.json.validate(s);
4644
47 var mem_buffer: [1024 * 20]u8 = undefined;
48 const allocator = &std.heap.FixedBufferAllocator.init(&mem_buffer).allocator;
49 var p = std.json.Parser.init(allocator, false);
45 var p = std.json.Parser.init(std.testing.allocator, false);
46 defer p.deinit();
5047
51 _ = p.parse(s) catch {};
48 var tree = p.parse(s) catch return;
49 defer tree.deinit();
5250}
5351
5452fn anyStreamingErrNonStreaming(comptime s: []const u8) void {
5553 _ = std.json.validate(s);
5654
57 var mem_buffer: [1024 * 20]u8 = undefined;
58 const allocator = &std.heap.FixedBufferAllocator.init(&mem_buffer).allocator;
59 var p = std.json.Parser.init(allocator, false);
55 var p = std.json.Parser.init(std.testing.allocator, false);
56 defer p.deinit();
6057
6158 if (p.parse(s)) |_| {
6259 unreachable;
lib/std/json/write_stream.zig+3-3
......@@ -254,11 +254,11 @@ test "json write stream" {
254254 var slice_stream = std.io.SliceOutStream.init(&out_buf);
255255 const out = &slice_stream.stream;
256256
257 var mem_buf: [1024 * 10]u8 = undefined;
258 const allocator = &std.heap.FixedBufferAllocator.init(&mem_buf).allocator;
257 var arena_allocator = std.heap.ArenaAllocator.init(std.testing.allocator);
258 defer arena_allocator.deinit();
259259
260260 var w = std.json.WriteStream(@TypeOf(out).Child, 10).init(out);
261 try w.emitJson(try getJson(allocator));
261 try w.emitJson(try getJson(&arena_allocator.allocator));
262262
263263 const result = slice_stream.getWritten();
264264 const expected =
lib/std/math/big/int.zig+503-262
......@@ -137,10 +137,9 @@ pub const Int = struct {
137137 }
138138
139139 /// Frees all memory associated with an Int.
140 pub fn deinit(self: *Int) void {
140 pub fn deinit(self: Int) void {
141141 self.assertWritable();
142142 self.allocator.?.free(self.limbs);
143 self.* = undefined;
144143 }
145144
146145 /// Clones an Int and returns a new Int with the same value. The new Int is a deep copy and
......@@ -1361,13 +1360,10 @@ pub const Int = struct {
13611360// They will still run on larger than this and should pass, but the multi-limb code-paths
13621361// may be untested in some cases.
13631362
1364var buffer: [64 * 8192]u8 = undefined;
1365var fixed = std.heap.FixedBufferAllocator.init(buffer[0..]);
1366const al = &fixed.allocator;
1367
13681363test "big.int comptime_int set" {
13691364 comptime var s = 0xefffffff00000001eeeeeeefaaaaaaab;
1370 var a = try Int.initSet(al, s);
1365 var a = try Int.initSet(testing.allocator, s);
1366 defer a.deinit();
13711367
13721368 const s_limb_count = 128 / Limb.bit_count;
13731369
......@@ -1381,39 +1377,45 @@ test "big.int comptime_int set" {
13811377}
13821378
13831379test "big.int comptime_int set negative" {
1384 var a = try Int.initSet(al, -10);
1380 var a = try Int.initSet(testing.allocator, -10);
1381 defer a.deinit();
13851382
13861383 testing.expect(a.limbs[0] == 10);
13871384 testing.expect(a.isPositive() == false);
13881385}
13891386
13901387test "big.int int set unaligned small" {
1391 var a = try Int.initSet(al, @as(u7, 45));
1388 var a = try Int.initSet(testing.allocator, @as(u7, 45));
1389 defer a.deinit();
13921390
13931391 testing.expect(a.limbs[0] == 45);
13941392 testing.expect(a.isPositive() == true);
13951393}
13961394
13971395test "big.int comptime_int to" {
1398 const a = try Int.initSet(al, 0xefffffff00000001eeeeeeefaaaaaaab);
1396 const a = try Int.initSet(testing.allocator, 0xefffffff00000001eeeeeeefaaaaaaab);
1397 defer a.deinit();
13991398
14001399 testing.expect((try a.to(u128)) == 0xefffffff00000001eeeeeeefaaaaaaab);
14011400}
14021401
14031402test "big.int sub-limb to" {
1404 const a = try Int.initSet(al, 10);
1403 const a = try Int.initSet(testing.allocator, 10);
1404 defer a.deinit();
14051405
14061406 testing.expect((try a.to(u8)) == 10);
14071407}
14081408
14091409test "big.int to target too small error" {
1410 const a = try Int.initSet(al, 0xffffffff);
1410 const a = try Int.initSet(testing.allocator, 0xffffffff);
1411 defer a.deinit();
14111412
14121413 testing.expectError(error.TargetTooSmall, a.to(u8));
14131414}
14141415
14151416test "big.int normalize" {
1416 var a = try Int.init(al);
1417 var a = try Int.init(testing.allocator);
1418 defer a.deinit();
14171419 try a.ensureCapacity(8);
14181420
14191421 a.limbs[0] = 1;
......@@ -1440,7 +1442,8 @@ test "big.int normalize" {
14401442}
14411443
14421444test "big.int normalize multi" {
1443 var a = try Int.init(al);
1445 var a = try Int.init(testing.allocator);
1446 defer a.deinit();
14441447 try a.ensureCapacity(8);
14451448
14461449 a.limbs[0] = 1;
......@@ -1469,7 +1472,9 @@ test "big.int normalize multi" {
14691472}
14701473
14711474test "big.int parity" {
1472 var a = try Int.init(al);
1475 var a = try Int.init(testing.allocator);
1476 defer a.deinit();
1477
14731478 try a.set(0);
14741479 testing.expect(a.isEven());
14751480 testing.expect(!a.isOdd());
......@@ -1480,7 +1485,8 @@ test "big.int parity" {
14801485}
14811486
14821487test "big.int bitcount + sizeInBase" {
1483 var a = try Int.init(al);
1488 var a = try Int.init(testing.allocator);
1489 defer a.deinit();
14841490
14851491 try a.set(0b100);
14861492 testing.expect(a.bitCountAbs() == 3);
......@@ -1507,7 +1513,8 @@ test "big.int bitcount + sizeInBase" {
15071513}
15081514
15091515test "big.int bitcount/to" {
1510 var a = try Int.init(al);
1516 var a = try Int.init(testing.allocator);
1517 defer a.deinit();
15111518
15121519 try a.set(0);
15131520 testing.expect(a.bitCountTwosComp() == 0);
......@@ -1537,7 +1544,8 @@ test "big.int bitcount/to" {
15371544}
15381545
15391546test "big.int fits" {
1540 var a = try Int.init(al);
1547 var a = try Int.init(testing.allocator);
1548 defer a.deinit();
15411549
15421550 try a.set(0);
15431551 testing.expect(a.fits(u0));
......@@ -1564,82 +1572,100 @@ test "big.int fits" {
15641572}
15651573
15661574test "big.int string set" {
1567 var a = try Int.init(al);
1568 try a.setString(10, "120317241209124781241290847124");
1575 var a = try Int.init(testing.allocator);
1576 defer a.deinit();
15691577
1578 try a.setString(10, "120317241209124781241290847124");
15701579 testing.expect((try a.to(u128)) == 120317241209124781241290847124);
15711580}
15721581
15731582test "big.int string negative" {
1574 var a = try Int.init(al);
1583 var a = try Int.init(testing.allocator);
1584 defer a.deinit();
1585
15751586 try a.setString(10, "-1023");
15761587 testing.expect((try a.to(i32)) == -1023);
15771588}
15781589
15791590test "big.int string set bad char error" {
1580 var a = try Int.init(al);
1591 var a = try Int.init(testing.allocator);
1592 defer a.deinit();
15811593 testing.expectError(error.InvalidCharForDigit, a.setString(10, "x"));
15821594}
15831595
15841596test "big.int string set bad base error" {
1585 var a = try Int.init(al);
1597 var a = try Int.init(testing.allocator);
1598 defer a.deinit();
15861599 testing.expectError(error.InvalidBase, a.setString(45, "10"));
15871600}
15881601
15891602test "big.int string to" {
1590 const a = try Int.initSet(al, 120317241209124781241290847124);
1603 const a = try Int.initSet(testing.allocator, 120317241209124781241290847124);
1604 defer a.deinit();
15911605
1592 const as = try a.toString(al, 10);
1606 const as = try a.toString(testing.allocator, 10);
1607 defer testing.allocator.free(as);
15931608 const es = "120317241209124781241290847124";
15941609
15951610 testing.expect(mem.eql(u8, as, es));
15961611}
15971612
15981613test "big.int string to base base error" {
1599 const a = try Int.initSet(al, 0xffffffff);
1614 const a = try Int.initSet(testing.allocator, 0xffffffff);
1615 defer a.deinit();
16001616
1601 testing.expectError(error.InvalidBase, a.toString(al, 45));
1617 testing.expectError(error.InvalidBase, a.toString(testing.allocator, 45));
16021618}
16031619
16041620test "big.int string to base 2" {
1605 const a = try Int.initSet(al, -0b1011);
1621 const a = try Int.initSet(testing.allocator, -0b1011);
1622 defer a.deinit();
16061623
1607 const as = try a.toString(al, 2);
1624 const as = try a.toString(testing.allocator, 2);
1625 defer testing.allocator.free(as);
16081626 const es = "-1011";
16091627
16101628 testing.expect(mem.eql(u8, as, es));
16111629}
16121630
16131631test "big.int string to base 16" {
1614 const a = try Int.initSet(al, 0xefffffff00000001eeeeeeefaaaaaaab);
1632 const a = try Int.initSet(testing.allocator, 0xefffffff00000001eeeeeeefaaaaaaab);
1633 defer a.deinit();
16151634
1616 const as = try a.toString(al, 16);
1635 const as = try a.toString(testing.allocator, 16);
1636 defer testing.allocator.free(as);
16171637 const es = "efffffff00000001eeeeeeefaaaaaaab";
16181638
16191639 testing.expect(mem.eql(u8, as, es));
16201640}
16211641
16221642test "big.int neg string to" {
1623 const a = try Int.initSet(al, -123907434);
1643 const a = try Int.initSet(testing.allocator, -123907434);
1644 defer a.deinit();
16241645
1625 const as = try a.toString(al, 10);
1646 const as = try a.toString(testing.allocator, 10);
1647 defer testing.allocator.free(as);
16261648 const es = "-123907434";
16271649
16281650 testing.expect(mem.eql(u8, as, es));
16291651}
16301652
16311653test "big.int zero string to" {
1632 const a = try Int.initSet(al, 0);
1654 const a = try Int.initSet(testing.allocator, 0);
1655 defer a.deinit();
16331656
1634 const as = try a.toString(al, 10);
1657 const as = try a.toString(testing.allocator, 10);
1658 defer testing.allocator.free(as);
16351659 const es = "0";
16361660
16371661 testing.expect(mem.eql(u8, as, es));
16381662}
16391663
16401664test "big.int clone" {
1641 var a = try Int.initSet(al, 1234);
1665 var a = try Int.initSet(testing.allocator, 1234);
1666 defer a.deinit();
16421667 const b = try a.clone();
1668 defer b.deinit();
16431669
16441670 testing.expect((try a.to(u32)) == 1234);
16451671 testing.expect((try b.to(u32)) == 1234);
......@@ -1650,8 +1676,10 @@ test "big.int clone" {
16501676}
16511677
16521678test "big.int swap" {
1653 var a = try Int.initSet(al, 1234);
1654 var b = try Int.initSet(al, 5678);
1679 var a = try Int.initSet(testing.allocator, 1234);
1680 defer a.deinit();
1681 var b = try Int.initSet(testing.allocator, 5678);
1682 defer b.deinit();
16551683
16561684 testing.expect((try a.to(u32)) == 1234);
16571685 testing.expect((try b.to(u32)) == 5678);
......@@ -1663,53 +1691,65 @@ test "big.int swap" {
16631691}
16641692
16651693test "big.int to negative" {
1666 var a = try Int.initSet(al, -10);
1694 var a = try Int.initSet(testing.allocator, -10);
1695 defer a.deinit();
16671696
16681697 testing.expect((try a.to(i32)) == -10);
16691698}
16701699
16711700test "big.int compare" {
1672 var a = try Int.initSet(al, -11);
1673 var b = try Int.initSet(al, 10);
1701 var a = try Int.initSet(testing.allocator, -11);
1702 defer a.deinit();
1703 var b = try Int.initSet(testing.allocator, 10);
1704 defer b.deinit();
16741705
16751706 testing.expect(a.cmpAbs(b) == 1);
16761707 testing.expect(a.cmp(b) == -1);
16771708}
16781709
16791710test "big.int compare similar" {
1680 var a = try Int.initSet(al, 0xffffffffeeeeeeeeffffffffeeeeeeee);
1681 var b = try Int.initSet(al, 0xffffffffeeeeeeeeffffffffeeeeeeef);
1711 var a = try Int.initSet(testing.allocator, 0xffffffffeeeeeeeeffffffffeeeeeeee);
1712 defer a.deinit();
1713 var b = try Int.initSet(testing.allocator, 0xffffffffeeeeeeeeffffffffeeeeeeef);
1714 defer b.deinit();
16821715
16831716 testing.expect(a.cmpAbs(b) == -1);
16841717 testing.expect(b.cmpAbs(a) == 1);
16851718}
16861719
16871720test "big.int compare different limb size" {
1688 var a = try Int.initSet(al, maxInt(Limb) + 1);
1689 var b = try Int.initSet(al, 1);
1721 var a = try Int.initSet(testing.allocator, maxInt(Limb) + 1);
1722 defer a.deinit();
1723 var b = try Int.initSet(testing.allocator, 1);
1724 defer b.deinit();
16901725
16911726 testing.expect(a.cmpAbs(b) == 1);
16921727 testing.expect(b.cmpAbs(a) == -1);
16931728}
16941729
16951730test "big.int compare multi-limb" {
1696 var a = try Int.initSet(al, -0x7777777799999999ffffeeeeffffeeeeffffeeeef);
1697 var b = try Int.initSet(al, 0x7777777799999999ffffeeeeffffeeeeffffeeeee);
1731 var a = try Int.initSet(testing.allocator, -0x7777777799999999ffffeeeeffffeeeeffffeeeef);
1732 defer a.deinit();
1733 var b = try Int.initSet(testing.allocator, 0x7777777799999999ffffeeeeffffeeeeffffeeeee);
1734 defer b.deinit();
16981735
16991736 testing.expect(a.cmpAbs(b) == 1);
17001737 testing.expect(a.cmp(b) == -1);
17011738}
17021739
17031740test "big.int equality" {
1704 var a = try Int.initSet(al, 0xffffffff1);
1705 var b = try Int.initSet(al, -0xffffffff1);
1741 var a = try Int.initSet(testing.allocator, 0xffffffff1);
1742 defer a.deinit();
1743 var b = try Int.initSet(testing.allocator, -0xffffffff1);
1744 defer b.deinit();
17061745
17071746 testing.expect(a.eqAbs(b));
17081747 testing.expect(!a.eq(b));
17091748}
17101749
17111750test "big.int abs" {
1712 var a = try Int.initSet(al, -5);
1751 var a = try Int.initSet(testing.allocator, -5);
1752 defer a.deinit();
17131753
17141754 a.abs();
17151755 testing.expect((try a.to(u32)) == 5);
......@@ -1719,7 +1759,8 @@ test "big.int abs" {
17191759}
17201760
17211761test "big.int negate" {
1722 var a = try Int.initSet(al, 5);
1762 var a = try Int.initSet(testing.allocator, 5);
1763 defer a.deinit();
17231764
17241765 a.negate();
17251766 testing.expect((try a.to(i32)) == -5);
......@@ -1729,20 +1770,26 @@ test "big.int negate" {
17291770}
17301771
17311772test "big.int add single-single" {
1732 var a = try Int.initSet(al, 50);
1733 var b = try Int.initSet(al, 5);
1773 var a = try Int.initSet(testing.allocator, 50);
1774 defer a.deinit();
1775 var b = try Int.initSet(testing.allocator, 5);
1776 defer b.deinit();
17341777
1735 var c = try Int.init(al);
1778 var c = try Int.init(testing.allocator);
1779 defer c.deinit();
17361780 try c.add(a, b);
17371781
17381782 testing.expect((try c.to(u32)) == 55);
17391783}
17401784
17411785test "big.int add multi-single" {
1742 var a = try Int.initSet(al, maxInt(Limb) + 1);
1743 var b = try Int.initSet(al, 1);
1786 var a = try Int.initSet(testing.allocator, maxInt(Limb) + 1);
1787 defer a.deinit();
1788 var b = try Int.initSet(testing.allocator, 1);
1789 defer b.deinit();
17441790
1745 var c = try Int.init(al);
1791 var c = try Int.init(testing.allocator);
1792 defer c.deinit();
17461793
17471794 try c.add(a, b);
17481795 testing.expect((try c.to(DoubleLimb)) == maxInt(Limb) + 2);
......@@ -1754,20 +1801,26 @@ test "big.int add multi-single" {
17541801test "big.int add multi-multi" {
17551802 const op1 = 0xefefefef7f7f7f7f;
17561803 const op2 = 0xfefefefe9f9f9f9f;
1757 var a = try Int.initSet(al, op1);
1758 var b = try Int.initSet(al, op2);
1804 var a = try Int.initSet(testing.allocator, op1);
1805 defer a.deinit();
1806 var b = try Int.initSet(testing.allocator, op2);
1807 defer b.deinit();
17591808
1760 var c = try Int.init(al);
1809 var c = try Int.init(testing.allocator);
1810 defer c.deinit();
17611811 try c.add(a, b);
17621812
17631813 testing.expect((try c.to(u128)) == op1 + op2);
17641814}
17651815
17661816test "big.int add zero-zero" {
1767 var a = try Int.initSet(al, 0);
1768 var b = try Int.initSet(al, 0);
1817 var a = try Int.initSet(testing.allocator, 0);
1818 defer a.deinit();
1819 var b = try Int.initSet(testing.allocator, 0);
1820 defer b.deinit();
17691821
1770 var c = try Int.init(al);
1822 var c = try Int.init(testing.allocator);
1823 defer c.deinit();
17711824 try c.add(a, b);
17721825
17731826 testing.expect((try c.to(u32)) == 0);
......@@ -1775,8 +1828,10 @@ test "big.int add zero-zero" {
17751828
17761829test "big.int add alias multi-limb nonzero-zero" {
17771830 const op1 = 0xffffffff777777771;
1778 var a = try Int.initSet(al, op1);
1779 var b = try Int.initSet(al, 0);
1831 var a = try Int.initSet(testing.allocator, op1);
1832 defer a.deinit();
1833 var b = try Int.initSet(testing.allocator, 0);
1834 defer b.deinit();
17801835
17811836 try a.add(a, b);
17821837
......@@ -1784,12 +1839,17 @@ test "big.int add alias multi-limb nonzero-zero" {
17841839}
17851840
17861841test "big.int add sign" {
1787 var a = try Int.init(al);
1788
1789 const one = try Int.initSet(al, 1);
1790 const two = try Int.initSet(al, 2);
1791 const neg_one = try Int.initSet(al, -1);
1792 const neg_two = try Int.initSet(al, -2);
1842 var a = try Int.init(testing.allocator);
1843 defer a.deinit();
1844
1845 const one = try Int.initSet(testing.allocator, 1);
1846 defer one.deinit();
1847 const two = try Int.initSet(testing.allocator, 2);
1848 defer two.deinit();
1849 const neg_one = try Int.initSet(testing.allocator, -1);
1850 defer neg_one.deinit();
1851 const neg_two = try Int.initSet(testing.allocator, -2);
1852 defer neg_two.deinit();
17931853
17941854 try a.add(one, two);
17951855 testing.expect((try a.to(i32)) == 3);
......@@ -1805,20 +1865,26 @@ test "big.int add sign" {
18051865}
18061866
18071867test "big.int sub single-single" {
1808 var a = try Int.initSet(al, 50);
1809 var b = try Int.initSet(al, 5);
1868 var a = try Int.initSet(testing.allocator, 50);
1869 defer a.deinit();
1870 var b = try Int.initSet(testing.allocator, 5);
1871 defer b.deinit();
18101872
1811 var c = try Int.init(al);
1873 var c = try Int.init(testing.allocator);
1874 defer c.deinit();
18121875 try c.sub(a, b);
18131876
18141877 testing.expect((try c.to(u32)) == 45);
18151878}
18161879
18171880test "big.int sub multi-single" {
1818 var a = try Int.initSet(al, maxInt(Limb) + 1);
1819 var b = try Int.initSet(al, 1);
1881 var a = try Int.initSet(testing.allocator, maxInt(Limb) + 1);
1882 defer a.deinit();
1883 var b = try Int.initSet(testing.allocator, 1);
1884 defer b.deinit();
18201885
1821 var c = try Int.init(al);
1886 var c = try Int.init(testing.allocator);
1887 defer c.deinit();
18221888 try c.sub(a, b);
18231889
18241890 testing.expect((try c.to(Limb)) == maxInt(Limb));
......@@ -1828,32 +1894,43 @@ test "big.int sub multi-multi" {
18281894 const op1 = 0xefefefefefefefefefefefef;
18291895 const op2 = 0xabababababababababababab;
18301896
1831 var a = try Int.initSet(al, op1);
1832 var b = try Int.initSet(al, op2);
1897 var a = try Int.initSet(testing.allocator, op1);
1898 defer a.deinit();
1899 var b = try Int.initSet(testing.allocator, op2);
1900 defer b.deinit();
18331901
1834 var c = try Int.init(al);
1902 var c = try Int.init(testing.allocator);
1903 defer c.deinit();
18351904 try c.sub(a, b);
18361905
18371906 testing.expect((try c.to(u128)) == op1 - op2);
18381907}
18391908
18401909test "big.int sub equal" {
1841 var a = try Int.initSet(al, 0x11efefefefefefefefefefefef);
1842 var b = try Int.initSet(al, 0x11efefefefefefefefefefefef);
1910 var a = try Int.initSet(testing.allocator, 0x11efefefefefefefefefefefef);
1911 defer a.deinit();
1912 var b = try Int.initSet(testing.allocator, 0x11efefefefefefefefefefefef);
1913 defer b.deinit();
18431914
1844 var c = try Int.init(al);
1915 var c = try Int.init(testing.allocator);
1916 defer c.deinit();
18451917 try c.sub(a, b);
18461918
18471919 testing.expect((try c.to(u32)) == 0);
18481920}
18491921
18501922test "big.int sub sign" {
1851 var a = try Int.init(al);
1852
1853 const one = try Int.initSet(al, 1);
1854 const two = try Int.initSet(al, 2);
1855 const neg_one = try Int.initSet(al, -1);
1856 const neg_two = try Int.initSet(al, -2);
1923 var a = try Int.init(testing.allocator);
1924 defer a.deinit();
1925
1926 const one = try Int.initSet(testing.allocator, 1);
1927 defer one.deinit();
1928 const two = try Int.initSet(testing.allocator, 2);
1929 defer two.deinit();
1930 const neg_one = try Int.initSet(testing.allocator, -1);
1931 defer neg_one.deinit();
1932 const neg_two = try Int.initSet(testing.allocator, -2);
1933 defer neg_two.deinit();
18571934
18581935 try a.sub(one, two);
18591936 testing.expect((try a.to(i32)) == -1);
......@@ -1872,20 +1949,26 @@ test "big.int sub sign" {
18721949}
18731950
18741951test "big.int mul single-single" {
1875 var a = try Int.initSet(al, 50);
1876 var b = try Int.initSet(al, 5);
1952 var a = try Int.initSet(testing.allocator, 50);
1953 defer a.deinit();
1954 var b = try Int.initSet(testing.allocator, 5);
1955 defer b.deinit();
18771956
1878 var c = try Int.init(al);
1957 var c = try Int.init(testing.allocator);
1958 defer c.deinit();
18791959 try c.mul(a, b);
18801960
18811961 testing.expect((try c.to(u64)) == 250);
18821962}
18831963
18841964test "big.int mul multi-single" {
1885 var a = try Int.initSet(al, maxInt(Limb));
1886 var b = try Int.initSet(al, 2);
1965 var a = try Int.initSet(testing.allocator, maxInt(Limb));
1966 defer a.deinit();
1967 var b = try Int.initSet(testing.allocator, 2);
1968 defer b.deinit();
18871969
1888 var c = try Int.init(al);
1970 var c = try Int.init(testing.allocator);
1971 defer c.deinit();
18891972 try c.mul(a, b);
18901973
18911974 testing.expect((try c.to(DoubleLimb)) == 2 * maxInt(Limb));
......@@ -1894,18 +1977,23 @@ test "big.int mul multi-single" {
18941977test "big.int mul multi-multi" {
18951978 const op1 = 0x998888efefefefefefefef;
18961979 const op2 = 0x333000abababababababab;
1897 var a = try Int.initSet(al, op1);
1898 var b = try Int.initSet(al, op2);
1980 var a = try Int.initSet(testing.allocator, op1);
1981 defer a.deinit();
1982 var b = try Int.initSet(testing.allocator, op2);
1983 defer b.deinit();
18991984
1900 var c = try Int.init(al);
1985 var c = try Int.init(testing.allocator);
1986 defer c.deinit();
19011987 try c.mul(a, b);
19021988
19031989 testing.expect((try c.to(u256)) == op1 * op2);
19041990}
19051991
19061992test "big.int mul alias r with a" {
1907 var a = try Int.initSet(al, maxInt(Limb));
1908 var b = try Int.initSet(al, 2);
1993 var a = try Int.initSet(testing.allocator, maxInt(Limb));
1994 defer a.deinit();
1995 var b = try Int.initSet(testing.allocator, 2);
1996 defer b.deinit();
19091997
19101998 try a.mul(a, b);
19111999
......@@ -1913,8 +2001,10 @@ test "big.int mul alias r with a" {
19132001}
19142002
19152003test "big.int mul alias r with b" {
1916 var a = try Int.initSet(al, maxInt(Limb));
1917 var b = try Int.initSet(al, 2);
2004 var a = try Int.initSet(testing.allocator, maxInt(Limb));
2005 defer a.deinit();
2006 var b = try Int.initSet(testing.allocator, 2);
2007 defer b.deinit();
19182008
19192009 try a.mul(b, a);
19202010
......@@ -1922,7 +2012,8 @@ test "big.int mul alias r with b" {
19222012}
19232013
19242014test "big.int mul alias r with a and b" {
1925 var a = try Int.initSet(al, maxInt(Limb));
2015 var a = try Int.initSet(testing.allocator, maxInt(Limb));
2016 defer a.deinit();
19262017
19272018 try a.mul(a, a);
19282019
......@@ -1930,31 +2021,41 @@ test "big.int mul alias r with a and b" {
19302021}
19312022
19322023test "big.int mul a*0" {
1933 var a = try Int.initSet(al, 0xefefefefefefefef);
1934 var b = try Int.initSet(al, 0);
2024 var a = try Int.initSet(testing.allocator, 0xefefefefefefefef);
2025 defer a.deinit();
2026 var b = try Int.initSet(testing.allocator, 0);
2027 defer b.deinit();
19352028
1936 var c = try Int.init(al);
2029 var c = try Int.init(testing.allocator);
2030 defer c.deinit();
19372031 try c.mul(a, b);
19382032
19392033 testing.expect((try c.to(u32)) == 0);
19402034}
19412035
19422036test "big.int mul 0*0" {
1943 var a = try Int.initSet(al, 0);
1944 var b = try Int.initSet(al, 0);
2037 var a = try Int.initSet(testing.allocator, 0);
2038 defer a.deinit();
2039 var b = try Int.initSet(testing.allocator, 0);
2040 defer b.deinit();
19452041
1946 var c = try Int.init(al);
2042 var c = try Int.init(testing.allocator);
2043 defer c.deinit();
19472044 try c.mul(a, b);
19482045
19492046 testing.expect((try c.to(u32)) == 0);
19502047}
19512048
19522049test "big.int div single-single no rem" {
1953 var a = try Int.initSet(al, 50);
1954 var b = try Int.initSet(al, 5);
1955
1956 var q = try Int.init(al);
1957 var r = try Int.init(al);
2050 var a = try Int.initSet(testing.allocator, 50);
2051 defer a.deinit();
2052 var b = try Int.initSet(testing.allocator, 5);
2053 defer b.deinit();
2054
2055 var q = try Int.init(testing.allocator);
2056 defer q.deinit();
2057 var r = try Int.init(testing.allocator);
2058 defer r.deinit();
19582059 try Int.divTrunc(&q, &r, a, b);
19592060
19602061 testing.expect((try q.to(u32)) == 10);
......@@ -1962,11 +2063,15 @@ test "big.int div single-single no rem" {
19622063}
19632064
19642065test "big.int div single-single with rem" {
1965 var a = try Int.initSet(al, 49);
1966 var b = try Int.initSet(al, 5);
1967
1968 var q = try Int.init(al);
1969 var r = try Int.init(al);
2066 var a = try Int.initSet(testing.allocator, 49);
2067 defer a.deinit();
2068 var b = try Int.initSet(testing.allocator, 5);
2069 defer b.deinit();
2070
2071 var q = try Int.init(testing.allocator);
2072 defer q.deinit();
2073 var r = try Int.init(testing.allocator);
2074 defer r.deinit();
19702075 try Int.divTrunc(&q, &r, a, b);
19712076
19722077 testing.expect((try q.to(u32)) == 9);
......@@ -1977,11 +2082,15 @@ test "big.int div multi-single no rem" {
19772082 const op1 = 0xffffeeeeddddcccc;
19782083 const op2 = 34;
19792084
1980 var a = try Int.initSet(al, op1);
1981 var b = try Int.initSet(al, op2);
2085 var a = try Int.initSet(testing.allocator, op1);
2086 defer a.deinit();
2087 var b = try Int.initSet(testing.allocator, op2);
2088 defer b.deinit();
19822089
1983 var q = try Int.init(al);
1984 var r = try Int.init(al);
2090 var q = try Int.init(testing.allocator);
2091 defer q.deinit();
2092 var r = try Int.init(testing.allocator);
2093 defer r.deinit();
19852094 try Int.divTrunc(&q, &r, a, b);
19862095
19872096 testing.expect((try q.to(u64)) == op1 / op2);
......@@ -1992,11 +2101,15 @@ test "big.int div multi-single with rem" {
19922101 const op1 = 0xffffeeeeddddcccf;
19932102 const op2 = 34;
19942103
1995 var a = try Int.initSet(al, op1);
1996 var b = try Int.initSet(al, op2);
2104 var a = try Int.initSet(testing.allocator, op1);
2105 defer a.deinit();
2106 var b = try Int.initSet(testing.allocator, op2);
2107 defer b.deinit();
19972108
1998 var q = try Int.init(al);
1999 var r = try Int.init(al);
2109 var q = try Int.init(testing.allocator);
2110 defer q.deinit();
2111 var r = try Int.init(testing.allocator);
2112 defer r.deinit();
20002113 try Int.divTrunc(&q, &r, a, b);
20012114
20022115 testing.expect((try q.to(u64)) == op1 / op2);
......@@ -2007,11 +2120,15 @@ test "big.int div multi>2-single" {
20072120 const op1 = 0xfefefefefefefefefefefefefefefefe;
20082121 const op2 = 0xefab8;
20092122
2010 var a = try Int.initSet(al, op1);
2011 var b = try Int.initSet(al, op2);
2123 var a = try Int.initSet(testing.allocator, op1);
2124 defer a.deinit();
2125 var b = try Int.initSet(testing.allocator, op2);
2126 defer b.deinit();
20122127
2013 var q = try Int.init(al);
2014 var r = try Int.init(al);
2128 var q = try Int.init(testing.allocator);
2129 defer q.deinit();
2130 var r = try Int.init(testing.allocator);
2131 defer r.deinit();
20152132 try Int.divTrunc(&q, &r, a, b);
20162133
20172134 testing.expect((try q.to(u128)) == op1 / op2);
......@@ -2019,11 +2136,15 @@ test "big.int div multi>2-single" {
20192136}
20202137
20212138test "big.int div single-single q < r" {
2022 var a = try Int.initSet(al, 0x0078f432);
2023 var b = try Int.initSet(al, 0x01000000);
2024
2025 var q = try Int.init(al);
2026 var r = try Int.init(al);
2139 var a = try Int.initSet(testing.allocator, 0x0078f432);
2140 defer a.deinit();
2141 var b = try Int.initSet(testing.allocator, 0x01000000);
2142 defer b.deinit();
2143
2144 var q = try Int.init(testing.allocator);
2145 defer q.deinit();
2146 var r = try Int.init(testing.allocator);
2147 defer r.deinit();
20272148 try Int.divTrunc(&q, &r, a, b);
20282149
20292150 testing.expect((try q.to(u64)) == 0);
......@@ -2031,11 +2152,15 @@ test "big.int div single-single q < r" {
20312152}
20322153
20332154test "big.int div single-single q == r" {
2034 var a = try Int.initSet(al, 10);
2035 var b = try Int.initSet(al, 10);
2036
2037 var q = try Int.init(al);
2038 var r = try Int.init(al);
2155 var a = try Int.initSet(testing.allocator, 10);
2156 defer a.deinit();
2157 var b = try Int.initSet(testing.allocator, 10);
2158 defer b.deinit();
2159
2160 var q = try Int.init(testing.allocator);
2161 defer q.deinit();
2162 var r = try Int.init(testing.allocator);
2163 defer r.deinit();
20392164 try Int.divTrunc(&q, &r, a, b);
20402165
20412166 testing.expect((try q.to(u64)) == 1);
......@@ -2043,8 +2168,10 @@ test "big.int div single-single q == r" {
20432168}
20442169
20452170test "big.int div q=0 alias" {
2046 var a = try Int.initSet(al, 3);
2047 var b = try Int.initSet(al, 10);
2171 var a = try Int.initSet(testing.allocator, 3);
2172 defer a.deinit();
2173 var b = try Int.initSet(testing.allocator, 10);
2174 defer b.deinit();
20482175
20492176 try Int.divTrunc(&a, &b, a, b);
20502177
......@@ -2055,11 +2182,15 @@ test "big.int div q=0 alias" {
20552182test "big.int div multi-multi q < r" {
20562183 const op1 = 0x1ffffffff0078f432;
20572184 const op2 = 0x1ffffffff01000000;
2058 var a = try Int.initSet(al, op1);
2059 var b = try Int.initSet(al, op2);
2060
2061 var q = try Int.init(al);
2062 var r = try Int.init(al);
2185 var a = try Int.initSet(testing.allocator, op1);
2186 defer a.deinit();
2187 var b = try Int.initSet(testing.allocator, op2);
2188 defer b.deinit();
2189
2190 var q = try Int.init(testing.allocator);
2191 defer q.deinit();
2192 var r = try Int.init(testing.allocator);
2193 defer r.deinit();
20632194 try Int.divTrunc(&q, &r, a, b);
20642195
20652196 testing.expect((try q.to(u128)) == 0);
......@@ -2070,11 +2201,15 @@ test "big.int div trunc single-single +/+" {
20702201 const u: i32 = 5;
20712202 const v: i32 = 3;
20722203
2073 var a = try Int.initSet(al, u);
2074 var b = try Int.initSet(al, v);
2204 var a = try Int.initSet(testing.allocator, u);
2205 defer a.deinit();
2206 var b = try Int.initSet(testing.allocator, v);
2207 defer b.deinit();
20752208
2076 var q = try Int.init(al);
2077 var r = try Int.init(al);
2209 var q = try Int.init(testing.allocator);
2210 defer q.deinit();
2211 var r = try Int.init(testing.allocator);
2212 defer r.deinit();
20782213 try Int.divTrunc(&q, &r, a, b);
20792214
20802215 // n = q * d + r
......@@ -2090,11 +2225,15 @@ test "big.int div trunc single-single -/+" {
20902225 const u: i32 = -5;
20912226 const v: i32 = 3;
20922227
2093 var a = try Int.initSet(al, u);
2094 var b = try Int.initSet(al, v);
2228 var a = try Int.initSet(testing.allocator, u);
2229 defer a.deinit();
2230 var b = try Int.initSet(testing.allocator, v);
2231 defer b.deinit();
20952232
2096 var q = try Int.init(al);
2097 var r = try Int.init(al);
2233 var q = try Int.init(testing.allocator);
2234 defer q.deinit();
2235 var r = try Int.init(testing.allocator);
2236 defer r.deinit();
20982237 try Int.divTrunc(&q, &r, a, b);
20992238
21002239 // n = q * d + r
......@@ -2110,11 +2249,15 @@ test "big.int div trunc single-single +/-" {
21102249 const u: i32 = 5;
21112250 const v: i32 = -3;
21122251
2113 var a = try Int.initSet(al, u);
2114 var b = try Int.initSet(al, v);
2252 var a = try Int.initSet(testing.allocator, u);
2253 defer a.deinit();
2254 var b = try Int.initSet(testing.allocator, v);
2255 defer b.deinit();
21152256
2116 var q = try Int.init(al);
2117 var r = try Int.init(al);
2257 var q = try Int.init(testing.allocator);
2258 defer q.deinit();
2259 var r = try Int.init(testing.allocator);
2260 defer r.deinit();
21182261 try Int.divTrunc(&q, &r, a, b);
21192262
21202263 // n = q * d + r
......@@ -2130,11 +2273,15 @@ test "big.int div trunc single-single -/-" {
21302273 const u: i32 = -5;
21312274 const v: i32 = -3;
21322275
2133 var a = try Int.initSet(al, u);
2134 var b = try Int.initSet(al, v);
2276 var a = try Int.initSet(testing.allocator, u);
2277 defer a.deinit();
2278 var b = try Int.initSet(testing.allocator, v);
2279 defer b.deinit();
21352280
2136 var q = try Int.init(al);
2137 var r = try Int.init(al);
2281 var q = try Int.init(testing.allocator);
2282 defer q.deinit();
2283 var r = try Int.init(testing.allocator);
2284 defer r.deinit();
21382285 try Int.divTrunc(&q, &r, a, b);
21392286
21402287 // n = q * d + r
......@@ -2150,11 +2297,15 @@ test "big.int div floor single-single +/+" {
21502297 const u: i32 = 5;
21512298 const v: i32 = 3;
21522299
2153 var a = try Int.initSet(al, u);
2154 var b = try Int.initSet(al, v);
2300 var a = try Int.initSet(testing.allocator, u);
2301 defer a.deinit();
2302 var b = try Int.initSet(testing.allocator, v);
2303 defer b.deinit();
21552304
2156 var q = try Int.init(al);
2157 var r = try Int.init(al);
2305 var q = try Int.init(testing.allocator);
2306 defer q.deinit();
2307 var r = try Int.init(testing.allocator);
2308 defer r.deinit();
21582309 try Int.divFloor(&q, &r, a, b);
21592310
21602311 // n = q * d + r
......@@ -2170,11 +2321,15 @@ test "big.int div floor single-single -/+" {
21702321 const u: i32 = -5;
21712322 const v: i32 = 3;
21722323
2173 var a = try Int.initSet(al, u);
2174 var b = try Int.initSet(al, v);
2324 var a = try Int.initSet(testing.allocator, u);
2325 defer a.deinit();
2326 var b = try Int.initSet(testing.allocator, v);
2327 defer b.deinit();
21752328
2176 var q = try Int.init(al);
2177 var r = try Int.init(al);
2329 var q = try Int.init(testing.allocator);
2330 defer q.deinit();
2331 var r = try Int.init(testing.allocator);
2332 defer r.deinit();
21782333 try Int.divFloor(&q, &r, a, b);
21792334
21802335 // n = q * d + r
......@@ -2190,11 +2345,15 @@ test "big.int div floor single-single +/-" {
21902345 const u: i32 = 5;
21912346 const v: i32 = -3;
21922347
2193 var a = try Int.initSet(al, u);
2194 var b = try Int.initSet(al, v);
2348 var a = try Int.initSet(testing.allocator, u);
2349 defer a.deinit();
2350 var b = try Int.initSet(testing.allocator, v);
2351 defer b.deinit();
21952352
2196 var q = try Int.init(al);
2197 var r = try Int.init(al);
2353 var q = try Int.init(testing.allocator);
2354 defer q.deinit();
2355 var r = try Int.init(testing.allocator);
2356 defer r.deinit();
21982357 try Int.divFloor(&q, &r, a, b);
21992358
22002359 // n = q * d + r
......@@ -2210,11 +2369,15 @@ test "big.int div floor single-single -/-" {
22102369 const u: i32 = -5;
22112370 const v: i32 = -3;
22122371
2213 var a = try Int.initSet(al, u);
2214 var b = try Int.initSet(al, v);
2372 var a = try Int.initSet(testing.allocator, u);
2373 defer a.deinit();
2374 var b = try Int.initSet(testing.allocator, v);
2375 defer b.deinit();
22152376
2216 var q = try Int.init(al);
2217 var r = try Int.init(al);
2377 var q = try Int.init(testing.allocator);
2378 defer q.deinit();
2379 var r = try Int.init(testing.allocator);
2380 defer r.deinit();
22182381 try Int.divFloor(&q, &r, a, b);
22192382
22202383 // n = q * d + r
......@@ -2227,11 +2390,15 @@ test "big.int div floor single-single -/-" {
22272390}
22282391
22292392test "big.int div multi-multi with rem" {
2230 var a = try Int.initSet(al, 0x8888999911110000ffffeeeeddddccccbbbbaaaa9999);
2231 var b = try Int.initSet(al, 0x99990000111122223333);
2232
2233 var q = try Int.init(al);
2234 var r = try Int.init(al);
2393 var a = try Int.initSet(testing.allocator, 0x8888999911110000ffffeeeeddddccccbbbbaaaa9999);
2394 defer a.deinit();
2395 var b = try Int.initSet(testing.allocator, 0x99990000111122223333);
2396 defer b.deinit();
2397
2398 var q = try Int.init(testing.allocator);
2399 defer q.deinit();
2400 var r = try Int.init(testing.allocator);
2401 defer r.deinit();
22352402 try Int.divTrunc(&q, &r, a, b);
22362403
22372404 testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b);
......@@ -2239,11 +2406,15 @@ test "big.int div multi-multi with rem" {
22392406}
22402407
22412408test "big.int div multi-multi no rem" {
2242 var a = try Int.initSet(al, 0x8888999911110000ffffeeeedb4fec200ee3a4286361);
2243 var b = try Int.initSet(al, 0x99990000111122223333);
2244
2245 var q = try Int.init(al);
2246 var r = try Int.init(al);
2409 var a = try Int.initSet(testing.allocator, 0x8888999911110000ffffeeeedb4fec200ee3a4286361);
2410 defer a.deinit();
2411 var b = try Int.initSet(testing.allocator, 0x99990000111122223333);
2412 defer b.deinit();
2413
2414 var q = try Int.init(testing.allocator);
2415 defer q.deinit();
2416 var r = try Int.init(testing.allocator);
2417 defer r.deinit();
22472418 try Int.divTrunc(&q, &r, a, b);
22482419
22492420 testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b);
......@@ -2251,11 +2422,15 @@ test "big.int div multi-multi no rem" {
22512422}
22522423
22532424test "big.int div multi-multi (2 branch)" {
2254 var a = try Int.initSet(al, 0x866666665555555588888887777777761111111111111111);
2255 var b = try Int.initSet(al, 0x86666666555555554444444433333333);
2256
2257 var q = try Int.init(al);
2258 var r = try Int.init(al);
2425 var a = try Int.initSet(testing.allocator, 0x866666665555555588888887777777761111111111111111);
2426 defer a.deinit();
2427 var b = try Int.initSet(testing.allocator, 0x86666666555555554444444433333333);
2428 defer b.deinit();
2429
2430 var q = try Int.init(testing.allocator);
2431 defer q.deinit();
2432 var r = try Int.init(testing.allocator);
2433 defer r.deinit();
22592434 try Int.divTrunc(&q, &r, a, b);
22602435
22612436 testing.expect((try q.to(u128)) == 0x10000000000000000);
......@@ -2263,11 +2438,15 @@ test "big.int div multi-multi (2 branch)" {
22632438}
22642439
22652440test "big.int div multi-multi (3.1/3.3 branch)" {
2266 var a = try Int.initSet(al, 0x11111111111111111111111111111111111111111111111111111111111111);
2267 var b = try Int.initSet(al, 0x1111111111111111111111111111111111111111171);
2268
2269 var q = try Int.init(al);
2270 var r = try Int.init(al);
2441 var a = try Int.initSet(testing.allocator, 0x11111111111111111111111111111111111111111111111111111111111111);
2442 defer a.deinit();
2443 var b = try Int.initSet(testing.allocator, 0x1111111111111111111111111111111111111111171);
2444 defer b.deinit();
2445
2446 var q = try Int.init(testing.allocator);
2447 defer q.deinit();
2448 var r = try Int.init(testing.allocator);
2449 defer r.deinit();
22712450 try Int.divTrunc(&q, &r, a, b);
22722451
22732452 testing.expect((try q.to(u128)) == 0xfffffffffffffffffff);
......@@ -2275,145 +2454,189 @@ test "big.int div multi-multi (3.1/3.3 branch)" {
22752454}
22762455
22772456test "big.int div multi-single zero-limb trailing" {
2278 var a = try Int.initSet(al, 0x60000000000000000000000000000000000000000000000000000000000000000);
2279 var b = try Int.initSet(al, 0x10000000000000000);
2280
2281 var q = try Int.init(al);
2282 var r = try Int.init(al);
2457 var a = try Int.initSet(testing.allocator, 0x60000000000000000000000000000000000000000000000000000000000000000);
2458 defer a.deinit();
2459 var b = try Int.initSet(testing.allocator, 0x10000000000000000);
2460 defer b.deinit();
2461
2462 var q = try Int.init(testing.allocator);
2463 defer q.deinit();
2464 var r = try Int.init(testing.allocator);
2465 defer r.deinit();
22832466 try Int.divTrunc(&q, &r, a, b);
22842467
2285 var expected = try Int.initSet(al, 0x6000000000000000000000000000000000000000000000000);
2468 var expected = try Int.initSet(testing.allocator, 0x6000000000000000000000000000000000000000000000000);
2469 defer expected.deinit();
22862470 testing.expect(q.eq(expected));
22872471 testing.expect(r.eqZero());
22882472}
22892473
22902474test "big.int div multi-multi zero-limb trailing (with rem)" {
2291 var a = try Int.initSet(al, 0x86666666555555558888888777777776111111111111111100000000000000000000000000000000);
2292 var b = try Int.initSet(al, 0x8666666655555555444444443333333300000000000000000000000000000000);
2293
2294 var q = try Int.init(al);
2295 var r = try Int.init(al);
2475 var a = try Int.initSet(testing.allocator, 0x86666666555555558888888777777776111111111111111100000000000000000000000000000000);
2476 defer a.deinit();
2477 var b = try Int.initSet(testing.allocator, 0x8666666655555555444444443333333300000000000000000000000000000000);
2478 defer b.deinit();
2479
2480 var q = try Int.init(testing.allocator);
2481 defer q.deinit();
2482 var r = try Int.init(testing.allocator);
2483 defer r.deinit();
22962484 try Int.divTrunc(&q, &r, a, b);
22972485
22982486 testing.expect((try q.to(u128)) == 0x10000000000000000);
22992487
2300 const rs = try r.toString(al, 16);
2488 const rs = try r.toString(testing.allocator, 16);
2489 defer testing.allocator.free(rs);
23012490 testing.expect(std.mem.eql(u8, rs, "4444444344444443111111111111111100000000000000000000000000000000"));
23022491}
23032492
23042493test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-limb count > divisor zero-limb count" {
2305 var a = try Int.initSet(al, 0x8666666655555555888888877777777611111111111111110000000000000000);
2306 var b = try Int.initSet(al, 0x8666666655555555444444443333333300000000000000000000000000000000);
2307
2308 var q = try Int.init(al);
2309 var r = try Int.init(al);
2494 var a = try Int.initSet(testing.allocator, 0x8666666655555555888888877777777611111111111111110000000000000000);
2495 defer a.deinit();
2496 var b = try Int.initSet(testing.allocator, 0x8666666655555555444444443333333300000000000000000000000000000000);
2497 defer b.deinit();
2498
2499 var q = try Int.init(testing.allocator);
2500 defer q.deinit();
2501 var r = try Int.init(testing.allocator);
2502 defer r.deinit();
23102503 try Int.divTrunc(&q, &r, a, b);
23112504
23122505 testing.expect((try q.to(u128)) == 0x1);
23132506
2314 const rs = try r.toString(al, 16);
2507 const rs = try r.toString(testing.allocator, 16);
2508 defer testing.allocator.free(rs);
23152509 testing.expect(std.mem.eql(u8, rs, "444444434444444311111111111111110000000000000000"));
23162510}
23172511
23182512test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-limb count < divisor zero-limb count" {
2319 var a = try Int.initSet(al, 0x86666666555555558888888777777776111111111111111100000000000000000000000000000000);
2320 var b = try Int.initSet(al, 0x866666665555555544444444333333330000000000000000);
2321
2322 var q = try Int.init(al);
2323 var r = try Int.init(al);
2513 var a = try Int.initSet(testing.allocator, 0x86666666555555558888888777777776111111111111111100000000000000000000000000000000);
2514 defer a.deinit();
2515 var b = try Int.initSet(testing.allocator, 0x866666665555555544444444333333330000000000000000);
2516 defer b.deinit();
2517
2518 var q = try Int.init(testing.allocator);
2519 defer q.deinit();
2520 var r = try Int.init(testing.allocator);
2521 defer r.deinit();
23242522 try Int.divTrunc(&q, &r, a, b);
23252523
2326 const qs = try q.toString(al, 16);
2524 const qs = try q.toString(testing.allocator, 16);
2525 defer testing.allocator.free(qs);
23272526 testing.expect(std.mem.eql(u8, qs, "10000000000000000820820803105186f"));
23282527
2329 const rs = try r.toString(al, 16);
2528 const rs = try r.toString(testing.allocator, 16);
2529 defer testing.allocator.free(rs);
23302530 testing.expect(std.mem.eql(u8, rs, "4e11f2baa5896a321d463b543d0104e30000000000000000"));
23312531}
23322532
23332533test "big.int div multi-multi fuzz case #1" {
2334 var a = try Int.init(al);
2335 var b = try Int.init(al);
2534 var a = try Int.init(testing.allocator);
2535 defer a.deinit();
2536 var b = try Int.init(testing.allocator);
2537 defer b.deinit();
23362538
23372539 try a.setString(16, "ffffffffffffffffffffffffffffc00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
23382540 try b.setString(16, "3ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0000000000000000000000000000000000001ffffffffffffffffffffffffffffffffffffffffffffffffffc000000000000000000000000000000007fffffffffff");
23392541
2340 var q = try Int.init(al);
2341 var r = try Int.init(al);
2542 var q = try Int.init(testing.allocator);
2543 defer q.deinit();
2544 var r = try Int.init(testing.allocator);
2545 defer r.deinit();
23422546 try Int.divTrunc(&q, &r, a, b);
23432547
2344 const qs = try q.toString(al, 16);
2548 const qs = try q.toString(testing.allocator, 16);
2549 defer testing.allocator.free(qs);
23452550 testing.expect(std.mem.eql(u8, qs, "3ffffffffffffffffffffffffffff0000000000000000000000000000000000001ffffffffffffffffffffffffffff7fffffffe000000000000000000000000000180000000000000000000003fffffbfffffffdfffffffffffffeffff800000100101000000100000000020003fffffdfbfffffe3ffffffffffffeffff7fffc00800a100000017ffe000002000400007efbfff7fe9f00000037ffff3fff7fffa004006100000009ffe00000190038200bf7d2ff7fefe80400060000f7d7f8fbf9401fe38e0403ffc0bdffffa51102c300d7be5ef9df4e5060007b0127ad3fa69f97d0f820b6605ff617ddf7f32ad7a05c0d03f2e7bc78a6000e087a8bbcdc59e07a5a079128a7861f553ddebed7e8e56701756f9ead39b48cd1b0831889ea6ec1fddf643d0565b075ff07e6caea4e2854ec9227fd635ed60a2f5eef2893052ffd54718fa08604acbf6a15e78a467c4a3c53c0278af06c4416573f925491b195e8fd79302cb1aaf7caf4ecfc9aec1254cc969786363ac729f914c6ddcc26738d6b0facd54eba026580aba2eb6482a088b0d224a8852420b91ec1"));
23462551
2347 const rs = try r.toString(al, 16);
2552 const rs = try r.toString(testing.allocator, 16);
2553 defer testing.allocator.free(rs);
23482554 testing.expect(std.mem.eql(u8, rs, "310d1d4c414426b4836c2635bad1df3a424e50cbdd167ffccb4dfff57d36b4aae0d6ca0910698220171a0f3373c1060a046c2812f0027e321f72979daa5e7973214170d49e885de0c0ecc167837d44502430674a82522e5df6a0759548052420b91ec1"));
23492555}
23502556
23512557test "big.int div multi-multi fuzz case #2" {
2352 var a = try Int.init(al);
2353 var b = try Int.init(al);
2558 var a = try Int.init(testing.allocator);
2559 defer a.deinit();
2560 var b = try Int.init(testing.allocator);
2561 defer b.deinit();
23542562
23552563 try a.setString(16, "3ffffffffe00000000000000000000000000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffe000000000000000000000000000000000000000000000000000000000000001fffffffffffffffff800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffc000000000000000000000000000000000000000000000000000000000000000");
23562564 try b.setString(16, "ffc0000000000000000000000000000000000000000000000000");
23572565
2358 var q = try Int.init(al);
2359 var r = try Int.init(al);
2566 var q = try Int.init(testing.allocator);
2567 defer q.deinit();
2568 var r = try Int.init(testing.allocator);
2569 defer r.deinit();
23602570 try Int.divTrunc(&q, &r, a, b);
23612571
2362 const qs = try q.toString(al, 16);
2572 const qs = try q.toString(testing.allocator, 16);
2573 defer testing.allocator.free(qs);
23632574 testing.expect(std.mem.eql(u8, qs, "40100400fe3f8fe3f8fe3f8fe3f8fe3f8fe4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f91e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4992649926499264991e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4792e4b92e4b92e4b92e4b92a4a92a4a92a4"));
23642575
2365 const rs = try r.toString(al, 16);
2576 const rs = try r.toString(testing.allocator, 16);
2577 defer testing.allocator.free(rs);
23662578 testing.expect(std.mem.eql(u8, rs, "a900000000000000000000000000000000000000000000000000"));
23672579}
23682580
23692581test "big.int shift-right single" {
2370 var a = try Int.initSet(al, 0xffff0000);
2582 var a = try Int.initSet(testing.allocator, 0xffff0000);
2583 defer a.deinit();
23712584 try a.shiftRight(a, 16);
23722585
23732586 testing.expect((try a.to(u32)) == 0xffff);
23742587}
23752588
23762589test "big.int shift-right multi" {
2377 var a = try Int.initSet(al, 0xffff0000eeee1111dddd2222cccc3333);
2590 var a = try Int.initSet(testing.allocator, 0xffff0000eeee1111dddd2222cccc3333);
2591 defer a.deinit();
23782592 try a.shiftRight(a, 67);
23792593
23802594 testing.expect((try a.to(u64)) == 0x1fffe0001dddc222);
23812595}
23822596
23832597test "big.int shift-left single" {
2384 var a = try Int.initSet(al, 0xffff);
2598 var a = try Int.initSet(testing.allocator, 0xffff);
2599 defer a.deinit();
23852600 try a.shiftLeft(a, 16);
23862601
23872602 testing.expect((try a.to(u64)) == 0xffff0000);
23882603}
23892604
23902605test "big.int shift-left multi" {
2391 var a = try Int.initSet(al, 0x1fffe0001dddc222);
2606 var a = try Int.initSet(testing.allocator, 0x1fffe0001dddc222);
2607 defer a.deinit();
23922608 try a.shiftLeft(a, 67);
23932609
23942610 testing.expect((try a.to(u128)) == 0xffff0000eeee11100000000000000000);
23952611}
23962612
23972613test "big.int shift-right negative" {
2398 var a = try Int.init(al);
2614 var a = try Int.init(testing.allocator);
2615 defer a.deinit();
23992616
2400 try a.shiftRight(try Int.initSet(al, -20), 2);
2617 try a.shiftRight(try Int.initSet(testing.allocator, -20), 2);
2618 defer a.deinit();
24012619 testing.expect((try a.to(i32)) == -20 >> 2);
24022620
2403 try a.shiftRight(try Int.initSet(al, -5), 10);
2621 try a.shiftRight(try Int.initSet(testing.allocator, -5), 10);
2622 defer a.deinit();
24042623 testing.expect((try a.to(i32)) == -5 >> 10);
24052624}
24062625
24072626test "big.int shift-left negative" {
2408 var a = try Int.init(al);
2627 var a = try Int.init(testing.allocator);
2628 defer a.deinit();
24092629
2410 try a.shiftRight(try Int.initSet(al, -10), 1232);
2630 try a.shiftRight(try Int.initSet(testing.allocator, -10), 1232);
2631 defer a.deinit();
24112632 testing.expect((try a.to(i32)) == -10 >> 1232);
24122633}
24132634
24142635test "big.int bitwise and simple" {
2415 var a = try Int.initSet(al, 0xffffffff11111111);
2416 var b = try Int.initSet(al, 0xeeeeeeee22222222);
2636 var a = try Int.initSet(testing.allocator, 0xffffffff11111111);
2637 defer a.deinit();
2638 var b = try Int.initSet(testing.allocator, 0xeeeeeeee22222222);
2639 defer b.deinit();
24172640
24182641 try a.bitAnd(a, b);
24192642
......@@ -2421,8 +2644,10 @@ test "big.int bitwise and simple" {
24212644}
24222645
24232646test "big.int bitwise and multi-limb" {
2424 var a = try Int.initSet(al, maxInt(Limb) + 1);
2425 var b = try Int.initSet(al, maxInt(Limb));
2647 var a = try Int.initSet(testing.allocator, maxInt(Limb) + 1);
2648 defer a.deinit();
2649 var b = try Int.initSet(testing.allocator, maxInt(Limb));
2650 defer b.deinit();
24262651
24272652 try a.bitAnd(a, b);
24282653
......@@ -2430,8 +2655,10 @@ test "big.int bitwise and multi-limb" {
24302655}
24312656
24322657test "big.int bitwise xor simple" {
2433 var a = try Int.initSet(al, 0xffffffff11111111);
2434 var b = try Int.initSet(al, 0xeeeeeeee22222222);
2658 var a = try Int.initSet(testing.allocator, 0xffffffff11111111);
2659 defer a.deinit();
2660 var b = try Int.initSet(testing.allocator, 0xeeeeeeee22222222);
2661 defer b.deinit();
24352662
24362663 try a.bitXor(a, b);
24372664
......@@ -2439,8 +2666,10 @@ test "big.int bitwise xor simple" {
24392666}
24402667
24412668test "big.int bitwise xor multi-limb" {
2442 var a = try Int.initSet(al, maxInt(Limb) + 1);
2443 var b = try Int.initSet(al, maxInt(Limb));
2669 var a = try Int.initSet(testing.allocator, maxInt(Limb) + 1);
2670 defer a.deinit();
2671 var b = try Int.initSet(testing.allocator, maxInt(Limb));
2672 defer b.deinit();
24442673
24452674 try a.bitXor(a, b);
24462675
......@@ -2448,8 +2677,10 @@ test "big.int bitwise xor multi-limb" {
24482677}
24492678
24502679test "big.int bitwise or simple" {
2451 var a = try Int.initSet(al, 0xffffffff11111111);
2452 var b = try Int.initSet(al, 0xeeeeeeee22222222);
2680 var a = try Int.initSet(testing.allocator, 0xffffffff11111111);
2681 defer a.deinit();
2682 var b = try Int.initSet(testing.allocator, 0xeeeeeeee22222222);
2683 defer b.deinit();
24532684
24542685 try a.bitOr(a, b);
24552686
......@@ -2457,8 +2688,10 @@ test "big.int bitwise or simple" {
24572688}
24582689
24592690test "big.int bitwise or multi-limb" {
2460 var a = try Int.initSet(al, maxInt(Limb) + 1);
2461 var b = try Int.initSet(al, maxInt(Limb));
2691 var a = try Int.initSet(testing.allocator, maxInt(Limb) + 1);
2692 defer a.deinit();
2693 var b = try Int.initSet(testing.allocator, maxInt(Limb));
2694 defer b.deinit();
24622695
24632696 try a.bitOr(a, b);
24642697
......@@ -2467,11 +2700,19 @@ test "big.int bitwise or multi-limb" {
24672700}
24682701
24692702test "big.int var args" {
2470 var a = try Int.initSet(al, 5);
2703 var a = try Int.initSet(testing.allocator, 5);
2704 defer a.deinit();
24712705
2472 try a.add(a, try Int.initSet(al, 6));
2706 const b = try Int.initSet(testing.allocator, 6);
2707 defer b.deinit();
2708 try a.add(a, b);
24732709 testing.expect((try a.to(u64)) == 11);
24742710
2475 testing.expect(a.cmp(try Int.initSet(al, 11)) == 0);
2476 testing.expect(a.cmp(try Int.initSet(al, 14)) <= 0);
2711 const c = try Int.initSet(testing.allocator, 11);
2712 defer c.deinit();
2713 testing.expect(a.cmp(c) == 0);
2714
2715 const d = try Int.initSet(testing.allocator, 14);
2716 defer d.deinit();
2717 testing.expect(a.cmp(d) <= 0);
24772718}
lib/std/math/big/rational.zig+98-53
......@@ -587,14 +587,13 @@ fn gcdLehmer(r: *Int, xa: Int, ya: Int) !void {
587587 r.swap(&x);
588588}
589589
590var buffer: [64 * 8192]u8 = undefined;
591var fixed = std.heap.FixedBufferAllocator.init(buffer[0..]);
592var al = &fixed.allocator;
593
594590test "big.rational gcd non-one small" {
595 var a = try Int.initSet(al, 17);
596 var b = try Int.initSet(al, 97);
597 var r = try Int.init(al);
591 var a = try Int.initSet(testing.allocator, 17);
592 defer a.deinit();
593 var b = try Int.initSet(testing.allocator, 97);
594 defer b.deinit();
595 var r = try Int.init(testing.allocator);
596 defer r.deinit();
598597
599598 try gcd(&r, a, b);
600599
......@@ -602,9 +601,12 @@ test "big.rational gcd non-one small" {
602601}
603602
604603test "big.rational gcd non-one small" {
605 var a = try Int.initSet(al, 4864);
606 var b = try Int.initSet(al, 3458);
607 var r = try Int.init(al);
604 var a = try Int.initSet(testing.allocator, 4864);
605 defer a.deinit();
606 var b = try Int.initSet(testing.allocator, 3458);
607 defer b.deinit();
608 var r = try Int.init(testing.allocator);
609 defer r.deinit();
608610
609611 try gcd(&r, a, b);
610612
......@@ -612,9 +614,12 @@ test "big.rational gcd non-one small" {
612614}
613615
614616test "big.rational gcd non-one large" {
615 var a = try Int.initSet(al, 0xffffffffffffffff);
616 var b = try Int.initSet(al, 0xffffffffffffffff7777);
617 var r = try Int.init(al);
617 var a = try Int.initSet(testing.allocator, 0xffffffffffffffff);
618 defer a.deinit();
619 var b = try Int.initSet(testing.allocator, 0xffffffffffffffff7777);
620 defer b.deinit();
621 var r = try Int.init(testing.allocator);
622 defer r.deinit();
618623
619624 try gcd(&r, a, b);
620625
......@@ -622,9 +627,12 @@ test "big.rational gcd non-one large" {
622627}
623628
624629test "big.rational gcd large multi-limb result" {
625 var a = try Int.initSet(al, 0x12345678123456781234567812345678123456781234567812345678);
626 var b = try Int.initSet(al, 0x12345671234567123456712345671234567123456712345671234567);
627 var r = try Int.init(al);
630 var a = try Int.initSet(testing.allocator, 0x12345678123456781234567812345678123456781234567812345678);
631 defer a.deinit();
632 var b = try Int.initSet(testing.allocator, 0x12345671234567123456712345671234567123456712345671234567);
633 defer b.deinit();
634 var r = try Int.init(testing.allocator);
635 defer r.deinit();
628636
629637 try gcd(&r, a, b);
630638
......@@ -632,9 +640,12 @@ test "big.rational gcd large multi-limb result" {
632640}
633641
634642test "big.rational gcd one large" {
635 var a = try Int.initSet(al, 1897056385327307);
636 var b = try Int.initSet(al, 2251799813685248);
637 var r = try Int.init(al);
643 var a = try Int.initSet(testing.allocator, 1897056385327307);
644 defer a.deinit();
645 var b = try Int.initSet(testing.allocator, 2251799813685248);
646 defer b.deinit();
647 var r = try Int.init(testing.allocator);
648 defer r.deinit();
638649
639650 try gcd(&r, a, b);
640651
......@@ -661,7 +672,8 @@ fn extractLowBits(a: Int, comptime T: type) T {
661672}
662673
663674test "big.rational extractLowBits" {
664 var a = try Int.initSet(al, 0x11112222333344441234567887654321);
675 var a = try Int.initSet(testing.allocator, 0x11112222333344441234567887654321);
676 defer a.deinit();
665677
666678 const a1 = extractLowBits(a, u8);
667679 testing.expect(a1 == 0x21);
......@@ -680,7 +692,8 @@ test "big.rational extractLowBits" {
680692}
681693
682694test "big.rational set" {
683 var a = try Rational.init(al);
695 var a = try Rational.init(testing.allocator);
696 defer a.deinit();
684697
685698 try a.setInt(5);
686699 testing.expect((try a.p.to(u32)) == 5);
......@@ -708,7 +721,8 @@ test "big.rational set" {
708721}
709722
710723test "big.rational setFloat" {
711 var a = try Rational.init(al);
724 var a = try Rational.init(testing.allocator);
725 defer a.deinit();
712726
713727 try a.setFloat(f64, 2.5);
714728 testing.expect((try a.p.to(i32)) == 5);
......@@ -732,7 +746,8 @@ test "big.rational setFloat" {
732746}
733747
734748test "big.rational setFloatString" {
735 var a = try Rational.init(al);
749 var a = try Rational.init(testing.allocator);
750 defer a.deinit();
736751
737752 try a.setFloatString("72.14159312071241458852455252781510353");
738753
......@@ -742,7 +757,8 @@ test "big.rational setFloatString" {
742757}
743758
744759test "big.rational toFloat" {
745 var a = try Rational.init(al);
760 var a = try Rational.init(testing.allocator);
761 defer a.deinit();
746762
747763 // = 3.14159297943115234375
748764 try a.setRatio(3294199, 1048576);
......@@ -754,7 +770,8 @@ test "big.rational toFloat" {
754770}
755771
756772test "big.rational set/to Float round-trip" {
757 var a = try Rational.init(al);
773 var a = try Rational.init(testing.allocator);
774 defer a.deinit();
758775 var prng = std.rand.DefaultPrng.init(0x5EED);
759776 var i: usize = 0;
760777 while (i < 512) : (i += 1) {
......@@ -765,23 +782,29 @@ test "big.rational set/to Float round-trip" {
765782}
766783
767784test "big.rational copy" {
768 var a = try Rational.init(al);
785 var a = try Rational.init(testing.allocator);
786 defer a.deinit();
769787
770 const b = try Int.initSet(al, 5);
788 const b = try Int.initSet(testing.allocator, 5);
789 defer b.deinit();
771790
772791 try a.copyInt(b);
773792 testing.expect((try a.p.to(u32)) == 5);
774793 testing.expect((try a.q.to(u32)) == 1);
775794
776 const c = try Int.initSet(al, 7);
777 const d = try Int.initSet(al, 3);
795 const c = try Int.initSet(testing.allocator, 7);
796 defer c.deinit();
797 const d = try Int.initSet(testing.allocator, 3);
798 defer d.deinit();
778799
779800 try a.copyRatio(c, d);
780801 testing.expect((try a.p.to(u32)) == 7);
781802 testing.expect((try a.q.to(u32)) == 3);
782803
783 const e = try Int.initSet(al, 9);
784 const f = try Int.initSet(al, 3);
804 const e = try Int.initSet(testing.allocator, 9);
805 defer e.deinit();
806 const f = try Int.initSet(testing.allocator, 3);
807 defer f.deinit();
785808
786809 try a.copyRatio(e, f);
787810 testing.expect((try a.p.to(u32)) == 3);
......@@ -789,7 +812,8 @@ test "big.rational copy" {
789812}
790813
791814test "big.rational negate" {
792 var a = try Rational.init(al);
815 var a = try Rational.init(testing.allocator);
816 defer a.deinit();
793817
794818 try a.setInt(-50);
795819 testing.expect((try a.p.to(i32)) == -50);
......@@ -805,7 +829,8 @@ test "big.rational negate" {
805829}
806830
807831test "big.rational abs" {
808 var a = try Rational.init(al);
832 var a = try Rational.init(testing.allocator);
833 defer a.deinit();
809834
810835 try a.setInt(-50);
811836 testing.expect((try a.p.to(i32)) == -50);
......@@ -821,8 +846,10 @@ test "big.rational abs" {
821846}
822847
823848test "big.rational swap" {
824 var a = try Rational.init(al);
825 var b = try Rational.init(al);
849 var a = try Rational.init(testing.allocator);
850 defer a.deinit();
851 var b = try Rational.init(testing.allocator);
852 defer b.deinit();
826853
827854 try a.setRatio(50, 23);
828855 try b.setRatio(17, 3);
......@@ -843,8 +870,10 @@ test "big.rational swap" {
843870}
844871
845872test "big.rational cmp" {
846 var a = try Rational.init(al);
847 var b = try Rational.init(al);
873 var a = try Rational.init(testing.allocator);
874 defer a.deinit();
875 var b = try Rational.init(testing.allocator);
876 defer b.deinit();
848877
849878 try a.setRatio(500, 231);
850879 try b.setRatio(18903, 8584);
......@@ -856,8 +885,10 @@ test "big.rational cmp" {
856885}
857886
858887test "big.rational add single-limb" {
859 var a = try Rational.init(al);
860 var b = try Rational.init(al);
888 var a = try Rational.init(testing.allocator);
889 defer a.deinit();
890 var b = try Rational.init(testing.allocator);
891 defer b.deinit();
861892
862893 try a.setRatio(500, 231);
863894 try b.setRatio(18903, 8584);
......@@ -869,9 +900,12 @@ test "big.rational add single-limb" {
869900}
870901
871902test "big.rational add" {
872 var a = try Rational.init(al);
873 var b = try Rational.init(al);
874 var r = try Rational.init(al);
903 var a = try Rational.init(testing.allocator);
904 defer a.deinit();
905 var b = try Rational.init(testing.allocator);
906 defer b.deinit();
907 var r = try Rational.init(testing.allocator);
908 defer r.deinit();
875909
876910 try a.setRatio(78923, 23341);
877911 try b.setRatio(123097, 12441414);
......@@ -882,9 +916,12 @@ test "big.rational add" {
882916}
883917
884918test "big.rational sub" {
885 var a = try Rational.init(al);
886 var b = try Rational.init(al);
887 var r = try Rational.init(al);
919 var a = try Rational.init(testing.allocator);
920 defer a.deinit();
921 var b = try Rational.init(testing.allocator);
922 defer b.deinit();
923 var r = try Rational.init(testing.allocator);
924 defer r.deinit();
888925
889926 try a.setRatio(78923, 23341);
890927 try b.setRatio(123097, 12441414);
......@@ -895,9 +932,12 @@ test "big.rational sub" {
895932}
896933
897934test "big.rational mul" {
898 var a = try Rational.init(al);
899 var b = try Rational.init(al);
900 var r = try Rational.init(al);
935 var a = try Rational.init(testing.allocator);
936 defer a.deinit();
937 var b = try Rational.init(testing.allocator);
938 defer b.deinit();
939 var r = try Rational.init(testing.allocator);
940 defer r.deinit();
901941
902942 try a.setRatio(78923, 23341);
903943 try b.setRatio(123097, 12441414);
......@@ -908,9 +948,12 @@ test "big.rational mul" {
908948}
909949
910950test "big.rational div" {
911 var a = try Rational.init(al);
912 var b = try Rational.init(al);
913 var r = try Rational.init(al);
951 var a = try Rational.init(testing.allocator);
952 defer a.deinit();
953 var b = try Rational.init(testing.allocator);
954 defer b.deinit();
955 var r = try Rational.init(testing.allocator);
956 defer r.deinit();
914957
915958 try a.setRatio(78923, 23341);
916959 try b.setRatio(123097, 12441414);
......@@ -921,8 +964,10 @@ test "big.rational div" {
921964}
922965
923966test "big.rational div" {
924 var a = try Rational.init(al);
925 var r = try Rational.init(al);
967 var a = try Rational.init(testing.allocator);
968 defer a.deinit();
969 var r = try Rational.init(testing.allocator);
970 defer r.deinit();
926971
927972 try a.setRatio(78923, 23341);
928973 a.invert();
lib/std/mem.zig+30-14
......@@ -1011,11 +1011,21 @@ pub fn join(allocator: *Allocator, separator: []const u8, slices: []const []cons
10111011}
10121012
10131013test "mem.join" {
1014 var buf: [1024]u8 = undefined;
1015 const a = &std.heap.FixedBufferAllocator.init(&buf).allocator;
1016 testing.expect(eql(u8, try join(a, ",", &[_][]const u8{ "a", "b", "c" }), "a,b,c"));
1017 testing.expect(eql(u8, try join(a, ",", &[_][]const u8{"a"}), "a"));
1018 testing.expect(eql(u8, try join(a, ",", &[_][]const u8{ "a", "", "b", "", "c" }), "a,,b,,c"));
1014 {
1015 const str = try join(testing.allocator, ",", &[_][]const u8{ "a", "b", "c" });
1016 defer testing.allocator.free(str);
1017 testing.expect(eql(u8, str, "a,b,c"));
1018 }
1019 {
1020 const str = try join(testing.allocator, ",", &[_][]const u8{"a"});
1021 defer testing.allocator.free(str);
1022 testing.expect(eql(u8, str, "a"));
1023 }
1024 {
1025 const str = try join(testing.allocator, ",", &[_][]const u8{ "a", "", "b", "", "c" });
1026 defer testing.allocator.free(str);
1027 testing.expect(eql(u8, str, "a,,b,,c"));
1028 }
10191029}
10201030
10211031/// Copies each T from slices into a new slice that exactly holds all the elements.
......@@ -1044,15 +1054,21 @@ pub fn concat(allocator: *Allocator, comptime T: type, slices: []const []const T
10441054}
10451055
10461056test "concat" {
1047 var buf: [1024]u8 = undefined;
1048 const a = &std.heap.FixedBufferAllocator.init(&buf).allocator;
1049 testing.expect(eql(u8, try concat(a, u8, &[_][]const u8{ "abc", "def", "ghi" }), "abcdefghi"));
1050 testing.expect(eql(u32, try concat(a, u32, &[_][]const u32{
1051 &[_]u32{ 0, 1 },
1052 &[_]u32{ 2, 3, 4 },
1053 &[_]u32{},
1054 &[_]u32{5},
1055 }), &[_]u32{ 0, 1, 2, 3, 4, 5 }));
1057 {
1058 const str = try concat(testing.allocator, u8, &[_][]const u8{ "abc", "def", "ghi" });
1059 defer testing.allocator.free(str);
1060 testing.expect(eql(u8, str, "abcdefghi"));
1061 }
1062 {
1063 const str = try concat(testing.allocator, u32, &[_][]const u32{
1064 &[_]u32{ 0, 1 },
1065 &[_]u32{ 2, 3, 4 },
1066 &[_]u32{},
1067 &[_]u32{5},
1068 });
1069 defer testing.allocator.free(str);
1070 testing.expect(eql(u32, str, &[_]u32{ 0, 1, 2, 3, 4, 5 }));
1071 }
10561072}
10571073
10581074test "testStringEquality" {
lib/std/meta.zig+64-59
......@@ -7,13 +7,12 @@ const testing = std.testing;
77
88pub const trait = @import("meta/trait.zig");
99
10const TypeId = builtin.TypeId;
1110const TypeInfo = builtin.TypeInfo;
1211
1312pub fn tagName(v: var) []const u8 {
1413 const T = @TypeOf(v);
1514 switch (@typeInfo(T)) {
16 TypeId.ErrorSet => return @errorName(v),
15 .ErrorSet => return @errorName(v),
1716 else => return @tagName(v),
1817 }
1918}
......@@ -55,7 +54,7 @@ test "std.meta.tagName" {
5554
5655pub fn stringToEnum(comptime T: type, str: []const u8) ?T {
5756 inline for (@typeInfo(T).Enum.fields) |enumField| {
58 if (std.mem.eql(u8, str, enumField.name)) {
57 if (mem.eql(u8, str, enumField.name)) {
5958 return @field(T, enumField.name);
6059 }
6160 }
......@@ -74,9 +73,9 @@ test "std.meta.stringToEnum" {
7473
7574pub fn bitCount(comptime T: type) comptime_int {
7675 return switch (@typeInfo(T)) {
77 TypeId.Bool => 1,
78 TypeId.Int => |info| info.bits,
79 TypeId.Float => |info| info.bits,
76 .Bool => 1,
77 .Int => |info| info.bits,
78 .Float => |info| info.bits,
8079 else => @compileError("Expected bool, int or float type, found '" ++ @typeName(T) ++ "'"),
8180 };
8281}
......@@ -88,7 +87,7 @@ test "std.meta.bitCount" {
8887
8988pub fn alignment(comptime T: type) comptime_int {
9089 //@alignOf works on non-pointer types
91 const P = if (comptime trait.is(TypeId.Pointer)(T)) T else *T;
90 const P = if (comptime trait.is(.Pointer)(T)) T else *T;
9291 return @typeInfo(P).Pointer.alignment;
9392}
9493
......@@ -102,9 +101,9 @@ test "std.meta.alignment" {
102101
103102pub fn Child(comptime T: type) type {
104103 return switch (@typeInfo(T)) {
105 TypeId.Array => |info| info.child,
106 TypeId.Pointer => |info| info.child,
107 TypeId.Optional => |info| info.child,
104 .Array => |info| info.child,
105 .Pointer => |info| info.child,
106 .Optional => |info| info.child,
108107 else => @compileError("Expected pointer, optional, or array type, " ++ "found '" ++ @typeName(T) ++ "'"),
109108 };
110109}
......@@ -118,9 +117,9 @@ test "std.meta.Child" {
118117
119118pub fn containerLayout(comptime T: type) TypeInfo.ContainerLayout {
120119 return switch (@typeInfo(T)) {
121 TypeId.Struct => |info| info.layout,
122 TypeId.Enum => |info| info.layout,
123 TypeId.Union => |info| info.layout,
120 .Struct => |info| info.layout,
121 .Enum => |info| info.layout,
122 .Union => |info| info.layout,
124123 else => @compileError("Expected struct, enum or union type, found '" ++ @typeName(T) ++ "'"),
125124 };
126125}
......@@ -148,22 +147,22 @@ test "std.meta.containerLayout" {
148147 a: u8,
149148 };
150149
151 testing.expect(containerLayout(E1) == TypeInfo.ContainerLayout.Auto);
152 testing.expect(containerLayout(E2) == TypeInfo.ContainerLayout.Packed);
153 testing.expect(containerLayout(E3) == TypeInfo.ContainerLayout.Extern);
154 testing.expect(containerLayout(S1) == TypeInfo.ContainerLayout.Auto);
155 testing.expect(containerLayout(S2) == TypeInfo.ContainerLayout.Packed);
156 testing.expect(containerLayout(S3) == TypeInfo.ContainerLayout.Extern);
157 testing.expect(containerLayout(U1) == TypeInfo.ContainerLayout.Auto);
158 testing.expect(containerLayout(U2) == TypeInfo.ContainerLayout.Packed);
159 testing.expect(containerLayout(U3) == TypeInfo.ContainerLayout.Extern);
150 testing.expect(containerLayout(E1) == .Auto);
151 testing.expect(containerLayout(E2) == .Packed);
152 testing.expect(containerLayout(E3) == .Extern);
153 testing.expect(containerLayout(S1) == .Auto);
154 testing.expect(containerLayout(S2) == .Packed);
155 testing.expect(containerLayout(S3) == .Extern);
156 testing.expect(containerLayout(U1) == .Auto);
157 testing.expect(containerLayout(U2) == .Packed);
158 testing.expect(containerLayout(U3) == .Extern);
160159}
161160
162161pub fn declarations(comptime T: type) []TypeInfo.Declaration {
163162 return switch (@typeInfo(T)) {
164 TypeId.Struct => |info| info.decls,
165 TypeId.Enum => |info| info.decls,
166 TypeId.Union => |info| info.decls,
163 .Struct => |info| info.decls,
164 .Enum => |info| info.decls,
165 .Union => |info| info.decls,
167166 else => @compileError("Expected struct, enum or union type, found '" ++ @typeName(T) ++ "'"),
168167 };
169168}
......@@ -232,17 +231,17 @@ test "std.meta.declarationInfo" {
232231}
233232
234233pub fn fields(comptime T: type) switch (@typeInfo(T)) {
235 TypeId.Struct => []TypeInfo.StructField,
236 TypeId.Union => []TypeInfo.UnionField,
237 TypeId.ErrorSet => []TypeInfo.Error,
238 TypeId.Enum => []TypeInfo.EnumField,
234 .Struct => []TypeInfo.StructField,
235 .Union => []TypeInfo.UnionField,
236 .ErrorSet => []TypeInfo.Error,
237 .Enum => []TypeInfo.EnumField,
239238 else => @compileError("Expected struct, union, error set or enum type, found '" ++ @typeName(T) ++ "'"),
240239} {
241240 return switch (@typeInfo(T)) {
242 TypeId.Struct => |info| info.fields,
243 TypeId.Union => |info| info.fields,
244 TypeId.Enum => |info| info.fields,
245 TypeId.ErrorSet => |errors| errors.?, // must be non global error set
241 .Struct => |info| info.fields,
242 .Union => |info| info.fields,
243 .Enum => |info| info.fields,
244 .ErrorSet => |errors| errors.?, // must be non global error set
246245 else => @compileError("Expected struct, union, error set or enum type, found '" ++ @typeName(T) ++ "'"),
247246 };
248247}
......@@ -277,10 +276,10 @@ test "std.meta.fields" {
277276}
278277
279278pub fn fieldInfo(comptime T: type, comptime field_name: []const u8) switch (@typeInfo(T)) {
280 TypeId.Struct => TypeInfo.StructField,
281 TypeId.Union => TypeInfo.UnionField,
282 TypeId.ErrorSet => TypeInfo.Error,
283 TypeId.Enum => TypeInfo.EnumField,
279 .Struct => TypeInfo.StructField,
280 .Union => TypeInfo.UnionField,
281 .ErrorSet => TypeInfo.Error,
282 .Enum => TypeInfo.EnumField,
284283 else => @compileError("Expected struct, union, error set or enum type, found '" ++ @typeName(T) ++ "'"),
285284} {
286285 inline for (comptime fields(T)) |field| {
......@@ -318,8 +317,8 @@ test "std.meta.fieldInfo" {
318317
319318pub fn TagType(comptime T: type) type {
320319 return switch (@typeInfo(T)) {
321 TypeId.Enum => |info| info.tag_type,
322 TypeId.Union => |info| if (info.tag_type) |Tag| Tag else null,
320 .Enum => |info| info.tag_type,
321 .Union => |info| if (info.tag_type) |Tag| Tag else null,
323322 else => @compileError("expected enum or union type, found '" ++ @typeName(T) ++ "'"),
324323 };
325324}
......@@ -365,7 +364,7 @@ test "std.meta.activeTag" {
365364///Given a tagged union type, and an enum, return the type of the union
366365/// field corresponding to the enum tag.
367366pub fn TagPayloadType(comptime U: type, tag: @TagType(U)) type {
368 testing.expect(trait.is(builtin.TypeId.Union)(U));
367 testing.expect(trait.is(.Union)(U));
369368
370369 const info = @typeInfo(U).Union;
371370
......@@ -387,30 +386,26 @@ test "std.meta.TagPayloadType" {
387386 testing.expect(MovedEvent == @TypeOf(e.Moved));
388387}
389388
390///Compares two of any type for equality. Containers are compared on a field-by-field basis,
389/// Compares two of any type for equality. Containers are compared on a field-by-field basis,
391390/// where possible. Pointers are not followed.
392391pub fn eql(a: var, b: @TypeOf(a)) bool {
393392 const T = @TypeOf(a);
394393
395 switch (@typeId(T)) {
396 builtin.TypeId.Struct => {
397 const info = @typeInfo(T).Struct;
398
394 switch (@typeInfo(T)) {
395 .Struct => |info| {
399396 inline for (info.fields) |field_info| {
400397 if (!eql(@field(a, field_info.name), @field(b, field_info.name))) return false;
401398 }
402399 return true;
403400 },
404 builtin.TypeId.ErrorUnion => {
401 .ErrorUnion => {
405402 if (a) |a_p| {
406403 if (b) |b_p| return eql(a_p, b_p) else |_| return false;
407404 } else |a_e| {
408405 if (b) |_| return false else |b_e| return a_e == b_e;
409406 }
410407 },
411 builtin.TypeId.Union => {
412 const info = @typeInfo(T).Union;
413
408 .Union => |info| {
414409 if (info.tag_type) |_| {
415410 const tag_a = activeTag(a);
416411 const tag_b = activeTag(b);
......@@ -427,23 +422,26 @@ pub fn eql(a: var, b: @TypeOf(a)) bool {
427422
428423 @compileError("cannot compare untagged union type " ++ @typeName(T));
429424 },
430 builtin.TypeId.Array => {
425 .Array => {
431426 if (a.len != b.len) return false;
432427 for (a) |e, i|
433428 if (!eql(e, b[i])) return false;
434429 return true;
435430 },
436 builtin.TypeId.Pointer => {
437 const info = @typeInfo(T).Pointer;
438 switch (info.size) {
439 builtin.TypeInfo.Pointer.Size.One,
440 builtin.TypeInfo.Pointer.Size.Many,
441 builtin.TypeInfo.Pointer.Size.C,
442 => return a == b,
443 builtin.TypeInfo.Pointer.Size.Slice => return a.ptr == b.ptr and a.len == b.len,
431 .Vector => |info| {
432 var i: usize = 0;
433 while (i < info.len) : (i += 1) {
434 if (!eql(a[i], b[i])) return false;
444435 }
436 return true;
445437 },
446 builtin.TypeId.Optional => {
438 .Pointer => |info| {
439 return switch (info.size) {
440 .One, .Many, .C, => a == b,
441 .Slice => a.ptr == b.ptr and a.len == b.len,
442 };
443 },
444 .Optional => {
447445 if (a == null and b == null) return true;
448446 if (a == null or b == null) return false;
449447 return eql(a.?, b.?);
......@@ -510,6 +508,13 @@ test "std.meta.eql" {
510508 testing.expect(eql(EU.tst(true), EU.tst(true)));
511509 testing.expect(eql(EU.tst(false), EU.tst(false)));
512510 testing.expect(!eql(EU.tst(false), EU.tst(true)));
511
512 var v1 = @splat(4, @as(u32, 1));
513 var v2 = @splat(4, @as(u32, 1));
514 var v3 = @splat(4, @as(u32, 2));
515
516 testing.expect(eql(v1, v2));
517 testing.expect(!eql(v1, v3));
513518}
514519
515520test "intToEnum with error return" {
lib/std/meta/trait.zig+43-64
......@@ -7,17 +7,11 @@ const warn = debug.warn;
77
88const meta = @import("../meta.zig");
99
10//This is necessary if we want to return generic functions directly because of how the
11// the type erasure works. see: #1375
12fn traitFnWorkaround(comptime T: type) bool {
13 return false;
14}
15
16pub const TraitFn = @TypeOf(traitFnWorkaround);
10pub const TraitFn = fn (type) bool;
1711
1812//////Trait generators
1913
20//Need TraitList because compiler can't do varargs at comptime yet
14// TODO convert to tuples when #4335 is done
2115pub const TraitList = []const TraitFn;
2216pub fn multiTrait(comptime traits: TraitList) TraitFn {
2317 const Closure = struct {
......@@ -60,8 +54,7 @@ pub fn hasFn(comptime name: []const u8) TraitFn {
6054 if (!comptime isContainer(T)) return false;
6155 if (!comptime @hasDecl(T, name)) return false;
6256 const DeclType = @TypeOf(@field(T, name));
63 const decl_type_id = @typeId(DeclType);
64 return decl_type_id == builtin.TypeId.Fn;
57 return @typeId(DeclType) == .Fn;
6558 }
6659 };
6760 return Closure.trait;
......@@ -80,11 +73,10 @@ test "std.meta.trait.hasFn" {
8073pub fn hasField(comptime name: []const u8) TraitFn {
8174 const Closure = struct {
8275 pub fn trait(comptime T: type) bool {
83 const info = @typeInfo(T);
84 const fields = switch (info) {
85 builtin.TypeId.Struct => |s| s.fields,
86 builtin.TypeId.Union => |u| u.fields,
87 builtin.TypeId.Enum => |e| e.fields,
76 const fields = switch (@typeInfo(T)) {
77 .Struct => |s| s.fields,
78 .Union => |u| u.fields,
79 .Enum => |e| e.fields,
8880 else => return false,
8981 };
9082
......@@ -120,11 +112,11 @@ pub fn is(comptime id: builtin.TypeId) TraitFn {
120112}
121113
122114test "std.meta.trait.is" {
123 testing.expect(is(builtin.TypeId.Int)(u8));
124 testing.expect(!is(builtin.TypeId.Int)(f32));
125 testing.expect(is(builtin.TypeId.Pointer)(*u8));
126 testing.expect(is(builtin.TypeId.Void)(void));
127 testing.expect(!is(builtin.TypeId.Optional)(anyerror));
115 testing.expect(is(.Int)(u8));
116 testing.expect(!is(.Int)(f32));
117 testing.expect(is(.Pointer)(*u8));
118 testing.expect(is(.Void)(void));
119 testing.expect(!is(.Optional)(anyerror));
128120}
129121
130122pub fn isPtrTo(comptime id: builtin.TypeId) TraitFn {
......@@ -138,9 +130,9 @@ pub fn isPtrTo(comptime id: builtin.TypeId) TraitFn {
138130}
139131
140132test "std.meta.trait.isPtrTo" {
141 testing.expect(!isPtrTo(builtin.TypeId.Struct)(struct {}));
142 testing.expect(isPtrTo(builtin.TypeId.Struct)(*struct {}));
143 testing.expect(!isPtrTo(builtin.TypeId.Struct)(**struct {}));
133 testing.expect(!isPtrTo(.Struct)(struct {}));
134 testing.expect(isPtrTo(.Struct)(*struct {}));
135 testing.expect(!isPtrTo(.Struct)(**struct {}));
144136}
145137
146138///////////Strait trait Fns
......@@ -149,12 +141,10 @@ test "std.meta.trait.isPtrTo" {
149141// Somewhat limited since we can't apply this logic to normal variables, fields, or
150142// Fns yet. Should be isExternType?
151143pub fn isExtern(comptime T: type) bool {
152 const Extern = builtin.TypeInfo.ContainerLayout.Extern;
153 const info = @typeInfo(T);
154 return switch (info) {
155 builtin.TypeId.Struct => |s| s.layout == Extern,
156 builtin.TypeId.Union => |u| u.layout == Extern,
157 builtin.TypeId.Enum => |e| e.layout == Extern,
144 return switch (@typeInfo(T)) {
145 .Struct => |s| s.layout == .Extern,
146 .Union => |u| u.layout == .Extern,
147 .Enum => |e| e.layout == .Extern,
158148 else => false,
159149 };
160150}
......@@ -169,12 +159,10 @@ test "std.meta.trait.isExtern" {
169159}
170160
171161pub fn isPacked(comptime T: type) bool {
172 const Packed = builtin.TypeInfo.ContainerLayout.Packed;
173 const info = @typeInfo(T);
174 return switch (info) {
175 builtin.TypeId.Struct => |s| s.layout == Packed,
176 builtin.TypeId.Union => |u| u.layout == Packed,
177 builtin.TypeId.Enum => |e| e.layout == Packed,
162 return switch (@typeInfo(T)) {
163 .Struct => |s| s.layout == .Packed,
164 .Union => |u| u.layout == .Packed,
165 .Enum => |e| e.layout == .Packed,
178166 else => false,
179167 };
180168}
......@@ -189,8 +177,8 @@ test "std.meta.trait.isPacked" {
189177}
190178
191179pub fn isUnsignedInt(comptime T: type) bool {
192 return switch (@typeId(T)) {
193 builtin.TypeId.Int => !@typeInfo(T).Int.is_signed,
180 return switch (@typeInfo(T)) {
181 .Int => |i| !i.is_signed,
194182 else => false,
195183 };
196184}
......@@ -203,9 +191,9 @@ test "isUnsignedInt" {
203191}
204192
205193pub fn isSignedInt(comptime T: type) bool {
206 return switch (@typeId(T)) {
207 builtin.TypeId.ComptimeInt => true,
208 builtin.TypeId.Int => @typeInfo(T).Int.is_signed,
194 return switch (@typeInfo(T)) {
195 .ComptimeInt => true,
196 .Int => |i| i.is_signed,
209197 else => false,
210198 };
211199}
......@@ -218,9 +206,8 @@ test "isSignedInt" {
218206}
219207
220208pub fn isSingleItemPtr(comptime T: type) bool {
221 if (comptime is(builtin.TypeId.Pointer)(T)) {
222 const info = @typeInfo(T);
223 return info.Pointer.size == builtin.TypeInfo.Pointer.Size.One;
209 if (comptime is(.Pointer)(T)) {
210 return @typeInfo(T).Pointer.size == .One;
224211 }
225212 return false;
226213}
......@@ -233,9 +220,8 @@ test "std.meta.trait.isSingleItemPtr" {
233220}
234221
235222pub fn isManyItemPtr(comptime T: type) bool {
236 if (comptime is(builtin.TypeId.Pointer)(T)) {
237 const info = @typeInfo(T);
238 return info.Pointer.size == builtin.TypeInfo.Pointer.Size.Many;
223 if (comptime is(.Pointer)(T)) {
224 return @typeInfo(T).Pointer.size == .Many;
239225 }
240226 return false;
241227}
......@@ -249,9 +235,8 @@ test "std.meta.trait.isManyItemPtr" {
249235}
250236
251237pub fn isSlice(comptime T: type) bool {
252 if (comptime is(builtin.TypeId.Pointer)(T)) {
253 const info = @typeInfo(T);
254 return info.Pointer.size == builtin.TypeInfo.Pointer.Size.Slice;
238 if (comptime is(.Pointer)(T)) {
239 return @typeInfo(T).Pointer.size == .Slice;
255240 }
256241 return false;
257242}
......@@ -264,15 +249,13 @@ test "std.meta.trait.isSlice" {
264249}
265250
266251pub fn isIndexable(comptime T: type) bool {
267 if (comptime is(builtin.TypeId.Pointer)(T)) {
268 const info = @typeInfo(T);
269 if (info.Pointer.size == builtin.TypeInfo.Pointer.Size.One) {
270 if (comptime is(builtin.TypeId.Array)(meta.Child(T))) return true;
271 return false;
252 if (comptime is(.Pointer)(T)) {
253 if (@typeInfo(T).Pointer.size == .One) {
254 return (comptime is(.Array)(meta.Child(T)));
272255 }
273256 return true;
274257 }
275 return comptime is(builtin.TypeId.Array)(T);
258 return comptime is(.Array)(T);
276259}
277260
278261test "std.meta.trait.isIndexable" {
......@@ -287,7 +270,7 @@ test "std.meta.trait.isIndexable" {
287270
288271pub fn isNumber(comptime T: type) bool {
289272 return switch (@typeId(T)) {
290 builtin.TypeId.Int, builtin.TypeId.Float, builtin.TypeId.ComptimeInt, builtin.TypeId.ComptimeFloat => true,
273 .Int, .Float, .ComptimeInt, .ComptimeFloat => true,
291274 else => false,
292275 };
293276}
......@@ -307,9 +290,8 @@ test "std.meta.trait.isNumber" {
307290}
308291
309292pub fn isConstPtr(comptime T: type) bool {
310 if (!comptime is(builtin.TypeId.Pointer)(T)) return false;
311 const info = @typeInfo(T);
312 return info.Pointer.is_const;
293 if (!comptime is(.Pointer)(T)) return false;
294 return @typeInfo(T).Pointer.is_const;
313295}
314296
315297test "std.meta.trait.isConstPtr" {
......@@ -322,11 +304,8 @@ test "std.meta.trait.isConstPtr" {
322304}
323305
324306pub fn isContainer(comptime T: type) bool {
325 const info = @typeInfo(T);
326 return switch (info) {
327 builtin.TypeId.Struct => true,
328 builtin.TypeId.Union => true,
329 builtin.TypeId.Enum => true,
307 return switch (@typeId(T)) {
308 .Struct, .Union, .Enum => true,
330309 else => false,
331310 };
332311}
lib/std/net/test.zig+1-3
......@@ -67,10 +67,8 @@ test "resolve DNS" {
6767 // DNS resolution not implemented on Windows yet.
6868 return error.SkipZigTest;
6969 }
70 var buf: [1000 * 10]u8 = undefined;
71 const a = &std.heap.FixedBufferAllocator.init(&buf).allocator;
7270
73 const address_list = net.getAddressList(a, "example.com", 80) catch |err| switch (err) {
71 const address_list = net.getAddressList(testing.allocator, "example.com", 80) catch |err| switch (err) {
7472 // The tests are required to work even when there is no Internet connection,
7573 // so some of these errors we must accept and skip the test.
7674 error.UnknownHostName => return error.SkipZigTest,
lib/std/os/test.zig+10-14
......@@ -95,8 +95,6 @@ test "cpu count" {
9595}
9696
9797test "AtomicFile" {
98 var buffer: [1024]u8 = undefined;
99 const allocator = &std.heap.FixedBufferAllocator.init(buffer[0..]).allocator;
10098 const test_out_file = "tmp_atomic_file_test_dest.txt";
10199 const test_content =
102100 \\ hello!
......@@ -108,7 +106,8 @@ test "AtomicFile" {
108106 try af.file.write(test_content);
109107 try af.finish();
110108 }
111 const content = try io.readFileAlloc(allocator, test_out_file);
109 const content = try io.readFileAlloc(testing.allocator, test_out_file);
110 defer testing.allocator.free(content);
112111 expect(mem.eql(u8, content, test_content));
113112
114113 try fs.cwd().deleteFile(test_out_file);
......@@ -276,8 +275,11 @@ test "mmap" {
276275 testing.expectEqual(@as(usize, 1234), data.len);
277276
278277 // By definition the data returned by mmap is zero-filled
279 std.mem.set(u8, data[0 .. data.len - 1], 0x55);
280 testing.expect(mem.indexOfScalar(u8, data, 0).? == 1234 - 1);
278 testing.expect(mem.eql(u8, data, &[_]u8{0x00} ** 1234));
279
280 // Make sure the memory is writeable as requested
281 std.mem.set(u8, data, 0x55);
282 testing.expect(mem.eql(u8, data, &[_]u8{0x55} ** 1234));
281283 }
282284
283285 const test_out_file = "os_tmp_test";
......@@ -300,10 +302,7 @@ test "mmap" {
300302
301303 // Map the whole file
302304 {
303 const file = try fs.cwd().createFile(test_out_file, .{
304 .read = true,
305 .truncate = false,
306 });
305 const file = try fs.cwd().openFile(test_out_file, .{});
307306 defer file.close();
308307
309308 const data = try os.mmap(
......@@ -327,15 +326,12 @@ test "mmap" {
327326
328327 // Map the upper half of the file
329328 {
330 const file = try fs.cwd().createFile(test_out_file, .{
331 .read = true,
332 .truncate = false,
333 });
329 const file = try fs.cwd().openFile(test_out_file, .{});
334330 defer file.close();
335331
336332 const data = try os.mmap(
337333 null,
338 alloc_size,
334 alloc_size / 2,
339335 os.PROT_READ,
340336 os.MAP_PRIVATE,
341337 file.handle,
lib/std/process.zig+2-4
......@@ -27,10 +27,8 @@ pub fn getCwdAlloc(allocator: *Allocator) ![]u8 {
2727}
2828
2929test "getCwdAlloc" {
30 // at least call it so it gets compiled
31 var buf: [1000]u8 = undefined;
32 const allocator = &std.heap.FixedBufferAllocator.init(&buf).allocator;
33 _ = getCwdAlloc(allocator) catch undefined;
30 const cwd = try getCwdAlloc(testing.allocator);
31 testing.allocator.free(cwd);
3432}
3533
3634/// Caller must free result when done.
lib/std/sort.zig+4-4
......@@ -1220,16 +1220,16 @@ test "sort fuzz testing" {
12201220 const test_case_count = 10;
12211221 var i: usize = 0;
12221222 while (i < test_case_count) : (i += 1) {
1223 fuzzTest(&prng.random);
1223 try fuzzTest(&prng.random);
12241224 }
12251225}
12261226
12271227var fixed_buffer_mem: [100 * 1024]u8 = undefined;
12281228
1229fn fuzzTest(rng: *std.rand.Random) void {
1229fn fuzzTest(rng: *std.rand.Random) !void {
12301230 const array_size = rng.range(usize, 0, 1000);
1231 var fixed_allocator = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]);
1232 var array = fixed_allocator.allocator.alloc(IdAndValue, array_size) catch unreachable;
1231 var array = try testing.allocator.alloc(IdAndValue, array_size);
1232 defer testing.allocator.free(array);
12331233 // populate with random data
12341234 for (array) |*item, index| {
12351235 item.id = index;
lib/std/special/compiler_rt.zig+1-1
......@@ -149,7 +149,7 @@ comptime {
149149
150150 @export(@import("compiler_rt/clzsi2.zig").__clzsi2, .{ .name = "__clzsi2", .linkage = linkage });
151151
152 if (builtin.arch.isARM() and !is_test) {
152 if ((builtin.arch.isARM() or builtin.arch.isThumb()) and !is_test) {
153153 @export(@import("compiler_rt/arm.zig").__aeabi_unwind_cpp_pr0, .{ .name = "__aeabi_unwind_cpp_pr0", .linkage = linkage });
154154 @export(@import("compiler_rt/arm.zig").__aeabi_unwind_cpp_pr1, .{ .name = "__aeabi_unwind_cpp_pr1", .linkage = linkage });
155155 @export(@import("compiler_rt/arm.zig").__aeabi_unwind_cpp_pr2, .{ .name = "__aeabi_unwind_cpp_pr2", .linkage = linkage });
lib/std/target/riscv.zig-2
......@@ -270,7 +270,6 @@ pub const cpu = struct {
270270 .d,
271271 .f,
272272 .m,
273 .relax,
274273 }),
275274 };
276275
......@@ -284,7 +283,6 @@ pub const cpu = struct {
284283 .d,
285284 .f,
286285 .m,
287 .relax,
288286 }),
289287 };
290288
lib/std/testing.zig+17-2
......@@ -12,7 +12,7 @@ pub var allocator_instance = LeakCountAllocator.init(&base_allocator_instance.al
1212pub const failing_allocator = &FailingAllocator.init(&base_allocator_instance.allocator, 0).allocator;
1313
1414pub var base_allocator_instance = std.heap.ThreadSafeFixedBufferAllocator.init(allocator_mem[0..]);
15var allocator_mem: [512 * 1024]u8 = undefined;
15var allocator_mem: [1024 * 1024]u8 = undefined;
1616
1717/// This function is intended to be used only in tests. It prints diagnostics to stderr
1818/// and then aborts when actual_error_union is not expected_error.
......@@ -56,7 +56,6 @@ pub fn expectEqual(expected: var, actual: @TypeOf(expected)) void {
5656 .EnumLiteral,
5757 .Enum,
5858 .Fn,
59 .Vector,
6059 .ErrorSet,
6160 => {
6261 if (actual != expected) {
......@@ -88,6 +87,15 @@ pub fn expectEqual(expected: var, actual: @TypeOf(expected)) void {
8887
8988 .Array => |array| expectEqualSlices(array.child, &expected, &actual),
9089
90 .Vector => |vectorType| {
91 var i: usize = 0;
92 while (i < vectorType.len) : (i += 1) {
93 if (!std.meta.eql(expected[i], actual[i])) {
94 std.debug.panic("index {} incorrect. expected {}, found {}", .{ i, expected[i], actual[i] });
95 }
96 }
97 },
98
9199 .Struct => |structType| {
92100 inline for (structType.fields) |field| {
93101 expectEqual(@field(expected, field.name), @field(actual, field.name));
......@@ -202,3 +210,10 @@ test "expectEqual nested array" {
202210
203211 expectEqual(a, b);
204212}
213
214test "expectEqual vector" {
215 var a = @splat(4, @as(u32, 4));
216 var b = @splat(4, @as(u32, 4));
217
218 expectEqual(a, b);
219}
lib/std/unicode.zig+4-6
......@@ -617,16 +617,14 @@ test "utf8ToUtf16Le" {
617617
618618test "utf8ToUtf16LeWithNull" {
619619 {
620 var bytes: [128]u8 = undefined;
621 const allocator = &std.heap.FixedBufferAllocator.init(bytes[0..]).allocator;
622 const utf16 = try utf8ToUtf16LeWithNull(allocator, "𐐷");
620 const utf16 = try utf8ToUtf16LeWithNull(testing.allocator, "𐐷");
621 defer testing.allocator.free(utf16);
623622 testing.expectEqualSlices(u8, "\x01\xd8\x37\xdc", @sliceToBytes(utf16[0..]));
624623 testing.expect(utf16[2] == 0);
625624 }
626625 {
627 var bytes: [128]u8 = undefined;
628 const allocator = &std.heap.FixedBufferAllocator.init(bytes[0..]).allocator;
629 const utf16 = try utf8ToUtf16LeWithNull(allocator, "\u{10FFFF}");
626 const utf16 = try utf8ToUtf16LeWithNull(testing.allocator, "\u{10FFFF}");
627 defer testing.allocator.free(utf16);
630628 testing.expectEqualSlices(u8, "\xff\xdb\xff\xdf", @sliceToBytes(utf16[0..]));
631629 testing.expect(utf16[2] == 0);
632630 }
lib/std/zig/parser_test.zig+1-2
......@@ -2886,8 +2886,7 @@ fn testCanonical(source: []const u8) !void {
28862886}
28872887
28882888fn testError(source: []const u8) !void {
2889 var fixed_allocator = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]);
2890 const tree = try std.zig.parse(&fixed_allocator.allocator, source);
2889 const tree = try std.zig.parse(std.testing.allocator, source);
28912890 defer tree.deinit();
28922891
28932892 std.testing.expect(tree.errors.len != 0);
src-self-hosted/translate_c.zig+25-8
......@@ -5123,6 +5123,8 @@ fn parseCNumLit(c: *Context, tok: *CToken, source: []const u8, source_loc: ZigCl
51235123 cast_node.rparen_token = try appendToken(c, .RParen, ")");
51245124 return &cast_node.base;
51255125 } else if (tok.id == .FloatLiteral) {
5126 if (lit_bytes[0] == '.')
5127 lit_bytes = try std.fmt.allocPrint(c.a(), "0{}", .{lit_bytes});
51265128 if (tok.id.FloatLiteral == .None) {
51275129 return transCreateNodeFloat(c, lit_bytes);
51285130 }
......@@ -5340,12 +5342,27 @@ fn parseCPrimaryExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8,
53405342 .LParen => {
53415343 const inner_node = try parseCExpr(c, it, source, source_loc, scope);
53425344
5343 if (it.peek().?.id == .RParen) {
5344 _ = it.next();
5345 if (it.peek().?.id != .LParen) {
5346 return inner_node;
5347 }
5348 _ = it.next();
5345 if (it.next().?.id != .RParen) {
5346 const first_tok = it.list.at(0);
5347 try failDecl(
5348 c,
5349 source_loc,
5350 source[first_tok.start..first_tok.end],
5351 "unable to translate C expr: expected ')'' here",
5352 .{},
5353 );
5354 return error.ParseError;
5355 }
5356 var saw_l_paren = false;
5357 switch (it.peek().?.id) {
5358 // (type)(to_cast)
5359 .LParen => {
5360 saw_l_paren = true;
5361 _ = it.next();
5362 },
5363 // (type)identifier
5364 .Identifier => {},
5365 else => return inner_node,
53495366 }
53505367
53515368 // hack to get zig fmt to render a comma in builtin calls
......@@ -5353,7 +5370,7 @@ fn parseCPrimaryExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8,
53535370
53545371 const node_to_cast = try parseCExpr(c, it, source, source_loc, scope);
53555372
5356 if (it.next().?.id != .RParen) {
5373 if (saw_l_paren and it.next().?.id != .RParen) {
53575374 const first_tok = it.list.at(0);
53585375 try failDecl(
53595376 c,
......@@ -5494,7 +5511,7 @@ fn parseCSuffixOpExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8,
54945511 // hack to get zig fmt to render a comma in builtin calls
54955512 _ = try appendToken(c, .Comma, ",");
54965513
5497 const ptr_kind = blk:{
5514 const ptr_kind = blk: {
54985515 // * token
54995516 _ = it.prev();
55005517 // last token of `node`
src/all_types.hpp+3-1
......@@ -1999,6 +1999,9 @@ struct CFile {
19991999
20002000// When adding fields, check if they should be added to the hash computation in build_with_cache
20012001struct CodeGen {
2002 // arena allocator destroyed just prior to codegen emit
2003 heap::ArenaAllocator *pass1_arena;
2004
20022005 //////////////////////////// Runtime State
20032006 LLVMModuleRef module;
20042007 ZigList<ErrorMsg*> errors;
......@@ -2279,7 +2282,6 @@ struct ZigVar {
22792282 Scope *parent_scope;
22802283 Scope *child_scope;
22812284 LLVMValueRef param_value_ref;
2282 IrExecutableSrc *owner_exec;
22832285
22842286 Buf *section_name;
22852287
src/analyze.cpp+94-99
......@@ -80,7 +80,7 @@ ErrorMsg *add_error_note(CodeGen *g, ErrorMsg *parent_msg, const AstNode *node,
8080}
8181
8282ZigType *new_type_table_entry(ZigTypeId id) {
83 ZigType *entry = allocate<ZigType>(1);
83 ZigType *entry = heap::c_allocator.create<ZigType>();
8484 entry->id = id;
8585 return entry;
8686}
......@@ -140,7 +140,7 @@ void init_scope(CodeGen *g, Scope *dest, ScopeId id, AstNode *source_node, Scope
140140static ScopeDecls *create_decls_scope(CodeGen *g, AstNode *node, Scope *parent, ZigType *container_type,
141141 ZigType *import, Buf *bare_name)
142142{
143 ScopeDecls *scope = allocate<ScopeDecls>(1);
143 ScopeDecls *scope = heap::c_allocator.create<ScopeDecls>();
144144 init_scope(g, &scope->base, ScopeIdDecls, node, parent);
145145 scope->decl_table.init(4);
146146 scope->container_type = container_type;
......@@ -151,7 +151,7 @@ static ScopeDecls *create_decls_scope(CodeGen *g, AstNode *node, Scope *parent,
151151
152152ScopeBlock *create_block_scope(CodeGen *g, AstNode *node, Scope *parent) {
153153 assert(node->type == NodeTypeBlock);
154 ScopeBlock *scope = allocate<ScopeBlock>(1);
154 ScopeBlock *scope = heap::c_allocator.create<ScopeBlock>();
155155 init_scope(g, &scope->base, ScopeIdBlock, node, parent);
156156 scope->name = node->data.block.name;
157157 return scope;
......@@ -159,20 +159,20 @@ ScopeBlock *create_block_scope(CodeGen *g, AstNode *node, Scope *parent) {
159159
160160ScopeDefer *create_defer_scope(CodeGen *g, AstNode *node, Scope *parent) {
161161 assert(node->type == NodeTypeDefer);
162 ScopeDefer *scope = allocate<ScopeDefer>(1);
162 ScopeDefer *scope = heap::c_allocator.create<ScopeDefer>();
163163 init_scope(g, &scope->base, ScopeIdDefer, node, parent);
164164 return scope;
165165}
166166
167167ScopeDeferExpr *create_defer_expr_scope(CodeGen *g, AstNode *node, Scope *parent) {
168168 assert(node->type == NodeTypeDefer);
169 ScopeDeferExpr *scope = allocate<ScopeDeferExpr>(1);
169 ScopeDeferExpr *scope = heap::c_allocator.create<ScopeDeferExpr>();
170170 init_scope(g, &scope->base, ScopeIdDeferExpr, node, parent);
171171 return scope;
172172}
173173
174174Scope *create_var_scope(CodeGen *g, AstNode *node, Scope *parent, ZigVar *var) {
175 ScopeVarDecl *scope = allocate<ScopeVarDecl>(1);
175 ScopeVarDecl *scope = heap::c_allocator.create<ScopeVarDecl>();
176176 init_scope(g, &scope->base, ScopeIdVarDecl, node, parent);
177177 scope->var = var;
178178 return &scope->base;
......@@ -180,14 +180,14 @@ Scope *create_var_scope(CodeGen *g, AstNode *node, Scope *parent, ZigVar *var) {
180180
181181ScopeCImport *create_cimport_scope(CodeGen *g, AstNode *node, Scope *parent) {
182182 assert(node->type == NodeTypeFnCallExpr);
183 ScopeCImport *scope = allocate<ScopeCImport>(1);
183 ScopeCImport *scope = heap::c_allocator.create<ScopeCImport>();
184184 init_scope(g, &scope->base, ScopeIdCImport, node, parent);
185185 buf_resize(&scope->buf, 0);
186186 return scope;
187187}
188188
189189ScopeLoop *create_loop_scope(CodeGen *g, AstNode *node, Scope *parent) {
190 ScopeLoop *scope = allocate<ScopeLoop>(1);
190 ScopeLoop *scope = heap::c_allocator.create<ScopeLoop>();
191191 init_scope(g, &scope->base, ScopeIdLoop, node, parent);
192192 if (node->type == NodeTypeWhileExpr) {
193193 scope->name = node->data.while_expr.name;
......@@ -200,7 +200,7 @@ ScopeLoop *create_loop_scope(CodeGen *g, AstNode *node, Scope *parent) {
200200}
201201
202202Scope *create_runtime_scope(CodeGen *g, AstNode *node, Scope *parent, IrInstSrc *is_comptime) {
203 ScopeRuntime *scope = allocate<ScopeRuntime>(1);
203 ScopeRuntime *scope = heap::c_allocator.create<ScopeRuntime>();
204204 scope->is_comptime = is_comptime;
205205 init_scope(g, &scope->base, ScopeIdRuntime, node, parent);
206206 return &scope->base;
......@@ -208,37 +208,37 @@ Scope *create_runtime_scope(CodeGen *g, AstNode *node, Scope *parent, IrInstSrc
208208
209209ScopeSuspend *create_suspend_scope(CodeGen *g, AstNode *node, Scope *parent) {
210210 assert(node->type == NodeTypeSuspend);
211 ScopeSuspend *scope = allocate<ScopeSuspend>(1);
211 ScopeSuspend *scope = heap::c_allocator.create<ScopeSuspend>();
212212 init_scope(g, &scope->base, ScopeIdSuspend, node, parent);
213213 return scope;
214214}
215215
216216ScopeFnDef *create_fndef_scope(CodeGen *g, AstNode *node, Scope *parent, ZigFn *fn_entry) {
217 ScopeFnDef *scope = allocate<ScopeFnDef>(1);
217 ScopeFnDef *scope = heap::c_allocator.create<ScopeFnDef>();
218218 init_scope(g, &scope->base, ScopeIdFnDef, node, parent);
219219 scope->fn_entry = fn_entry;
220220 return scope;
221221}
222222
223223Scope *create_comptime_scope(CodeGen *g, AstNode *node, Scope *parent) {
224 ScopeCompTime *scope = allocate<ScopeCompTime>(1);
224 ScopeCompTime *scope = heap::c_allocator.create<ScopeCompTime>();
225225 init_scope(g, &scope->base, ScopeIdCompTime, node, parent);
226226 return &scope->base;
227227}
228228
229229Scope *create_typeof_scope(CodeGen *g, AstNode *node, Scope *parent) {
230 ScopeTypeOf *scope = allocate<ScopeTypeOf>(1);
230 ScopeTypeOf *scope = heap::c_allocator.create<ScopeTypeOf>();
231231 init_scope(g, &scope->base, ScopeIdTypeOf, node, parent);
232232 return &scope->base;
233233}
234234
235235ScopeExpr *create_expr_scope(CodeGen *g, AstNode *node, Scope *parent) {
236 ScopeExpr *scope = allocate<ScopeExpr>(1);
236 ScopeExpr *scope = heap::c_allocator.create<ScopeExpr>();
237237 init_scope(g, &scope->base, ScopeIdExpr, node, parent);
238238 ScopeExpr *parent_expr = find_expr_scope(parent);
239239 if (parent_expr != nullptr) {
240240 size_t new_len = parent_expr->children_len + 1;
241 parent_expr->children_ptr = reallocate_nonzero<ScopeExpr *>(
241 parent_expr->children_ptr = heap::c_allocator.reallocate_nonzero<ScopeExpr *>(
242242 parent_expr->children_ptr, parent_expr->children_len, new_len);
243243 parent_expr->children_ptr[parent_expr->children_len] = scope;
244244 parent_expr->children_len = new_len;
......@@ -1104,8 +1104,8 @@ ZigValue *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, ZigType *
11041104{
11051105 Error err;
11061106
1107 ZigValue *result = create_const_vals(1);
1108 ZigValue *result_ptr = create_const_vals(1);
1107 ZigValue *result = g->pass1_arena->create<ZigValue>();
1108 ZigValue *result_ptr = g->pass1_arena->create<ZigValue>();
11091109 result->special = ConstValSpecialUndef;
11101110 result->type = (type_entry == nullptr) ? g->builtin_types.entry_var : type_entry;
11111111 result_ptr->special = ConstValSpecialStatic;
......@@ -1122,7 +1122,6 @@ ZigValue *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, ZigType *
11221122 {
11231123 return g->invalid_inst_gen->value;
11241124 }
1125 destroy(result_ptr, "ZigValue");
11261125 return result;
11271126}
11281127
......@@ -1507,7 +1506,7 @@ void init_fn_type_id(FnTypeId *fn_type_id, AstNode *proto_node, CallingConventio
15071506
15081507 fn_type_id->cc = cc;
15091508 fn_type_id->param_count = fn_proto->params.length;
1510 fn_type_id->param_info = allocate<FnTypeParamInfo>(param_count_alloc);
1509 fn_type_id->param_info = heap::c_allocator.allocate<FnTypeParamInfo>(param_count_alloc);
15111510 fn_type_id->next_param_index = 0;
15121511 fn_type_id->is_var_args = fn_proto->is_var_args;
15131512}
......@@ -2171,7 +2170,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {
21712170 bool packed = (struct_type->data.structure.layout == ContainerLayoutPacked);
21722171 struct_type->data.structure.resolve_loop_flag_other = true;
21732172
2174 uint32_t *host_int_bytes = packed ? allocate<uint32_t>(struct_type->data.structure.gen_field_count) : nullptr;
2173 uint32_t *host_int_bytes = packed ? heap::c_allocator.allocate<uint32_t>(struct_type->data.structure.gen_field_count) : nullptr;
21752174
21762175 size_t packed_bits_offset = 0;
21772176 size_t next_offset = 0;
......@@ -2657,7 +2656,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) {
26572656 }
26582657
26592658 enum_type->data.enumeration.src_field_count = field_count;
2660 enum_type->data.enumeration.fields = allocate<TypeEnumField>(field_count);
2659 enum_type->data.enumeration.fields = heap::c_allocator.allocate<TypeEnumField>(field_count);
26612660 enum_type->data.enumeration.fields_by_name.init(field_count);
26622661
26632662 HashMap<BigInt, AstNode *, bigint_hash, bigint_eql> occupied_tag_values = {};
......@@ -3034,7 +3033,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
30343033 return ErrorSemanticAnalyzeFail;
30353034 }
30363035 union_type->data.unionation.src_field_count = field_count;
3037 union_type->data.unionation.fields = allocate<TypeUnionField>(field_count);
3036 union_type->data.unionation.fields = heap::c_allocator.allocate<TypeUnionField>(field_count);
30383037 union_type->data.unionation.fields_by_name.init(field_count);
30393038
30403039 Scope *scope = &union_type->data.unionation.decls_scope->base;
......@@ -3053,7 +3052,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
30533052 if (create_enum_type) {
30543053 occupied_tag_values.init(field_count);
30553054
3056 di_enumerators = allocate<ZigLLVMDIEnumerator*>(field_count);
3055 di_enumerators = heap::c_allocator.allocate<ZigLLVMDIEnumerator*>(field_count);
30573056
30583057 ZigType *tag_int_type;
30593058 if (enum_type_node != nullptr) {
......@@ -3086,7 +3085,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
30863085 tag_type->data.enumeration.decl_node = decl_node;
30873086 tag_type->data.enumeration.layout = ContainerLayoutAuto;
30883087 tag_type->data.enumeration.src_field_count = field_count;
3089 tag_type->data.enumeration.fields = allocate<TypeEnumField>(field_count);
3088 tag_type->data.enumeration.fields = heap::c_allocator.allocate<TypeEnumField>(field_count);
30903089 tag_type->data.enumeration.fields_by_name.init(field_count);
30913090 tag_type->data.enumeration.decls_scope = union_type->data.unionation.decls_scope;
30923091 } else if (enum_type_node != nullptr) {
......@@ -3106,7 +3105,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
31063105 return err;
31073106 }
31083107 tag_type = enum_type;
3109 covered_enum_fields = allocate<bool>(enum_type->data.enumeration.src_field_count);
3108 covered_enum_fields = heap::c_allocator.allocate<bool>(enum_type->data.enumeration.src_field_count);
31103109 } else {
31113110 tag_type = nullptr;
31123111 }
......@@ -3244,7 +3243,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
32443243 }
32453244 covered_enum_fields[union_field->enum_field->decl_index] = true;
32463245 } else {
3247 union_field->enum_field = allocate<TypeEnumField>(1);
3246 union_field->enum_field = heap::c_allocator.create<TypeEnumField>();
32483247 union_field->enum_field->name = field_name;
32493248 union_field->enum_field->decl_index = i;
32503249 bigint_init_unsigned(&union_field->enum_field->value, i);
......@@ -3366,8 +3365,8 @@ static void get_fully_qualified_decl_name(CodeGen *g, Buf *buf, Tld *tld, bool i
33663365}
33673366
33683367ZigFn *create_fn_raw(CodeGen *g, FnInline inline_value) {
3369 ZigFn *fn_entry = allocate<ZigFn>(1, "ZigFn");
3370 fn_entry->ir_executable = allocate<IrExecutableSrc>(1, "IrExecutableSrc");
3368 ZigFn *fn_entry = heap::c_allocator.create<ZigFn>();
3369 fn_entry->ir_executable = heap::c_allocator.create<IrExecutableSrc>();
33713370
33723371 fn_entry->prealloc_backward_branch_quota = default_backward_branch_quota;
33733372
......@@ -3642,7 +3641,7 @@ static void preview_test_decl(CodeGen *g, AstNode *node, ScopeDecls *decls_scope
36423641 return;
36433642 }
36443643
3645 TldFn *tld_fn = allocate<TldFn>(1);
3644 TldFn *tld_fn = heap::c_allocator.create<TldFn>();
36463645 init_tld(&tld_fn->base, TldIdFn, test_name, VisibModPrivate, node, &decls_scope->base);
36473646 g->resolve_queue.append(&tld_fn->base);
36483647}
......@@ -3650,7 +3649,7 @@ static void preview_test_decl(CodeGen *g, AstNode *node, ScopeDecls *decls_scope
36503649static void preview_comptime_decl(CodeGen *g, AstNode *node, ScopeDecls *decls_scope) {
36513650 assert(node->type == NodeTypeCompTime);
36523651
3653 TldCompTime *tld_comptime = allocate<TldCompTime>(1);
3652 TldCompTime *tld_comptime = heap::c_allocator.create<TldCompTime>();
36543653 init_tld(&tld_comptime->base, TldIdCompTime, nullptr, VisibModPrivate, node, &decls_scope->base);
36553654 g->resolve_queue.append(&tld_comptime->base);
36563655}
......@@ -3673,7 +3672,7 @@ void update_compile_var(CodeGen *g, Buf *name, ZigValue *value) {
36733672 resolve_top_level_decl(g, tld, tld->source_node, false);
36743673 assert(tld->id == TldIdVar && tld->resolution == TldResolutionOk);
36753674 TldVar *tld_var = (TldVar *)tld;
3676 copy_const_val(tld_var->var->const_value, value);
3675 copy_const_val(g, tld_var->var->const_value, value);
36773676 tld_var->var->var_type = value->type;
36783677 tld_var->var->align_bytes = get_abi_alignment(g, value->type);
36793678}
......@@ -3693,7 +3692,7 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {
36933692 {
36943693 Buf *name = node->data.variable_declaration.symbol;
36953694 VisibMod visib_mod = node->data.variable_declaration.visib_mod;
3696 TldVar *tld_var = allocate<TldVar>(1);
3695 TldVar *tld_var = heap::c_allocator.create<TldVar>();
36973696 init_tld(&tld_var->base, TldIdVar, name, visib_mod, node, &decls_scope->base);
36983697 tld_var->extern_lib_name = node->data.variable_declaration.lib_name;
36993698 add_top_level_decl(g, decls_scope, &tld_var->base);
......@@ -3709,7 +3708,7 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {
37093708 }
37103709
37113710 VisibMod visib_mod = node->data.fn_proto.visib_mod;
3712 TldFn *tld_fn = allocate<TldFn>(1);
3711 TldFn *tld_fn = heap::c_allocator.create<TldFn>();
37133712 init_tld(&tld_fn->base, TldIdFn, fn_name, visib_mod, node, &decls_scope->base);
37143713 tld_fn->extern_lib_name = node->data.fn_proto.lib_name;
37153714 add_top_level_decl(g, decls_scope, &tld_fn->base);
......@@ -3718,7 +3717,7 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {
37183717 }
37193718 case NodeTypeUsingNamespace: {
37203719 VisibMod visib_mod = node->data.using_namespace.visib_mod;
3721 TldUsingNamespace *tld_using_namespace = allocate<TldUsingNamespace>(1);
3720 TldUsingNamespace *tld_using_namespace = heap::c_allocator.create<TldUsingNamespace>();
37223721 init_tld(&tld_using_namespace->base, TldIdUsingNamespace, nullptr, visib_mod, node, &decls_scope->base);
37233722 add_top_level_decl(g, decls_scope, &tld_using_namespace->base);
37243723 decls_scope->use_decls.append(tld_using_namespace);
......@@ -3845,7 +3844,7 @@ ZigVar *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf
38453844 assert(const_value != nullptr);
38463845 assert(var_type != nullptr);
38473846
3848 ZigVar *variable_entry = allocate<ZigVar>(1);
3847 ZigVar *variable_entry = heap::c_allocator.create<ZigVar>();
38493848 variable_entry->const_value = const_value;
38503849 variable_entry->var_type = var_type;
38513850 variable_entry->parent_scope = parent_scope;
......@@ -3984,7 +3983,7 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var, bool allow_lazy) {
39843983 ZigType *type = explicit_type ? explicit_type : implicit_type;
39853984 assert(type != nullptr); // should have been caught by the parser
39863985
3987 ZigValue *init_val = (init_value != nullptr) ? init_value : create_const_runtime(type);
3986 ZigValue *init_val = (init_value != nullptr) ? init_value : create_const_runtime(g, type);
39883987
39893988 tld_var->var = add_variable(g, source_node, tld_var->base.parent_scope, var_decl->symbol,
39903989 is_const, init_val, &tld_var->base, type);
......@@ -4491,7 +4490,7 @@ static Error define_local_param_variables(CodeGen *g, ZigFn *fn_table_entry) {
44914490 }
44924491
44934492 ZigVar *var = add_variable(g, param_decl_node, fn_table_entry->child_scope,
4494 param_name, true, create_const_runtime(param_type), nullptr, param_type);
4493 param_name, true, create_const_runtime(g, param_type), nullptr, param_type);
44954494 var->src_arg_index = i;
44964495 fn_table_entry->child_scope = var->child_scope;
44974496 var->shadowable = var->shadowable || is_var_args;
......@@ -4786,7 +4785,7 @@ static void analyze_fn_ir(CodeGen *g, ZigFn *fn, AstNode *return_type_node) {
47864785 } else {
47874786 return_err_set_type->data.error_set.err_count = inferred_err_set_type->data.error_set.err_count;
47884787 if (inferred_err_set_type->data.error_set.err_count > 0) {
4789 return_err_set_type->data.error_set.errors = allocate<ErrorTableEntry *>(inferred_err_set_type->data.error_set.err_count);
4788 return_err_set_type->data.error_set.errors = heap::c_allocator.allocate<ErrorTableEntry *>(inferred_err_set_type->data.error_set.err_count);
47904789 for (uint32_t i = 0; i < inferred_err_set_type->data.error_set.err_count; i += 1) {
47914790 return_err_set_type->data.error_set.errors[i] = inferred_err_set_type->data.error_set.errors[i];
47924791 }
......@@ -4919,7 +4918,7 @@ ZigType *add_source_file(CodeGen *g, ZigPackage *package, Buf *resolved_path, Bu
49194918 Buf *bare_name = buf_alloc();
49204919 os_path_extname(src_basename, bare_name, nullptr);
49214920
4922 RootStruct *root_struct = allocate<RootStruct>(1);
4921 RootStruct *root_struct = heap::c_allocator.create<RootStruct>();
49234922 root_struct->package = package;
49244923 root_struct->source_code = source_code;
49254924 root_struct->line_offsets = tokenization.line_offsets;
......@@ -4946,7 +4945,7 @@ ZigType *add_source_file(CodeGen *g, ZigPackage *package, Buf *resolved_path, Bu
49464945 scan_decls(g, import_entry->data.structure.decls_scope, top_level_decl);
49474946 }
49484947
4949 TldContainer *tld_container = allocate<TldContainer>(1);
4948 TldContainer *tld_container = heap::c_allocator.create<TldContainer>();
49504949 init_tld(&tld_container->base, TldIdContainer, namespace_name, VisibModPub, root_node, nullptr);
49514950 tld_container->type_entry = import_entry;
49524951 tld_container->decls_scope = import_entry->data.structure.decls_scope;
......@@ -5694,14 +5693,14 @@ ZigValue *get_the_one_possible_value(CodeGen *g, ZigType *type_entry) {
56945693 if (entry != nullptr) {
56955694 return entry->value;
56965695 }
5697 ZigValue *result = create_const_vals(1);
5696 ZigValue *result = g->pass1_arena->create<ZigValue>();
56985697 result->type = type_entry;
56995698 result->special = ConstValSpecialStatic;
57005699 if (result->type->id == ZigTypeIdStruct) {
57015700 // The fields array cannot be left unpopulated
57025701 const ZigType *struct_type = result->type;
57035702 const size_t field_count = struct_type->data.structure.src_field_count;
5704 result->data.x_struct.fields = alloc_const_vals_ptrs(field_count);
5703 result->data.x_struct.fields = alloc_const_vals_ptrs(g, field_count);
57055704 for (size_t i = 0; i < field_count; i += 1) {
57065705 TypeStructField *field = struct_type->data.structure.fields[i];
57075706 ZigType *field_type = resolve_struct_field_type(g, field);
......@@ -5786,7 +5785,7 @@ void init_const_str_lit(CodeGen *g, ZigValue *const_val, Buf *str) {
57865785 }
57875786
57885787 // first we build the underlying array
5789 ZigValue *array_val = create_const_vals(1);
5788 ZigValue *array_val = g->pass1_arena->create<ZigValue>();
57905789 array_val->special = ConstValSpecialStatic;
57915790 array_val->type = get_array_type(g, g->builtin_types.entry_u8, buf_len(str), g->intern.for_zero_byte());
57925791 array_val->data.x_array.special = ConstArraySpecialBuf;
......@@ -5803,7 +5802,7 @@ void init_const_str_lit(CodeGen *g, ZigValue *const_val, Buf *str) {
58035802}
58045803
58055804ZigValue *create_const_str_lit(CodeGen *g, Buf *str) {
5806 ZigValue *const_val = create_const_vals(1);
5805 ZigValue *const_val = g->pass1_arena->create<ZigValue>();
58075806 init_const_str_lit(g, const_val, str);
58085807 return const_val;
58095808}
......@@ -5814,8 +5813,8 @@ void init_const_bigint(ZigValue *const_val, ZigType *type, const BigInt *bigint)
58145813 bigint_init_bigint(&const_val->data.x_bigint, bigint);
58155814}
58165815
5817ZigValue *create_const_bigint(ZigType *type, const BigInt *bigint) {
5818 ZigValue *const_val = create_const_vals(1);
5816ZigValue *create_const_bigint(CodeGen *g, ZigType *type, const BigInt *bigint) {
5817 ZigValue *const_val = g->pass1_arena->create<ZigValue>();
58195818 init_const_bigint(const_val, type, bigint);
58205819 return const_val;
58215820}
......@@ -5828,8 +5827,8 @@ void init_const_unsigned_negative(ZigValue *const_val, ZigType *type, uint64_t x
58285827 const_val->data.x_bigint.is_negative = negative;
58295828}
58305829
5831ZigValue *create_const_unsigned_negative(ZigType *type, uint64_t x, bool negative) {
5832 ZigValue *const_val = create_const_vals(1);
5830ZigValue *create_const_unsigned_negative(CodeGen *g, ZigType *type, uint64_t x, bool negative) {
5831 ZigValue *const_val = g->pass1_arena->create<ZigValue>();
58335832 init_const_unsigned_negative(const_val, type, x, negative);
58345833 return const_val;
58355834}
......@@ -5839,7 +5838,7 @@ void init_const_usize(CodeGen *g, ZigValue *const_val, uint64_t x) {
58395838}
58405839
58415840ZigValue *create_const_usize(CodeGen *g, uint64_t x) {
5842 return create_const_unsigned_negative(g->builtin_types.entry_usize, x, false);
5841 return create_const_unsigned_negative(g, g->builtin_types.entry_usize, x, false);
58435842}
58445843
58455844void init_const_signed(ZigValue *const_val, ZigType *type, int64_t x) {
......@@ -5848,8 +5847,8 @@ void init_const_signed(ZigValue *const_val, ZigType *type, int64_t x) {
58485847 bigint_init_signed(&const_val->data.x_bigint, x);
58495848}
58505849
5851ZigValue *create_const_signed(ZigType *type, int64_t x) {
5852 ZigValue *const_val = create_const_vals(1);
5850ZigValue *create_const_signed(CodeGen *g, ZigType *type, int64_t x) {
5851 ZigValue *const_val = g->pass1_arena->create<ZigValue>();
58535852 init_const_signed(const_val, type, x);
58545853 return const_val;
58555854}
......@@ -5860,8 +5859,8 @@ void init_const_null(ZigValue *const_val, ZigType *type) {
58605859 const_val->data.x_optional = nullptr;
58615860}
58625861
5863ZigValue *create_const_null(ZigType *type) {
5864 ZigValue *const_val = create_const_vals(1);
5862ZigValue *create_const_null(CodeGen *g, ZigType *type) {
5863 ZigValue *const_val = g->pass1_arena->create<ZigValue>();
58655864 init_const_null(const_val, type);
58665865 return const_val;
58675866}
......@@ -5893,8 +5892,8 @@ void init_const_float(ZigValue *const_val, ZigType *type, double value) {
58935892 }
58945893}
58955894
5896ZigValue *create_const_float(ZigType *type, double value) {
5897 ZigValue *const_val = create_const_vals(1);
5895ZigValue *create_const_float(CodeGen *g, ZigType *type, double value) {
5896 ZigValue *const_val = g->pass1_arena->create<ZigValue>();
58985897 init_const_float(const_val, type, value);
58995898 return const_val;
59005899}
......@@ -5905,8 +5904,8 @@ void init_const_enum(ZigValue *const_val, ZigType *type, const BigInt *tag) {
59055904 bigint_init_bigint(&const_val->data.x_enum_tag, tag);
59065905}
59075906
5908ZigValue *create_const_enum(ZigType *type, const BigInt *tag) {
5909 ZigValue *const_val = create_const_vals(1);
5907ZigValue *create_const_enum(CodeGen *g, ZigType *type, const BigInt *tag) {
5908 ZigValue *const_val = g->pass1_arena->create<ZigValue>();
59105909 init_const_enum(const_val, type, tag);
59115910 return const_val;
59125911}
......@@ -5919,7 +5918,7 @@ void init_const_bool(CodeGen *g, ZigValue *const_val, bool value) {
59195918}
59205919
59215920ZigValue *create_const_bool(CodeGen *g, bool value) {
5922 ZigValue *const_val = create_const_vals(1);
5921 ZigValue *const_val = g->pass1_arena->create<ZigValue>();
59235922 init_const_bool(g, const_val, value);
59245923 return const_val;
59255924}
......@@ -5929,8 +5928,8 @@ void init_const_runtime(ZigValue *const_val, ZigType *type) {
59295928 const_val->type = type;
59305929}
59315930
5932ZigValue *create_const_runtime(ZigType *type) {
5933 ZigValue *const_val = create_const_vals(1);
5931ZigValue *create_const_runtime(CodeGen *g, ZigType *type) {
5932 ZigValue *const_val = g->pass1_arena->create<ZigValue>();
59345933 init_const_runtime(const_val, type);
59355934 return const_val;
59365935}
......@@ -5942,7 +5941,7 @@ void init_const_type(CodeGen *g, ZigValue *const_val, ZigType *type_value) {
59425941}
59435942
59445943ZigValue *create_const_type(CodeGen *g, ZigType *type_value) {
5945 ZigValue *const_val = create_const_vals(1);
5944 ZigValue *const_val = g->pass1_arena->create<ZigValue>();
59465945 init_const_type(g, const_val, type_value);
59475946 return const_val;
59485947}
......@@ -5957,7 +5956,7 @@ void init_const_slice(CodeGen *g, ZigValue *const_val, ZigValue *array_val,
59575956
59585957 const_val->special = ConstValSpecialStatic;
59595958 const_val->type = get_slice_type(g, ptr_type);
5960 const_val->data.x_struct.fields = alloc_const_vals_ptrs(2);
5959 const_val->data.x_struct.fields = alloc_const_vals_ptrs(g, 2);
59615960
59625961 init_const_ptr_array(g, const_val->data.x_struct.fields[slice_ptr_index], array_val, start, is_const,
59635962 PtrLenUnknown);
......@@ -5965,7 +5964,7 @@ void init_const_slice(CodeGen *g, ZigValue *const_val, ZigValue *array_val,
59655964}
59665965
59675966ZigValue *create_const_slice(CodeGen *g, ZigValue *array_val, size_t start, size_t len, bool is_const) {
5968 ZigValue *const_val = create_const_vals(1);
5967 ZigValue *const_val = g->pass1_arena->create<ZigValue>();
59695968 init_const_slice(g, const_val, array_val, start, len, is_const);
59705969 return const_val;
59715970}
......@@ -5987,7 +5986,7 @@ void init_const_ptr_array(CodeGen *g, ZigValue *const_val, ZigValue *array_val,
59875986ZigValue *create_const_ptr_array(CodeGen *g, ZigValue *array_val, size_t elem_index, bool is_const,
59885987 PtrLen ptr_len)
59895988{
5990 ZigValue *const_val = create_const_vals(1);
5989 ZigValue *const_val = g->pass1_arena->create<ZigValue>();
59915990 init_const_ptr_array(g, const_val, array_val, elem_index, is_const, ptr_len);
59925991 return const_val;
59935992}
......@@ -6000,7 +5999,7 @@ void init_const_ptr_ref(CodeGen *g, ZigValue *const_val, ZigValue *pointee_val,
60005999}
60016000
60026001ZigValue *create_const_ptr_ref(CodeGen *g, ZigValue *pointee_val, bool is_const) {
6003 ZigValue *const_val = create_const_vals(1);
6002 ZigValue *const_val = g->pass1_arena->create<ZigValue>();
60046003 init_const_ptr_ref(g, const_val, pointee_val, is_const);
60056004 return const_val;
60066005}
......@@ -6017,25 +6016,21 @@ void init_const_ptr_hard_coded_addr(CodeGen *g, ZigValue *const_val, ZigType *po
60176016ZigValue *create_const_ptr_hard_coded_addr(CodeGen *g, ZigType *pointee_type,
60186017 size_t addr, bool is_const)
60196018{
6020 ZigValue *const_val = create_const_vals(1);
6019 ZigValue *const_val = g->pass1_arena->create<ZigValue>();
60216020 init_const_ptr_hard_coded_addr(g, const_val, pointee_type, addr, is_const);
60226021 return const_val;
60236022}
60246023
6025ZigValue *create_const_vals(size_t count) {
6026 return allocate<ZigValue>(count, "ZigValue");
6024ZigValue **alloc_const_vals_ptrs(CodeGen *g, size_t count) {
6025 return realloc_const_vals_ptrs(g, nullptr, 0, count);
60276026}
60286027
6029ZigValue **alloc_const_vals_ptrs(size_t count) {
6030 return realloc_const_vals_ptrs(nullptr, 0, count);
6031}
6032
6033ZigValue **realloc_const_vals_ptrs(ZigValue **ptr, size_t old_count, size_t new_count) {
6028ZigValue **realloc_const_vals_ptrs(CodeGen *g, ZigValue **ptr, size_t old_count, size_t new_count) {
60346029 assert(new_count >= old_count);
60356030
60366031 size_t new_item_count = new_count - old_count;
6037 ZigValue **result = reallocate(ptr, old_count, new_count, "ZigValue*");
6038 ZigValue *vals = create_const_vals(new_item_count);
6032 ZigValue **result = heap::c_allocator.reallocate(ptr, old_count, new_count);
6033 ZigValue *vals = g->pass1_arena->allocate<ZigValue>(new_item_count);
60396034 for (size_t i = old_count; i < new_count; i += 1) {
60406035 result[i] = &vals[i - old_count];
60416036 }
......@@ -6050,8 +6045,8 @@ TypeStructField **realloc_type_struct_fields(TypeStructField **ptr, size_t old_c
60506045 assert(new_count >= old_count);
60516046
60526047 size_t new_item_count = new_count - old_count;
6053 TypeStructField **result = reallocate(ptr, old_count, new_count, "TypeStructField*");
6054 TypeStructField *vals = allocate<TypeStructField>(new_item_count, "TypeStructField");
6048 TypeStructField **result = heap::c_allocator.reallocate(ptr, old_count, new_count);
6049 TypeStructField *vals = heap::c_allocator.allocate<TypeStructField>(new_item_count);
60556050 for (size_t i = old_count; i < new_count; i += 1) {
60566051 result[i] = &vals[i - old_count];
60576052 }
......@@ -6062,7 +6057,7 @@ static ZigType *get_async_fn_type(CodeGen *g, ZigType *orig_fn_type) {
60626057 if (orig_fn_type->data.fn.fn_type_id.cc == CallingConventionAsync)
60636058 return orig_fn_type;
60646059
6065 ZigType *fn_type = allocate_nonzero<ZigType>(1);
6060 ZigType *fn_type = heap::c_allocator.allocate_nonzero<ZigType>(1);
60666061 *fn_type = *orig_fn_type;
60676062 fn_type->data.fn.fn_type_id.cc = CallingConventionAsync;
60686063 fn_type->llvm_type = nullptr;
......@@ -6236,11 +6231,11 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
62366231 ZigType *fn_type = get_async_fn_type(g, fn->type_entry);
62376232
62386233 if (fn->analyzed_executable.need_err_code_spill) {
6239 IrInstGenAlloca *alloca_gen = allocate<IrInstGenAlloca>(1);
6234 IrInstGenAlloca *alloca_gen = heap::c_allocator.create<IrInstGenAlloca>();
62406235 alloca_gen->base.id = IrInstGenIdAlloca;
62416236 alloca_gen->base.base.source_node = fn->proto_node;
62426237 alloca_gen->base.base.scope = fn->child_scope;
6243 alloca_gen->base.value = allocate<ZigValue>(1, "ZigValue");
6238 alloca_gen->base.value = g->pass1_arena->create<ZigValue>();
62446239 alloca_gen->base.value->type = get_pointer_to_type(g, g->builtin_types.entry_global_error_set, false);
62456240 alloca_gen->base.base.ref_count = 1;
62466241 alloca_gen->name_hint = "";
......@@ -6942,9 +6937,9 @@ static void render_const_val_array(CodeGen *g, Buf *buf, Buf *type_name, ZigValu
69426937 return;
69436938 }
69446939 case ConstArraySpecialNone: {
6945 ZigValue *base = &array->data.s_none.elements[start];
6946 assert(base != nullptr);
69476940 assert(start + len <= const_val->type->data.array.len);
6941 ZigValue *base = &array->data.s_none.elements[start];
6942 assert(len == 0 || base != nullptr);
69486943
69496944 buf_appendf(buf, "%s{", buf_ptr(type_name));
69506945 for (uint64_t i = 0; i < len; i += 1) {
......@@ -7375,7 +7370,7 @@ static void init_const_undefined(CodeGen *g, ZigValue *const_val) {
73757370
73767371 const_val->special = ConstValSpecialStatic;
73777372 size_t field_count = wanted_type->data.structure.src_field_count;
7378 const_val->data.x_struct.fields = alloc_const_vals_ptrs(field_count);
7373 const_val->data.x_struct.fields = alloc_const_vals_ptrs(g, field_count);
73797374 for (size_t i = 0; i < field_count; i += 1) {
73807375 ZigValue *field_val = const_val->data.x_struct.fields[i];
73817376 field_val->type = resolve_struct_field_type(g, wanted_type->data.structure.fields[i]);
......@@ -7418,7 +7413,7 @@ void expand_undef_array(CodeGen *g, ZigValue *const_val) {
74187413 return;
74197414 case ConstArraySpecialUndef: {
74207415 const_val->data.x_array.special = ConstArraySpecialNone;
7421 const_val->data.x_array.data.s_none.elements = create_const_vals(elem_count);
7416 const_val->data.x_array.data.s_none.elements = g->pass1_arena->allocate<ZigValue>(elem_count);
74227417 for (size_t i = 0; i < elem_count; i += 1) {
74237418 ZigValue *element_val = &const_val->data.x_array.data.s_none.elements[i];
74247419 element_val->type = elem_type;
......@@ -7437,7 +7432,7 @@ void expand_undef_array(CodeGen *g, ZigValue *const_val) {
74377432
74387433 const_val->data.x_array.special = ConstArraySpecialNone;
74397434 assert(elem_count == buf_len(buf));
7440 const_val->data.x_array.data.s_none.elements = create_const_vals(elem_count);
7435 const_val->data.x_array.data.s_none.elements = g->pass1_arena->allocate<ZigValue>(elem_count);
74417436 for (size_t i = 0; i < elem_count; i += 1) {
74427437 ZigValue *this_char = &const_val->data.x_array.data.s_none.elements[i];
74437438 this_char->special = ConstValSpecialStatic;
......@@ -7609,7 +7604,7 @@ const char *type_id_name(ZigTypeId id) {
76097604}
76107605
76117606LinkLib *create_link_lib(Buf *name) {
7612 LinkLib *link_lib = allocate<LinkLib>(1);
7607 LinkLib *link_lib = heap::c_allocator.create<LinkLib>();
76137608 link_lib->name = name;
76147609 return link_lib;
76157610}
......@@ -8137,7 +8132,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS
81378132
81388133 size_t field_count = struct_type->data.structure.src_field_count;
81398134 // Every field could potentially have a generated padding field after it.
8140 LLVMTypeRef *element_types = allocate<LLVMTypeRef>(field_count * 2);
8135 LLVMTypeRef *element_types = heap::c_allocator.allocate<LLVMTypeRef>(field_count * 2);
81418136
81428137 bool packed = (struct_type->data.structure.layout == ContainerLayoutPacked);
81438138 size_t packed_bits_offset = 0;
......@@ -8272,7 +8267,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS
82728267 (unsigned)struct_type->data.structure.gen_field_count, packed);
82738268 }
82748269
8275 ZigLLVMDIType **di_element_types = allocate<ZigLLVMDIType*>(debug_field_count);
8270 ZigLLVMDIType **di_element_types = heap::c_allocator.allocate<ZigLLVMDIType*>(debug_field_count);
82768271 size_t debug_field_index = 0;
82778272 for (size_t i = 0; i < field_count; i += 1) {
82788273 TypeStructField *field = struct_type->data.structure.fields[i];
......@@ -8389,7 +8384,7 @@ static void resolve_llvm_types_enum(CodeGen *g, ZigType *enum_type, ResolveStatu
83898384 uint32_t field_count = enum_type->data.enumeration.src_field_count;
83908385
83918386 assert(field_count == 0 || enum_type->data.enumeration.fields != nullptr);
8392 ZigLLVMDIEnumerator **di_enumerators = allocate<ZigLLVMDIEnumerator*>(field_count);
8387 ZigLLVMDIEnumerator **di_enumerators = heap::c_allocator.allocate<ZigLLVMDIEnumerator*>(field_count);
83938388
83948389 for (uint32_t i = 0; i < field_count; i += 1) {
83958390 TypeEnumField *enum_field = &enum_type->data.enumeration.fields[i];
......@@ -8456,7 +8451,7 @@ static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type, ResolveSta
84568451 if (ResolveStatusLLVMFwdDecl >= wanted_resolve_status) return;
84578452 }
84588453
8459 ZigLLVMDIType **union_inner_di_types = allocate<ZigLLVMDIType*>(gen_field_count);
8454 ZigLLVMDIType **union_inner_di_types = heap::c_allocator.allocate<ZigLLVMDIType*>(gen_field_count);
84608455 uint32_t field_count = union_type->data.unionation.src_field_count;
84618456 for (uint32_t i = 0; i < field_count; i += 1) {
84628457 TypeUnionField *union_field = &union_type->data.unionation.fields[i];
......@@ -8895,7 +8890,7 @@ static void resolve_llvm_types_fn_type(CodeGen *g, ZigType *fn_type) {
88958890 param_di_types.append(get_llvm_di_type(g, gen_type));
88968891 }
88978892 if (is_async) {
8898 fn_type->data.fn.gen_param_info = allocate<FnGenParamInfo>(2);
8893 fn_type->data.fn.gen_param_info = heap::c_allocator.allocate<FnGenParamInfo>(2);
88998894
89008895 ZigType *frame_type = get_any_frame_type(g, fn_type_id->return_type);
89018896 gen_param_types.append(get_llvm_type(g, frame_type));
......@@ -8912,7 +8907,7 @@ static void resolve_llvm_types_fn_type(CodeGen *g, ZigType *fn_type) {
89128907 fn_type->data.fn.gen_param_info[1].gen_index = 1;
89138908 fn_type->data.fn.gen_param_info[1].type = g->builtin_types.entry_usize;
89148909 } else {
8915 fn_type->data.fn.gen_param_info = allocate<FnGenParamInfo>(fn_type_id->param_count);
8910 fn_type->data.fn.gen_param_info = heap::c_allocator.allocate<FnGenParamInfo>(fn_type_id->param_count);
89168911 for (size_t i = 0; i < fn_type_id->param_count; i += 1) {
89178912 FnTypeParamInfo *src_param_info = &fn_type->data.fn.fn_type_id.param_info[i];
89188913 ZigType *type_entry = src_param_info->type;
......@@ -9369,7 +9364,7 @@ bool type_has_optional_repr(ZigType *ty) {
93699364 }
93709365}
93719366
9372void copy_const_val(ZigValue *dest, ZigValue *src) {
9367void copy_const_val(CodeGen *g, ZigValue *dest, ZigValue *src) {
93739368 uint32_t prev_align = dest->llvm_align;
93749369 ConstParent prev_parent = dest->parent;
93759370 memcpy(dest, src, sizeof(ZigValue));
......@@ -9378,26 +9373,26 @@ void copy_const_val(ZigValue *dest, ZigValue *src) {
93789373 return;
93799374 dest->parent = prev_parent;
93809375 if (dest->type->id == ZigTypeIdStruct) {
9381 dest->data.x_struct.fields = alloc_const_vals_ptrs(dest->type->data.structure.src_field_count);
9376 dest->data.x_struct.fields = alloc_const_vals_ptrs(g, dest->type->data.structure.src_field_count);
93829377 for (size_t i = 0; i < dest->type->data.structure.src_field_count; i += 1) {
9383 copy_const_val(dest->data.x_struct.fields[i], src->data.x_struct.fields[i]);
9378 copy_const_val(g, dest->data.x_struct.fields[i], src->data.x_struct.fields[i]);
93849379 dest->data.x_struct.fields[i]->parent.id = ConstParentIdStruct;
93859380 dest->data.x_struct.fields[i]->parent.data.p_struct.struct_val = dest;
93869381 dest->data.x_struct.fields[i]->parent.data.p_struct.field_index = i;
93879382 }
93889383 } else if (dest->type->id == ZigTypeIdArray) {
93899384 if (dest->data.x_array.special == ConstArraySpecialNone) {
9390 dest->data.x_array.data.s_none.elements = create_const_vals(dest->type->data.array.len);
9385 dest->data.x_array.data.s_none.elements = g->pass1_arena->allocate<ZigValue>(dest->type->data.array.len);
93919386 for (uint64_t i = 0; i < dest->type->data.array.len; i += 1) {
9392 copy_const_val(&dest->data.x_array.data.s_none.elements[i], &src->data.x_array.data.s_none.elements[i]);
9387 copy_const_val(g, &dest->data.x_array.data.s_none.elements[i], &src->data.x_array.data.s_none.elements[i]);
93939388 dest->data.x_array.data.s_none.elements[i].parent.id = ConstParentIdArray;
93949389 dest->data.x_array.data.s_none.elements[i].parent.data.p_array.array_val = dest;
93959390 dest->data.x_array.data.s_none.elements[i].parent.data.p_array.elem_index = i;
93969391 }
93979392 }
93989393 } else if (type_has_optional_repr(dest->type) && dest->data.x_optional != nullptr) {
9399 dest->data.x_optional = create_const_vals(1);
9400 copy_const_val(dest->data.x_optional, src->data.x_optional);
9394 dest->data.x_optional = g->pass1_arena->create<ZigValue>();
9395 copy_const_val(g, dest->data.x_optional, src->data.x_optional);
94019396 dest->data.x_optional->parent.id = ConstParentIdOptionalPayload;
94029397 dest->data.x_optional->parent.data.p_optional_payload.optional_val = dest;
94039398 }
src/analyze.hpp+10-11
......@@ -128,22 +128,22 @@ void init_const_str_lit(CodeGen *g, ZigValue *const_val, Buf *str);
128128ZigValue *create_const_str_lit(CodeGen *g, Buf *str);
129129
130130void init_const_bigint(ZigValue *const_val, ZigType *type, const BigInt *bigint);
131ZigValue *create_const_bigint(ZigType *type, const BigInt *bigint);
131ZigValue *create_const_bigint(CodeGen *g, ZigType *type, const BigInt *bigint);
132132
133133void init_const_unsigned_negative(ZigValue *const_val, ZigType *type, uint64_t x, bool negative);
134ZigValue *create_const_unsigned_negative(ZigType *type, uint64_t x, bool negative);
134ZigValue *create_const_unsigned_negative(CodeGen *g, ZigType *type, uint64_t x, bool negative);
135135
136136void init_const_signed(ZigValue *const_val, ZigType *type, int64_t x);
137ZigValue *create_const_signed(ZigType *type, int64_t x);
137ZigValue *create_const_signed(CodeGen *g, ZigType *type, int64_t x);
138138
139139void init_const_usize(CodeGen *g, ZigValue *const_val, uint64_t x);
140140ZigValue *create_const_usize(CodeGen *g, uint64_t x);
141141
142142void init_const_float(ZigValue *const_val, ZigType *type, double value);
143ZigValue *create_const_float(ZigType *type, double value);
143ZigValue *create_const_float(CodeGen *g, ZigType *type, double value);
144144
145145void init_const_enum(ZigValue *const_val, ZigType *type, const BigInt *tag);
146ZigValue *create_const_enum(ZigType *type, const BigInt *tag);
146ZigValue *create_const_enum(CodeGen *g, ZigType *type, const BigInt *tag);
147147
148148void init_const_bool(CodeGen *g, ZigValue *const_val, bool value);
149149ZigValue *create_const_bool(CodeGen *g, bool value);
......@@ -152,7 +152,7 @@ void init_const_type(CodeGen *g, ZigValue *const_val, ZigType *type_value);
152152ZigValue *create_const_type(CodeGen *g, ZigType *type_value);
153153
154154void init_const_runtime(ZigValue *const_val, ZigType *type);
155ZigValue *create_const_runtime(ZigType *type);
155ZigValue *create_const_runtime(CodeGen *g, ZigType *type);
156156
157157void init_const_ptr_ref(CodeGen *g, ZigValue *const_val, ZigValue *pointee_val, bool is_const);
158158ZigValue *create_const_ptr_ref(CodeGen *g, ZigValue *pointee_val, bool is_const);
......@@ -172,11 +172,10 @@ void init_const_slice(CodeGen *g, ZigValue *const_val, ZigValue *array_val,
172172ZigValue *create_const_slice(CodeGen *g, ZigValue *array_val, size_t start, size_t len, bool is_const);
173173
174174void init_const_null(ZigValue *const_val, ZigType *type);
175ZigValue *create_const_null(ZigType *type);
175ZigValue *create_const_null(CodeGen *g, ZigType *type);
176176
177ZigValue *create_const_vals(size_t count);
178ZigValue **alloc_const_vals_ptrs(size_t count);
179ZigValue **realloc_const_vals_ptrs(ZigValue **ptr, size_t old_count, size_t new_count);
177ZigValue **alloc_const_vals_ptrs(CodeGen *g, size_t count);
178ZigValue **realloc_const_vals_ptrs(CodeGen *g, ZigValue **ptr, size_t old_count, size_t new_count);
180179
181180TypeStructField **alloc_type_struct_fields(size_t count);
182181TypeStructField **realloc_type_struct_fields(TypeStructField **ptr, size_t old_count, size_t new_count);
......@@ -275,7 +274,7 @@ Error analyze_import(CodeGen *codegen, ZigType *source_import, Buf *import_targe
275274 ZigType **out_import, Buf **out_import_target_path, Buf *out_full_path);
276275ZigValue *get_the_one_possible_value(CodeGen *g, ZigType *type_entry);
277276bool is_anon_container(ZigType *ty);
278void copy_const_val(ZigValue *dest, ZigValue *src);
277void copy_const_val(CodeGen *g, ZigValue *dest, ZigValue *src);
279278bool type_has_optional_repr(ZigType *ty);
280279bool is_opt_err_set(ZigType *ty);
281280bool type_is_numeric(ZigType *ty);
src/bigint.cpp+16-16
......@@ -93,7 +93,7 @@ static void to_twos_complement(BigInt *dest, const BigInt *op, size_t bit_count)
9393 if (dest->data.digit == 0) dest->digit_count = 0;
9494 return;
9595 }
96 dest->data.digits = allocate_nonzero<uint64_t>(dest->digit_count);
96 dest->data.digits = heap::c_allocator.allocate_nonzero<uint64_t>(dest->digit_count);
9797 for (size_t i = 0; i < digits_to_copy; i += 1) {
9898 uint64_t digit = (i < op->digit_count) ? op_digits[i] : 0;
9999 dest->data.digits[i] = digit;
......@@ -174,7 +174,7 @@ void bigint_init_data(BigInt *dest, const uint64_t *digits, size_t digit_count,
174174
175175 dest->digit_count = digit_count;
176176 dest->is_negative = is_negative;
177 dest->data.digits = allocate_nonzero<uint64_t>(digit_count);
177 dest->data.digits = heap::c_allocator.allocate_nonzero<uint64_t>(digit_count);
178178 memcpy(dest->data.digits, digits, sizeof(uint64_t) * digit_count);
179179
180180 bigint_normalize(dest);
......@@ -191,13 +191,13 @@ void bigint_init_bigint(BigInt *dest, const BigInt *src) {
191191 }
192192 dest->is_negative = src->is_negative;
193193 dest->digit_count = src->digit_count;
194 dest->data.digits = allocate_nonzero<uint64_t>(dest->digit_count);
194 dest->data.digits = heap::c_allocator.allocate_nonzero<uint64_t>(dest->digit_count);
195195 memcpy(dest->data.digits, src->data.digits, sizeof(uint64_t) * dest->digit_count);
196196}
197197
198198void bigint_deinit(BigInt *bi) {
199199 if (bi->digit_count > 1)
200 deallocate<uint64_t>(bi->data.digits, bi->digit_count);
200 heap::c_allocator.deallocate(bi->data.digits, bi->digit_count);
201201}
202202
203203void bigint_init_bigfloat(BigInt *dest, const BigFloat *op) {
......@@ -227,7 +227,7 @@ void bigint_init_bigfloat(BigInt *dest, const BigFloat *op) {
227227 f128M_rem(&abs_val, &max_u64, &remainder);
228228
229229 dest->digit_count = 2;
230 dest->data.digits = allocate_nonzero<uint64_t>(dest->digit_count);
230 dest->data.digits = heap::c_allocator.allocate_nonzero<uint64_t>(dest->digit_count);
231231 dest->data.digits[0] = f128M_to_ui64(&remainder, softfloat_round_minMag, false);
232232 dest->data.digits[1] = f128M_to_ui64(&amt, softfloat_round_minMag, false);
233233 bigint_normalize(dest);
......@@ -345,7 +345,7 @@ void bigint_read_twos_complement(BigInt *dest, const uint8_t *buf, size_t bit_co
345345 if (dest->digit_count == 1) {
346346 digits = &dest->data.digit;
347347 } else {
348 digits = allocate_nonzero<uint64_t>(dest->digit_count);
348 digits = heap::c_allocator.allocate_nonzero<uint64_t>(dest->digit_count);
349349 dest->data.digits = digits;
350350 }
351351
......@@ -464,7 +464,7 @@ void bigint_add(BigInt *dest, const BigInt *op1, const BigInt *op2) {
464464 }
465465 size_t i = 1;
466466 uint64_t first_digit = dest->data.digit;
467 dest->data.digits = allocate_nonzero<uint64_t>(max(op1->digit_count, op2->digit_count) + 1);
467 dest->data.digits = heap::c_allocator.allocate_nonzero<uint64_t>(max(op1->digit_count, op2->digit_count) + 1);
468468 dest->data.digits[0] = first_digit;
469469
470470 for (;;) {
......@@ -532,7 +532,7 @@ void bigint_add(BigInt *dest, const BigInt *op1, const BigInt *op2) {
532532 return;
533533 }
534534 uint64_t first_digit = dest->data.digit;
535 dest->data.digits = allocate_nonzero<uint64_t>(bigger_op->digit_count);
535 dest->data.digits = heap::c_allocator.allocate_nonzero<uint64_t>(bigger_op->digit_count);
536536 dest->data.digits[0] = first_digit;
537537 size_t i = 1;
538538
......@@ -1032,7 +1032,7 @@ static void bigint_unsigned_division(const BigInt *op1, const BigInt *op2, BigIn
10321032 if (lhsWords == 1) {
10331033 Quotient->data.digit = Make_64(Q[1], Q[0]);
10341034 } else {
1035 Quotient->data.digits = allocate<uint64_t>(lhsWords);
1035 Quotient->data.digits = heap::c_allocator.allocate<uint64_t>(lhsWords);
10361036 for (size_t i = 0; i < lhsWords; i += 1) {
10371037 Quotient->data.digits[i] = Make_64(Q[i*2+1], Q[i*2]);
10381038 }
......@@ -1046,7 +1046,7 @@ static void bigint_unsigned_division(const BigInt *op1, const BigInt *op2, BigIn
10461046 if (rhsWords == 1) {
10471047 Remainder->data.digit = Make_64(R[1], R[0]);
10481048 } else {
1049 Remainder->data.digits = allocate<uint64_t>(rhsWords);
1049 Remainder->data.digits = heap::c_allocator.allocate<uint64_t>(rhsWords);
10501050 for (size_t i = 0; i < rhsWords; i += 1) {
10511051 Remainder->data.digits[i] = Make_64(R[i*2+1], R[i*2]);
10521052 }
......@@ -1218,7 +1218,7 @@ void bigint_or(BigInt *dest, const BigInt *op1, const BigInt *op2) {
12181218 return;
12191219 }
12201220 dest->digit_count = max(op1->digit_count, op2->digit_count);
1221 dest->data.digits = allocate_nonzero<uint64_t>(dest->digit_count);
1221 dest->data.digits = heap::c_allocator.allocate_nonzero<uint64_t>(dest->digit_count);
12221222 for (size_t i = 0; i < dest->digit_count; i += 1) {
12231223 uint64_t digit = 0;
12241224 if (i < op1->digit_count) {
......@@ -1262,7 +1262,7 @@ void bigint_and(BigInt *dest, const BigInt *op1, const BigInt *op2) {
12621262 }
12631263
12641264 dest->digit_count = max(op1->digit_count, op2->digit_count);
1265 dest->data.digits = allocate_nonzero<uint64_t>(dest->digit_count);
1265 dest->data.digits = heap::c_allocator.allocate_nonzero<uint64_t>(dest->digit_count);
12661266
12671267 size_t i = 0;
12681268 for (; i < op1->digit_count && i < op2->digit_count; i += 1) {
......@@ -1308,7 +1308,7 @@ void bigint_xor(BigInt *dest, const BigInt *op1, const BigInt *op2) {
13081308 return;
13091309 }
13101310 dest->digit_count = max(op1->digit_count, op2->digit_count);
1311 dest->data.digits = allocate_nonzero<uint64_t>(dest->digit_count);
1311 dest->data.digits = heap::c_allocator.allocate_nonzero<uint64_t>(dest->digit_count);
13121312 size_t i = 0;
13131313 for (; i < op1->digit_count && i < op2->digit_count; i += 1) {
13141314 dest->data.digits[i] = op1_digits[i] ^ op2_digits[i];
......@@ -1358,7 +1358,7 @@ void bigint_shl(BigInt *dest, const BigInt *op1, const BigInt *op2) {
13581358 uint64_t digit_shift_count = shift_amt / 64;
13591359 uint64_t leftover_shift_count = shift_amt % 64;
13601360
1361 dest->data.digits = allocate<uint64_t>(op1->digit_count + digit_shift_count + 1);
1361 dest->data.digits = heap::c_allocator.allocate<uint64_t>(op1->digit_count + digit_shift_count + 1);
13621362 dest->digit_count = digit_shift_count;
13631363 uint64_t carry = 0;
13641364 for (size_t i = 0; i < op1->digit_count; i += 1) {
......@@ -1421,7 +1421,7 @@ void bigint_shr(BigInt *dest, const BigInt *op1, const BigInt *op2) {
14211421 if (dest->digit_count == 1) {
14221422 digits = &dest->data.digit;
14231423 } else {
1424 digits = allocate<uint64_t>(dest->digit_count);
1424 digits = heap::c_allocator.allocate<uint64_t>(dest->digit_count);
14251425 dest->data.digits = digits;
14261426 }
14271427
......@@ -1492,7 +1492,7 @@ void bigint_not(BigInt *dest, const BigInt *op, size_t bit_count, bool is_signed
14921492 }
14931493 dest->digit_count = (bit_count + 63) / 64;
14941494 assert(dest->digit_count >= op->digit_count);
1495 dest->data.digits = allocate_nonzero<uint64_t>(dest->digit_count);
1495 dest->data.digits = heap::c_allocator.allocate_nonzero<uint64_t>(dest->digit_count);
14961496 size_t i = 0;
14971497 for (; i < op->digit_count; i += 1) {
14981498 dest->data.digits[i] = ~op_digits[i];
src/buffer.hpp+4-5
......@@ -50,7 +50,7 @@ static inline void buf_resize(Buf *buf, size_t new_len) {
5050}
5151
5252static inline Buf *buf_alloc_fixed(size_t size) {
53 Buf *buf = allocate<Buf>(1);
53 Buf *buf = heap::c_allocator.create<Buf>();
5454 buf_resize(buf, size);
5555 return buf;
5656}
......@@ -65,7 +65,7 @@ static inline void buf_deinit(Buf *buf) {
6565
6666static inline void buf_destroy(Buf *buf) {
6767 buf_deinit(buf);
68 free(buf);
68 heap::c_allocator.destroy(buf);
6969}
7070
7171static inline void buf_init_from_mem(Buf *buf, const char *ptr, size_t len) {
......@@ -85,7 +85,7 @@ static inline void buf_init_from_buf(Buf *buf, Buf *other) {
8585
8686static inline Buf *buf_create_from_mem(const char *ptr, size_t len) {
8787 assert(len != SIZE_MAX);
88 Buf *buf = allocate<Buf>(1);
88 Buf *buf = heap::c_allocator.create<Buf>();
8989 buf_init_from_mem(buf, ptr, len);
9090 return buf;
9191}
......@@ -108,7 +108,7 @@ static inline Buf *buf_slice(Buf *in_buf, size_t start, size_t end) {
108108 assert(end != SIZE_MAX);
109109 assert(start < buf_len(in_buf));
110110 assert(end <= buf_len(in_buf));
111 Buf *out_buf = allocate<Buf>(1);
111 Buf *out_buf = heap::c_allocator.create<Buf>();
112112 out_buf->list.resize(end - start + 1);
113113 memcpy(buf_ptr(out_buf), buf_ptr(in_buf) + start, end - start);
114114 out_buf->list.at(buf_len(out_buf)) = 0;
......@@ -211,5 +211,4 @@ static inline void buf_replace(Buf* buf, char from, char to) {
211211 }
212212}
213213
214
215214#endif
src/codegen.cpp+40-35
......@@ -21,6 +21,7 @@
2121#include "userland.h"
2222#include "dump_analysis.hpp"
2323#include "softfloat.hpp"
24#include "mem_profile.hpp"
2425
2526#include <stdio.h>
2627#include <errno.h>
......@@ -57,7 +58,7 @@ static void init_darwin_native(CodeGen *g) {
5758}
5859
5960static ZigPackage *new_package(const char *root_src_dir, const char *root_src_path, const char *pkg_path) {
60 ZigPackage *entry = allocate<ZigPackage>(1);
61 ZigPackage *entry = heap::c_allocator.create<ZigPackage>();
6162 entry->package_table.init(4);
6263 buf_init_from_str(&entry->root_src_dir, root_src_dir);
6364 buf_init_from_str(&entry->root_src_path, root_src_path);
......@@ -4323,7 +4324,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutableGen *executable, IrIn
43234324 }
43244325 size_t field_count = arg_calc.field_index;
43254326
4326 LLVMTypeRef *field_types = allocate_nonzero<LLVMTypeRef>(field_count);
4327 LLVMTypeRef *field_types = heap::c_allocator.allocate_nonzero<LLVMTypeRef>(field_count);
43274328 LLVMGetStructElementTypes(LLVMGetElementType(LLVMTypeOf(frame_result_loc)), field_types);
43284329 assert(LLVMCountStructElementTypes(LLVMGetElementType(LLVMTypeOf(frame_result_loc))) == arg_calc_start.field_index);
43294330
......@@ -4676,8 +4677,8 @@ static LLVMValueRef ir_render_asm_gen(CodeGen *g, IrExecutableGen *executable, I
46764677 instruction->return_count;
46774678 size_t total_index = 0;
46784679 size_t param_index = 0;
4679 LLVMTypeRef *param_types = allocate<LLVMTypeRef>(input_and_output_count);
4680 LLVMValueRef *param_values = allocate<LLVMValueRef>(input_and_output_count);
4680 LLVMTypeRef *param_types = heap::c_allocator.allocate<LLVMTypeRef>(input_and_output_count);
4681 LLVMValueRef *param_values = heap::c_allocator.allocate<LLVMValueRef>(input_and_output_count);
46814682 for (size_t i = 0; i < asm_expr->output_list.length; i += 1, total_index += 1) {
46824683 AsmOutput *asm_output = asm_expr->output_list.at(i);
46834684 bool is_return = (asm_output->return_type != nullptr);
......@@ -4919,7 +4920,7 @@ static LLVMValueRef ir_render_shuffle_vector(CodeGen *g, IrExecutableGen *execut
49194920 // second vector. These start at -1 and go down, and are easiest to use
49204921 // with the ~ operator. Here we convert between the two formats.
49214922 IrInstGen *mask = instruction->mask;
4922 LLVMValueRef *values = allocate<LLVMValueRef>(len_mask);
4923 LLVMValueRef *values = heap::c_allocator.allocate<LLVMValueRef>(len_mask);
49234924 for (uint64_t i = 0; i < len_mask; i++) {
49244925 if (mask->value->data.x_array.data.s_none.elements[i].special == ConstValSpecialUndef) {
49254926 values[i] = LLVMGetUndef(LLVMInt32Type());
......@@ -4931,7 +4932,7 @@ static LLVMValueRef ir_render_shuffle_vector(CodeGen *g, IrExecutableGen *execut
49314932 }
49324933
49334934 LLVMValueRef llvm_mask_value = LLVMConstVector(values, len_mask);
4934 free(values);
4935 heap::c_allocator.deallocate(values, len_mask);
49354936
49364937 return LLVMBuildShuffleVector(g->builder,
49374938 ir_llvm_value(g, instruction->a),
......@@ -4999,8 +5000,8 @@ static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutableGen *executable, IrIns
49995000 }
50005001
50015002 LLVMValueRef phi = LLVMBuildPhi(g->builder, phi_type, "");
5002 LLVMValueRef *incoming_values = allocate<LLVMValueRef>(instruction->incoming_count);
5003 LLVMBasicBlockRef *incoming_blocks = allocate<LLVMBasicBlockRef>(instruction->incoming_count);
5003 LLVMValueRef *incoming_values = heap::c_allocator.allocate<LLVMValueRef>(instruction->incoming_count);
5004 LLVMBasicBlockRef *incoming_blocks = heap::c_allocator.allocate<LLVMBasicBlockRef>(instruction->incoming_count);
50045005 for (size_t i = 0; i < instruction->incoming_count; i += 1) {
50055006 incoming_values[i] = ir_llvm_value(g, instruction->incoming_values[i]);
50065007 incoming_blocks[i] = instruction->incoming_blocks[i]->llvm_exit_block;
......@@ -5972,12 +5973,12 @@ static LLVMValueRef ir_render_bswap(CodeGen *g, IrExecutableGen *executable, IrI
59725973 LLVMValueRef shift_amt = LLVMConstInt(get_llvm_type(g, extended_type), 8, false);
59735974 if (is_vector) {
59745975 extended_type = get_vector_type(g, expr_type->data.vector.len, extended_type);
5975 LLVMValueRef *values = allocate_nonzero<LLVMValueRef>(expr_type->data.vector.len);
5976 LLVMValueRef *values = heap::c_allocator.allocate_nonzero<LLVMValueRef>(expr_type->data.vector.len);
59765977 for (uint32_t i = 0; i < expr_type->data.vector.len; i += 1) {
59775978 values[i] = shift_amt;
59785979 }
59795980 shift_amt = LLVMConstVector(values, expr_type->data.vector.len);
5980 free(values);
5981 heap::c_allocator.deallocate(values, expr_type->data.vector.len);
59815982 }
59825983 // aabbcc
59835984 LLVMValueRef extended = LLVMBuildZExt(g->builder, op, get_llvm_type(g, extended_type), "");
......@@ -7010,7 +7011,7 @@ check: switch (const_val->special) {
70107011 }
70117012 case ZigTypeIdStruct:
70127013 {
7013 LLVMValueRef *fields = allocate<LLVMValueRef>(type_entry->data.structure.gen_field_count);
7014 LLVMValueRef *fields = heap::c_allocator.allocate<LLVMValueRef>(type_entry->data.structure.gen_field_count);
70147015 size_t src_field_count = type_entry->data.structure.src_field_count;
70157016 bool make_unnamed_struct = false;
70167017 assert(type_entry->data.structure.resolve_status == ResolveStatusLLVMFull);
......@@ -7069,7 +7070,7 @@ check: switch (const_val->special) {
70697070 } else {
70707071 const LLVMValueRef AMT = LLVMConstInt(LLVMTypeOf(val), 8, false);
70717072
7072 LLVMValueRef *values = allocate<LLVMValueRef>(size_in_bytes);
7073 LLVMValueRef *values = heap::c_allocator.allocate<LLVMValueRef>(size_in_bytes);
70737074 for (size_t i = 0; i < size_in_bytes; i++) {
70747075 const size_t idx = is_big_endian ? size_in_bytes - 1 - i : i;
70757076 values[idx] = LLVMConstTruncOrBitCast(val, LLVMInt8Type());
......@@ -7133,7 +7134,7 @@ check: switch (const_val->special) {
71337134 case ConstArraySpecialNone: {
71347135 uint64_t extra_len_from_sentinel = (type_entry->data.array.sentinel != nullptr) ? 1 : 0;
71357136 uint64_t full_len = len + extra_len_from_sentinel;
7136 LLVMValueRef *values = allocate<LLVMValueRef>(full_len);
7137 LLVMValueRef *values = heap::c_allocator.allocate<LLVMValueRef>(full_len);
71377138 LLVMTypeRef element_type_ref = get_llvm_type(g, type_entry->data.array.child_type);
71387139 bool make_unnamed_struct = false;
71397140 for (uint64_t i = 0; i < len; i += 1) {
......@@ -7165,7 +7166,7 @@ check: switch (const_val->special) {
71657166 case ConstArraySpecialUndef:
71667167 return LLVMGetUndef(get_llvm_type(g, type_entry));
71677168 case ConstArraySpecialNone: {
7168 LLVMValueRef *values = allocate<LLVMValueRef>(len);
7169 LLVMValueRef *values = heap::c_allocator.allocate<LLVMValueRef>(len);
71697170 for (uint64_t i = 0; i < len; i += 1) {
71707171 ZigValue *elem_value = &const_val->data.x_array.data.s_none.elements[i];
71717172 values[i] = gen_const_val(g, elem_value, "");
......@@ -7175,7 +7176,7 @@ check: switch (const_val->special) {
71757176 case ConstArraySpecialBuf: {
71767177 Buf *buf = const_val->data.x_array.data.s_buf;
71777178 assert(buf_len(buf) == len);
7178 LLVMValueRef *values = allocate<LLVMValueRef>(len);
7179 LLVMValueRef *values = heap::c_allocator.allocate<LLVMValueRef>(len);
71797180 for (uint64_t i = 0; i < len; i += 1) {
71807181 values[i] = LLVMConstInt(g->builtin_types.entry_u8->llvm_type, buf_ptr(buf)[i], false);
71817182 }
......@@ -7377,7 +7378,7 @@ static void generate_error_name_table(CodeGen *g) {
73777378 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0, false);
73787379 ZigType *str_type = get_slice_type(g, u8_ptr_type);
73797380
7380 LLVMValueRef *values = allocate<LLVMValueRef>(g->errors_by_index.length);
7381 LLVMValueRef *values = heap::c_allocator.allocate<LLVMValueRef>(g->errors_by_index.length);
73817382 values[0] = LLVMGetUndef(get_llvm_type(g, str_type));
73827383 for (size_t i = 1; i < g->errors_by_index.length; i += 1) {
73837384 ErrorTableEntry *err_entry = g->errors_by_index.at(i);
......@@ -7906,6 +7907,9 @@ static void do_code_gen(CodeGen *g) {
79067907}
79077908
79087909static void zig_llvm_emit_output(CodeGen *g) {
7910 g->pass1_arena->destruct(&heap::c_allocator);
7911 g->pass1_arena = nullptr;
7912
79097913 bool is_small = g->build_mode == BuildModeSmallRelease;
79107914
79117915 Buf *output_path = &g->o_file_output_path;
......@@ -8202,7 +8206,7 @@ static void define_intern_values(CodeGen *g) {
82028206}
82038207
82048208static BuiltinFnEntry *create_builtin_fn(CodeGen *g, BuiltinFnId id, const char *name, size_t count) {
8205 BuiltinFnEntry *builtin_fn = allocate<BuiltinFnEntry>(1);
8209 BuiltinFnEntry *builtin_fn = heap::c_allocator.create<BuiltinFnEntry>();
82068210 buf_init_from_str(&builtin_fn->name, name);
82078211 builtin_fn->id = id;
82088212 builtin_fn->param_count = count;
......@@ -8919,16 +8923,16 @@ static void init(CodeGen *g) {
89198923 define_builtin_types(g);
89208924 define_intern_values(g);
89218925
8922 IrInstGen *sentinel_instructions = allocate<IrInstGen>(2);
8926 IrInstGen *sentinel_instructions = heap::c_allocator.allocate<IrInstGen>(2);
89238927 g->invalid_inst_gen = &sentinel_instructions[0];
8924 g->invalid_inst_gen->value = allocate<ZigValue>(1, "ZigValue");
8928 g->invalid_inst_gen->value = g->pass1_arena->create<ZigValue>();
89258929 g->invalid_inst_gen->value->type = g->builtin_types.entry_invalid;
89268930
89278931 g->unreach_instruction = &sentinel_instructions[1];
8928 g->unreach_instruction->value = allocate<ZigValue>(1, "ZigValue");
8932 g->unreach_instruction->value = g->pass1_arena->create<ZigValue>();
89298933 g->unreach_instruction->value->type = g->builtin_types.entry_unreachable;
89308934
8931 g->invalid_inst_src = allocate<IrInstSrc>(1);
8935 g->invalid_inst_src = heap::c_allocator.create<IrInstSrc>();
89328936
89338937 define_builtin_fns(g);
89348938 Error err;
......@@ -9010,7 +9014,7 @@ static void detect_libc(CodeGen *g) {
90109014 buf_ptr(g->zig_lib_dir), target_os_name(g->zig_target->os));
90119015
90129016 g->libc_include_dir_len = 4;
9013 g->libc_include_dir_list = allocate<Buf*>(g->libc_include_dir_len);
9017 g->libc_include_dir_list = heap::c_allocator.allocate<Buf*>(g->libc_include_dir_len);
90149018 g->libc_include_dir_list[0] = arch_include_dir;
90159019 g->libc_include_dir_list[1] = generic_include_dir;
90169020 g->libc_include_dir_list[2] = arch_os_include_dir;
......@@ -9019,7 +9023,7 @@ static void detect_libc(CodeGen *g) {
90199023 }
90209024
90219025 if (g->zig_target->is_native) {
9022 g->libc = allocate<ZigLibCInstallation>(1);
9026 g->libc = heap::c_allocator.create<ZigLibCInstallation>();
90239027
90249028 // search for native_libc.txt in following dirs:
90259029 // - LOCAL_CACHE_DIR
......@@ -9099,7 +9103,7 @@ static void detect_libc(CodeGen *g) {
90999103 size_t want_um_and_shared_dirs = (g->zig_target->os == OsWindows) ? 2 : 0;
91009104 size_t dir_count = 1 + want_sys_dir + want_um_and_shared_dirs;
91019105 g->libc_include_dir_len = 0;
9102 g->libc_include_dir_list = allocate<Buf*>(dir_count);
9106 g->libc_include_dir_list = heap::c_allocator.allocate<Buf*>(dir_count);
91039107
91049108 g->libc_include_dir_list[g->libc_include_dir_len] = &g->libc->include_dir;
91059109 g->libc_include_dir_len += 1;
......@@ -9466,10 +9470,10 @@ static void update_test_functions_builtin_decl(CodeGen *g) {
94669470 if ((err = type_resolve(g, struct_type, ResolveStatusSizeKnown)))
94679471 zig_unreachable();
94689472
9469 ZigValue *test_fn_array = create_const_vals(1);
9473 ZigValue *test_fn_array = g->pass1_arena->create<ZigValue>();
94709474 test_fn_array->type = get_array_type(g, struct_type, g->test_fns.length, nullptr);
94719475 test_fn_array->special = ConstValSpecialStatic;
9472 test_fn_array->data.x_array.data.s_none.elements = create_const_vals(g->test_fns.length);
9476 test_fn_array->data.x_array.data.s_none.elements = g->pass1_arena->allocate<ZigValue>(g->test_fns.length);
94739477
94749478 for (size_t i = 0; i < g->test_fns.length; i += 1) {
94759479 ZigFn *test_fn_entry = g->test_fns.at(i);
......@@ -9480,7 +9484,7 @@ static void update_test_functions_builtin_decl(CodeGen *g) {
94809484 this_val->parent.id = ConstParentIdArray;
94819485 this_val->parent.data.p_array.array_val = test_fn_array;
94829486 this_val->parent.data.p_array.elem_index = i;
9483 this_val->data.x_struct.fields = alloc_const_vals_ptrs(3);
9487 this_val->data.x_struct.fields = alloc_const_vals_ptrs(g, 3);
94849488
94859489 ZigValue *name_field = this_val->data.x_struct.fields[0];
94869490 ZigValue *name_array_val = create_const_str_lit(g, &test_fn_entry->symbol_name)->data.x_ptr.data.ref.pointee;
......@@ -9499,7 +9503,7 @@ static void update_test_functions_builtin_decl(CodeGen *g) {
94999503 frame_size_field->data.x_optional = nullptr;
95009504
95019505 if (fn_is_async(test_fn_entry)) {
9502 frame_size_field->data.x_optional = create_const_vals(1);
9506 frame_size_field->data.x_optional = g->pass1_arena->create<ZigValue>();
95039507 frame_size_field->data.x_optional->special = ConstValSpecialStatic;
95049508 frame_size_field->data.x_optional->type = g->builtin_types.entry_usize;
95059509 bigint_init_unsigned(&frame_size_field->data.x_optional->data.x_bigint,
......@@ -9634,7 +9638,7 @@ static Error get_tmp_filename(CodeGen *g, Buf *out, Buf *suffix) {
96349638
96359639Error create_c_object_cache(CodeGen *g, CacheHash **out_cache_hash, bool verbose) {
96369640 Error err;
9637 CacheHash *cache_hash = allocate<CacheHash>(1);
9641 CacheHash *cache_hash = heap::c_allocator.create<CacheHash>();
96389642 Buf *manifest_dir = buf_sprintf("%s" OS_SEP CACHE_HASH_SUBDIR, buf_ptr(g->cache_dir));
96399643 cache_init(cache_hash, manifest_dir);
96409644
......@@ -10788,7 +10792,8 @@ CodeGen *codegen_create(Buf *main_pkg_path, Buf *root_src_path, const ZigTarget
1078810792 OutType out_type, BuildMode build_mode, Buf *override_lib_dir,
1078910793 ZigLibCInstallation *libc, Buf *cache_dir, bool is_test_build, Stage2ProgressNode *progress_node)
1079010794{
10791 CodeGen *g = allocate<CodeGen>(1);
10795 CodeGen *g = heap::c_allocator.create<CodeGen>();
10796 g->pass1_arena = heap::ArenaAllocator::construct(&heap::c_allocator, &heap::c_allocator, "pass1");
1079210797 g->main_progress_node = progress_node;
1079310798
1079410799 codegen_add_time_event(g, "Initialize");
......@@ -10931,35 +10936,35 @@ void codegen_switch_sub_prog_node(CodeGen *g, Stage2ProgressNode *node) {
1093110936
1093210937ZigValue *CodeGen::Intern::for_undefined() {
1093310938#ifdef ZIG_ENABLE_MEM_PROFILE
10934 memprof_intern_count.x_undefined += 1;
10939 mem::intern_counters.x_undefined += 1;
1093510940#endif
1093610941 return &this->x_undefined;
1093710942}
1093810943
1093910944ZigValue *CodeGen::Intern::for_void() {
1094010945#ifdef ZIG_ENABLE_MEM_PROFILE
10941 memprof_intern_count.x_void += 1;
10946 mem::intern_counters.x_void += 1;
1094210947#endif
1094310948 return &this->x_void;
1094410949}
1094510950
1094610951ZigValue *CodeGen::Intern::for_null() {
1094710952#ifdef ZIG_ENABLE_MEM_PROFILE
10948 memprof_intern_count.x_null += 1;
10953 mem::intern_counters.x_null += 1;
1094910954#endif
1095010955 return &this->x_null;
1095110956}
1095210957
1095310958ZigValue *CodeGen::Intern::for_unreachable() {
1095410959#ifdef ZIG_ENABLE_MEM_PROFILE
10955 memprof_intern_count.x_unreachable += 1;
10960 mem::intern_counters.x_unreachable += 1;
1095610961#endif
1095710962 return &this->x_unreachable;
1095810963}
1095910964
1096010965ZigValue *CodeGen::Intern::for_zero_byte() {
1096110966#ifdef ZIG_ENABLE_MEM_PROFILE
10962 memprof_intern_count.zero_byte += 1;
10967 mem::intern_counters.zero_byte += 1;
1096310968#endif
1096410969 return &this->zero_byte;
1096510970}
src/errmsg.cpp+2-2
......@@ -99,7 +99,7 @@ void err_msg_add_note(ErrorMsg *parent, ErrorMsg *note) {
9999ErrorMsg *err_msg_create_with_offset(Buf *path, size_t line, size_t column, size_t offset,
100100 const char *source, Buf *msg)
101101{
102 ErrorMsg *err_msg = allocate<ErrorMsg>(1);
102 ErrorMsg *err_msg = heap::c_allocator.create<ErrorMsg>();
103103 err_msg->path = path;
104104 err_msg->line_start = line;
105105 err_msg->column_start = column;
......@@ -138,7 +138,7 @@ ErrorMsg *err_msg_create_with_offset(Buf *path, size_t line, size_t column, size
138138ErrorMsg *err_msg_create_with_line(Buf *path, size_t line, size_t column,
139139 Buf *source, ZigList<size_t> *line_offsets, Buf *msg)
140140{
141 ErrorMsg *err_msg = allocate<ErrorMsg>(1);
141 ErrorMsg *err_msg = heap::c_allocator.create<ErrorMsg>();
142142 err_msg->path = path;
143143 err_msg->line_start = line;
144144 err_msg->column_start = column;
src/glibc.cpp+4-4
......@@ -21,7 +21,7 @@ static const ZigGLibCLib glibc_libs[] = {
2121Error glibc_load_metadata(ZigGLibCAbi **out_result, Buf *zig_lib_dir, bool verbose) {
2222 Error err;
2323
24 ZigGLibCAbi *glibc_abi = allocate<ZigGLibCAbi>(1);
24 ZigGLibCAbi *glibc_abi = heap::c_allocator.create<ZigGLibCAbi>();
2525 glibc_abi->vers_txt_path = buf_sprintf("%s" OS_SEP "libc" OS_SEP "glibc" OS_SEP "vers.txt", buf_ptr(zig_lib_dir));
2626 glibc_abi->fns_txt_path = buf_sprintf("%s" OS_SEP "libc" OS_SEP "glibc" OS_SEP "fns.txt", buf_ptr(zig_lib_dir));
2727 glibc_abi->abi_txt_path = buf_sprintf("%s" OS_SEP "libc" OS_SEP "glibc" OS_SEP "abi.txt", buf_ptr(zig_lib_dir));
......@@ -100,10 +100,10 @@ Error glibc_load_metadata(ZigGLibCAbi **out_result, Buf *zig_lib_dir, bool verbo
100100 Optional<Slice<uint8_t>> opt_line = SplitIterator_next_separate(&it);
101101 if (!opt_line.is_some) break;
102102
103 ver_list_base = allocate<ZigGLibCVerList>(glibc_abi->all_functions.length);
103 ver_list_base = heap::c_allocator.allocate<ZigGLibCVerList>(glibc_abi->all_functions.length);
104104 SplitIterator line_it = memSplit(opt_line.value, str(" "));
105105 for (;;) {
106 ZigTarget *target = allocate<ZigTarget>(1);
106 ZigTarget *target = heap::c_allocator.create<ZigTarget>();
107107 Optional<Slice<uint8_t>> opt_target = SplitIterator_next(&line_it);
108108 if (!opt_target.is_some) break;
109109
......@@ -174,7 +174,7 @@ Error glibc_build_dummies_and_maps(CodeGen *g, const ZigGLibCAbi *glibc_abi, con
174174 Error err;
175175
176176 Buf *cache_dir = get_global_cache_dir();
177 CacheHash *cache_hash = allocate<CacheHash>(1);
177 CacheHash *cache_hash = heap::c_allocator.create<CacheHash>();
178178 Buf *manifest_dir = buf_sprintf("%s" OS_SEP CACHE_HASH_SUBDIR, buf_ptr(cache_dir));
179179 cache_init(cache_hash, manifest_dir);
180180
src/hash_map.hpp+3-3
......@@ -19,7 +19,7 @@ public:
1919 init_capacity(capacity);
2020 }
2121 void deinit(void) {
22 free(_entries);
22 heap::c_allocator.deallocate(_entries, _capacity);
2323 }
2424
2525 struct Entry {
......@@ -57,7 +57,7 @@ public:
5757 if (old_entry->used)
5858 internal_put(old_entry->key, old_entry->value);
5959 }
60 free(old_entries);
60 heap::c_allocator.deallocate(old_entries, old_capacity);
6161 }
6262 }
6363
......@@ -164,7 +164,7 @@ private:
164164
165165 void init_capacity(int capacity) {
166166 _capacity = capacity;
167 _entries = allocate<Entry>(_capacity);
167 _entries = heap::c_allocator.allocate<Entry>(_capacity);
168168 _size = 0;
169169 _max_distance_from_start_index = 0;
170170 for (int i = 0; i < _capacity; i += 1) {
src/heap.cpp created+377
......@@ -0,0 +1,377 @@
1/*
2 * Copyright (c) 2020 Andrew Kelley
3 *
4 * This file is part of zig, which is MIT licensed.
5 * See http://opensource.org/licenses/MIT
6 */
7
8#include <new>
9#include <string.h>
10
11#include "config.h"
12#include "heap.hpp"
13#include "mem_profile.hpp"
14
15namespace heap {
16
17extern mem::Allocator &bootstrap_allocator;
18
19//
20// BootstrapAllocator implementation is identical to CAllocator minus
21// profile profile functionality. Splitting off to a base interface doesn't
22// seem worthwhile.
23//
24
25void BootstrapAllocator::init(const char *name) {}
26void BootstrapAllocator::deinit() {}
27
28void *BootstrapAllocator::internal_allocate(const mem::TypeInfo &info, size_t count) {
29 return mem::os::calloc(count, info.size);
30}
31
32void *BootstrapAllocator::internal_allocate_nonzero(const mem::TypeInfo &info, size_t count) {
33 return mem::os::malloc(count * info.size);
34}
35
36void *BootstrapAllocator::internal_reallocate(const mem::TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) {
37 auto new_ptr = this->internal_reallocate_nonzero(info, old_ptr, old_count, new_count);
38 if (new_count > old_count)
39 memset(reinterpret_cast<uint8_t *>(new_ptr) + (old_count * info.size), 0, (new_count - old_count) * info.size);
40 return new_ptr;
41}
42
43void *BootstrapAllocator::internal_reallocate_nonzero(const mem::TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) {
44 return mem::os::realloc(old_ptr, new_count * info.size);
45}
46
47void BootstrapAllocator::internal_deallocate(const mem::TypeInfo &info, void *ptr, size_t count) {
48 mem::os::free(ptr);
49}
50
51void CAllocator::init(const char *name) {
52#ifdef ZIG_ENABLE_MEM_PROFILE
53 this->profile = bootstrap_allocator.create<mem::Profile>();
54 this->profile->init(name, "CAllocator");
55#endif
56}
57
58void CAllocator::deinit() {
59#ifdef ZIG_ENABLE_MEM_PROFILE
60 assert(this->profile);
61 this->profile->deinit();
62 bootstrap_allocator.destroy(this->profile);
63 this->profile = nullptr;
64#endif
65}
66
67CAllocator *CAllocator::construct(mem::Allocator *allocator, const char *name) {
68 auto p = new(allocator->create<CAllocator>()) CAllocator();
69 p->init(name);
70 return p;
71}
72
73void CAllocator::destruct(mem::Allocator *allocator) {
74 this->deinit();
75 allocator->destroy(this);
76}
77
78#ifdef ZIG_ENABLE_MEM_PROFILE
79void CAllocator::print_report(FILE *file) {
80 this->profile->print_report(file);
81}
82#endif
83
84void *CAllocator::internal_allocate(const mem::TypeInfo &info, size_t count) {
85#ifdef ZIG_ENABLE_MEM_PROFILE
86 this->profile->record_alloc(info, count);
87#endif
88 return mem::os::calloc(count, info.size);
89}
90
91void *CAllocator::internal_allocate_nonzero(const mem::TypeInfo &info, size_t count) {
92#ifdef ZIG_ENABLE_MEM_PROFILE
93 this->profile->record_alloc(info, count);
94#endif
95 return mem::os::malloc(count * info.size);
96}
97
98void *CAllocator::internal_reallocate(const mem::TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) {
99 auto new_ptr = this->internal_reallocate_nonzero(info, old_ptr, old_count, new_count);
100 if (new_count > old_count)
101 memset(reinterpret_cast<uint8_t *>(new_ptr) + (old_count * info.size), 0, (new_count - old_count) * info.size);
102 return new_ptr;
103}
104
105void *CAllocator::internal_reallocate_nonzero(const mem::TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) {
106#ifdef ZIG_ENABLE_MEM_PROFILE
107 this->profile->record_dealloc(info, old_count);
108 this->profile->record_alloc(info, new_count);
109#endif
110 return mem::os::realloc(old_ptr, new_count * info.size);
111}
112
113void CAllocator::internal_deallocate(const mem::TypeInfo &info, void *ptr, size_t count) {
114#ifdef ZIG_ENABLE_MEM_PROFILE
115 this->profile->record_dealloc(info, count);
116#endif
117 mem::os::free(ptr);
118}
119
120struct ArenaAllocator::Impl {
121 Allocator *backing;
122
123 // regular allocations bump through a segment of static size
124 struct Segment {
125 static constexpr size_t size = 65536;
126 static constexpr size_t object_threshold = 4096;
127
128 uint8_t data[size];
129 };
130
131 // active segment
132 Segment *segment;
133 size_t segment_offset;
134
135 // keep track of segments
136 struct SegmentTrack {
137 static constexpr size_t size = (4096 - sizeof(SegmentTrack *)) / sizeof(Segment *);
138
139 // null if first
140 SegmentTrack *prev;
141 Segment *segments[size];
142 };
143 static_assert(sizeof(SegmentTrack) <= 4096, "unwanted struct padding");
144
145 // active segment track
146 SegmentTrack *segment_track;
147 size_t segment_track_remain;
148
149 // individual allocations punted to backing allocator
150 struct Object {
151 uint8_t *ptr;
152 size_t len;
153 };
154
155 // keep track of objects
156 struct ObjectTrack {
157 static constexpr size_t size = (4096 - sizeof(ObjectTrack *)) / sizeof(Object);
158
159 // null if first
160 ObjectTrack *prev;
161 Object objects[size];
162 };
163 static_assert(sizeof(ObjectTrack) <= 4096, "unwanted struct padding");
164
165 // active object track
166 ObjectTrack *object_track;
167 size_t object_track_remain;
168
169 ATTRIBUTE_RETURNS_NOALIAS inline void *allocate(const mem::TypeInfo& info, size_t count);
170 inline void *reallocate(const mem::TypeInfo& info, void *old_ptr, size_t old_count, size_t new_count);
171
172 inline void new_segment();
173 inline void track_segment();
174 inline void track_object(Object object);
175};
176
177void *ArenaAllocator::Impl::allocate(const mem::TypeInfo& info, size_t count) {
178#ifndef NDEBUG
179 // make behavior when size == 0 portable
180 if (info.size == 0 || count == 0)
181 return nullptr;
182#endif
183 const size_t nbytes = info.size * count;
184 this->segment_offset = (this->segment_offset + (info.alignment - 1)) & ~(info.alignment - 1);
185 if (nbytes >= Segment::object_threshold) {
186 auto ptr = this->backing->allocate<uint8_t>(nbytes);
187 this->track_object({ptr, nbytes});
188 return ptr;
189 }
190 if (this->segment_offset + nbytes > Segment::size)
191 this->new_segment();
192 auto ptr = &this->segment->data[this->segment_offset];
193 this->segment_offset += nbytes;
194 return ptr;
195}
196
197void *ArenaAllocator::Impl::reallocate(const mem::TypeInfo& info, void *old_ptr, size_t old_count, size_t new_count) {
198#ifndef NDEBUG
199 // make behavior when size == 0 portable
200 if (info.size == 0 && old_ptr == nullptr)
201 return nullptr;
202#endif
203 const size_t new_nbytes = info.size * new_count;
204 if (new_nbytes <= info.size * old_count)
205 return old_ptr;
206 const size_t old_nbytes = info.size * old_count;
207 this->segment_offset = (this->segment_offset + (info.alignment - 1)) & ~(info.alignment - 1);
208 if (new_nbytes >= Segment::object_threshold) {
209 auto new_ptr = this->backing->allocate<uint8_t>(new_nbytes);
210 this->track_object({new_ptr, new_nbytes});
211 memcpy(new_ptr, old_ptr, old_nbytes);
212 return new_ptr;
213 }
214 if (this->segment_offset + new_nbytes > Segment::size)
215 this->new_segment();
216 auto new_ptr = &this->segment->data[this->segment_offset];
217 this->segment_offset += new_nbytes;
218 memcpy(new_ptr, old_ptr, old_nbytes);
219 return new_ptr;
220}
221
222void ArenaAllocator::Impl::new_segment() {
223 this->segment = this->backing->create<Segment>();
224 this->segment_offset = 0;
225 this->track_segment();
226}
227
228void ArenaAllocator::Impl::track_segment() {
229 assert(this->segment != nullptr);
230 if (this->segment_track_remain < 1) {
231 auto prev = this->segment_track;
232 this->segment_track = this->backing->create<SegmentTrack>();
233 this->segment_track->prev = prev;
234 this->segment_track_remain = SegmentTrack::size;
235 }
236 this->segment_track_remain -= 1;
237 this->segment_track->segments[this->segment_track_remain] = this->segment;
238}
239
240void ArenaAllocator::Impl::track_object(Object object) {
241 if (this->object_track_remain < 1) {
242 auto prev = this->object_track;
243 this->object_track = this->backing->create<ObjectTrack>();
244 this->object_track->prev = prev;
245 this->object_track_remain = ObjectTrack::size;
246 }
247 this->object_track_remain -= 1;
248 this->object_track->objects[this->object_track_remain] = object;
249}
250
251void ArenaAllocator::init(Allocator *backing, const char *name) {
252#ifdef ZIG_ENABLE_MEM_PROFILE
253 this->profile = bootstrap_allocator.create<mem::Profile>();
254 this->profile->init(name, "ArenaAllocator");
255#endif
256 this->impl = bootstrap_allocator.create<Impl>();
257 {
258 auto &r = *this->impl;
259 r.backing = backing;
260 r.segment_offset = Impl::Segment::size;
261 }
262}
263
264void ArenaAllocator::deinit() {
265 auto &backing = *this->impl->backing;
266
267 // segments
268 if (this->impl->segment_track) {
269 // active track is not full and bounded by track_remain
270 auto prev = this->impl->segment_track->prev;
271 {
272 auto t = this->impl->segment_track;
273 for (size_t i = this->impl->segment_track_remain; i < Impl::SegmentTrack::size; ++i)
274 backing.destroy(t->segments[i]);
275 backing.destroy(t);
276 }
277
278 // previous tracks are full
279 for (auto t = prev; t != nullptr;) {
280 for (size_t i = 0; i < Impl::SegmentTrack::size; ++i)
281 backing.destroy(t->segments[i]);
282 prev = t->prev;
283 backing.destroy(t);
284 t = prev;
285 }
286 }
287
288 // objects
289 if (this->impl->object_track) {
290 // active track is not full and bounded by track_remain
291 auto prev = this->impl->object_track->prev;
292 {
293 auto t = this->impl->object_track;
294 for (size_t i = this->impl->object_track_remain; i < Impl::ObjectTrack::size; ++i) {
295 auto &obj = t->objects[i];
296 backing.deallocate(obj.ptr, obj.len);
297 }
298 backing.destroy(t);
299 }
300
301 // previous tracks are full
302 for (auto t = prev; t != nullptr;) {
303 for (size_t i = 0; i < Impl::ObjectTrack::size; ++i) {
304 auto &obj = t->objects[i];
305 backing.deallocate(obj.ptr, obj.len);
306 }
307 prev = t->prev;
308 backing.destroy(t);
309 t = prev;
310 }
311 }
312
313#ifdef ZIG_ENABLE_MEM_PROFILE
314 assert(this->profile);
315 this->profile->deinit();
316 bootstrap_allocator.destroy(this->profile);
317 this->profile = nullptr;
318#endif
319}
320
321ArenaAllocator *ArenaAllocator::construct(mem::Allocator *allocator, mem::Allocator *backing, const char *name) {
322 auto p = new(allocator->create<ArenaAllocator>()) ArenaAllocator;
323 p->init(backing, name);
324 return p;
325}
326
327void ArenaAllocator::destruct(mem::Allocator *allocator) {
328 this->deinit();
329 allocator->destroy(this);
330}
331
332#ifdef ZIG_ENABLE_MEM_PROFILE
333void ArenaAllocator::print_report(FILE *file) {
334 this->profile->print_report(file);
335}
336#endif
337
338void *ArenaAllocator::internal_allocate(const mem::TypeInfo &info, size_t count) {
339#ifdef ZIG_ENABLE_MEM_PROFILE
340 this->profile->record_alloc(info, count);
341#endif
342 return this->impl->allocate(info, count);
343}
344
345void *ArenaAllocator::internal_allocate_nonzero(const mem::TypeInfo &info, size_t count) {
346#ifdef ZIG_ENABLE_MEM_PROFILE
347 this->profile->record_alloc(info, count);
348#endif
349 return this->impl->allocate(info, count);
350}
351
352void *ArenaAllocator::internal_reallocate(const mem::TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) {
353 return this->internal_reallocate_nonzero(info, old_ptr, old_count, new_count);
354}
355
356void *ArenaAllocator::internal_reallocate_nonzero(const mem::TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) {
357#ifdef ZIG_ENABLE_MEM_PROFILE
358 this->profile->record_dealloc(info, old_count);
359 this->profile->record_alloc(info, new_count);
360#endif
361 return this->impl->reallocate(info, old_ptr, old_count, new_count);
362}
363
364void ArenaAllocator::internal_deallocate(const mem::TypeInfo &info, void *ptr, size_t count) {
365#ifdef ZIG_ENABLE_MEM_PROFILE
366 this->profile->record_dealloc(info, count);
367#endif
368 // noop
369}
370
371BootstrapAllocator bootstrap_allocator_state;
372mem::Allocator &bootstrap_allocator = bootstrap_allocator_state;
373
374CAllocator c_allocator_state;
375mem::Allocator &c_allocator = c_allocator_state;
376
377} // namespace heap
src/heap.hpp created+101
......@@ -0,0 +1,101 @@
1/*
2 * Copyright (c) 2020 Andrew Kelley
3 *
4 * This file is part of zig, which is MIT licensed.
5 * See http://opensource.org/licenses/MIT
6 */
7
8#ifndef ZIG_HEAP_HPP
9#define ZIG_HEAP_HPP
10
11#include "config.h"
12#include "util_base.hpp"
13#include "mem.hpp"
14
15#ifdef ZIG_ENABLE_MEM_PROFILE
16namespace mem {
17 struct Profile;
18}
19#endif
20
21namespace heap {
22
23struct BootstrapAllocator final : mem::Allocator {
24 void init(const char *name);
25 void deinit();
26 void destruct(Allocator *allocator) {}
27
28private:
29 ATTRIBUTE_RETURNS_NOALIAS void *internal_allocate(const mem::TypeInfo &info, size_t count) final;
30 ATTRIBUTE_RETURNS_NOALIAS void *internal_allocate_nonzero(const mem::TypeInfo &info, size_t count) final;
31 void *internal_reallocate(const mem::TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) final;
32 void *internal_reallocate_nonzero(const mem::TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) final;
33 void internal_deallocate(const mem::TypeInfo &info, void *ptr, size_t count) final;
34};
35
36struct CAllocator final : mem::Allocator {
37 void init(const char *name);
38 void deinit();
39
40 static CAllocator *construct(mem::Allocator *allocator, const char *name);
41 void destruct(mem::Allocator *allocator) final;
42
43#ifdef ZIG_ENABLE_MEM_PROFILE
44 void print_report(FILE *file = nullptr);
45#endif
46
47private:
48 ATTRIBUTE_RETURNS_NOALIAS void *internal_allocate(const mem::TypeInfo &info, size_t count) final;
49 ATTRIBUTE_RETURNS_NOALIAS void *internal_allocate_nonzero(const mem::TypeInfo &info, size_t count) final;
50 void *internal_reallocate(const mem::TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) final;
51 void *internal_reallocate_nonzero(const mem::TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) final;
52 void internal_deallocate(const mem::TypeInfo &info, void *ptr, size_t count) final;
53
54#ifdef ZIG_ENABLE_MEM_PROFILE
55 mem::Profile *profile;
56#endif
57};
58
59//
60// arena allocator
61//
62// - allocations are backed by the underlying allocator's memory
63// - allocations are N:1 relationship to underlying allocations
64// - dellocations are noops
65// - deinit() releases all underlying memory
66//
67struct ArenaAllocator final : mem::Allocator {
68 void init(Allocator *backing, const char *name);
69 void deinit();
70
71 static ArenaAllocator *construct(mem::Allocator *allocator, mem::Allocator *backing, const char *name);
72 void destruct(mem::Allocator *allocator) final;
73
74#ifdef ZIG_ENABLE_MEM_PROFILE
75 void print_report(FILE *file = nullptr);
76#endif
77
78private:
79 ATTRIBUTE_RETURNS_NOALIAS void *internal_allocate(const mem::TypeInfo &info, size_t count) final;
80 ATTRIBUTE_RETURNS_NOALIAS void *internal_allocate_nonzero(const mem::TypeInfo &info, size_t count) final;
81 void *internal_reallocate(const mem::TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) final;
82 void *internal_reallocate_nonzero(const mem::TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) final;
83 void internal_deallocate(const mem::TypeInfo &info, void *ptr, size_t count) final;
84
85#ifdef ZIG_ENABLE_MEM_PROFILE
86 mem::Profile *profile;
87#endif
88
89 struct Impl;
90 Impl *impl;
91};
92
93extern BootstrapAllocator bootstrap_allocator_state;
94extern mem::Allocator &bootstrap_allocator;
95
96extern CAllocator c_allocator_state;
97extern mem::Allocator &c_allocator;
98
99} // namespace heap
100
101#endif
src/ir.cpp+557-560
......@@ -267,479 +267,470 @@ static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,
267267static ResultLoc *no_result_loc(void);
268268static IrInstGen *ir_analyze_test_non_null(IrAnalyze *ira, IrInst *source_inst, IrInstGen *value);
269269static IrInstGen *ir_error_dependency_loop(IrAnalyze *ira, IrInst *source_instr);
270static IrInstGen *ir_const_undef(IrAnalyze *ira, IrInst *source_instruction, ZigType *ty);
270271
271272static void destroy_instruction_src(IrInstSrc *inst) {
272#ifdef ZIG_ENABLE_MEM_PROFILE
273 const char *name = ir_inst_src_type_str(inst->id);
274#else
275 const char *name = nullptr;
276#endif
277273 switch (inst->id) {
278274 case IrInstSrcIdInvalid:
279275 zig_unreachable();
280276 case IrInstSrcIdReturn:
281 return destroy(reinterpret_cast<IrInstSrcReturn *>(inst), name);
277 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcReturn *>(inst));
282278 case IrInstSrcIdConst:
283 return destroy(reinterpret_cast<IrInstSrcConst *>(inst), name);
279 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcConst *>(inst));
284280 case IrInstSrcIdBinOp:
285 return destroy(reinterpret_cast<IrInstSrcBinOp *>(inst), name);
281 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcBinOp *>(inst));
286282 case IrInstSrcIdMergeErrSets:
287 return destroy(reinterpret_cast<IrInstSrcMergeErrSets *>(inst), name);
283 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcMergeErrSets *>(inst));
288284 case IrInstSrcIdDeclVar:
289 return destroy(reinterpret_cast<IrInstSrcDeclVar *>(inst), name);
285 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcDeclVar *>(inst));
290286 case IrInstSrcIdCall:
291 return destroy(reinterpret_cast<IrInstSrcCall *>(inst), name);
287 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCall *>(inst));
292288 case IrInstSrcIdCallExtra:
293 return destroy(reinterpret_cast<IrInstSrcCallExtra *>(inst), name);
289 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCallExtra *>(inst));
294290 case IrInstSrcIdUnOp:
295 return destroy(reinterpret_cast<IrInstSrcUnOp *>(inst), name);
291 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcUnOp *>(inst));
296292 case IrInstSrcIdCondBr:
297 return destroy(reinterpret_cast<IrInstSrcCondBr *>(inst), name);
293 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCondBr *>(inst));
298294 case IrInstSrcIdBr:
299 return destroy(reinterpret_cast<IrInstSrcBr *>(inst), name);
295 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcBr *>(inst));
300296 case IrInstSrcIdPhi:
301 return destroy(reinterpret_cast<IrInstSrcPhi *>(inst), name);
297 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcPhi *>(inst));
302298 case IrInstSrcIdContainerInitList:
303 return destroy(reinterpret_cast<IrInstSrcContainerInitList *>(inst), name);
299 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcContainerInitList *>(inst));
304300 case IrInstSrcIdContainerInitFields:
305 return destroy(reinterpret_cast<IrInstSrcContainerInitFields *>(inst), name);
301 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcContainerInitFields *>(inst));
306302 case IrInstSrcIdUnreachable:
307 return destroy(reinterpret_cast<IrInstSrcUnreachable *>(inst), name);
303 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcUnreachable *>(inst));
308304 case IrInstSrcIdElemPtr:
309 return destroy(reinterpret_cast<IrInstSrcElemPtr *>(inst), name);
305 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcElemPtr *>(inst));
310306 case IrInstSrcIdVarPtr:
311 return destroy(reinterpret_cast<IrInstSrcVarPtr *>(inst), name);
307 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcVarPtr *>(inst));
312308 case IrInstSrcIdLoadPtr:
313 return destroy(reinterpret_cast<IrInstSrcLoadPtr *>(inst), name);
309 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcLoadPtr *>(inst));
314310 case IrInstSrcIdStorePtr:
315 return destroy(reinterpret_cast<IrInstSrcStorePtr *>(inst), name);
311 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcStorePtr *>(inst));
316312 case IrInstSrcIdTypeOf:
317 return destroy(reinterpret_cast<IrInstSrcTypeOf *>(inst), name);
313 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcTypeOf *>(inst));
318314 case IrInstSrcIdFieldPtr:
319 return destroy(reinterpret_cast<IrInstSrcFieldPtr *>(inst), name);
315 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFieldPtr *>(inst));
320316 case IrInstSrcIdSetCold:
321 return destroy(reinterpret_cast<IrInstSrcSetCold *>(inst), name);
317 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSetCold *>(inst));
322318 case IrInstSrcIdSetRuntimeSafety:
323 return destroy(reinterpret_cast<IrInstSrcSetRuntimeSafety *>(inst), name);
319 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSetRuntimeSafety *>(inst));
324320 case IrInstSrcIdSetFloatMode:
325 return destroy(reinterpret_cast<IrInstSrcSetFloatMode *>(inst), name);
321 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSetFloatMode *>(inst));
326322 case IrInstSrcIdArrayType:
327 return destroy(reinterpret_cast<IrInstSrcArrayType *>(inst), name);
323 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcArrayType *>(inst));
328324 case IrInstSrcIdSliceType:
329 return destroy(reinterpret_cast<IrInstSrcSliceType *>(inst), name);
325 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSliceType *>(inst));
330326 case IrInstSrcIdAnyFrameType:
331 return destroy(reinterpret_cast<IrInstSrcAnyFrameType *>(inst), name);
327 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcAnyFrameType *>(inst));
332328 case IrInstSrcIdAsm:
333 return destroy(reinterpret_cast<IrInstSrcAsm *>(inst), name);
329 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcAsm *>(inst));
334330 case IrInstSrcIdSizeOf:
335 return destroy(reinterpret_cast<IrInstSrcSizeOf *>(inst), name);
331 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSizeOf *>(inst));
336332 case IrInstSrcIdTestNonNull:
337 return destroy(reinterpret_cast<IrInstSrcTestNonNull *>(inst), name);
333 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcTestNonNull *>(inst));
338334 case IrInstSrcIdOptionalUnwrapPtr:
339 return destroy(reinterpret_cast<IrInstSrcOptionalUnwrapPtr *>(inst), name);
335 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcOptionalUnwrapPtr *>(inst));
340336 case IrInstSrcIdPopCount:
341 return destroy(reinterpret_cast<IrInstSrcPopCount *>(inst), name);
337 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcPopCount *>(inst));
342338 case IrInstSrcIdClz:
343 return destroy(reinterpret_cast<IrInstSrcClz *>(inst), name);
339 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcClz *>(inst));
344340 case IrInstSrcIdCtz:
345 return destroy(reinterpret_cast<IrInstSrcCtz *>(inst), name);
341 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCtz *>(inst));
346342 case IrInstSrcIdBswap:
347 return destroy(reinterpret_cast<IrInstSrcBswap *>(inst), name);
343 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcBswap *>(inst));
348344 case IrInstSrcIdBitReverse:
349 return destroy(reinterpret_cast<IrInstSrcBitReverse *>(inst), name);
345 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcBitReverse *>(inst));
350346 case IrInstSrcIdSwitchBr:
351 return destroy(reinterpret_cast<IrInstSrcSwitchBr *>(inst), name);
347 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSwitchBr *>(inst));
352348 case IrInstSrcIdSwitchVar:
353 return destroy(reinterpret_cast<IrInstSrcSwitchVar *>(inst), name);
349 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSwitchVar *>(inst));
354350 case IrInstSrcIdSwitchElseVar:
355 return destroy(reinterpret_cast<IrInstSrcSwitchElseVar *>(inst), name);
351 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSwitchElseVar *>(inst));
356352 case IrInstSrcIdSwitchTarget:
357 return destroy(reinterpret_cast<IrInstSrcSwitchTarget *>(inst), name);
353 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSwitchTarget *>(inst));
358354 case IrInstSrcIdImport:
359 return destroy(reinterpret_cast<IrInstSrcImport *>(inst), name);
355 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcImport *>(inst));
360356 case IrInstSrcIdRef:
361 return destroy(reinterpret_cast<IrInstSrcRef *>(inst), name);
357 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcRef *>(inst));
362358 case IrInstSrcIdCompileErr:
363 return destroy(reinterpret_cast<IrInstSrcCompileErr *>(inst), name);
359 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCompileErr *>(inst));
364360 case IrInstSrcIdCompileLog:
365 return destroy(reinterpret_cast<IrInstSrcCompileLog *>(inst), name);
361 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCompileLog *>(inst));
366362 case IrInstSrcIdErrName:
367 return destroy(reinterpret_cast<IrInstSrcErrName *>(inst), name);
363 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcErrName *>(inst));
368364 case IrInstSrcIdCImport:
369 return destroy(reinterpret_cast<IrInstSrcCImport *>(inst), name);
365 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCImport *>(inst));
370366 case IrInstSrcIdCInclude:
371 return destroy(reinterpret_cast<IrInstSrcCInclude *>(inst), name);
367 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCInclude *>(inst));
372368 case IrInstSrcIdCDefine:
373 return destroy(reinterpret_cast<IrInstSrcCDefine *>(inst), name);
369 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCDefine *>(inst));
374370 case IrInstSrcIdCUndef:
375 return destroy(reinterpret_cast<IrInstSrcCUndef *>(inst), name);
371 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCUndef *>(inst));
376372 case IrInstSrcIdEmbedFile:
377 return destroy(reinterpret_cast<IrInstSrcEmbedFile *>(inst), name);
373 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcEmbedFile *>(inst));
378374 case IrInstSrcIdCmpxchg:
379 return destroy(reinterpret_cast<IrInstSrcCmpxchg *>(inst), name);
375 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCmpxchg *>(inst));
380376 case IrInstSrcIdFence:
381 return destroy(reinterpret_cast<IrInstSrcFence *>(inst), name);
377 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFence *>(inst));
382378 case IrInstSrcIdTruncate:
383 return destroy(reinterpret_cast<IrInstSrcTruncate *>(inst), name);
379 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcTruncate *>(inst));
384380 case IrInstSrcIdIntCast:
385 return destroy(reinterpret_cast<IrInstSrcIntCast *>(inst), name);
381 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcIntCast *>(inst));
386382 case IrInstSrcIdFloatCast:
387 return destroy(reinterpret_cast<IrInstSrcFloatCast *>(inst), name);
383 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFloatCast *>(inst));
388384 case IrInstSrcIdErrSetCast:
389 return destroy(reinterpret_cast<IrInstSrcErrSetCast *>(inst), name);
385 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcErrSetCast *>(inst));
390386 case IrInstSrcIdFromBytes:
391 return destroy(reinterpret_cast<IrInstSrcFromBytes *>(inst), name);
387 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFromBytes *>(inst));
392388 case IrInstSrcIdToBytes:
393 return destroy(reinterpret_cast<IrInstSrcToBytes *>(inst), name);
389 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcToBytes *>(inst));
394390 case IrInstSrcIdIntToFloat:
395 return destroy(reinterpret_cast<IrInstSrcIntToFloat *>(inst), name);
391 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcIntToFloat *>(inst));
396392 case IrInstSrcIdFloatToInt:
397 return destroy(reinterpret_cast<IrInstSrcFloatToInt *>(inst), name);
393 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFloatToInt *>(inst));
398394 case IrInstSrcIdBoolToInt:
399 return destroy(reinterpret_cast<IrInstSrcBoolToInt *>(inst), name);
395 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcBoolToInt *>(inst));
400396 case IrInstSrcIdIntType:
401 return destroy(reinterpret_cast<IrInstSrcIntType *>(inst), name);
397 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcIntType *>(inst));
402398 case IrInstSrcIdVectorType:
403 return destroy(reinterpret_cast<IrInstSrcVectorType *>(inst), name);
399 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcVectorType *>(inst));
404400 case IrInstSrcIdShuffleVector:
405 return destroy(reinterpret_cast<IrInstSrcShuffleVector *>(inst), name);
401 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcShuffleVector *>(inst));
406402 case IrInstSrcIdSplat:
407 return destroy(reinterpret_cast<IrInstSrcSplat *>(inst), name);
403 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSplat *>(inst));
408404 case IrInstSrcIdBoolNot:
409 return destroy(reinterpret_cast<IrInstSrcBoolNot *>(inst), name);
405 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcBoolNot *>(inst));
410406 case IrInstSrcIdMemset:
411 return destroy(reinterpret_cast<IrInstSrcMemset *>(inst), name);
407 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcMemset *>(inst));
412408 case IrInstSrcIdMemcpy:
413 return destroy(reinterpret_cast<IrInstSrcMemcpy *>(inst), name);
409 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcMemcpy *>(inst));
414410 case IrInstSrcIdSlice:
415 return destroy(reinterpret_cast<IrInstSrcSlice *>(inst), name);
411 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSlice *>(inst));
416412 case IrInstSrcIdMemberCount:
417 return destroy(reinterpret_cast<IrInstSrcMemberCount *>(inst), name);
413 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcMemberCount *>(inst));
418414 case IrInstSrcIdMemberType:
419 return destroy(reinterpret_cast<IrInstSrcMemberType *>(inst), name);
415 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcMemberType *>(inst));
420416 case IrInstSrcIdMemberName:
421 return destroy(reinterpret_cast<IrInstSrcMemberName *>(inst), name);
417 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcMemberName *>(inst));
422418 case IrInstSrcIdBreakpoint:
423 return destroy(reinterpret_cast<IrInstSrcBreakpoint *>(inst), name);
419 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcBreakpoint *>(inst));
424420 case IrInstSrcIdReturnAddress:
425 return destroy(reinterpret_cast<IrInstSrcReturnAddress *>(inst), name);
421 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcReturnAddress *>(inst));
426422 case IrInstSrcIdFrameAddress:
427 return destroy(reinterpret_cast<IrInstSrcFrameAddress *>(inst), name);
423 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFrameAddress *>(inst));
428424 case IrInstSrcIdFrameHandle:
429 return destroy(reinterpret_cast<IrInstSrcFrameHandle *>(inst), name);
425 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFrameHandle *>(inst));
430426 case IrInstSrcIdFrameType:
431 return destroy(reinterpret_cast<IrInstSrcFrameType *>(inst), name);
427 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFrameType *>(inst));
432428 case IrInstSrcIdFrameSize:
433 return destroy(reinterpret_cast<IrInstSrcFrameSize *>(inst), name);
429 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFrameSize *>(inst));
434430 case IrInstSrcIdAlignOf:
435 return destroy(reinterpret_cast<IrInstSrcAlignOf *>(inst), name);
431 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcAlignOf *>(inst));
436432 case IrInstSrcIdOverflowOp:
437 return destroy(reinterpret_cast<IrInstSrcOverflowOp *>(inst), name);
433 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcOverflowOp *>(inst));
438434 case IrInstSrcIdTestErr:
439 return destroy(reinterpret_cast<IrInstSrcTestErr *>(inst), name);
435 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcTestErr *>(inst));
440436 case IrInstSrcIdUnwrapErrCode:
441 return destroy(reinterpret_cast<IrInstSrcUnwrapErrCode *>(inst), name);
437 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcUnwrapErrCode *>(inst));
442438 case IrInstSrcIdUnwrapErrPayload:
443 return destroy(reinterpret_cast<IrInstSrcUnwrapErrPayload *>(inst), name);
439 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcUnwrapErrPayload *>(inst));
444440 case IrInstSrcIdFnProto:
445 return destroy(reinterpret_cast<IrInstSrcFnProto *>(inst), name);
441 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFnProto *>(inst));
446442 case IrInstSrcIdTestComptime:
447 return destroy(reinterpret_cast<IrInstSrcTestComptime *>(inst), name);
443 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcTestComptime *>(inst));
448444 case IrInstSrcIdPtrCast:
449 return destroy(reinterpret_cast<IrInstSrcPtrCast *>(inst), name);
445 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcPtrCast *>(inst));
450446 case IrInstSrcIdBitCast:
451 return destroy(reinterpret_cast<IrInstSrcBitCast *>(inst), name);
447 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcBitCast *>(inst));
452448 case IrInstSrcIdPtrToInt:
453 return destroy(reinterpret_cast<IrInstSrcPtrToInt *>(inst), name);
449 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcPtrToInt *>(inst));
454450 case IrInstSrcIdIntToPtr:
455 return destroy(reinterpret_cast<IrInstSrcIntToPtr *>(inst), name);
451 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcIntToPtr *>(inst));
456452 case IrInstSrcIdIntToEnum:
457 return destroy(reinterpret_cast<IrInstSrcIntToEnum *>(inst), name);
453 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcIntToEnum *>(inst));
458454 case IrInstSrcIdIntToErr:
459 return destroy(reinterpret_cast<IrInstSrcIntToErr *>(inst), name);
455 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcIntToErr *>(inst));
460456 case IrInstSrcIdErrToInt:
461 return destroy(reinterpret_cast<IrInstSrcErrToInt *>(inst), name);
457 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcErrToInt *>(inst));
462458 case IrInstSrcIdCheckSwitchProngs:
463 return destroy(reinterpret_cast<IrInstSrcCheckSwitchProngs *>(inst), name);
459 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCheckSwitchProngs *>(inst));
464460 case IrInstSrcIdCheckStatementIsVoid:
465 return destroy(reinterpret_cast<IrInstSrcCheckStatementIsVoid *>(inst), name);
461 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCheckStatementIsVoid *>(inst));
466462 case IrInstSrcIdTypeName:
467 return destroy(reinterpret_cast<IrInstSrcTypeName *>(inst), name);
463 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcTypeName *>(inst));
468464 case IrInstSrcIdTagName:
469 return destroy(reinterpret_cast<IrInstSrcTagName *>(inst), name);
465 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcTagName *>(inst));
470466 case IrInstSrcIdPtrType:
471 return destroy(reinterpret_cast<IrInstSrcPtrType *>(inst), name);
467 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcPtrType *>(inst));
472468 case IrInstSrcIdDeclRef:
473 return destroy(reinterpret_cast<IrInstSrcDeclRef *>(inst), name);
469 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcDeclRef *>(inst));
474470 case IrInstSrcIdPanic:
475 return destroy(reinterpret_cast<IrInstSrcPanic *>(inst), name);
471 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcPanic *>(inst));
476472 case IrInstSrcIdFieldParentPtr:
477 return destroy(reinterpret_cast<IrInstSrcFieldParentPtr *>(inst), name);
473 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFieldParentPtr *>(inst));
478474 case IrInstSrcIdByteOffsetOf:
479 return destroy(reinterpret_cast<IrInstSrcByteOffsetOf *>(inst), name);
475 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcByteOffsetOf *>(inst));
480476 case IrInstSrcIdBitOffsetOf:
481 return destroy(reinterpret_cast<IrInstSrcBitOffsetOf *>(inst), name);
477 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcBitOffsetOf *>(inst));
482478 case IrInstSrcIdTypeInfo:
483 return destroy(reinterpret_cast<IrInstSrcTypeInfo *>(inst), name);
479 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcTypeInfo *>(inst));
484480 case IrInstSrcIdType:
485 return destroy(reinterpret_cast<IrInstSrcType *>(inst), name);
481 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcType *>(inst));
486482 case IrInstSrcIdHasField:
487 return destroy(reinterpret_cast<IrInstSrcHasField *>(inst), name);
483 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcHasField *>(inst));
488484 case IrInstSrcIdTypeId:
489 return destroy(reinterpret_cast<IrInstSrcTypeId *>(inst), name);
485 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcTypeId *>(inst));
490486 case IrInstSrcIdSetEvalBranchQuota:
491 return destroy(reinterpret_cast<IrInstSrcSetEvalBranchQuota *>(inst), name);
487 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSetEvalBranchQuota *>(inst));
492488 case IrInstSrcIdAlignCast:
493 return destroy(reinterpret_cast<IrInstSrcAlignCast *>(inst), name);
489 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcAlignCast *>(inst));
494490 case IrInstSrcIdImplicitCast:
495 return destroy(reinterpret_cast<IrInstSrcImplicitCast *>(inst), name);
491 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcImplicitCast *>(inst));
496492 case IrInstSrcIdResolveResult:
497 return destroy(reinterpret_cast<IrInstSrcResolveResult *>(inst), name);
493 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcResolveResult *>(inst));
498494 case IrInstSrcIdResetResult:
499 return destroy(reinterpret_cast<IrInstSrcResetResult *>(inst), name);
495 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcResetResult *>(inst));
500496 case IrInstSrcIdOpaqueType:
501 return destroy(reinterpret_cast<IrInstSrcOpaqueType *>(inst), name);
497 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcOpaqueType *>(inst));
502498 case IrInstSrcIdSetAlignStack:
503 return destroy(reinterpret_cast<IrInstSrcSetAlignStack *>(inst), name);
499 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSetAlignStack *>(inst));
504500 case IrInstSrcIdArgType:
505 return destroy(reinterpret_cast<IrInstSrcArgType *>(inst), name);
501 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcArgType *>(inst));
506502 case IrInstSrcIdTagType:
507 return destroy(reinterpret_cast<IrInstSrcTagType *>(inst), name);
503 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcTagType *>(inst));
508504 case IrInstSrcIdExport:
509 return destroy(reinterpret_cast<IrInstSrcExport *>(inst), name);
505 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcExport *>(inst));
510506 case IrInstSrcIdErrorReturnTrace:
511 return destroy(reinterpret_cast<IrInstSrcErrorReturnTrace *>(inst), name);
507 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcErrorReturnTrace *>(inst));
512508 case IrInstSrcIdErrorUnion:
513 return destroy(reinterpret_cast<IrInstSrcErrorUnion *>(inst), name);
509 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcErrorUnion *>(inst));
514510 case IrInstSrcIdAtomicRmw:
515 return destroy(reinterpret_cast<IrInstSrcAtomicRmw *>(inst), name);
511 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcAtomicRmw *>(inst));
516512 case IrInstSrcIdSaveErrRetAddr:
517 return destroy(reinterpret_cast<IrInstSrcSaveErrRetAddr *>(inst), name);
513 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSaveErrRetAddr *>(inst));
518514 case IrInstSrcIdAddImplicitReturnType:
519 return destroy(reinterpret_cast<IrInstSrcAddImplicitReturnType *>(inst), name);
515 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcAddImplicitReturnType *>(inst));
520516 case IrInstSrcIdFloatOp:
521 return destroy(reinterpret_cast<IrInstSrcFloatOp *>(inst), name);
517 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFloatOp *>(inst));
522518 case IrInstSrcIdMulAdd:
523 return destroy(reinterpret_cast<IrInstSrcMulAdd *>(inst), name);
519 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcMulAdd *>(inst));
524520 case IrInstSrcIdAtomicLoad:
525 return destroy(reinterpret_cast<IrInstSrcAtomicLoad *>(inst), name);
521 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcAtomicLoad *>(inst));
526522 case IrInstSrcIdAtomicStore:
527 return destroy(reinterpret_cast<IrInstSrcAtomicStore *>(inst), name);
523 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcAtomicStore *>(inst));
528524 case IrInstSrcIdEnumToInt:
529 return destroy(reinterpret_cast<IrInstSrcEnumToInt *>(inst), name);
525 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcEnumToInt *>(inst));
530526 case IrInstSrcIdCheckRuntimeScope:
531 return destroy(reinterpret_cast<IrInstSrcCheckRuntimeScope *>(inst), name);
527 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCheckRuntimeScope *>(inst));
532528 case IrInstSrcIdHasDecl:
533 return destroy(reinterpret_cast<IrInstSrcHasDecl *>(inst), name);
529 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcHasDecl *>(inst));
534530 case IrInstSrcIdUndeclaredIdent:
535 return destroy(reinterpret_cast<IrInstSrcUndeclaredIdent *>(inst), name);
531 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcUndeclaredIdent *>(inst));
536532 case IrInstSrcIdAlloca:
537 return destroy(reinterpret_cast<IrInstSrcAlloca *>(inst), name);
533 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcAlloca *>(inst));
538534 case IrInstSrcIdEndExpr:
539 return destroy(reinterpret_cast<IrInstSrcEndExpr *>(inst), name);
535 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcEndExpr *>(inst));
540536 case IrInstSrcIdUnionInitNamedField:
541 return destroy(reinterpret_cast<IrInstSrcUnionInitNamedField *>(inst), name);
537 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcUnionInitNamedField *>(inst));
542538 case IrInstSrcIdSuspendBegin:
543 return destroy(reinterpret_cast<IrInstSrcSuspendBegin *>(inst), name);
539 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSuspendBegin *>(inst));
544540 case IrInstSrcIdSuspendFinish:
545 return destroy(reinterpret_cast<IrInstSrcSuspendFinish *>(inst), name);
541 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSuspendFinish *>(inst));
546542 case IrInstSrcIdResume:
547 return destroy(reinterpret_cast<IrInstSrcResume *>(inst), name);
543 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcResume *>(inst));
548544 case IrInstSrcIdAwait:
549 return destroy(reinterpret_cast<IrInstSrcAwait *>(inst), name);
545 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcAwait *>(inst));
550546 case IrInstSrcIdSpillBegin:
551 return destroy(reinterpret_cast<IrInstSrcSpillBegin *>(inst), name);
547 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSpillBegin *>(inst));
552548 case IrInstSrcIdSpillEnd:
553 return destroy(reinterpret_cast<IrInstSrcSpillEnd *>(inst), name);
549 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSpillEnd *>(inst));
554550 case IrInstSrcIdCallArgs:
555 return destroy(reinterpret_cast<IrInstSrcCallArgs *>(inst), name);
551 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCallArgs *>(inst));
556552 }
557553 zig_unreachable();
558554}
559555
560556void destroy_instruction_gen(IrInstGen *inst) {
561#ifdef ZIG_ENABLE_MEM_PROFILE
562 const char *name = ir_inst_gen_type_str(inst->id);
563#else
564 const char *name = nullptr;
565#endif
566557 switch (inst->id) {
567558 case IrInstGenIdInvalid:
568559 zig_unreachable();
569560 case IrInstGenIdReturn:
570 return destroy(reinterpret_cast<IrInstGenReturn *>(inst), name);
561 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenReturn *>(inst));
571562 case IrInstGenIdConst:
572 return destroy(reinterpret_cast<IrInstGenConst *>(inst), name);
563 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenConst *>(inst));
573564 case IrInstGenIdBinOp:
574 return destroy(reinterpret_cast<IrInstGenBinOp *>(inst), name);
565 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenBinOp *>(inst));
575566 case IrInstGenIdCast:
576 return destroy(reinterpret_cast<IrInstGenCast *>(inst), name);
567 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenCast *>(inst));
577568 case IrInstGenIdCall:
578 return destroy(reinterpret_cast<IrInstGenCall *>(inst), name);
569 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenCall *>(inst));
579570 case IrInstGenIdCondBr:
580 return destroy(reinterpret_cast<IrInstGenCondBr *>(inst), name);
571 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenCondBr *>(inst));
581572 case IrInstGenIdBr:
582 return destroy(reinterpret_cast<IrInstGenBr *>(inst), name);
573 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenBr *>(inst));
583574 case IrInstGenIdPhi:
584 return destroy(reinterpret_cast<IrInstGenPhi *>(inst), name);
575 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenPhi *>(inst));
585576 case IrInstGenIdUnreachable:
586 return destroy(reinterpret_cast<IrInstGenUnreachable *>(inst), name);
577 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenUnreachable *>(inst));
587578 case IrInstGenIdElemPtr:
588 return destroy(reinterpret_cast<IrInstGenElemPtr *>(inst), name);
579 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenElemPtr *>(inst));
589580 case IrInstGenIdVarPtr:
590 return destroy(reinterpret_cast<IrInstGenVarPtr *>(inst), name);
581 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenVarPtr *>(inst));
591582 case IrInstGenIdReturnPtr:
592 return destroy(reinterpret_cast<IrInstGenReturnPtr *>(inst), name);
583 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenReturnPtr *>(inst));
593584 case IrInstGenIdLoadPtr:
594 return destroy(reinterpret_cast<IrInstGenLoadPtr *>(inst), name);
585 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenLoadPtr *>(inst));
595586 case IrInstGenIdStorePtr:
596 return destroy(reinterpret_cast<IrInstGenStorePtr *>(inst), name);
587 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenStorePtr *>(inst));
597588 case IrInstGenIdVectorStoreElem:
598 return destroy(reinterpret_cast<IrInstGenVectorStoreElem *>(inst), name);
589 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenVectorStoreElem *>(inst));
599590 case IrInstGenIdStructFieldPtr:
600 return destroy(reinterpret_cast<IrInstGenStructFieldPtr *>(inst), name);
591 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenStructFieldPtr *>(inst));
601592 case IrInstGenIdUnionFieldPtr:
602 return destroy(reinterpret_cast<IrInstGenUnionFieldPtr *>(inst), name);
593 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenUnionFieldPtr *>(inst));
603594 case IrInstGenIdAsm:
604 return destroy(reinterpret_cast<IrInstGenAsm *>(inst), name);
595 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenAsm *>(inst));
605596 case IrInstGenIdTestNonNull:
606 return destroy(reinterpret_cast<IrInstGenTestNonNull *>(inst), name);
597 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenTestNonNull *>(inst));
607598 case IrInstGenIdOptionalUnwrapPtr:
608 return destroy(reinterpret_cast<IrInstGenOptionalUnwrapPtr *>(inst), name);
599 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenOptionalUnwrapPtr *>(inst));
609600 case IrInstGenIdPopCount:
610 return destroy(reinterpret_cast<IrInstGenPopCount *>(inst), name);
601 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenPopCount *>(inst));
611602 case IrInstGenIdClz:
612 return destroy(reinterpret_cast<IrInstGenClz *>(inst), name);
603 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenClz *>(inst));
613604 case IrInstGenIdCtz:
614 return destroy(reinterpret_cast<IrInstGenCtz *>(inst), name);
605 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenCtz *>(inst));
615606 case IrInstGenIdBswap:
616 return destroy(reinterpret_cast<IrInstGenBswap *>(inst), name);
607 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenBswap *>(inst));
617608 case IrInstGenIdBitReverse:
618 return destroy(reinterpret_cast<IrInstGenBitReverse *>(inst), name);
609 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenBitReverse *>(inst));
619610 case IrInstGenIdSwitchBr:
620 return destroy(reinterpret_cast<IrInstGenSwitchBr *>(inst), name);
611 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenSwitchBr *>(inst));
621612 case IrInstGenIdUnionTag:
622 return destroy(reinterpret_cast<IrInstGenUnionTag *>(inst), name);
613 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenUnionTag *>(inst));
623614 case IrInstGenIdRef:
624 return destroy(reinterpret_cast<IrInstGenRef *>(inst), name);
615 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenRef *>(inst));
625616 case IrInstGenIdErrName:
626 return destroy(reinterpret_cast<IrInstGenErrName *>(inst), name);
617 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenErrName *>(inst));
627618 case IrInstGenIdCmpxchg:
628 return destroy(reinterpret_cast<IrInstGenCmpxchg *>(inst), name);
619 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenCmpxchg *>(inst));
629620 case IrInstGenIdFence:
630 return destroy(reinterpret_cast<IrInstGenFence *>(inst), name);
621 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenFence *>(inst));
631622 case IrInstGenIdTruncate:
632 return destroy(reinterpret_cast<IrInstGenTruncate *>(inst), name);
623 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenTruncate *>(inst));
633624 case IrInstGenIdShuffleVector:
634 return destroy(reinterpret_cast<IrInstGenShuffleVector *>(inst), name);
625 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenShuffleVector *>(inst));
635626 case IrInstGenIdSplat:
636 return destroy(reinterpret_cast<IrInstGenSplat *>(inst), name);
627 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenSplat *>(inst));
637628 case IrInstGenIdBoolNot:
638 return destroy(reinterpret_cast<IrInstGenBoolNot *>(inst), name);
629 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenBoolNot *>(inst));
639630 case IrInstGenIdMemset:
640 return destroy(reinterpret_cast<IrInstGenMemset *>(inst), name);
631 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenMemset *>(inst));
641632 case IrInstGenIdMemcpy:
642 return destroy(reinterpret_cast<IrInstGenMemcpy *>(inst), name);
633 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenMemcpy *>(inst));
643634 case IrInstGenIdSlice:
644 return destroy(reinterpret_cast<IrInstGenSlice *>(inst), name);
635 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenSlice *>(inst));
645636 case IrInstGenIdBreakpoint:
646 return destroy(reinterpret_cast<IrInstGenBreakpoint *>(inst), name);
637 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenBreakpoint *>(inst));
647638 case IrInstGenIdReturnAddress:
648 return destroy(reinterpret_cast<IrInstGenReturnAddress *>(inst), name);
639 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenReturnAddress *>(inst));
649640 case IrInstGenIdFrameAddress:
650 return destroy(reinterpret_cast<IrInstGenFrameAddress *>(inst), name);
641 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenFrameAddress *>(inst));
651642 case IrInstGenIdFrameHandle:
652 return destroy(reinterpret_cast<IrInstGenFrameHandle *>(inst), name);
643 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenFrameHandle *>(inst));
653644 case IrInstGenIdFrameSize:
654 return destroy(reinterpret_cast<IrInstGenFrameSize *>(inst), name);
645 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenFrameSize *>(inst));
655646 case IrInstGenIdOverflowOp:
656 return destroy(reinterpret_cast<IrInstGenOverflowOp *>(inst), name);
647 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenOverflowOp *>(inst));
657648 case IrInstGenIdTestErr:
658 return destroy(reinterpret_cast<IrInstGenTestErr *>(inst), name);
649 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenTestErr *>(inst));
659650 case IrInstGenIdUnwrapErrCode:
660 return destroy(reinterpret_cast<IrInstGenUnwrapErrCode *>(inst), name);
651 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenUnwrapErrCode *>(inst));
661652 case IrInstGenIdUnwrapErrPayload:
662 return destroy(reinterpret_cast<IrInstGenUnwrapErrPayload *>(inst), name);
653 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenUnwrapErrPayload *>(inst));
663654 case IrInstGenIdOptionalWrap:
664 return destroy(reinterpret_cast<IrInstGenOptionalWrap *>(inst), name);
655 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenOptionalWrap *>(inst));
665656 case IrInstGenIdErrWrapCode:
666 return destroy(reinterpret_cast<IrInstGenErrWrapCode *>(inst), name);
657 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenErrWrapCode *>(inst));
667658 case IrInstGenIdErrWrapPayload:
668 return destroy(reinterpret_cast<IrInstGenErrWrapPayload *>(inst), name);
659 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenErrWrapPayload *>(inst));
669660 case IrInstGenIdPtrCast:
670 return destroy(reinterpret_cast<IrInstGenPtrCast *>(inst), name);
661 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenPtrCast *>(inst));
671662 case IrInstGenIdBitCast:
672 return destroy(reinterpret_cast<IrInstGenBitCast *>(inst), name);
663 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenBitCast *>(inst));
673664 case IrInstGenIdWidenOrShorten:
674 return destroy(reinterpret_cast<IrInstGenWidenOrShorten *>(inst), name);
665 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenWidenOrShorten *>(inst));
675666 case IrInstGenIdPtrToInt:
676 return destroy(reinterpret_cast<IrInstGenPtrToInt *>(inst), name);
667 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenPtrToInt *>(inst));
677668 case IrInstGenIdIntToPtr:
678 return destroy(reinterpret_cast<IrInstGenIntToPtr *>(inst), name);
669 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenIntToPtr *>(inst));
679670 case IrInstGenIdIntToEnum:
680 return destroy(reinterpret_cast<IrInstGenIntToEnum *>(inst), name);
671 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenIntToEnum *>(inst));
681672 case IrInstGenIdIntToErr:
682 return destroy(reinterpret_cast<IrInstGenIntToErr *>(inst), name);
673 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenIntToErr *>(inst));
683674 case IrInstGenIdErrToInt:
684 return destroy(reinterpret_cast<IrInstGenErrToInt *>(inst), name);
675 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenErrToInt *>(inst));
685676 case IrInstGenIdTagName:
686 return destroy(reinterpret_cast<IrInstGenTagName *>(inst), name);
677 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenTagName *>(inst));
687678 case IrInstGenIdPanic:
688 return destroy(reinterpret_cast<IrInstGenPanic *>(inst), name);
679 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenPanic *>(inst));
689680 case IrInstGenIdFieldParentPtr:
690 return destroy(reinterpret_cast<IrInstGenFieldParentPtr *>(inst), name);
681 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenFieldParentPtr *>(inst));
691682 case IrInstGenIdAlignCast:
692 return destroy(reinterpret_cast<IrInstGenAlignCast *>(inst), name);
683 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenAlignCast *>(inst));
693684 case IrInstGenIdErrorReturnTrace:
694 return destroy(reinterpret_cast<IrInstGenErrorReturnTrace *>(inst), name);
685 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenErrorReturnTrace *>(inst));
695686 case IrInstGenIdAtomicRmw:
696 return destroy(reinterpret_cast<IrInstGenAtomicRmw *>(inst), name);
687 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenAtomicRmw *>(inst));
697688 case IrInstGenIdSaveErrRetAddr:
698 return destroy(reinterpret_cast<IrInstGenSaveErrRetAddr *>(inst), name);
689 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenSaveErrRetAddr *>(inst));
699690 case IrInstGenIdFloatOp:
700 return destroy(reinterpret_cast<IrInstGenFloatOp *>(inst), name);
691 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenFloatOp *>(inst));
701692 case IrInstGenIdMulAdd:
702 return destroy(reinterpret_cast<IrInstGenMulAdd *>(inst), name);
693 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenMulAdd *>(inst));
703694 case IrInstGenIdAtomicLoad:
704 return destroy(reinterpret_cast<IrInstGenAtomicLoad *>(inst), name);
695 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenAtomicLoad *>(inst));
705696 case IrInstGenIdAtomicStore:
706 return destroy(reinterpret_cast<IrInstGenAtomicStore *>(inst), name);
697 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenAtomicStore *>(inst));
707698 case IrInstGenIdDeclVar:
708 return destroy(reinterpret_cast<IrInstGenDeclVar *>(inst), name);
699 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenDeclVar *>(inst));
709700 case IrInstGenIdArrayToVector:
710 return destroy(reinterpret_cast<IrInstGenArrayToVector *>(inst), name);
701 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenArrayToVector *>(inst));
711702 case IrInstGenIdVectorToArray:
712 return destroy(reinterpret_cast<IrInstGenVectorToArray *>(inst), name);
703 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenVectorToArray *>(inst));
713704 case IrInstGenIdPtrOfArrayToSlice:
714 return destroy(reinterpret_cast<IrInstGenPtrOfArrayToSlice *>(inst), name);
705 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenPtrOfArrayToSlice *>(inst));
715706 case IrInstGenIdAssertZero:
716 return destroy(reinterpret_cast<IrInstGenAssertZero *>(inst), name);
707 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenAssertZero *>(inst));
717708 case IrInstGenIdAssertNonNull:
718 return destroy(reinterpret_cast<IrInstGenAssertNonNull *>(inst), name);
709 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenAssertNonNull *>(inst));
719710 case IrInstGenIdResizeSlice:
720 return destroy(reinterpret_cast<IrInstGenResizeSlice *>(inst), name);
711 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenResizeSlice *>(inst));
721712 case IrInstGenIdAlloca:
722 return destroy(reinterpret_cast<IrInstGenAlloca *>(inst), name);
713 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenAlloca *>(inst));
723714 case IrInstGenIdSuspendBegin:
724 return destroy(reinterpret_cast<IrInstGenSuspendBegin *>(inst), name);
715 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenSuspendBegin *>(inst));
725716 case IrInstGenIdSuspendFinish:
726 return destroy(reinterpret_cast<IrInstGenSuspendFinish *>(inst), name);
717 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenSuspendFinish *>(inst));
727718 case IrInstGenIdResume:
728 return destroy(reinterpret_cast<IrInstGenResume *>(inst), name);
719 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenResume *>(inst));
729720 case IrInstGenIdAwait:
730 return destroy(reinterpret_cast<IrInstGenAwait *>(inst), name);
721 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenAwait *>(inst));
731722 case IrInstGenIdSpillBegin:
732 return destroy(reinterpret_cast<IrInstGenSpillBegin *>(inst), name);
723 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenSpillBegin *>(inst));
733724 case IrInstGenIdSpillEnd:
734 return destroy(reinterpret_cast<IrInstGenSpillEnd *>(inst), name);
725 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenSpillEnd *>(inst));
735726 case IrInstGenIdVectorExtractElem:
736 return destroy(reinterpret_cast<IrInstGenVectorExtractElem *>(inst), name);
727 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenVectorExtractElem *>(inst));
737728 case IrInstGenIdBinaryNot:
738 return destroy(reinterpret_cast<IrInstGenBinaryNot *>(inst), name);
729 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenBinaryNot *>(inst));
739730 case IrInstGenIdNegation:
740 return destroy(reinterpret_cast<IrInstGenNegation *>(inst), name);
731 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenNegation *>(inst));
741732 case IrInstGenIdNegationWrapping:
742 return destroy(reinterpret_cast<IrInstGenNegationWrapping *>(inst), name);
733 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenNegationWrapping *>(inst));
743734 }
744735 zig_unreachable();
745736}
......@@ -760,34 +751,19 @@ static void ira_deref(IrAnalyze *ira) {
760751 IrInstSrc *pass1_inst = pass1_bb->instruction_list.items[inst_i];
761752 destroy_instruction_src(pass1_inst);
762753 }
763 destroy(pass1_bb, "IrBasicBlockSrc");
754 heap::c_allocator.destroy(pass1_bb);
764755 }
765756 ira->old_irb.exec->basic_block_list.deinit();
766757 ira->old_irb.exec->tld_list.deinit();
767 // cannot destroy here because of var->owner_exec
768 //destroy(ira->old_irb.exec, "IrExecutableSrc");
758 heap::c_allocator.destroy(ira->old_irb.exec);
769759 ira->src_implicit_return_type_list.deinit();
770760 ira->resume_stack.deinit();
771 destroy(ira, "IrAnalyze");
761 heap::c_allocator.destroy(ira);
772762}
773763
774static ZigValue *const_ptr_pointee_unchecked(CodeGen *g, ZigValue *const_val) {
764static ZigValue *const_ptr_pointee_unchecked_no_isf(CodeGen *g, ZigValue *const_val) {
775765 assert(get_src_ptr_type(const_val->type) != nullptr);
776766 assert(const_val->special == ConstValSpecialStatic);
777 ZigValue *result;
778
779 InferredStructField *isf = const_val->type->data.pointer.inferred_struct_field;
780 if (isf != nullptr) {
781 TypeStructField *field = find_struct_type_field(isf->inferred_struct_type, isf->field_name);
782 assert(field != nullptr);
783 if (field->is_comptime) {
784 assert(field->init_val != nullptr);
785 return field->init_val;
786 }
787 assert(const_val->data.x_ptr.special == ConstPtrSpecialRef);
788 ZigValue *struct_val = const_val->data.x_ptr.data.ref.pointee;
789 return struct_val->data.x_struct.fields[field->src_index];
790 }
791767
792768 switch (type_has_one_possible_value(g, const_val->type->data.pointer.child_type)) {
793769 case OnePossibleValueInvalid:
......@@ -798,6 +774,7 @@ static ZigValue *const_ptr_pointee_unchecked(CodeGen *g, ZigValue *const_val) {
798774 break;
799775 }
800776
777 ZigValue *result;
801778 switch (const_val->data.x_ptr.special) {
802779 case ConstPtrSpecialInvalid:
803780 zig_unreachable();
......@@ -843,6 +820,26 @@ static ZigValue *const_ptr_pointee_unchecked(CodeGen *g, ZigValue *const_val) {
843820 return result;
844821}
845822
823static ZigValue *const_ptr_pointee_unchecked(CodeGen *g, ZigValue *const_val) {
824 assert(get_src_ptr_type(const_val->type) != nullptr);
825 assert(const_val->special == ConstValSpecialStatic);
826
827 InferredStructField *isf = const_val->type->data.pointer.inferred_struct_field;
828 if (isf != nullptr) {
829 TypeStructField *field = find_struct_type_field(isf->inferred_struct_type, isf->field_name);
830 assert(field != nullptr);
831 if (field->is_comptime) {
832 assert(field->init_val != nullptr);
833 return field->init_val;
834 }
835 ZigValue *struct_val = const_ptr_pointee_unchecked_no_isf(g, const_val);
836 assert(struct_val->type->id == ZigTypeIdStruct);
837 return struct_val->data.x_struct.fields[field->src_index];
838 }
839
840 return const_ptr_pointee_unchecked_no_isf(g, const_val);
841}
842
846843static bool is_tuple(ZigType *type) {
847844 return type->id == ZigTypeIdStruct && type->data.structure.special == StructSpecialInferredTuple;
848845}
......@@ -1010,8 +1007,8 @@ static void ir_ref_var(ZigVar *var) {
10101007static void create_result_ptr(CodeGen *codegen, ZigType *expected_type,
10111008 ZigValue **out_result, ZigValue **out_result_ptr)
10121009{
1013 ZigValue *result = create_const_vals(1);
1014 ZigValue *result_ptr = create_const_vals(1);
1010 ZigValue *result = codegen->pass1_arena->create<ZigValue>();
1011 ZigValue *result_ptr = codegen->pass1_arena->create<ZigValue>();
10151012 result->special = ConstValSpecialUndef;
10161013 result->type = expected_type;
10171014 result_ptr->special = ConstValSpecialStatic;
......@@ -1043,14 +1040,11 @@ ZigType *ir_analyze_type_expr(IrAnalyze *ira, Scope *scope, AstNode *node) {
10431040 assert(result->special != ConstValSpecialRuntime);
10441041 ZigType *res_type = result->data.x_type;
10451042
1046 destroy(result_ptr, "ZigValue");
1047 destroy(result, "ZigValue");
1048
10491043 return res_type;
10501044}
10511045
10521046static IrBasicBlockSrc *ir_create_basic_block(IrBuilderSrc *irb, Scope *scope, const char *name_hint) {
1053 IrBasicBlockSrc *result = allocate<IrBasicBlockSrc>(1, "IrBasicBlockSrc");
1047 IrBasicBlockSrc *result = heap::c_allocator.create<IrBasicBlockSrc>();
10541048 result->scope = scope;
10551049 result->name_hint = name_hint;
10561050 result->debug_id = exec_next_debug_id(irb->exec);
......@@ -1059,7 +1053,7 @@ static IrBasicBlockSrc *ir_create_basic_block(IrBuilderSrc *irb, Scope *scope, c
10591053}
10601054
10611055static IrBasicBlockGen *ir_create_basic_block_gen(IrAnalyze *ira, Scope *scope, const char *name_hint) {
1062 IrBasicBlockGen *result = allocate<IrBasicBlockGen>(1, "IrBasicBlockGen");
1056 IrBasicBlockGen *result = heap::c_allocator.create<IrBasicBlockGen>();
10631057 result->scope = scope;
10641058 result->name_hint = name_hint;
10651059 result->debug_id = exec_next_debug_id_gen(ira->new_irb.exec);
......@@ -1976,12 +1970,7 @@ static constexpr IrInstGenId ir_inst_id(IrInstGenConst *) {
19761970
19771971template<typename T>
19781972static T *ir_create_instruction(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
1979 const char *name = nullptr;
1980#ifdef ZIG_ENABLE_MEM_PROFILE
1981 T *dummy = nullptr;
1982 name = ir_inst_src_type_str(ir_inst_id(dummy));
1983#endif
1984 T *special_instruction = allocate<T>(1, name);
1973 T *special_instruction = heap::c_allocator.create<T>();
19851974 special_instruction->base.id = ir_inst_id(special_instruction);
19861975 special_instruction->base.base.scope = scope;
19871976 special_instruction->base.base.source_node = source_node;
......@@ -1992,29 +1981,19 @@ static T *ir_create_instruction(IrBuilderSrc *irb, Scope *scope, AstNode *source
19921981
19931982template<typename T>
19941983static T *ir_create_inst_gen(IrBuilderGen *irb, Scope *scope, AstNode *source_node) {
1995 const char *name = nullptr;
1996#ifdef ZIG_ENABLE_MEM_PROFILE
1997 T *dummy = nullptr;
1998 name = ir_inst_gen_type_str(ir_inst_id(dummy));
1999#endif
2000 T *special_instruction = allocate<T>(1, name);
1984 T *special_instruction = heap::c_allocator.create<T>();
20011985 special_instruction->base.id = ir_inst_id(special_instruction);
20021986 special_instruction->base.base.scope = scope;
20031987 special_instruction->base.base.source_node = source_node;
20041988 special_instruction->base.base.debug_id = exec_next_debug_id_gen(irb->exec);
20051989 special_instruction->base.owner_bb = irb->current_basic_block;
2006 special_instruction->base.value = allocate<ZigValue>(1, "ZigValue");
1990 special_instruction->base.value = irb->codegen->pass1_arena->create<ZigValue>();
20071991 return special_instruction;
20081992}
20091993
20101994template<typename T>
20111995static T *ir_create_inst_noval(IrBuilderGen *irb, Scope *scope, AstNode *source_node) {
2012 const char *name = nullptr;
2013#ifdef ZIG_ENABLE_MEM_PROFILE
2014 T *dummy = nullptr;
2015 name = ir_inst_gen_type_str(ir_inst_id(dummy));
2016#endif
2017 T *special_instruction = allocate<T>(1, name);
1996 T *special_instruction = heap::c_allocator.create<T>();
20181997 special_instruction->base.id = ir_inst_id(special_instruction);
20191998 special_instruction->base.base.scope = scope;
20201999 special_instruction->base.base.source_node = source_node;
......@@ -2056,11 +2035,11 @@ static T *ir_build_inst_void(IrBuilderGen *irb, Scope *scope, AstNode *source_no
20562035IrInstGen *ir_create_alloca(CodeGen *g, Scope *scope, AstNode *source_node, ZigFn *fn,
20572036 ZigType *var_type, const char *name_hint)
20582037{
2059 IrInstGenAlloca *alloca_gen = allocate<IrInstGenAlloca>(1);
2038 IrInstGenAlloca *alloca_gen = heap::c_allocator.create<IrInstGenAlloca>();
20602039 alloca_gen->base.id = IrInstGenIdAlloca;
20612040 alloca_gen->base.base.source_node = source_node;
20622041 alloca_gen->base.base.scope = scope;
2063 alloca_gen->base.value = allocate<ZigValue>(1, "ZigValue");
2042 alloca_gen->base.value = g->pass1_arena->create<ZigValue>();
20642043 alloca_gen->base.value->type = get_pointer_to_type(g, var_type, false);
20652044 alloca_gen->base.base.ref_count = 1;
20662045 alloca_gen->name_hint = name_hint;
......@@ -2150,7 +2129,7 @@ static IrInstSrc *ir_build_const_undefined(IrBuilderSrc *irb, Scope *scope, AstN
21502129
21512130static IrInstSrc *ir_build_const_uint(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, uint64_t value) {
21522131 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
2153 const_instruction->value = create_const_vals(1);
2132 const_instruction->value = irb->codegen->pass1_arena->create<ZigValue>();
21542133 const_instruction->value->type = irb->codegen->builtin_types.entry_num_lit_int;
21552134 const_instruction->value->special = ConstValSpecialStatic;
21562135 bigint_init_unsigned(&const_instruction->value->data.x_bigint, value);
......@@ -2159,7 +2138,7 @@ static IrInstSrc *ir_build_const_uint(IrBuilderSrc *irb, Scope *scope, AstNode *
21592138
21602139static IrInstSrc *ir_build_const_bigint(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, BigInt *bigint) {
21612140 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
2162 const_instruction->value = create_const_vals(1);
2141 const_instruction->value = irb->codegen->pass1_arena->create<ZigValue>();
21632142 const_instruction->value->type = irb->codegen->builtin_types.entry_num_lit_int;
21642143 const_instruction->value->special = ConstValSpecialStatic;
21652144 bigint_init_bigint(&const_instruction->value->data.x_bigint, bigint);
......@@ -2168,7 +2147,7 @@ static IrInstSrc *ir_build_const_bigint(IrBuilderSrc *irb, Scope *scope, AstNode
21682147
21692148static IrInstSrc *ir_build_const_bigfloat(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, BigFloat *bigfloat) {
21702149 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
2171 const_instruction->value = create_const_vals(1);
2150 const_instruction->value = irb->codegen->pass1_arena->create<ZigValue>();
21722151 const_instruction->value->type = irb->codegen->builtin_types.entry_num_lit_float;
21732152 const_instruction->value->special = ConstValSpecialStatic;
21742153 bigfloat_init_bigfloat(&const_instruction->value->data.x_bigfloat, bigfloat);
......@@ -2184,7 +2163,7 @@ static IrInstSrc *ir_build_const_null(IrBuilderSrc *irb, Scope *scope, AstNode *
21842163
21852164static IrInstSrc *ir_build_const_usize(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, uint64_t value) {
21862165 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
2187 const_instruction->value = create_const_vals(1);
2166 const_instruction->value = irb->codegen->pass1_arena->create<ZigValue>();
21882167 const_instruction->value->type = irb->codegen->builtin_types.entry_usize;
21892168 const_instruction->value->special = ConstValSpecialStatic;
21902169 bigint_init_unsigned(&const_instruction->value->data.x_bigint, value);
......@@ -2195,7 +2174,7 @@ static IrInstSrc *ir_create_const_type(IrBuilderSrc *irb, Scope *scope, AstNode
21952174 ZigType *type_entry)
21962175{
21972176 IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node);
2198 const_instruction->value = create_const_vals(1);
2177 const_instruction->value = irb->codegen->pass1_arena->create<ZigValue>();
21992178 const_instruction->value->type = irb->codegen->builtin_types.entry_type;
22002179 const_instruction->value->special = ConstValSpecialStatic;
22012180 const_instruction->value->data.x_type = type_entry;
......@@ -2212,7 +2191,7 @@ static IrInstSrc *ir_build_const_type(IrBuilderSrc *irb, Scope *scope, AstNode *
22122191
22132192static IrInstSrc *ir_build_const_import(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, ZigType *import) {
22142193 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
2215 const_instruction->value = create_const_vals(1);
2194 const_instruction->value = irb->codegen->pass1_arena->create<ZigValue>();
22162195 const_instruction->value->type = irb->codegen->builtin_types.entry_type;
22172196 const_instruction->value->special = ConstValSpecialStatic;
22182197 const_instruction->value->data.x_type = import;
......@@ -2221,7 +2200,7 @@ static IrInstSrc *ir_build_const_import(IrBuilderSrc *irb, Scope *scope, AstNode
22212200
22222201static IrInstSrc *ir_build_const_bool(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, bool value) {
22232202 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
2224 const_instruction->value = create_const_vals(1);
2203 const_instruction->value = irb->codegen->pass1_arena->create<ZigValue>();
22252204 const_instruction->value->type = irb->codegen->builtin_types.entry_bool;
22262205 const_instruction->value->special = ConstValSpecialStatic;
22272206 const_instruction->value->data.x_bool = value;
......@@ -2230,7 +2209,7 @@ static IrInstSrc *ir_build_const_bool(IrBuilderSrc *irb, Scope *scope, AstNode *
22302209
22312210static IrInstSrc *ir_build_const_enum_literal(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Buf *name) {
22322211 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
2233 const_instruction->value = create_const_vals(1);
2212 const_instruction->value = irb->codegen->pass1_arena->create<ZigValue>();
22342213 const_instruction->value->type = irb->codegen->builtin_types.entry_enum_literal;
22352214 const_instruction->value->special = ConstValSpecialStatic;
22362215 const_instruction->value->data.x_enum_literal = name;
......@@ -2239,7 +2218,7 @@ static IrInstSrc *ir_build_const_enum_literal(IrBuilderSrc *irb, Scope *scope, A
22392218
22402219static IrInstSrc *ir_create_const_str_lit(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Buf *str) {
22412220 IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node);
2242 const_instruction->value = create_const_vals(1);
2221 const_instruction->value = irb->codegen->pass1_arena->create<ZigValue>();
22432222 init_const_str_lit(irb->codegen, const_instruction->value, str);
22442223
22452224 return &const_instruction->base;
......@@ -5237,7 +5216,7 @@ static IrInstSrc *ir_gen_return(IrBuilderSrc *irb, Scope *scope, AstNode *node,
52375216 switch (node->data.return_expr.kind) {
52385217 case ReturnKindUnconditional:
52395218 {
5240 ResultLocReturn *result_loc_ret = allocate<ResultLocReturn>(1, "ResultLocReturn");
5219 ResultLocReturn *result_loc_ret = heap::c_allocator.create<ResultLocReturn>();
52415220 result_loc_ret->base.id = ResultLocIdReturn;
52425221 ir_build_reset_result(irb, scope, node, &result_loc_ret->base);
52435222
......@@ -5325,7 +5304,7 @@ static IrInstSrc *ir_gen_return(IrBuilderSrc *irb, Scope *scope, AstNode *node,
53255304 ir_mark_gen(ir_build_add_implicit_return_type(irb, scope, node, err_val, nullptr));
53265305 IrInstSrcSpillBegin *spill_begin = ir_build_spill_begin_src(irb, scope, node, err_val,
53275306 SpillIdRetErrCode);
5328 ResultLocReturn *result_loc_ret = allocate<ResultLocReturn>(1, "ResultLocReturn");
5307 ResultLocReturn *result_loc_ret = heap::c_allocator.create<ResultLocReturn>();
53295308 result_loc_ret->base.id = ResultLocIdReturn;
53305309 ir_build_reset_result(irb, scope, node, &result_loc_ret->base);
53315310 ir_build_end_expr(irb, scope, node, err_val, &result_loc_ret->base);
......@@ -5353,12 +5332,12 @@ static ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_s
53535332 Buf *name, bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstSrc *is_comptime,
53545333 bool skip_name_check)
53555334{
5356 ZigVar *variable_entry = allocate<ZigVar>(1, "ZigVar");
5335 ZigVar *variable_entry = heap::c_allocator.create<ZigVar>();
53575336 variable_entry->parent_scope = parent_scope;
53585337 variable_entry->shadowable = is_shadowable;
53595338 variable_entry->is_comptime = is_comptime;
53605339 variable_entry->src_arg_index = SIZE_MAX;
5361 variable_entry->const_value = create_const_vals(1);
5340 variable_entry->const_value = codegen->pass1_arena->create<ZigValue>();
53625341
53635342 if (is_comptime != nullptr) {
53645343 is_comptime->base.ref_count += 1;
......@@ -5418,15 +5397,12 @@ static ZigVar *ir_create_var(IrBuilderSrc *irb, AstNode *node, Scope *scope, Buf
54185397 ZigVar *var = create_local_var(irb->codegen, node, scope,
54195398 (is_underscored ? nullptr : name), src_is_const, gen_is_const,
54205399 (is_underscored ? true : is_shadowable), is_comptime, false);
5421 if (is_comptime != nullptr || gen_is_const) {
5422 var->owner_exec = irb->exec;
5423 }
54245400 assert(var->child_scope);
54255401 return var;
54265402}
54275403
54285404static ResultLocPeer *create_peer_result(ResultLocPeerParent *peer_parent) {
5429 ResultLocPeer *result = allocate<ResultLocPeer>(1, "ResultLocPeer");
5405 ResultLocPeer *result = heap::c_allocator.create<ResultLocPeer>();
54305406 result->base.id = ResultLocIdPeer;
54315407 result->base.source_instruction = peer_parent->base.source_instruction;
54325408 result->parent = peer_parent;
......@@ -5465,7 +5441,7 @@ static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode *
54655441 scope_block->is_comptime = ir_build_const_bool(irb, parent_scope, block_node,
54665442 ir_should_inline(irb->exec, parent_scope));
54675443
5468 scope_block->peer_parent = allocate<ResultLocPeerParent>(1, "ResultLocPeerParent");
5444 scope_block->peer_parent = heap::c_allocator.create<ResultLocPeerParent>();
54695445 scope_block->peer_parent->base.id = ResultLocIdPeerParent;
54705446 scope_block->peer_parent->base.source_instruction = scope_block->is_comptime;
54715447 scope_block->peer_parent->base.allow_write_through_const = result_loc->allow_write_through_const;
......@@ -5555,7 +5531,7 @@ static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode *
55555531 // only generate unconditional defers
55565532
55575533 ir_mark_gen(ir_build_add_implicit_return_type(irb, child_scope, block_node, result, nullptr));
5558 ResultLocReturn *result_loc_ret = allocate<ResultLocReturn>(1, "ResultLocReturn");
5534 ResultLocReturn *result_loc_ret = heap::c_allocator.create<ResultLocReturn>();
55595535 result_loc_ret->base.id = ResultLocIdReturn;
55605536 ir_build_reset_result(irb, parent_scope, block_node, &result_loc_ret->base);
55615537 ir_mark_gen(ir_build_end_expr(irb, parent_scope, block_node, result, &result_loc_ret->base));
......@@ -5597,7 +5573,7 @@ static IrInstSrc *ir_gen_assign(IrBuilderSrc *irb, Scope *scope, AstNode *node)
55975573 if (lvalue == irb->codegen->invalid_inst_src)
55985574 return irb->codegen->invalid_inst_src;
55995575
5600 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1, "ResultLocInstruction");
5576 ResultLocInstruction *result_loc_inst = heap::c_allocator.create<ResultLocInstruction>();
56015577 result_loc_inst->base.id = ResultLocIdInstruction;
56025578 result_loc_inst->base.source_instruction = lvalue;
56035579 ir_ref_instruction(lvalue, irb->current_basic_block);
......@@ -5669,10 +5645,10 @@ static IrInstSrc *ir_gen_bool_or(IrBuilderSrc *irb, Scope *scope, AstNode *node)
56695645
56705646 ir_set_cursor_at_end_and_append_block(irb, true_block);
56715647
5672 IrInstSrc **incoming_values = allocate<IrInstSrc *>(2, "IrInstSrc *");
5648 IrInstSrc **incoming_values = heap::c_allocator.allocate<IrInstSrc *>(2);
56735649 incoming_values[0] = val1;
56745650 incoming_values[1] = val2;
5675 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
5651 IrBasicBlockSrc **incoming_blocks = heap::c_allocator.allocate<IrBasicBlockSrc *>(2);
56765652 incoming_blocks[0] = post_val1_block;
56775653 incoming_blocks[1] = post_val2_block;
56785654
......@@ -5711,10 +5687,10 @@ static IrInstSrc *ir_gen_bool_and(IrBuilderSrc *irb, Scope *scope, AstNode *node
57115687
57125688 ir_set_cursor_at_end_and_append_block(irb, false_block);
57135689
5714 IrInstSrc **incoming_values = allocate<IrInstSrc *>(2);
5690 IrInstSrc **incoming_values = heap::c_allocator.allocate<IrInstSrc *>(2);
57155691 incoming_values[0] = val1;
57165692 incoming_values[1] = val2;
5717 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
5693 IrBasicBlockSrc **incoming_blocks = heap::c_allocator.allocate<IrBasicBlockSrc *>(2);
57185694 incoming_blocks[0] = post_val1_block;
57195695 incoming_blocks[1] = post_val2_block;
57205696
......@@ -5724,7 +5700,7 @@ static IrInstSrc *ir_gen_bool_and(IrBuilderSrc *irb, Scope *scope, AstNode *node
57245700static ResultLocPeerParent *ir_build_result_peers(IrBuilderSrc *irb, IrInstSrc *cond_br_inst,
57255701 IrBasicBlockSrc *end_block, ResultLoc *parent, IrInstSrc *is_comptime)
57265702{
5727 ResultLocPeerParent *peer_parent = allocate<ResultLocPeerParent>(1);
5703 ResultLocPeerParent *peer_parent = heap::c_allocator.create<ResultLocPeerParent>();
57285704 peer_parent->base.id = ResultLocIdPeerParent;
57295705 peer_parent->base.source_instruction = cond_br_inst;
57305706 peer_parent->base.allow_write_through_const = parent->allow_write_through_const;
......@@ -5802,10 +5778,10 @@ static IrInstSrc *ir_gen_orelse(IrBuilderSrc *irb, Scope *parent_scope, AstNode
58025778 ir_build_br(irb, parent_scope, node, end_block, is_comptime);
58035779
58045780 ir_set_cursor_at_end_and_append_block(irb, end_block);
5805 IrInstSrc **incoming_values = allocate<IrInstSrc *>(2);
5781 IrInstSrc **incoming_values = heap::c_allocator.allocate<IrInstSrc *>(2);
58065782 incoming_values[0] = null_result;
58075783 incoming_values[1] = unwrapped_payload;
5808 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
5784 IrBasicBlockSrc **incoming_blocks = heap::c_allocator.allocate<IrBasicBlockSrc *>(2);
58095785 incoming_blocks[0] = after_null_block;
58105786 incoming_blocks[1] = after_ok_block;
58115787 IrInstSrc *phi = ir_build_phi(irb, parent_scope, node, 2, incoming_blocks, incoming_values, peer_parent);
......@@ -5959,7 +5935,7 @@ static void populate_invalid_variable_in_scope(CodeGen *g, Scope *scope, AstNode
59595935 }
59605936 scope = scope->parent;
59615937 }
5962 TldVar *tld_var = allocate<TldVar>(1);
5938 TldVar *tld_var = heap::c_allocator.create<TldVar>();
59635939 init_tld(&tld_var->base, TldIdVar, var_name, VisibModPub, node, &scope_decls->base);
59645940 tld_var->base.resolution = TldResolutionInvalid;
59655941 tld_var->var = add_variable(g, node, &scope_decls->base, var_name, false,
......@@ -5976,7 +5952,7 @@ static IrInstSrc *ir_gen_symbol(IrBuilderSrc *irb, Scope *scope, AstNode *node,
59765952 if (buf_eql_str(variable_name, "_")) {
59775953 if (lval == LValPtr) {
59785954 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, node);
5979 const_instruction->value = create_const_vals(1);
5955 const_instruction->value = irb->codegen->pass1_arena->create<ZigValue>();
59805956 const_instruction->value->type = get_pointer_to_type(irb->codegen,
59815957 irb->codegen->builtin_types.entry_void, false);
59825958 const_instruction->value->special = ConstValSpecialStatic;
......@@ -6170,7 +6146,7 @@ static IrInstSrc *ir_gen_async_call(IrBuilderSrc *irb, Scope *scope, AstNode *aw
61706146 return fn_ref;
61716147
61726148 size_t arg_count = call_node->data.fn_call_expr.params.length - arg_offset;
6173 IrInstSrc **args = allocate<IrInstSrc*>(arg_count);
6149 IrInstSrc **args = heap::c_allocator.allocate<IrInstSrc*>(arg_count);
61746150 for (size_t i = 0; i < arg_count; i += 1) {
61756151 AstNode *arg_node = call_node->data.fn_call_expr.params.at(i + arg_offset);
61766152 IrInstSrc *arg = ir_gen_node(irb, arg_node, scope);
......@@ -6196,7 +6172,7 @@ static IrInstSrc *ir_gen_fn_call_with_args(IrBuilderSrc *irb, Scope *scope, AstN
61966172
61976173 IrInstSrc *fn_type = ir_build_typeof(irb, scope, source_node, fn_ref);
61986174
6199 IrInstSrc **args = allocate<IrInstSrc*>(args_len);
6175 IrInstSrc **args = heap::c_allocator.allocate<IrInstSrc*>(args_len);
62006176 for (size_t i = 0; i < args_len; i += 1) {
62016177 AstNode *arg_node = args_ptr[i];
62026178
......@@ -6381,7 +6357,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod
63816357 }
63826358 case BuiltinFnIdCompileLog:
63836359 {
6384 IrInstSrc **args = allocate<IrInstSrc*>(actual_param_count);
6360 IrInstSrc **args = heap::c_allocator.allocate<IrInstSrc*>(actual_param_count);
63856361
63866362 for (size_t i = 0; i < actual_param_count; i += 1) {
63876363 AstNode *arg_node = node->data.fn_call_expr.params.at(i);
......@@ -7006,7 +6982,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod
70066982 if (dest_type == irb->codegen->invalid_inst_src)
70076983 return dest_type;
70086984
7009 ResultLocBitCast *result_loc_bit_cast = allocate<ResultLocBitCast>(1);
6985 ResultLocBitCast *result_loc_bit_cast = heap::c_allocator.create<ResultLocBitCast>();
70106986 result_loc_bit_cast->base.id = ResultLocIdBitCast;
70116987 result_loc_bit_cast->base.source_instruction = dest_type;
70126988 result_loc_bit_cast->base.allow_write_through_const = result_loc->allow_write_through_const;
......@@ -7555,10 +7531,10 @@ static IrInstSrc *ir_gen_if_bool_expr(IrBuilderSrc *irb, Scope *scope, AstNode *
75557531 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));
75567532
75577533 ir_set_cursor_at_end_and_append_block(irb, endif_block);
7558 IrInstSrc **incoming_values = allocate<IrInstSrc *>(2);
7534 IrInstSrc **incoming_values = heap::c_allocator.allocate<IrInstSrc *>(2);
75597535 incoming_values[0] = then_expr_result;
75607536 incoming_values[1] = else_expr_result;
7561 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
7537 IrBasicBlockSrc **incoming_blocks = heap::c_allocator.allocate<IrBasicBlockSrc *>(2);
75627538 incoming_blocks[0] = after_then_block;
75637539 incoming_blocks[1] = after_else_block;
75647540
......@@ -7759,7 +7735,7 @@ static IrInstSrc *ir_gen_union_init_expr(IrBuilderSrc *irb, Scope *scope, AstNod
77597735 IrInstSrc *field_ptr = ir_build_field_ptr_instruction(irb, scope, source_node, container_ptr,
77607736 field_name, true);
77617737
7762 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1);
7738 ResultLocInstruction *result_loc_inst = heap::c_allocator.create<ResultLocInstruction>();
77637739 result_loc_inst->base.id = ResultLocIdInstruction;
77647740 result_loc_inst->base.source_instruction = field_ptr;
77657741 ir_ref_instruction(field_ptr, irb->current_basic_block);
......@@ -7835,7 +7811,7 @@ static IrInstSrc *ir_gen_container_init_expr(IrBuilderSrc *irb, Scope *scope, As
78357811 nullptr);
78367812
78377813 size_t field_count = container_init_expr->entries.length;
7838 IrInstSrcContainerInitFieldsField *fields = allocate<IrInstSrcContainerInitFieldsField>(field_count);
7814 IrInstSrcContainerInitFieldsField *fields = heap::c_allocator.allocate<IrInstSrcContainerInitFieldsField>(field_count);
78397815 for (size_t i = 0; i < field_count; i += 1) {
78407816 AstNode *entry_node = container_init_expr->entries.at(i);
78417817 assert(entry_node->type == NodeTypeStructValueField);
......@@ -7844,7 +7820,7 @@ static IrInstSrc *ir_gen_container_init_expr(IrBuilderSrc *irb, Scope *scope, As
78447820 AstNode *expr_node = entry_node->data.struct_val_field.expr;
78457821
78467822 IrInstSrc *field_ptr = ir_build_field_ptr(irb, scope, entry_node, container_ptr, name, true);
7847 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1);
7823 ResultLocInstruction *result_loc_inst = heap::c_allocator.create<ResultLocInstruction>();
78487824 result_loc_inst->base.id = ResultLocIdInstruction;
78497825 result_loc_inst->base.source_instruction = field_ptr;
78507826 result_loc_inst->base.allow_write_through_const = true;
......@@ -7874,14 +7850,14 @@ static IrInstSrc *ir_gen_container_init_expr(IrBuilderSrc *irb, Scope *scope, As
78747850 IrInstSrc *container_ptr = ir_build_resolve_result(irb, scope, node, child_result_loc,
78757851 nullptr);
78767852
7877 IrInstSrc **result_locs = allocate<IrInstSrc *>(item_count);
7853 IrInstSrc **result_locs = heap::c_allocator.allocate<IrInstSrc *>(item_count);
78787854 for (size_t i = 0; i < item_count; i += 1) {
78797855 AstNode *expr_node = container_init_expr->entries.at(i);
78807856
78817857 IrInstSrc *elem_index = ir_build_const_usize(irb, scope, expr_node, i);
78827858 IrInstSrc *elem_ptr = ir_build_elem_ptr(irb, scope, expr_node, container_ptr,
78837859 elem_index, false, PtrLenSingle, init_array_type_source_node);
7884 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1);
7860 ResultLocInstruction *result_loc_inst = heap::c_allocator.create<ResultLocInstruction>();
78857861 result_loc_inst->base.id = ResultLocIdInstruction;
78867862 result_loc_inst->base.source_instruction = elem_ptr;
78877863 result_loc_inst->base.allow_write_through_const = true;
......@@ -7907,7 +7883,7 @@ static IrInstSrc *ir_gen_container_init_expr(IrBuilderSrc *irb, Scope *scope, As
79077883}
79087884
79097885static ResultLocVar *ir_build_var_result_loc(IrBuilderSrc *irb, IrInstSrc *alloca, ZigVar *var) {
7910 ResultLocVar *result_loc_var = allocate<ResultLocVar>(1);
7886 ResultLocVar *result_loc_var = heap::c_allocator.create<ResultLocVar>();
79117887 result_loc_var->base.id = ResultLocIdVar;
79127888 result_loc_var->base.source_instruction = alloca;
79137889 result_loc_var->base.allow_write_through_const = true;
......@@ -7921,7 +7897,7 @@ static ResultLocVar *ir_build_var_result_loc(IrBuilderSrc *irb, IrInstSrc *alloc
79217897static ResultLocCast *ir_build_cast_result_loc(IrBuilderSrc *irb, IrInstSrc *dest_type,
79227898 ResultLoc *parent_result_loc)
79237899{
7924 ResultLocCast *result_loc_cast = allocate<ResultLocCast>(1);
7900 ResultLocCast *result_loc_cast = heap::c_allocator.create<ResultLocCast>();
79257901 result_loc_cast->base.id = ResultLocIdCast;
79267902 result_loc_cast->base.source_instruction = dest_type;
79277903 result_loc_cast->base.allow_write_through_const = parent_result_loc->allow_write_through_const;
......@@ -8764,9 +8740,9 @@ static IrInstSrc *ir_gen_asm_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node
87648740 nullptr, 0, is_volatile, true);
87658741 }
87668742
8767 IrInstSrc **input_list = allocate<IrInstSrc *>(asm_expr->input_list.length);
8768 IrInstSrc **output_types = allocate<IrInstSrc *>(asm_expr->output_list.length);
8769 ZigVar **output_vars = allocate<ZigVar *>(asm_expr->output_list.length);
8743 IrInstSrc **input_list = heap::c_allocator.allocate<IrInstSrc *>(asm_expr->input_list.length);
8744 IrInstSrc **output_types = heap::c_allocator.allocate<IrInstSrc *>(asm_expr->output_list.length);
8745 ZigVar **output_vars = heap::c_allocator.allocate<ZigVar *>(asm_expr->output_list.length);
87708746 size_t return_count = 0;
87718747 if (!is_volatile && asm_expr->output_list.length == 0) {
87728748 add_node_error(irb->codegen, node,
......@@ -8900,10 +8876,10 @@ static IrInstSrc *ir_gen_if_optional_expr(IrBuilderSrc *irb, Scope *scope, AstNo
89008876 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));
89018877
89028878 ir_set_cursor_at_end_and_append_block(irb, endif_block);
8903 IrInstSrc **incoming_values = allocate<IrInstSrc *>(2);
8879 IrInstSrc **incoming_values = heap::c_allocator.allocate<IrInstSrc *>(2);
89048880 incoming_values[0] = then_expr_result;
89058881 incoming_values[1] = else_expr_result;
8906 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
8882 IrBasicBlockSrc **incoming_blocks = heap::c_allocator.allocate<IrBasicBlockSrc *>(2);
89078883 incoming_blocks[0] = after_then_block;
89088884 incoming_blocks[1] = after_else_block;
89098885
......@@ -8997,10 +8973,10 @@ static IrInstSrc *ir_gen_if_err_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n
89978973 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));
89988974
89998975 ir_set_cursor_at_end_and_append_block(irb, endif_block);
9000 IrInstSrc **incoming_values = allocate<IrInstSrc *>(2);
8976 IrInstSrc **incoming_values = heap::c_allocator.allocate<IrInstSrc *>(2);
90018977 incoming_values[0] = then_expr_result;
90028978 incoming_values[1] = else_expr_result;
9003 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
8979 IrBasicBlockSrc **incoming_blocks = heap::c_allocator.allocate<IrBasicBlockSrc *>(2);
90048980 incoming_blocks[0] = after_then_block;
90058981 incoming_blocks[1] = after_else_block;
90068982
......@@ -9093,7 +9069,7 @@ static IrInstSrc *ir_gen_switch_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n
90939069
90949070 IrInstSrcSwitchElseVar *switch_else_var = nullptr;
90959071
9096 ResultLocPeerParent *peer_parent = allocate<ResultLocPeerParent>(1);
9072 ResultLocPeerParent *peer_parent = heap::c_allocator.create<ResultLocPeerParent>();
90979073 peer_parent->base.id = ResultLocIdPeerParent;
90989074 peer_parent->base.allow_write_through_const = result_loc->allow_write_through_const;
90999075 peer_parent->end_bb = end_block;
......@@ -9255,7 +9231,7 @@ static IrInstSrc *ir_gen_switch_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n
92559231 ResultLocPeer *this_peer_result_loc = create_peer_result(peer_parent);
92569232
92579233 IrBasicBlockSrc *prong_block = ir_create_basic_block(irb, scope, "SwitchProng");
9258 IrInstSrc **items = allocate<IrInstSrc *>(prong_item_count);
9234 IrInstSrc **items = heap::c_allocator.allocate<IrInstSrc *>(prong_item_count);
92599235
92609236 for (size_t item_i = 0; item_i < prong_item_count; item_i += 1) {
92619237 AstNode *item_node = prong_node->data.switch_prong.items.at(item_i);
......@@ -9637,10 +9613,10 @@ static IrInstSrc *ir_gen_catch(IrBuilderSrc *irb, Scope *parent_scope, AstNode *
96379613 ir_build_br(irb, parent_scope, node, end_block, is_comptime);
96389614
96399615 ir_set_cursor_at_end_and_append_block(irb, end_block);
9640 IrInstSrc **incoming_values = allocate<IrInstSrc *>(2);
9616 IrInstSrc **incoming_values = heap::c_allocator.allocate<IrInstSrc *>(2);
96419617 incoming_values[0] = err_result;
96429618 incoming_values[1] = unwrapped_payload;
9643 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
9619 IrBasicBlockSrc **incoming_blocks = heap::c_allocator.allocate<IrBasicBlockSrc *>(2);
96449620 incoming_blocks[0] = after_err_block;
96459621 incoming_blocks[1] = after_ok_block;
96469622 IrInstSrc *phi = ir_build_phi(irb, parent_scope, node, 2, incoming_blocks, incoming_values, peer_parent);
......@@ -9707,7 +9683,7 @@ static IrInstSrc *ir_gen_container_decl(IrBuilderSrc *irb, Scope *parent_scope,
97079683 scan_decls(irb->codegen, child_scope, child_node);
97089684 }
97099685
9710 TldContainer *tld_container = allocate<TldContainer>(1);
9686 TldContainer *tld_container = heap::c_allocator.create<TldContainer>();
97119687 init_tld(&tld_container->base, TldIdContainer, bare_name, VisibModPub, node, parent_scope);
97129688 tld_container->type_entry = container_type;
97139689 tld_container->decls_scope = child_scope;
......@@ -9750,7 +9726,7 @@ static ZigType *get_error_set_union(CodeGen *g, ErrorTableEntry **errors, ZigTyp
97509726 }
97519727
97529728 err_set_type->data.error_set.err_count = count;
9753 err_set_type->data.error_set.errors = allocate<ErrorTableEntry *>(count);
9729 err_set_type->data.error_set.errors = heap::c_allocator.allocate<ErrorTableEntry *>(count);
97549730
97559731 bool need_comma = false;
97569732 for (uint32_t i = 0; i < set1->data.error_set.err_count; i += 1) {
......@@ -9797,7 +9773,7 @@ static ZigType *make_err_set_with_one_item(CodeGen *g, Scope *parent_scope, AstN
97979773 err_set_type->abi_align = g->builtin_types.entry_global_error_set->abi_align;
97989774 err_set_type->abi_size = g->builtin_types.entry_global_error_set->abi_size;
97999775 err_set_type->data.error_set.err_count = 1;
9800 err_set_type->data.error_set.errors = allocate<ErrorTableEntry *>(1);
9776 err_set_type->data.error_set.errors = heap::c_allocator.create<ErrorTableEntry *>();
98019777
98029778 err_set_type->data.error_set.errors[0] = err_entry;
98039779
......@@ -9828,16 +9804,16 @@ static IrInstSrc *ir_gen_err_set_decl(IrBuilderSrc *irb, Scope *parent_scope, As
98289804 err_set_type->size_in_bits = irb->codegen->builtin_types.entry_global_error_set->size_in_bits;
98299805 err_set_type->abi_align = irb->codegen->builtin_types.entry_global_error_set->abi_align;
98309806 err_set_type->abi_size = irb->codegen->builtin_types.entry_global_error_set->abi_size;
9831 err_set_type->data.error_set.errors = allocate<ErrorTableEntry *>(err_count);
9807 err_set_type->data.error_set.errors = heap::c_allocator.allocate<ErrorTableEntry *>(err_count);
98329808
98339809 size_t errors_count = irb->codegen->errors_by_index.length + err_count;
9834 ErrorTableEntry **errors = allocate<ErrorTableEntry *>(errors_count, "ErrorTableEntry *");
9810 ErrorTableEntry **errors = heap::c_allocator.allocate<ErrorTableEntry *>(errors_count);
98359811
98369812 for (uint32_t i = 0; i < err_count; i += 1) {
98379813 AstNode *field_node = node->data.err_set_decl.decls.at(i);
98389814 AstNode *symbol_node = ast_field_to_symbol_node(field_node);
98399815 Buf *err_name = symbol_node->data.symbol_expr.symbol;
9840 ErrorTableEntry *err = allocate<ErrorTableEntry>(1);
9816 ErrorTableEntry *err = heap::c_allocator.create<ErrorTableEntry>();
98419817 err->decl_node = field_node;
98429818 buf_init_from_buf(&err->name, err_name);
98439819
......@@ -9862,7 +9838,7 @@ static IrInstSrc *ir_gen_err_set_decl(IrBuilderSrc *irb, Scope *parent_scope, As
98629838 }
98639839 errors[err->value] = err;
98649840 }
9865 deallocate(errors, errors_count, "ErrorTableEntry *");
9841 heap::c_allocator.deallocate(errors, errors_count);
98669842 return ir_build_const_type(irb, parent_scope, node, err_set_type);
98679843}
98689844
......@@ -9870,7 +9846,7 @@ static IrInstSrc *ir_gen_fn_proto(IrBuilderSrc *irb, Scope *parent_scope, AstNod
98709846 assert(node->type == NodeTypeFnProto);
98719847
98729848 size_t param_count = node->data.fn_proto.params.length;
9873 IrInstSrc **param_types = allocate<IrInstSrc*>(param_count);
9849 IrInstSrc **param_types = heap::c_allocator.allocate<IrInstSrc*>(param_count);
98749850
98759851 bool is_var_args = false;
98769852 for (size_t i = 0; i < param_count; i += 1) {
......@@ -10151,7 +10127,7 @@ static IrInstSrc *ir_gen_node_raw(IrBuilderSrc *irb, AstNode *node, Scope *scope
1015110127}
1015210128
1015310129static ResultLoc *no_result_loc(void) {
10154 ResultLocNone *result_loc_none = allocate<ResultLocNone>(1);
10130 ResultLocNone *result_loc_none = heap::c_allocator.create<ResultLocNone>();
1015510131 result_loc_none->base.id = ResultLocIdNone;
1015610132 return &result_loc_none->base;
1015710133}
......@@ -10240,7 +10216,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutableSrc *ir_e
1024010216 if (!instr_is_unreachable(result)) {
1024110217 ir_mark_gen(ir_build_add_implicit_return_type(irb, scope, result->base.source_node, result, nullptr));
1024210218 // no need for save_err_ret_addr because this cannot return error
10243 ResultLocReturn *result_loc_ret = allocate<ResultLocReturn>(1, "ResultLocReturn");
10219 ResultLocReturn *result_loc_ret = heap::c_allocator.create<ResultLocReturn>();
1024410220 result_loc_ret->base.id = ResultLocIdReturn;
1024510221 ir_build_reset_result(irb, scope, node, &result_loc_ret->base);
1024610222 ir_mark_gen(ir_build_end_expr(irb, scope, node, result, &result_loc_ret->base));
......@@ -10332,7 +10308,7 @@ static Error eval_comptime_ptr_reinterpret(IrAnalyze *ira, CodeGen *codegen, Ast
1033210308 if ((err = ir_read_const_ptr(ira, codegen, source_node, &tmp, ptr_val)))
1033310309 return err;
1033410310 ZigValue *child_val = const_ptr_pointee_unchecked(codegen, ptr_val);
10335 copy_const_val(child_val, &tmp);
10311 copy_const_val(codegen, child_val, &tmp);
1033610312 return ErrorNone;
1033710313}
1033810314
......@@ -11482,7 +11458,7 @@ static ZigType *get_error_set_intersection(IrAnalyze *ira, ZigType *set1, ZigTyp
1148211458 return set1;
1148311459 }
1148411460 size_t errors_count = ira->codegen->errors_by_index.length;
11485 ErrorTableEntry **errors = allocate<ErrorTableEntry *>(errors_count, "ErrorTableEntry *");
11461 ErrorTableEntry **errors = heap::c_allocator.allocate<ErrorTableEntry *>(errors_count);
1148611462 populate_error_set_table(errors, set1);
1148711463 ZigList<ErrorTableEntry *> intersection_list = {};
1148811464
......@@ -11503,7 +11479,7 @@ static ZigType *get_error_set_intersection(IrAnalyze *ira, ZigType *set1, ZigTyp
1150311479 buf_appendf(&err_set_type->name, "%s%s", comma, buf_ptr(&existing_entry_with_docs->name));
1150411480 }
1150511481 }
11506 deallocate(errors, errors_count, "ErrorTableEntry *");
11482 heap::c_allocator.deallocate(errors, errors_count);
1150711483
1150811484 err_set_type->data.error_set.err_count = intersection_list.length;
1150911485 err_set_type->data.error_set.errors = intersection_list.items;
......@@ -11552,10 +11528,11 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
1155211528 wanted_ptr_type->data.pointer.sentinel == nullptr ||
1155311529 (actual_ptr_type->data.pointer.sentinel != nullptr &&
1155411530 const_values_equal(ira->codegen, wanted_ptr_type->data.pointer.sentinel,
11555 actual_ptr_type->data.pointer.sentinel));
11531 actual_ptr_type->data.pointer.sentinel)) ||
11532 actual_ptr_type->data.pointer.ptr_len == PtrLenC;
1155611533 if (!ok_null_term_ptrs) {
1155711534 result.id = ConstCastResultIdPtrSentinel;
11558 result.data.bad_ptr_sentinel = allocate_nonzero<ConstCastPtrSentinel>(1);
11535 result.data.bad_ptr_sentinel = heap::c_allocator.allocate_nonzero<ConstCastPtrSentinel>(1);
1155911536 result.data.bad_ptr_sentinel->wanted_type = wanted_ptr_type;
1156011537 result.data.bad_ptr_sentinel->actual_type = actual_ptr_type;
1156111538 return result;
......@@ -11571,7 +11548,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
1157111548 (!actual_ptr_type->data.pointer.is_volatile || wanted_ptr_type->data.pointer.is_volatile);
1157211549 if (!ok_cv_qualifiers) {
1157311550 result.id = ConstCastResultIdCV;
11574 result.data.bad_cv = allocate_nonzero<ConstCastBadCV>(1);
11551 result.data.bad_cv = heap::c_allocator.allocate_nonzero<ConstCastBadCV>(1);
1157511552 result.data.bad_cv->wanted_type = wanted_ptr_type;
1157611553 result.data.bad_cv->actual_type = actual_ptr_type;
1157711554 return result;
......@@ -11583,7 +11560,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
1158311560 return child;
1158411561 if (child.id != ConstCastResultIdOk) {
1158511562 result.id = ConstCastResultIdPointerChild;
11586 result.data.pointer_mismatch = allocate_nonzero<ConstCastPointerMismatch>(1);
11563 result.data.pointer_mismatch = heap::c_allocator.allocate_nonzero<ConstCastPointerMismatch>(1);
1158711564 result.data.pointer_mismatch->child = child;
1158811565 result.data.pointer_mismatch->wanted_child = wanted_ptr_type->data.pointer.child_type;
1158911566 result.data.pointer_mismatch->actual_child = actual_ptr_type->data.pointer.child_type;
......@@ -11594,7 +11571,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
1159411571 (!wanted_allows_zero && !actual_allows_zero);
1159511572 if (!ok_allows_zero) {
1159611573 result.id = ConstCastResultIdBadAllowsZero;
11597 result.data.bad_allows_zero = allocate_nonzero<ConstCastBadAllowsZero>(1);
11574 result.data.bad_allows_zero = heap::c_allocator.allocate_nonzero<ConstCastBadAllowsZero>(1);
1159811575 result.data.bad_allows_zero->wanted_type = wanted_type;
1159911576 result.data.bad_allows_zero->actual_type = actual_type;
1160011577 return result;
......@@ -11634,7 +11611,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
1163411611 return child;
1163511612 if (child.id != ConstCastResultIdOk) {
1163611613 result.id = ConstCastResultIdArrayChild;
11637 result.data.array_mismatch = allocate_nonzero<ConstCastArrayMismatch>(1);
11614 result.data.array_mismatch = heap::c_allocator.allocate_nonzero<ConstCastArrayMismatch>(1);
1163811615 result.data.array_mismatch->child = child;
1163911616 result.data.array_mismatch->wanted_child = wanted_type->data.array.child_type;
1164011617 result.data.array_mismatch->actual_child = actual_type->data.array.child_type;
......@@ -11645,7 +11622,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
1164511622 const_values_equal(ira->codegen, wanted_type->data.array.sentinel, actual_type->data.array.sentinel));
1164611623 if (!ok_null_terminated) {
1164711624 result.id = ConstCastResultIdSentinelArrays;
11648 result.data.sentinel_arrays = allocate_nonzero<ConstCastBadNullTermArrays>(1);
11625 result.data.sentinel_arrays = heap::c_allocator.allocate_nonzero<ConstCastBadNullTermArrays>(1);
1164911626 result.data.sentinel_arrays->child = child;
1165011627 result.data.sentinel_arrays->wanted_type = wanted_type;
1165111628 result.data.sentinel_arrays->actual_type = actual_type;
......@@ -11673,7 +11650,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
1167311650 actual_ptr_type->data.pointer.sentinel));
1167411651 if (!ok_sentinels) {
1167511652 result.id = ConstCastResultIdPtrSentinel;
11676 result.data.bad_ptr_sentinel = allocate_nonzero<ConstCastPtrSentinel>(1);
11653 result.data.bad_ptr_sentinel = heap::c_allocator.allocate_nonzero<ConstCastPtrSentinel>(1);
1167711654 result.data.bad_ptr_sentinel->wanted_type = wanted_ptr_type;
1167811655 result.data.bad_ptr_sentinel->actual_type = actual_ptr_type;
1167911656 return result;
......@@ -11690,7 +11667,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
1169011667 return child;
1169111668 if (child.id != ConstCastResultIdOk) {
1169211669 result.id = ConstCastResultIdSliceChild;
11693 result.data.slice_mismatch = allocate_nonzero<ConstCastSliceMismatch>(1);
11670 result.data.slice_mismatch = heap::c_allocator.allocate_nonzero<ConstCastSliceMismatch>(1);
1169411671 result.data.slice_mismatch->child = child;
1169511672 result.data.slice_mismatch->actual_child = actual_ptr_type->data.pointer.child_type;
1169611673 result.data.slice_mismatch->wanted_child = wanted_ptr_type->data.pointer.child_type;
......@@ -11707,7 +11684,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
1170711684 return child;
1170811685 if (child.id != ConstCastResultIdOk) {
1170911686 result.id = ConstCastResultIdOptionalChild;
11710 result.data.optional = allocate_nonzero<ConstCastOptionalMismatch>(1);
11687 result.data.optional = heap::c_allocator.allocate_nonzero<ConstCastOptionalMismatch>(1);
1171111688 result.data.optional->child = child;
1171211689 result.data.optional->wanted_child = wanted_type->data.maybe.child_type;
1171311690 result.data.optional->actual_child = actual_type->data.maybe.child_type;
......@@ -11723,7 +11700,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
1172311700 return payload_child;
1172411701 if (payload_child.id != ConstCastResultIdOk) {
1172511702 result.id = ConstCastResultIdErrorUnionPayload;
11726 result.data.error_union_payload = allocate_nonzero<ConstCastErrUnionPayloadMismatch>(1);
11703 result.data.error_union_payload = heap::c_allocator.allocate_nonzero<ConstCastErrUnionPayloadMismatch>(1);
1172711704 result.data.error_union_payload->child = payload_child;
1172811705 result.data.error_union_payload->wanted_payload = wanted_type->data.error_union.payload_type;
1172911706 result.data.error_union_payload->actual_payload = actual_type->data.error_union.payload_type;
......@@ -11735,7 +11712,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
1173511712 return error_set_child;
1173611713 if (error_set_child.id != ConstCastResultIdOk) {
1173711714 result.id = ConstCastResultIdErrorUnionErrorSet;
11738 result.data.error_union_error_set = allocate_nonzero<ConstCastErrUnionErrSetMismatch>(1);
11715 result.data.error_union_error_set = heap::c_allocator.allocate_nonzero<ConstCastErrUnionErrSetMismatch>(1);
1173911716 result.data.error_union_error_set->child = error_set_child;
1174011717 result.data.error_union_error_set->wanted_err_set = wanted_type->data.error_union.err_set_type;
1174111718 result.data.error_union_error_set->actual_err_set = actual_type->data.error_union.err_set_type;
......@@ -11769,7 +11746,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
1176911746 }
1177011747
1177111748 size_t errors_count = g->errors_by_index.length;
11772 ErrorTableEntry **errors = allocate<ErrorTableEntry *>(errors_count, "ErrorTableEntry *");
11749 ErrorTableEntry **errors = heap::c_allocator.allocate<ErrorTableEntry *>(errors_count);
1177311750 for (uint32_t i = 0; i < container_set->data.error_set.err_count; i += 1) {
1177411751 ErrorTableEntry *error_entry = container_set->data.error_set.errors[i];
1177511752 assert(errors[error_entry->value] == nullptr);
......@@ -11781,12 +11758,12 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
1178111758 if (error_entry == nullptr) {
1178211759 if (result.id == ConstCastResultIdOk) {
1178311760 result.id = ConstCastResultIdErrSet;
11784 result.data.error_set_mismatch = allocate<ConstCastErrSetMismatch>(1);
11761 result.data.error_set_mismatch = heap::c_allocator.create<ConstCastErrSetMismatch>();
1178511762 }
1178611763 result.data.error_set_mismatch->missing_errors.append(contained_error_entry);
1178711764 }
1178811765 }
11789 deallocate(errors, errors_count, "ErrorTableEntry *");
11766 heap::c_allocator.deallocate(errors, errors_count);
1179011767 return result;
1179111768 }
1179211769
......@@ -11815,7 +11792,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
1181511792 return child;
1181611793 if (child.id != ConstCastResultIdOk) {
1181711794 result.id = ConstCastResultIdFnReturnType;
11818 result.data.return_type = allocate_nonzero<ConstCastOnly>(1);
11795 result.data.return_type = heap::c_allocator.allocate_nonzero<ConstCastOnly>(1);
1181911796 *result.data.return_type = child;
1182011797 return result;
1182111798 }
......@@ -11844,7 +11821,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
1184411821 result.data.fn_arg.arg_index = i;
1184511822 result.data.fn_arg.actual_param_type = actual_param_info->type;
1184611823 result.data.fn_arg.expected_param_type = expected_param_info->type;
11847 result.data.fn_arg.child = allocate_nonzero<ConstCastOnly>(1);
11824 result.data.fn_arg.child = heap::c_allocator.allocate_nonzero<ConstCastOnly>(1);
1184811825 *result.data.fn_arg.child = arg_child;
1184911826 return result;
1185011827 }
......@@ -11864,15 +11841,20 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
1186411841 }
1186511842
1186611843 if (wanted_type->id == ZigTypeIdInt && actual_type->id == ZigTypeIdInt) {
11867 result.id = ConstCastResultIdIntShorten;
11868 result.data.int_shorten = allocate_nonzero<ConstCastIntShorten>(1);
11869 result.data.int_shorten->wanted_type = wanted_type;
11870 result.data.int_shorten->actual_type = actual_type;
11844 if (wanted_type->data.integral.is_signed != actual_type->data.integral.is_signed ||
11845 wanted_type->data.integral.bit_count != actual_type->data.integral.bit_count)
11846 {
11847 result.id = ConstCastResultIdIntShorten;
11848 result.data.int_shorten = heap::c_allocator.allocate_nonzero<ConstCastIntShorten>(1);
11849 result.data.int_shorten->wanted_type = wanted_type;
11850 result.data.int_shorten->actual_type = actual_type;
11851 return result;
11852 }
1187111853 return result;
1187211854 }
1187311855
1187411856 result.id = ConstCastResultIdType;
11875 result.data.type_mismatch = allocate_nonzero<ConstCastTypeMismatch>(1);
11857 result.data.type_mismatch = heap::c_allocator.allocate_nonzero<ConstCastTypeMismatch>(1);
1187611858 result.data.type_mismatch->wanted_type = wanted_type;
1187711859 result.data.type_mismatch->actual_type = actual_type;
1187811860 return result;
......@@ -11881,7 +11863,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
1188111863static void update_errors_helper(CodeGen *g, ErrorTableEntry ***errors, size_t *errors_count) {
1188211864 size_t old_errors_count = *errors_count;
1188311865 *errors_count = g->errors_by_index.length;
11884 *errors = reallocate(*errors, old_errors_count, *errors_count);
11866 *errors = heap::c_allocator.reallocate(*errors, old_errors_count, *errors_count);
1188511867}
1188611868
1188711869static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigType *expected_type,
......@@ -12551,7 +12533,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1255112533 return ira->codegen->builtin_types.entry_invalid;
1255212534 }
1255312535
12554 free(errors);
12536 heap::c_allocator.deallocate(errors, errors_count);
1255512537
1255612538 if (convert_to_const_slice) {
1255712539 if (prev_inst->value->type->id == ZigTypeIdPointer) {
......@@ -12630,7 +12612,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInst *source_instr,
1263012612 case CastOpBitCast:
1263112613 zig_panic("TODO");
1263212614 case CastOpNoop: {
12633 copy_const_val(const_val, other_val);
12615 copy_const_val(ira->codegen, const_val, other_val);
1263412616 const_val->type = new_type;
1263512617 break;
1263612618 }
......@@ -12770,13 +12752,19 @@ static IrInstGen *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, IrI
1277012752 wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, value->value->type));
1277112753
1277212754 if (instr_is_comptime(value)) {
12773 ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, value->value, source_instr->source_node);
12755 ZigValue *val = ir_resolve_const(ira, value, UndefOk);
12756 if (val == nullptr)
12757 return ira->codegen->invalid_inst_gen;
12758 if (val->special == ConstValSpecialUndef)
12759 return ir_const_undef(ira, source_instr, wanted_type);
12760
12761 ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node);
1277412762 if (pointee == nullptr)
1277512763 return ira->codegen->invalid_inst_gen;
1277612764 if (pointee->special != ConstValSpecialRuntime) {
1277712765 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1277812766 result->value->data.x_ptr.special = ConstPtrSpecialBaseArray;
12779 result->value->data.x_ptr.mut = value->value->data.x_ptr.mut;
12767 result->value->data.x_ptr.mut = val->data.x_ptr.mut;
1278012768 result->value->data.x_ptr.data.base_array.array_val = pointee;
1278112769 result->value->data.x_ptr.data.base_array.elem_index = 0;
1278212770 return result;
......@@ -13159,7 +13147,7 @@ Error ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
1315913147 if (type_is_invalid(return_ptr->type))
1316013148 return ErrorSemanticAnalyzeFail;
1316113149
13162 IrExecutableSrc *ir_executable = allocate<IrExecutableSrc>(1, "IrExecutableSrc");
13150 IrExecutableSrc *ir_executable = heap::c_allocator.create<IrExecutableSrc>();
1316313151 ir_executable->source_node = source_node;
1316413152 ir_executable->parent_exec = parent_exec;
1316513153 ir_executable->name = exec_name;
......@@ -13183,7 +13171,7 @@ Error ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
1318313171 ir_print_src(codegen, stderr, ir_executable, 2);
1318413172 fprintf(stderr, "}\n");
1318513173 }
13186 IrExecutableGen *analyzed_executable = allocate<IrExecutableGen>(1, "IrExecutableGen");
13174 IrExecutableGen *analyzed_executable = heap::c_allocator.create<IrExecutableGen>();
1318713175 analyzed_executable->source_node = source_node;
1318813176 analyzed_executable->parent_exec = parent_exec;
1318913177 analyzed_executable->source_exec = ir_executable;
......@@ -13384,7 +13372,7 @@ static IrInstGen *ir_analyze_optional_wrap(IrAnalyze *ira, IrInst* source_instr,
1338413372 source_instr->scope, source_instr->source_node);
1338513373 const_instruction->base.value->special = ConstValSpecialStatic;
1338613374 if (types_have_same_zig_comptime_repr(ira->codegen, wanted_type, payload_type)) {
13387 copy_const_val(const_instruction->base.value, val);
13375 copy_const_val(ira->codegen, const_instruction->base.value, val);
1338813376 } else {
1338913377 const_instruction->base.value->data.x_optional = val;
1339013378 }
......@@ -13425,7 +13413,7 @@ static IrInstGen *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInst* source_ins
1342513413 if (val == nullptr)
1342613414 return ira->codegen->invalid_inst_gen;
1342713415
13428 ZigValue *err_set_val = create_const_vals(1);
13416 ZigValue *err_set_val = ira->codegen->pass1_arena->create<ZigValue>();
1342913417 err_set_val->type = err_set_type;
1343013418 err_set_val->special = ConstValSpecialStatic;
1343113419 err_set_val->data.x_err_set = nullptr;
......@@ -13537,7 +13525,7 @@ static IrInstGen *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInst* source_instr,
1353713525 if (!val)
1353813526 return ira->codegen->invalid_inst_gen;
1353913527
13540 ZigValue *err_set_val = create_const_vals(1);
13528 ZigValue *err_set_val = ira->codegen->pass1_arena->create<ZigValue>();
1354113529 err_set_val->special = ConstValSpecialStatic;
1354213530 err_set_val->type = wanted_type->data.error_union.err_set_type;
1354313531 err_set_val->data.x_err_set = val->data.x_err_set;
......@@ -13802,7 +13790,7 @@ static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, IrInst* source_instr,
1380213790 result->value->special = ConstValSpecialStatic;
1380313791 result->value->type = wanted_type;
1380413792 bigint_init_bigint(&result->value->data.x_union.tag, &val->data.x_enum_tag);
13805 result->value->data.x_union.payload = create_const_vals(1);
13793 result->value->data.x_union.payload = ira->codegen->pass1_arena->create<ZigValue>();
1380613794 result->value->data.x_union.payload->special = ConstValSpecialStatic;
1380713795 result->value->data.x_union.payload->type = field_type;
1380813796 return result;
......@@ -14107,7 +14095,7 @@ static IrInstGen *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInst* source_instr,
1410714095 if (pointee == nullptr)
1410814096 return ira->codegen->invalid_inst_gen;
1410914097 if (pointee->special != ConstValSpecialRuntime) {
14110 ZigValue *array_val = create_const_vals(1);
14098 ZigValue *array_val = ira->codegen->pass1_arena->create<ZigValue>();
1411114099 array_val->special = ConstValSpecialStatic;
1411214100 array_val->type = array_type;
1411314101 array_val->data.x_array.special = ConstArraySpecialNone;
......@@ -14321,7 +14309,7 @@ static IrInstGen *ir_analyze_array_to_vector(IrAnalyze *ira, IrInst* source_inst
1432114309 if (instr_is_comptime(array)) {
1432214310 // arrays and vectors have the same ZigValue representation
1432314311 IrInstGen *result = ir_const(ira, source_instr, vector_type);
14324 copy_const_val(result->value, array->value);
14312 copy_const_val(ira->codegen, result->value, array->value);
1432514313 result->value->type = vector_type;
1432614314 return result;
1432714315 }
......@@ -14334,7 +14322,7 @@ static IrInstGen *ir_analyze_vector_to_array(IrAnalyze *ira, IrInst* source_inst
1433414322 if (instr_is_comptime(vector)) {
1433514323 // arrays and vectors have the same ZigValue representation
1433614324 IrInstGen *result = ir_const(ira, source_instr, array_type);
14337 copy_const_val(result->value, vector->value);
14325 copy_const_val(ira->codegen, result->value, vector->value);
1433814326 result->value->type = array_type;
1433914327 return result;
1434014328 }
......@@ -14634,7 +14622,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
1463414622 if (wanted_type->id == ZigTypeIdComptimeInt || wanted_type->id == ZigTypeIdInt) {
1463514623 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1463614624 if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) {
14637 copy_const_val(result->value, value->value);
14625 copy_const_val(ira->codegen, result->value, value->value);
1463814626 result->value->type = wanted_type;
1463914627 } else {
1464014628 float_init_bigint(&result->value->data.x_bigint, value->value);
......@@ -14826,6 +14814,16 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
1482614814 }
1482714815 }
1482814816
14817 // @Vector(N,T1) to @Vector(N,T2)
14818 if (actual_type->id == ZigTypeIdVector && wanted_type->id == ZigTypeIdVector) {
14819 if (actual_type->data.vector.len == wanted_type->data.vector.len &&
14820 types_match_const_cast_only(ira, wanted_type->data.vector.elem_type,
14821 actual_type->data.vector.elem_type, source_node, false).id == ConstCastResultIdOk)
14822 {
14823 return ir_analyze_bit_cast(ira, source_instr, value, wanted_type);
14824 }
14825 }
14826
1482914827 // *@Frame(func) to anyframe->T or anyframe
1483014828 // *@Frame(func) to ?anyframe->T or ?anyframe
1483114829 // *@Frame(func) to E!anyframe->T or E!anyframe
......@@ -16395,9 +16393,11 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i
1639516393 case ZigTypeIdComptimeInt:
1639616394 case ZigTypeIdInt:
1639716395 case ZigTypeIdFloat:
16398 case ZigTypeIdVector:
1639916396 zig_unreachable(); // handled with the type_is_numeric checks above
1640016397
16398 case ZigTypeIdVector:
16399 // Not every case is handled by the type_is_numeric checks above,
16400 // vectors of bool trigger this code path
1640116401 case ZigTypeIdBool:
1640216402 case ZigTypeIdMetaType:
1640316403 case ZigTypeIdVoid:
......@@ -16467,7 +16467,7 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i
1646716467 IrInstGen *result = ir_const(ira, &bin_op_instruction->base.base,
1646816468 get_vector_type(ira->codegen, resolved_type->data.vector.len, ira->codegen->builtin_types.entry_bool));
1646916469 result->value->data.x_array.data.s_none.elements =
16470 create_const_vals(resolved_type->data.vector.len);
16470 ira->codegen->pass1_arena->allocate<ZigValue>(resolved_type->data.vector.len);
1647116471
1647216472 expand_undef_array(ira->codegen, result->value);
1647316473 for (size_t i = 0;i < resolved_type->data.vector.len;i++) {
......@@ -16475,7 +16475,7 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i
1647516475 &op1_val->data.x_array.data.s_none.elements[i],
1647616476 &op2_val->data.x_array.data.s_none.elements[i],
1647716477 bin_op_instruction, op_id, one_possible_value);
16478 copy_const_val(&result->value->data.x_array.data.s_none.elements[i], cur_res->value);
16478 copy_const_val(ira->codegen, &result->value->data.x_array.data.s_none.elements[i], cur_res->value);
1647916479 }
1648016480 return result;
1648116481 }
......@@ -17375,7 +17375,7 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi
1737517375 ZigValue *out_array_val;
1737617376 size_t new_len = (op1_array_end - op1_array_index) + (op2_array_end - op2_array_index);
1737717377 if (op1_type->id == ZigTypeIdPointer || op2_type->id == ZigTypeIdPointer) {
17378 out_array_val = create_const_vals(1);
17378 out_array_val = ira->codegen->pass1_arena->create<ZigValue>();
1737917379 out_array_val->special = ConstValSpecialStatic;
1738017380 out_array_val->type = get_array_type(ira->codegen, child_type, new_len, sentinel);
1738117381
......@@ -17387,11 +17387,11 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi
1738717387 true, false, PtrLenUnknown, 0, 0, 0, false,
1738817388 VECTOR_INDEX_NONE, nullptr, sentinel);
1738917389 result->value->type = get_slice_type(ira->codegen, ptr_type);
17390 out_array_val = create_const_vals(1);
17390 out_array_val = ira->codegen->pass1_arena->create<ZigValue>();
1739117391 out_array_val->special = ConstValSpecialStatic;
1739217392 out_array_val->type = get_array_type(ira->codegen, child_type, new_len, sentinel);
1739317393
17394 out_val->data.x_struct.fields = alloc_const_vals_ptrs(2);
17394 out_val->data.x_struct.fields = alloc_const_vals_ptrs(ira->codegen, 2);
1739517395
1739617396 out_val->data.x_struct.fields[slice_ptr_index]->type = ptr_type;
1739717397 out_val->data.x_struct.fields[slice_ptr_index]->special = ConstValSpecialStatic;
......@@ -17408,7 +17408,7 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi
1740817408 } else {
1740917409 result->value->type = get_pointer_to_type_extra2(ira->codegen, child_type, true, false, PtrLenUnknown,
1741017410 0, 0, 0, false, VECTOR_INDEX_NONE, nullptr, sentinel);
17411 out_array_val = create_const_vals(1);
17411 out_array_val = ira->codegen->pass1_arena->create<ZigValue>();
1741217412 out_array_val->special = ConstValSpecialStatic;
1741317413 out_array_val->type = get_array_type(ira->codegen, child_type, new_len, sentinel);
1741417414 out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;
......@@ -17424,7 +17424,7 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi
1742417424 }
1742517425
1742617426 uint64_t full_len = new_len + ((sentinel != nullptr) ? 1 : 0);
17427 out_array_val->data.x_array.data.s_none.elements = create_const_vals(full_len);
17427 out_array_val->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(full_len);
1742817428 // TODO handle the buf case here for an optimization
1742917429 expand_undef_array(ira->codegen, op1_array_val);
1743017430 expand_undef_array(ira->codegen, op2_array_val);
......@@ -17432,21 +17432,21 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi
1743217432 size_t next_index = 0;
1743317433 for (size_t i = op1_array_index; i < op1_array_end; i += 1, next_index += 1) {
1743417434 ZigValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index];
17435 copy_const_val(elem_dest_val, &op1_array_val->data.x_array.data.s_none.elements[i]);
17435 copy_const_val(ira->codegen, elem_dest_val, &op1_array_val->data.x_array.data.s_none.elements[i]);
1743617436 elem_dest_val->parent.id = ConstParentIdArray;
1743717437 elem_dest_val->parent.data.p_array.array_val = out_array_val;
1743817438 elem_dest_val->parent.data.p_array.elem_index = next_index;
1743917439 }
1744017440 for (size_t i = op2_array_index; i < op2_array_end; i += 1, next_index += 1) {
1744117441 ZigValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index];
17442 copy_const_val(elem_dest_val, &op2_array_val->data.x_array.data.s_none.elements[i]);
17442 copy_const_val(ira->codegen, elem_dest_val, &op2_array_val->data.x_array.data.s_none.elements[i]);
1744317443 elem_dest_val->parent.id = ConstParentIdArray;
1744417444 elem_dest_val->parent.data.p_array.array_val = out_array_val;
1744517445 elem_dest_val->parent.data.p_array.elem_index = next_index;
1744617446 }
1744717447 if (next_index < full_len) {
1744817448 ZigValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index];
17449 copy_const_val(elem_dest_val, sentinel);
17449 copy_const_val(ira->codegen, elem_dest_val, sentinel);
1745017450 elem_dest_val->parent.id = ConstParentIdArray;
1745117451 elem_dest_val->parent.data.p_array.array_val = out_array_val;
1745217452 elem_dest_val->parent.data.p_array.elem_index = next_index;
......@@ -17525,13 +17525,13 @@ static IrInstGen *ir_analyze_array_mult(IrAnalyze *ira, IrInstSrcBinOp *instruct
1752517525 // TODO optimize the buf case
1752617526 expand_undef_array(ira->codegen, array_val);
1752717527 size_t extra_null_term = (array_type->data.array.sentinel != nullptr) ? 1 : 0;
17528 out_val->data.x_array.data.s_none.elements = create_const_vals(new_array_len + extra_null_term);
17528 out_val->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(new_array_len + extra_null_term);
1752917529
1753017530 uint64_t i = 0;
1753117531 for (uint64_t x = 0; x < mult_amt; x += 1) {
1753217532 for (uint64_t y = 0; y < old_array_len; y += 1) {
1753317533 ZigValue *elem_dest_val = &out_val->data.x_array.data.s_none.elements[i];
17534 copy_const_val(elem_dest_val, &array_val->data.x_array.data.s_none.elements[y]);
17534 copy_const_val(ira->codegen, elem_dest_val, &array_val->data.x_array.data.s_none.elements[y]);
1753517535 elem_dest_val->parent.id = ConstParentIdArray;
1753617536 elem_dest_val->parent.data.p_array.array_val = out_val;
1753717537 elem_dest_val->parent.data.p_array.elem_index = i;
......@@ -17542,7 +17542,7 @@ static IrInstGen *ir_analyze_array_mult(IrAnalyze *ira, IrInstSrcBinOp *instruct
1754217542
1754317543 if (array_type->data.array.sentinel != nullptr) {
1754417544 ZigValue *elem_dest_val = &out_val->data.x_array.data.s_none.elements[i];
17545 copy_const_val(elem_dest_val, array_type->data.array.sentinel);
17545 copy_const_val(ira->codegen, elem_dest_val, array_type->data.array.sentinel);
1754617546 elem_dest_val->parent.id = ConstParentIdArray;
1754717547 elem_dest_val->parent.data.p_array.array_val = out_val;
1754817548 elem_dest_val->parent.data.p_array.elem_index = i;
......@@ -17583,14 +17583,14 @@ static IrInstGen *ir_analyze_instruction_merge_err_sets(IrAnalyze *ira,
1758317583 }
1758417584
1758517585 size_t errors_count = ira->codegen->errors_by_index.length;
17586 ErrorTableEntry **errors = allocate<ErrorTableEntry *>(errors_count, "ErrorTableEntry *");
17586 ErrorTableEntry **errors = heap::c_allocator.allocate<ErrorTableEntry *>(errors_count);
1758717587 for (uint32_t i = 0, count = op1_type->data.error_set.err_count; i < count; i += 1) {
1758817588 ErrorTableEntry *error_entry = op1_type->data.error_set.errors[i];
1758917589 assert(errors[error_entry->value] == nullptr);
1759017590 errors[error_entry->value] = error_entry;
1759117591 }
1759217592 ZigType *result_type = get_error_set_union(ira->codegen, errors, op1_type, op2_type, instruction->type_name);
17593 deallocate(errors, errors_count, "ErrorTableEntry *");
17593 heap::c_allocator.deallocate(errors, errors_count);
1759417594
1759517595 return ir_const_type(ira, &instruction->base.base, result_type);
1759617596}
......@@ -17689,8 +17689,8 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV
1768917689 if (var->gen_is_const) {
1769017690 var->const_value = init_val;
1769117691 } else {
17692 var->const_value = create_const_vals(1);
17693 copy_const_val(var->const_value, init_val);
17692 var->const_value = ira->codegen->pass1_arena->create<ZigValue>();
17693 copy_const_val(ira->codegen, var->const_value, init_val);
1769417694 }
1769517695 }
1769617696 }
......@@ -17864,7 +17864,7 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport
1786417864 // It's not clear how all the different types are supposed to be handled.
1786517865 // Need comprehensive tests for exporting one thing in one file and declaring an extern var
1786617866 // in another file.
17867 TldFn *tld_fn = allocate<TldFn>(1);
17867 TldFn *tld_fn = heap::c_allocator.create<TldFn>();
1786817868 tld_fn->base.id = TldIdFn;
1786917869 tld_fn->base.source_node = instruction->base.base.source_node;
1787017870
......@@ -18093,7 +18093,7 @@ static IrInstGen *ir_analyze_instruction_error_union(IrAnalyze *ira, IrInstSrcEr
1809318093 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type);
1809418094 result->value->special = ConstValSpecialLazy;
1809518095
18096 LazyValueErrUnionType *lazy_err_union_type = allocate<LazyValueErrUnionType>(1, "LazyValueErrUnionType");
18096 LazyValueErrUnionType *lazy_err_union_type = heap::c_allocator.create<LazyValueErrUnionType>();
1809718097 lazy_err_union_type->ira = ira; ira_ref(ira);
1809818098 result->value->data.x_lazy = &lazy_err_union_type->base;
1809918099 lazy_err_union_type->base.id = LazyValueIdErrUnionType;
......@@ -18114,7 +18114,7 @@ static IrInstGen *ir_analyze_alloca(IrAnalyze *ira, IrInst *source_inst, ZigType
1811418114{
1811518115 Error err;
1811618116
18117 ZigValue *pointee = create_const_vals(1);
18117 ZigValue *pointee = ira->codegen->pass1_arena->create<ZigValue>();
1811818118 pointee->special = ConstValSpecialUndef;
1811918119 pointee->llvm_align = align;
1812018120
......@@ -18195,8 +18195,8 @@ static bool type_can_bit_cast(ZigType *t) {
1819518195 }
1819618196}
1819718197
18198static void set_up_result_loc_for_inferred_comptime(IrInstGen *ptr) {
18199 ZigValue *undef_child = create_const_vals(1);
18198static void set_up_result_loc_for_inferred_comptime(IrAnalyze *ira, IrInstGen *ptr) {
18199 ZigValue *undef_child = ira->codegen->pass1_arena->create<ZigValue>();
1820018200 undef_child->type = ptr->value->type->data.pointer.child_type;
1820118201 undef_child->special = ConstValSpecialUndef;
1820218202 ptr->value->special = ConstValSpecialStatic;
......@@ -18242,7 +18242,7 @@ static IrInstGen *ir_resolve_no_result_loc(IrAnalyze *ira, IrInst *suspend_sourc
1824218242 IrInstGenAlloca *alloca_gen = ir_build_alloca_gen(ira, suspend_source_instr, 0, "");
1824318243 alloca_gen->base.value->type = get_pointer_to_type_extra(ira->codegen, value_type, false, false,
1824418244 PtrLenSingle, 0, 0, 0, false);
18245 set_up_result_loc_for_inferred_comptime(&alloca_gen->base);
18245 set_up_result_loc_for_inferred_comptime(ira, &alloca_gen->base);
1824618246 ZigFn *fn_entry = ira->new_irb.exec->fn_entry;
1824718247 if (fn_entry != nullptr && get_scope_typeof(suspend_source_instr->scope) == nullptr) {
1824818248 fn_entry->alloca_gen_list.append(alloca_gen);
......@@ -18306,7 +18306,6 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i
1830618306 ZigVar *new_var = create_local_var(ira->codegen, var->decl_node, var->child_scope,
1830718307 buf_create_from_str(var->name), var->src_is_const, var->gen_is_const,
1830818308 var->shadowable, var->is_comptime, true);
18309 new_var->owner_exec = var->owner_exec;
1831018309 new_var->align_bytes = var->align_bytes;
1831118310
1831218311 var->next_var = new_var;
......@@ -18645,15 +18644,15 @@ static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr
1864518644 if (!val)
1864618645 return ira->codegen->invalid_inst_gen;
1864718646 field->is_comptime = true;
18648 field->init_val = create_const_vals(1);
18649 copy_const_val(field->init_val, val);
18647 field->init_val = ira->codegen->pass1_arena->create<ZigValue>();
18648 copy_const_val(ira->codegen, field->init_val, val);
1865018649 return result_loc;
1865118650 }
1865218651
1865318652 ZigType *struct_ptr_type = get_pointer_to_type(ira->codegen, isf->inferred_struct_type, false);
1865418653 if (instr_is_comptime(result_loc)) {
1865518654 casted_ptr = ir_const(ira, suspend_source_instr, struct_ptr_type);
18656 copy_const_val(casted_ptr->value, result_loc->value);
18655 copy_const_val(ira->codegen, casted_ptr->value, result_loc->value);
1865718656 casted_ptr->value->type = struct_ptr_type;
1865818657 } else {
1865918658 casted_ptr = result_loc;
......@@ -18666,8 +18665,8 @@ static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr
1866618665 ZigValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val,
1866718666 suspend_source_instr->source_node);
1866818667 struct_val->special = ConstValSpecialStatic;
18669 struct_val->data.x_struct.fields = realloc_const_vals_ptrs(struct_val->data.x_struct.fields,
18670 old_field_count, new_field_count);
18668 struct_val->data.x_struct.fields = realloc_const_vals_ptrs(ira->codegen,
18669 struct_val->data.x_struct.fields, old_field_count, new_field_count);
1867118670
1867218671 ZigValue *field_val = struct_val->data.x_struct.fields[old_field_count];
1867318672 field_val->special = ConstValSpecialUndef;
......@@ -18967,10 +18966,10 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
1896718966 if (!arg_val)
1896818967 return false;
1896918968 } else {
18970 arg_val = create_const_runtime(casted_arg->value->type);
18969 arg_val = create_const_runtime(ira->codegen, casted_arg->value->type);
1897118970 }
1897218971 if (arg_part_of_generic_id) {
18973 copy_const_val(&generic_id->params[generic_id->param_count], arg_val);
18972 copy_const_val(ira->codegen, &generic_id->params[generic_id->param_count], arg_val);
1897418973 generic_id->param_count += 1;
1897518974 }
1897618975
......@@ -19119,7 +19118,7 @@ static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr,
1911919118 if (dest_val == nullptr)
1912019119 return ira->codegen->invalid_inst_gen;
1912119120 if (dest_val->special != ConstValSpecialRuntime) {
19122 copy_const_val(dest_val, value->value);
19121 copy_const_val(ira->codegen, dest_val, value->value);
1912319122
1912419123 if (ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar &&
1912519124 !ira->new_irb.current_basic_block->must_be_comptime_source_instr)
......@@ -19354,8 +19353,6 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1935419353 {
1935519354 return ira->codegen->invalid_inst_gen;
1935619355 }
19357 destroy(result_ptr, "ZigValue");
19358 result_ptr = nullptr;
1935919356
1936019357 if (inferred_err_set_type != nullptr) {
1936119358 inferred_err_set_type->data.error_set.incomplete = false;
......@@ -19363,7 +19360,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1936319360 ErrorTableEntry *err = result->data.x_err_union.error_set->data.x_err_set;
1936419361 if (err != nullptr) {
1936519362 inferred_err_set_type->data.error_set.err_count = 1;
19366 inferred_err_set_type->data.error_set.errors = allocate<ErrorTableEntry *>(1);
19363 inferred_err_set_type->data.error_set.errors = heap::c_allocator.create<ErrorTableEntry *>();
1936719364 inferred_err_set_type->data.error_set.errors[0] = err;
1936819365 }
1936919366 ZigType *fn_inferred_err_set_type = result->type->data.error_union.err_set_type;
......@@ -19397,12 +19394,12 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1939719394
1939819395 size_t new_fn_arg_count = first_arg_1_or_0 + args_len;
1939919396
19400 IrInstGen **casted_args = allocate<IrInstGen *>(new_fn_arg_count);
19397 IrInstGen **casted_args = heap::c_allocator.allocate<IrInstGen *>(new_fn_arg_count);
1940119398
1940219399 // Fork a scope of the function with known values for the parameters.
1940319400 Scope *parent_scope = fn_entry->fndef_scope->base.parent;
1940419401 ZigFn *impl_fn = create_fn(ira->codegen, fn_proto_node);
19405 impl_fn->param_source_nodes = allocate<AstNode *>(new_fn_arg_count);
19402 impl_fn->param_source_nodes = heap::c_allocator.allocate<AstNode *>(new_fn_arg_count);
1940619403 buf_init_from_buf(&impl_fn->symbol_name, &fn_entry->symbol_name);
1940719404 impl_fn->fndef_scope = create_fndef_scope(ira->codegen, impl_fn->body_node, parent_scope, impl_fn);
1940819405 impl_fn->child_scope = &impl_fn->fndef_scope->base;
......@@ -19413,10 +19410,10 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1941319410
1941419411 // TODO maybe GenericFnTypeId can be replaced with using the child_scope directly
1941519412 // as the key in generic_table
19416 GenericFnTypeId *generic_id = allocate<GenericFnTypeId>(1);
19413 GenericFnTypeId *generic_id = heap::c_allocator.create<GenericFnTypeId>();
1941719414 generic_id->fn_entry = fn_entry;
1941819415 generic_id->param_count = 0;
19419 generic_id->params = create_const_vals(new_fn_arg_count);
19416 generic_id->params = ira->codegen->pass1_arena->allocate<ZigValue>(new_fn_arg_count);
1942019417 size_t next_proto_i = 0;
1942119418
1942219419 if (first_arg_ptr) {
......@@ -19476,7 +19473,6 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1947619473 IrInstGenConst *const_instruction = ir_create_inst_noval<IrInstGenConst>(&ira->new_irb,
1947719474 impl_fn->child_scope, fn_proto_node->data.fn_proto.align_expr);
1947819475 const_instruction->base.value = align_result;
19479 destroy(result_ptr, "ZigValue");
1948019476
1948119477 uint32_t align_bytes = 0;
1948219478 ir_resolve_align(ira, &const_instruction->base, nullptr, &align_bytes);
......@@ -19609,7 +19605,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1960919605 }
1961019606
1961119607
19612 IrInstGen **casted_args = allocate<IrInstGen *>(call_param_count);
19608 IrInstGen **casted_args = heap::c_allocator.allocate<IrInstGen *>(call_param_count);
1961319609 size_t next_arg_index = 0;
1961419610 if (first_arg_ptr) {
1961519611 assert(first_arg_ptr->value->type->id == ZigTypeIdPointer);
......@@ -19741,7 +19737,7 @@ static IrInstGen *ir_analyze_fn_call_src(IrAnalyze *ira, IrInstSrcCall *call_ins
1974119737 return ira->codegen->invalid_inst_gen;
1974219738 new_stack_src = &call_instruction->new_stack->base;
1974319739 }
19744 IrInstGen **args_ptr = allocate<IrInstGen *>(call_instruction->arg_count, "IrInstGen *");
19740 IrInstGen **args_ptr = heap::c_allocator.allocate<IrInstGen *>(call_instruction->arg_count);
1974519741 for (size_t i = 0; i < call_instruction->arg_count; i += 1) {
1974619742 args_ptr[i] = call_instruction->args[i]->child;
1974719743 if (type_is_invalid(args_ptr[i]->value->type))
......@@ -19757,7 +19753,7 @@ static IrInstGen *ir_analyze_fn_call_src(IrAnalyze *ira, IrInstSrcCall *call_ins
1975719753 first_arg_ptr, first_arg_ptr_src, modifier, new_stack, new_stack_src,
1975819754 call_instruction->is_async_call_builtin, args_ptr, call_instruction->arg_count, ret_ptr,
1975919755 call_instruction->result_loc);
19760 deallocate(args_ptr, call_instruction->arg_count, "IrInstGen *");
19756 heap::c_allocator.deallocate(args_ptr, call_instruction->arg_count);
1976119757 return result;
1976219758}
1976319759
......@@ -19877,7 +19873,7 @@ static IrInstGen *ir_analyze_instruction_call_extra(IrAnalyze *ira, IrInstSrcCal
1987719873
1987819874 if (is_tuple(args_type)) {
1987919875 args_len = args_type->data.structure.src_field_count;
19880 args_ptr = allocate<IrInstGen *>(args_len, "IrInstGen *");
19876 args_ptr = heap::c_allocator.allocate<IrInstGen *>(args_len);
1988119877 for (size_t i = 0; i < args_len; i += 1) {
1988219878 TypeStructField *arg_field = args_type->data.structure.fields[i];
1988319879 args_ptr[i] = ir_analyze_struct_value_field_value(ira, &instruction->base.base, args, arg_field);
......@@ -19890,12 +19886,12 @@ static IrInstGen *ir_analyze_instruction_call_extra(IrAnalyze *ira, IrInstSrcCal
1989019886 }
1989119887 IrInstGen *result = ir_analyze_call_extra(ira, &instruction->base.base, instruction->options,
1989219888 instruction->fn_ref, args_ptr, args_len, instruction->result_loc);
19893 deallocate(args_ptr, args_len, "IrInstGen *");
19889 heap::c_allocator.deallocate(args_ptr, args_len);
1989419890 return result;
1989519891}
1989619892
1989719893static IrInstGen *ir_analyze_instruction_call_args(IrAnalyze *ira, IrInstSrcCallArgs *instruction) {
19898 IrInstGen **args_ptr = allocate<IrInstGen *>(instruction->args_len, "IrInstGen *");
19894 IrInstGen **args_ptr = heap::c_allocator.allocate<IrInstGen *>(instruction->args_len);
1989919895 for (size_t i = 0; i < instruction->args_len; i += 1) {
1990019896 args_ptr[i] = instruction->args_ptr[i]->child;
1990119897 if (type_is_invalid(args_ptr[i]->value->type))
......@@ -19904,7 +19900,7 @@ static IrInstGen *ir_analyze_instruction_call_args(IrAnalyze *ira, IrInstSrcCall
1990419900
1990519901 IrInstGen *result = ir_analyze_call_extra(ira, &instruction->base.base, instruction->options,
1990619902 instruction->fn_ref, args_ptr, instruction->args_len, instruction->result_loc);
19907 deallocate(args_ptr, instruction->args_len, "IrInstGen *");
19903 heap::c_allocator.deallocate(args_ptr, instruction->args_len);
1990819904 return result;
1990919905}
1991019906
......@@ -19979,7 +19975,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source
1997919975
1998019976 if (dst_size <= src_size) {
1998119977 if (src_size == dst_size && types_have_same_zig_comptime_repr(codegen, out_val->type, pointee->type)) {
19982 copy_const_val(out_val, pointee);
19978 copy_const_val(codegen, out_val, pointee);
1998319979 return ErrorNone;
1998419980 }
1998519981 Buf buf = BUF_INIT;
......@@ -20047,7 +20043,7 @@ static IrInstGen *ir_analyze_optional_type(IrAnalyze *ira, IrInstSrcUnOp *instru
2004720043 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type);
2004820044 result->value->special = ConstValSpecialLazy;
2004920045
20050 LazyValueOptType *lazy_opt_type = allocate<LazyValueOptType>(1, "LazyValueOptType");
20046 LazyValueOptType *lazy_opt_type = heap::c_allocator.create<LazyValueOptType>();
2005120047 lazy_opt_type->ira = ira; ira_ref(ira);
2005220048 result->value->data.x_lazy = &lazy_opt_type->base;
2005320049 lazy_opt_type->base.id = LazyValueIdOptType;
......@@ -20331,7 +20327,7 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i
2033120327
2033220328 if (value->value->special != ConstValSpecialRuntime) {
2033320329 IrInstGen *result = ir_const(ira, &phi_instruction->base.base, nullptr);
20334 copy_const_val(result->value, value->value);
20330 copy_const_val(ira->codegen, result->value, value->value);
2033520331 return result;
2033620332 } else {
2033720333 return value;
......@@ -20345,7 +20341,7 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i
2034520341 peer_parent->peers.length >= 2)
2034620342 {
2034720343 if (peer_parent->resolved_type == nullptr) {
20348 IrInstGen **instructions = allocate<IrInstGen *>(peer_parent->peers.length);
20344 IrInstGen **instructions = heap::c_allocator.allocate<IrInstGen *>(peer_parent->peers.length);
2034920345 for (size_t i = 0; i < peer_parent->peers.length; i += 1) {
2035020346 ResultLocPeer *this_peer = peer_parent->peers.at(i);
2035120347
......@@ -20718,7 +20714,7 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
2071820714 if (index == array_len && array_type->data.array.sentinel != nullptr) {
2071920715 ZigType *elem_type = array_type->data.array.child_type;
2072020716 IrInstGen *sentinel_elem = ir_const(ira, &elem_ptr_instruction->base.base, elem_type);
20721 copy_const_val(sentinel_elem->value, array_type->data.array.sentinel);
20717 copy_const_val(ira->codegen, sentinel_elem->value, array_type->data.array.sentinel);
2072220718 return ir_get_ref(ira, &elem_ptr_instruction->base.base, sentinel_elem, true, false);
2072320719 }
2072420720 if (index >= array_len) {
......@@ -20782,7 +20778,7 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
2078220778 {
2078320779 if (array_type->id == ZigTypeIdArray || array_type->id == ZigTypeIdVector) {
2078420780 array_ptr_val->data.x_array.special = ConstArraySpecialNone;
20785 array_ptr_val->data.x_array.data.s_none.elements = create_const_vals(array_type->data.array.len);
20781 array_ptr_val->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(array_type->data.array.len);
2078620782 array_ptr_val->special = ConstValSpecialStatic;
2078720783 for (size_t i = 0; i < array_type->data.array.len; i += 1) {
2078820784 ZigValue *elem_val = &array_ptr_val->data.x_array.data.s_none.elements[i];
......@@ -20805,11 +20801,11 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
2080520801 return ira->codegen->invalid_inst_gen;
2080620802 }
2080720803
20808 ZigValue *array_init_val = create_const_vals(1);
20804 ZigValue *array_init_val = ira->codegen->pass1_arena->create<ZigValue>();
2080920805 array_init_val->special = ConstValSpecialStatic;
2081020806 array_init_val->type = actual_array_type;
2081120807 array_init_val->data.x_array.special = ConstArraySpecialNone;
20812 array_init_val->data.x_array.data.s_none.elements = create_const_vals(actual_array_type->data.array.len);
20808 array_init_val->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(actual_array_type->data.array.len);
2081320809 array_init_val->special = ConstValSpecialStatic;
2081420810 for (size_t i = 0; i < actual_array_type->data.array.len; i += 1) {
2081520811 ZigValue *elem_val = &array_init_val->data.x_array.data.s_none.elements[i];
......@@ -21135,7 +21131,7 @@ static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_ins
2113521131 if (field->is_comptime) {
2113621132 IrInstGen *elem = ir_const(ira, source_instr, field_type);
2113721133 memoize_field_init_val(ira->codegen, struct_type, field);
21138 copy_const_val(elem->value, field->init_val);
21134 copy_const_val(ira->codegen, elem->value, field->init_val);
2113921135 return ir_get_ref2(ira, source_instr, elem, field_type, true, false);
2114021136 }
2114121137 switch (type_has_one_possible_value(ira->codegen, field_type)) {
......@@ -21183,7 +21179,7 @@ static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_ins
2118321179 if (type_is_invalid(struct_val->type))
2118421180 return ira->codegen->invalid_inst_gen;
2118521181 if (initializing && struct_val->special == ConstValSpecialUndef) {
21186 struct_val->data.x_struct.fields = alloc_const_vals_ptrs(struct_type->data.structure.src_field_count);
21182 struct_val->data.x_struct.fields = alloc_const_vals_ptrs(ira->codegen, struct_type->data.structure.src_field_count);
2118721183 struct_val->special = ConstValSpecialStatic;
2118821184 for (size_t i = 0; i < struct_type->data.structure.src_field_count; i += 1) {
2118921185 ZigValue *field_val = struct_val->data.x_struct.fields[i];
......@@ -21225,7 +21221,7 @@ static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,
2122521221 ZigType *container_ptr_type = container_ptr->value->type;
2122621222 ir_assert(container_ptr_type->id == ZigTypeIdPointer, source_instr);
2122721223
21228 InferredStructField *inferred_struct_field = allocate<InferredStructField>(1, "InferredStructField");
21224 InferredStructField *inferred_struct_field = heap::c_allocator.create<InferredStructField>();
2122921225 inferred_struct_field->inferred_struct_type = container_type;
2123021226 inferred_struct_field->field_name = field_name;
2123121227
......@@ -21245,7 +21241,7 @@ static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,
2124521241 } else {
2124621242 result = ir_const(ira, source_instr, field_ptr_type);
2124721243 }
21248 copy_const_val(result->value, ptr_val);
21244 copy_const_val(ira->codegen, result->value, ptr_val);
2124921245 result->value->type = field_ptr_type;
2125021246 return result;
2125121247 }
......@@ -21316,7 +21312,7 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name
2131621312 return ira->codegen->invalid_inst_gen;
2131721313
2131821314 if (initializing) {
21319 ZigValue *payload_val = create_const_vals(1);
21315 ZigValue *payload_val = ira->codegen->pass1_arena->create<ZigValue>();
2132021316 payload_val->special = ConstValSpecialUndef;
2132121317 payload_val->type = field_type;
2132221318 payload_val->parent.id = ConstParentIdUnion;
......@@ -21499,7 +21495,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
2149921495 }
2150021496 } else if (is_array_ref(container_type) && !field_ptr_instruction->initializing) {
2150121497 if (buf_eql_str(field_name, "len")) {
21502 ZigValue *len_val = create_const_vals(1);
21498 ZigValue *len_val = ira->codegen->pass1_arena->create<ZigValue>();
2150321499 if (container_type->id == ZigTypeIdPointer) {
2150421500 init_const_usize(ira->codegen, len_val, container_type->data.pointer.child_type->data.array.len);
2150521501 } else {
......@@ -21545,7 +21541,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
2154521541 bool ptr_is_const = true;
2154621542 bool ptr_is_volatile = false;
2154721543 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
21548 create_const_enum(child_type, &field->value), child_type,
21544 create_const_enum(ira->codegen, child_type, &field->value), child_type,
2154921545 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
2155021546 }
2155121547 }
......@@ -21574,7 +21570,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
2157421570 bool ptr_is_const = true;
2157521571 bool ptr_is_volatile = false;
2157621572 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
21577 create_const_enum(enum_type, &field->enum_field->value), enum_type,
21573 create_const_enum(ira->codegen, enum_type, &field->enum_field->value), enum_type,
2157821574 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
2157921575 }
2158021576 }
......@@ -21592,7 +21588,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
2159221588 if (existing_entry) {
2159321589 err_entry = existing_entry->value;
2159421590 } else {
21595 err_entry = allocate<ErrorTableEntry>(1);
21591 err_entry = heap::c_allocator.create<ErrorTableEntry>();
2159621592 err_entry->decl_node = field_ptr_instruction->base.base.source_node;
2159721593 buf_init_from_buf(&err_entry->name, field_name);
2159821594 size_t error_value_count = ira->codegen->errors_by_index.length;
......@@ -21619,7 +21615,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
2161921615 }
2162021616 err_set_type = child_type;
2162121617 }
21622 ZigValue *const_val = create_const_vals(1);
21618 ZigValue *const_val = ira->codegen->pass1_arena->create<ZigValue>();
2162321619 const_val->special = ConstValSpecialStatic;
2162421620 const_val->type = err_set_type;
2162521621 const_val->data.x_err_set = err_entry;
......@@ -21633,7 +21629,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
2163321629 bool ptr_is_const = true;
2163421630 bool ptr_is_volatile = false;
2163521631 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
21636 create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int,
21632 create_const_unsigned_negative(ira->codegen, ira->codegen->builtin_types.entry_num_lit_int,
2163721633 child_type->data.integral.bit_count, false),
2163821634 ira->codegen->builtin_types.entry_num_lit_int,
2163921635 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
......@@ -21655,7 +21651,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
2165521651 bool ptr_is_const = true;
2165621652 bool ptr_is_volatile = false;
2165721653 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
21658 create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int,
21654 create_const_unsigned_negative(ira->codegen, ira->codegen->builtin_types.entry_num_lit_int,
2165921655 child_type->data.floating.bit_count, false),
2166021656 ira->codegen->builtin_types.entry_num_lit_int,
2166121657 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
......@@ -21682,7 +21678,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
2168221678 return ira->codegen->invalid_inst_gen;
2168321679 }
2168421680 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
21685 create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int,
21681 create_const_unsigned_negative(ira->codegen, ira->codegen->builtin_types.entry_num_lit_int,
2168621682 get_ptr_align(ira->codegen, child_type), false),
2168721683 ira->codegen->builtin_types.entry_num_lit_int,
2168821684 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
......@@ -21704,7 +21700,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
2170421700 bool ptr_is_const = true;
2170521701 bool ptr_is_volatile = false;
2170621702 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
21707 create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int,
21703 create_const_unsigned_negative(ira->codegen, ira->codegen->builtin_types.entry_num_lit_int,
2170821704 child_type->data.array.len, false),
2170921705 ira->codegen->builtin_types.entry_num_lit_int,
2171021706 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
......@@ -21984,7 +21980,7 @@ static IrInstGen *ir_analyze_instruction_slice_type(IrAnalyze *ira, IrInstSrcSli
2198421980 IrInstGen *result = ir_const(ira, &slice_type_instruction->base.base, ira->codegen->builtin_types.entry_type);
2198521981 result->value->special = ConstValSpecialLazy;
2198621982
21987 LazyValueSliceType *lazy_slice_type = allocate<LazyValueSliceType>(1, "LazyValueSliceType");
21983 LazyValueSliceType *lazy_slice_type = heap::c_allocator.create<LazyValueSliceType>();
2198821984 lazy_slice_type->ira = ira; ira_ref(ira);
2198921985 result->value->data.x_lazy = &lazy_slice_type->base;
2199021986 lazy_slice_type->base.id = LazyValueIdSliceType;
......@@ -22057,8 +22053,8 @@ static IrInstGen *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstSrcAsm *asm_i
2205722053
2205822054 // TODO validate the output types and variable types
2205922055
22060 IrInstGen **input_list = allocate<IrInstGen *>(asm_expr->input_list.length);
22061 IrInstGen **output_types = allocate<IrInstGen *>(asm_expr->output_list.length);
22056 IrInstGen **input_list = heap::c_allocator.allocate<IrInstGen *>(asm_expr->input_list.length);
22057 IrInstGen **output_types = heap::c_allocator.allocate<IrInstGen *>(asm_expr->output_list.length);
2206222058
2206322059 ZigType *return_type = ira->codegen->builtin_types.entry_void;
2206422060 for (size_t i = 0; i < asm_expr->output_list.length; i += 1) {
......@@ -22097,7 +22093,7 @@ static IrInstGen *ir_analyze_instruction_array_type(IrAnalyze *ira, IrInstSrcArr
2209722093 IrInstGen *result = ir_const(ira, &array_type_instruction->base.base, ira->codegen->builtin_types.entry_type);
2209822094 result->value->special = ConstValSpecialLazy;
2209922095
22100 LazyValueArrayType *lazy_array_type = allocate<LazyValueArrayType>(1, "LazyValueArrayType");
22096 LazyValueArrayType *lazy_array_type = heap::c_allocator.create<LazyValueArrayType>();
2210122097 lazy_array_type->ira = ira; ira_ref(ira);
2210222098 result->value->data.x_lazy = &lazy_array_type->base;
2210322099 lazy_array_type->base.id = LazyValueIdArrayType;
......@@ -22122,7 +22118,7 @@ static IrInstGen *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstSrcSizeOf
2212222118 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int);
2212322119 result->value->special = ConstValSpecialLazy;
2212422120
22125 LazyValueSizeOf *lazy_size_of = allocate<LazyValueSizeOf>(1, "LazyValueSizeOf");
22121 LazyValueSizeOf *lazy_size_of = heap::c_allocator.create<LazyValueSizeOf>();
2212622122 lazy_size_of->ira = ira; ira_ref(ira);
2212722123 result->value->data.x_lazy = &lazy_size_of->base;
2212822124 lazy_size_of->base.id = LazyValueIdSizeOf;
......@@ -22242,7 +22238,7 @@ static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* sou
2224222238 return ira->codegen->invalid_inst_gen;
2224322239 case OnePossibleValueNo:
2224422240 if (!same_comptime_repr) {
22245 ZigValue *payload_val = create_const_vals(1);
22241 ZigValue *payload_val = ira->codegen->pass1_arena->create<ZigValue>();
2224622242 payload_val->type = child_type;
2224722243 payload_val->special = ConstValSpecialUndef;
2224822244 payload_val->parent.id = ConstParentIdOptionalPayload;
......@@ -22489,7 +22485,7 @@ static IrInstGen *ir_analyze_instruction_switch_br(IrAnalyze *ira,
2248922485 }
2249022486 }
2249122487
22492 IrInstGenSwitchBrCase *cases = allocate<IrInstGenSwitchBrCase>(case_count);
22488 IrInstGenSwitchBrCase *cases = heap::c_allocator.allocate<IrInstGenSwitchBrCase>(case_count);
2249322489 for (size_t i = 0; i < case_count; i += 1) {
2249422490 IrInstSrcSwitchBrCase *old_case = &switch_br_instruction->cases[i];
2249522491 IrInstGenSwitchBrCase *new_case = &cases[i];
......@@ -22574,7 +22570,7 @@ static IrInstGen *ir_analyze_instruction_switch_target(IrAnalyze *ira,
2257422570 case ZigTypeIdErrorSet: {
2257522571 if (pointee_val) {
2257622572 IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, nullptr);
22577 copy_const_val(result->value, pointee_val);
22573 copy_const_val(ira->codegen, result->value, pointee_val);
2257822574 result->value->type = target_type;
2257922575 return result;
2258022576 }
......@@ -22794,7 +22790,7 @@ static IrInstGen *ir_analyze_instruction_switch_else_var(IrAnalyze *ira,
2279422790 return target_value_ptr;
2279522791 }
2279622792 // Make note of the errors handled by other cases
22797 ErrorTableEntry **errors = allocate<ErrorTableEntry *>(ira->codegen->errors_by_index.length);
22793 ErrorTableEntry **errors = heap::c_allocator.allocate<ErrorTableEntry *>(ira->codegen->errors_by_index.length);
2279822794 // We may not have any case in the switch if this is a lone else
2279922795 const size_t switch_cases = instruction->switch_br ? instruction->switch_br->case_count : 0;
2280022796 for (size_t case_i = 0; case_i < switch_cases; case_i += 1) {
......@@ -22830,7 +22826,7 @@ static IrInstGen *ir_analyze_instruction_switch_else_var(IrAnalyze *ira,
2283022826 buf_appendf(&err_set_type->name, "%s,", buf_ptr(&error_entry->name));
2283122827 }
2283222828 }
22833 free(errors);
22829 heap::c_allocator.deallocate(errors, ira->codegen->errors_by_index.length);
2283422830
2283522831 err_set_type->data.error_set.err_count = result_list.length;
2283622832 err_set_type->data.error_set.errors = result_list.items;
......@@ -22978,7 +22974,7 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc
2297822974
2297922975 IrInstGen *first_non_const_instruction = nullptr;
2298022976
22981 AstNode **field_assign_nodes = allocate<AstNode *>(actual_field_count);
22977 AstNode **field_assign_nodes = heap::c_allocator.allocate<AstNode *>(actual_field_count);
2298222978 ZigList<IrInstGen *> const_ptrs = {};
2298322979
2298422980 bool is_comptime = ir_should_inline(ira->old_irb.exec, source_instr->scope)
......@@ -23049,7 +23045,7 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc
2304923045 return ira->codegen->invalid_inst_gen;
2305023046
2305123047 IrInstGen *runtime_inst = ir_const(ira, source_instr, field->init_val->type);
23052 copy_const_val(runtime_inst->value, field->init_val);
23048 copy_const_val(ira->codegen, runtime_inst->value, field->init_val);
2305323049
2305423050 IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, field, result_loc,
2305523051 container_type, true);
......@@ -23313,7 +23309,7 @@ static IrInstGen *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstSrcErrNa
2331323309 err->cached_error_name_val = create_const_slice(ira->codegen, array_val, 0, buf_len(&err->name), true);
2331423310 }
2331523311 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
23316 copy_const_val(result->value, err->cached_error_name_val);
23312 copy_const_val(ira->codegen, result->value, err->cached_error_name_val);
2331723313 result->value->type = str_type;
2331823314 return result;
2331923315 }
......@@ -23639,11 +23635,11 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa
2363923635 }
2364023636 }
2364123637
23642 ZigValue *declaration_array = create_const_vals(1);
23638 ZigValue *declaration_array = ira->codegen->pass1_arena->create<ZigValue>();
2364323639 declaration_array->special = ConstValSpecialStatic;
2364423640 declaration_array->type = get_array_type(ira->codegen, type_info_declaration_type, declaration_count, nullptr);
2364523641 declaration_array->data.x_array.special = ConstArraySpecialNone;
23646 declaration_array->data.x_array.data.s_none.elements = create_const_vals(declaration_count);
23642 declaration_array->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(declaration_count);
2364723643 init_const_slice(ira->codegen, out_val, declaration_array, 0, declaration_count, false);
2364823644
2364923645 // Loop through the declarations and generate info.
......@@ -23665,7 +23661,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa
2366523661 declaration_val->special = ConstValSpecialStatic;
2366623662 declaration_val->type = type_info_declaration_type;
2366723663
23668 ZigValue **inner_fields = alloc_const_vals_ptrs(3);
23664 ZigValue **inner_fields = alloc_const_vals_ptrs(ira->codegen, 3);
2366923665 ZigValue *name = create_const_str_lit(ira->codegen, curr_entry->key)->data.x_ptr.data.ref.pointee;
2367023666 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(curr_entry->key), true);
2367123667 inner_fields[1]->special = ConstValSpecialStatic;
......@@ -23696,7 +23692,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa
2369623692 // 1: Data.Var: type
2369723693 bigint_init_unsigned(&inner_fields[2]->data.x_union.tag, 1);
2369823694
23699 ZigValue *payload = create_const_vals(1);
23695 ZigValue *payload = ira->codegen->pass1_arena->create<ZigValue>();
2370023696 payload->special = ConstValSpecialStatic;
2370123697 payload->type = ira->codegen->builtin_types.entry_type;
2370223698 payload->data.x_type = var->const_value->type;
......@@ -23717,13 +23713,13 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa
2371723713
2371823714 AstNodeFnProto *fn_node = &fn_entry->proto_node->data.fn_proto;
2371923715
23720 ZigValue *fn_decl_val = create_const_vals(1);
23716 ZigValue *fn_decl_val = ira->codegen->pass1_arena->create<ZigValue>();
2372123717 fn_decl_val->special = ConstValSpecialStatic;
2372223718 fn_decl_val->type = type_info_fn_decl_type;
2372323719 fn_decl_val->parent.id = ConstParentIdUnion;
2372423720 fn_decl_val->parent.data.p_union.union_val = inner_fields[2];
2372523721
23726 ZigValue **fn_decl_fields = alloc_const_vals_ptrs(9);
23722 ZigValue **fn_decl_fields = alloc_const_vals_ptrs(ira->codegen, 9);
2372723723 fn_decl_val->data.x_struct.fields = fn_decl_fields;
2372823724
2372923725 // fn_type: type
......@@ -23761,7 +23757,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa
2376123757 0, 0, 0, false);
2376223758 fn_decl_fields[5]->type = get_optional_type(ira->codegen, get_slice_type(ira->codegen, u8_ptr));
2376323759 if (fn_node->is_extern && fn_node->lib_name != nullptr && buf_len(fn_node->lib_name) > 0) {
23764 fn_decl_fields[5]->data.x_optional = create_const_vals(1);
23760 fn_decl_fields[5]->data.x_optional = ira->codegen->pass1_arena->create<ZigValue>();
2376523761 ZigValue *lib_name = create_const_str_lit(ira->codegen, fn_node->lib_name)->data.x_ptr.data.ref.pointee;
2376623762 init_const_slice(ira->codegen, fn_decl_fields[5]->data.x_optional, lib_name, 0,
2376723763 buf_len(fn_node->lib_name), true);
......@@ -23776,12 +23772,12 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa
2377623772 // arg_names: [][] const u8
2377723773 ensure_field_index(fn_decl_val->type, "arg_names", 7);
2377823774 size_t fn_arg_count = fn_entry->variable_list.length;
23779 ZigValue *fn_arg_name_array = create_const_vals(1);
23775 ZigValue *fn_arg_name_array = ira->codegen->pass1_arena->create<ZigValue>();
2378023776 fn_arg_name_array->special = ConstValSpecialStatic;
2378123777 fn_arg_name_array->type = get_array_type(ira->codegen,
2378223778 get_slice_type(ira->codegen, u8_ptr), fn_arg_count, nullptr);
2378323779 fn_arg_name_array->data.x_array.special = ConstArraySpecialNone;
23784 fn_arg_name_array->data.x_array.data.s_none.elements = create_const_vals(fn_arg_count);
23780 fn_arg_name_array->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(fn_arg_count);
2378523781
2378623782 init_const_slice(ira->codegen, fn_decl_fields[7], fn_arg_name_array, 0, fn_arg_count, false);
2378723783
......@@ -23808,7 +23804,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa
2380823804 // This is a type.
2380923805 bigint_init_unsigned(&inner_fields[2]->data.x_union.tag, 0);
2381023806
23811 ZigValue *payload = create_const_vals(1);
23807 ZigValue *payload = ira->codegen->pass1_arena->create<ZigValue>();
2381223808 payload->special = ConstValSpecialStatic;
2381323809 payload->type = ira->codegen->builtin_types.entry_type;
2381423810 payload->data.x_type = type_entry;
......@@ -23874,11 +23870,11 @@ static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_type_ent
2387423870 ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr);
2387523871 assertNoError(type_resolve(ira->codegen, type_info_pointer_type, ResolveStatusSizeKnown));
2387623872
23877 ZigValue *result = create_const_vals(1);
23873 ZigValue *result = ira->codegen->pass1_arena->create<ZigValue>();
2387823874 result->special = ConstValSpecialStatic;
2387923875 result->type = type_info_pointer_type;
2388023876
23881 ZigValue **fields = alloc_const_vals_ptrs(7);
23877 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 7);
2388223878 result->data.x_struct.fields = fields;
2388323879
2388423880 // size: Size
......@@ -23933,7 +23929,7 @@ static void make_enum_field_val(IrAnalyze *ira, ZigValue *enum_field_val, TypeEn
2393323929 enum_field_val->special = ConstValSpecialStatic;
2393423930 enum_field_val->type = type_info_enum_field_type;
2393523931
23936 ZigValue **inner_fields = alloc_const_vals_ptrs(2);
23932 ZigValue **inner_fields = alloc_const_vals_ptrs(ira->codegen, 2);
2393723933 inner_fields[1]->special = ConstValSpecialStatic;
2393823934 inner_fields[1]->type = ira->codegen->builtin_types.entry_num_lit_int;
2393923935
......@@ -23979,11 +23975,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2397923975 break;
2398023976 case ZigTypeIdInt:
2398123977 {
23982 result = create_const_vals(1);
23978 result = ira->codegen->pass1_arena->create<ZigValue>();
2398323979 result->special = ConstValSpecialStatic;
2398423980 result->type = ir_type_info_get_type(ira, "Int", nullptr);
2398523981
23986 ZigValue **fields = alloc_const_vals_ptrs(2);
23982 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 2);
2398723983 result->data.x_struct.fields = fields;
2398823984
2398923985 // is_signed: bool
......@@ -24001,11 +23997,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2400123997 }
2400223998 case ZigTypeIdFloat:
2400323999 {
24004 result = create_const_vals(1);
24000 result = ira->codegen->pass1_arena->create<ZigValue>();
2400524001 result->special = ConstValSpecialStatic;
2400624002 result->type = ir_type_info_get_type(ira, "Float", nullptr);
2400724003
24008 ZigValue **fields = alloc_const_vals_ptrs(1);
24004 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 1);
2400924005 result->data.x_struct.fields = fields;
2401024006
2401124007 // bits: u8
......@@ -24025,11 +24021,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2402524021 }
2402624022 case ZigTypeIdArray:
2402724023 {
24028 result = create_const_vals(1);
24024 result = ira->codegen->pass1_arena->create<ZigValue>();
2402924025 result->special = ConstValSpecialStatic;
2403024026 result->type = ir_type_info_get_type(ira, "Array", nullptr);
2403124027
24032 ZigValue **fields = alloc_const_vals_ptrs(3);
24028 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 3);
2403324029 result->data.x_struct.fields = fields;
2403424030
2403524031 // len: usize
......@@ -24049,11 +24045,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2404924045 break;
2405024046 }
2405124047 case ZigTypeIdVector: {
24052 result = create_const_vals(1);
24048 result = ira->codegen->pass1_arena->create<ZigValue>();
2405324049 result->special = ConstValSpecialStatic;
2405424050 result->type = ir_type_info_get_type(ira, "Vector", nullptr);
2405524051
24056 ZigValue **fields = alloc_const_vals_ptrs(2);
24052 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 2);
2405724053 result->data.x_struct.fields = fields;
2405824054
2405924055 // len: usize
......@@ -24071,11 +24067,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2407124067 }
2407224068 case ZigTypeIdOptional:
2407324069 {
24074 result = create_const_vals(1);
24070 result = ira->codegen->pass1_arena->create<ZigValue>();
2407524071 result->special = ConstValSpecialStatic;
2407624072 result->type = ir_type_info_get_type(ira, "Optional", nullptr);
2407724073
24078 ZigValue **fields = alloc_const_vals_ptrs(1);
24074 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 1);
2407924075 result->data.x_struct.fields = fields;
2408024076
2408124077 // child: type
......@@ -24087,11 +24083,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2408724083 break;
2408824084 }
2408924085 case ZigTypeIdAnyFrame: {
24090 result = create_const_vals(1);
24086 result = ira->codegen->pass1_arena->create<ZigValue>();
2409124087 result->special = ConstValSpecialStatic;
2409224088 result->type = ir_type_info_get_type(ira, "AnyFrame", nullptr);
2409324089
24094 ZigValue **fields = alloc_const_vals_ptrs(1);
24090 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 1);
2409524091 result->data.x_struct.fields = fields;
2409624092
2409724093 // child: ?type
......@@ -24104,11 +24100,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2410424100 }
2410524101 case ZigTypeIdEnum:
2410624102 {
24107 result = create_const_vals(1);
24103 result = ira->codegen->pass1_arena->create<ZigValue>();
2410824104 result->special = ConstValSpecialStatic;
2410924105 result->type = ir_type_info_get_type(ira, "Enum", nullptr);
2411024106
24111 ZigValue **fields = alloc_const_vals_ptrs(5);
24107 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 5);
2411224108 result->data.x_struct.fields = fields;
2411324109
2411424110 // layout: ContainerLayout
......@@ -24130,11 +24126,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2413024126 }
2413124127 uint32_t enum_field_count = type_entry->data.enumeration.src_field_count;
2413224128
24133 ZigValue *enum_field_array = create_const_vals(1);
24129 ZigValue *enum_field_array = ira->codegen->pass1_arena->create<ZigValue>();
2413424130 enum_field_array->special = ConstValSpecialStatic;
2413524131 enum_field_array->type = get_array_type(ira->codegen, type_info_enum_field_type, enum_field_count, nullptr);
2413624132 enum_field_array->data.x_array.special = ConstArraySpecialNone;
24137 enum_field_array->data.x_array.data.s_none.elements = create_const_vals(enum_field_count);
24133 enum_field_array->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(enum_field_count);
2413824134
2413924135 init_const_slice(ira->codegen, fields[2], enum_field_array, 0, enum_field_count, false);
2414024136
......@@ -24164,7 +24160,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2416424160 }
2416524161 case ZigTypeIdErrorSet:
2416624162 {
24167 result = create_const_vals(1);
24163 result = ira->codegen->pass1_arena->create<ZigValue>();
2416824164 result->special = ConstValSpecialStatic;
2416924165 result->type = ir_type_info_get_type(ira, "ErrorSet", nullptr);
2417024166
......@@ -24179,15 +24175,15 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2417924175 if ((err = type_resolve(ira->codegen, type_info_error_type, ResolveStatusSizeKnown))) {
2418024176 zig_unreachable();
2418124177 }
24182 ZigValue *slice_val = create_const_vals(1);
24178 ZigValue *slice_val = ira->codegen->pass1_arena->create<ZigValue>();
2418324179 result->data.x_optional = slice_val;
2418424180
2418524181 uint32_t error_count = type_entry->data.error_set.err_count;
24186 ZigValue *error_array = create_const_vals(1);
24182 ZigValue *error_array = ira->codegen->pass1_arena->create<ZigValue>();
2418724183 error_array->special = ConstValSpecialStatic;
2418824184 error_array->type = get_array_type(ira->codegen, type_info_error_type, error_count, nullptr);
2418924185 error_array->data.x_array.special = ConstArraySpecialNone;
24190 error_array->data.x_array.data.s_none.elements = create_const_vals(error_count);
24186 error_array->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(error_count);
2419124187
2419224188 init_const_slice(ira->codegen, slice_val, error_array, 0, error_count, false);
2419324189 for (uint32_t error_index = 0; error_index < error_count; error_index++) {
......@@ -24197,7 +24193,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2419724193 error_val->special = ConstValSpecialStatic;
2419824194 error_val->type = type_info_error_type;
2419924195
24200 ZigValue **inner_fields = alloc_const_vals_ptrs(2);
24196 ZigValue **inner_fields = alloc_const_vals_ptrs(ira->codegen, 2);
2420124197 inner_fields[1]->special = ConstValSpecialStatic;
2420224198 inner_fields[1]->type = ira->codegen->builtin_types.entry_num_lit_int;
2420324199
......@@ -24219,11 +24215,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2421924215 }
2422024216 case ZigTypeIdErrorUnion:
2422124217 {
24222 result = create_const_vals(1);
24218 result = ira->codegen->pass1_arena->create<ZigValue>();
2422324219 result->special = ConstValSpecialStatic;
2422424220 result->type = ir_type_info_get_type(ira, "ErrorUnion", nullptr);
2422524221
24226 ZigValue **fields = alloc_const_vals_ptrs(2);
24222 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 2);
2422724223 result->data.x_struct.fields = fields;
2422824224
2422924225 // error_set: type
......@@ -24242,11 +24238,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2424224238 }
2424324239 case ZigTypeIdUnion:
2424424240 {
24245 result = create_const_vals(1);
24241 result = ira->codegen->pass1_arena->create<ZigValue>();
2424624242 result->special = ConstValSpecialStatic;
2424724243 result->type = ir_type_info_get_type(ira, "Union", nullptr);
2424824244
24249 ZigValue **fields = alloc_const_vals_ptrs(4);
24245 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 4);
2425024246 result->data.x_struct.fields = fields;
2425124247
2425224248 // layout: ContainerLayout
......@@ -24263,7 +24259,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2426324259 if (union_decl_node->data.container_decl.auto_enum ||
2426424260 union_decl_node->data.container_decl.init_arg_expr != nullptr)
2426524261 {
24266 ZigValue *tag_type = create_const_vals(1);
24262 ZigValue *tag_type = ira->codegen->pass1_arena->create<ZigValue>();
2426724263 tag_type->special = ConstValSpecialStatic;
2426824264 tag_type->type = ira->codegen->builtin_types.entry_type;
2426924265 tag_type->data.x_type = type_entry->data.unionation.tag_type;
......@@ -24279,11 +24275,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2427924275 zig_unreachable();
2428024276 uint32_t union_field_count = type_entry->data.unionation.src_field_count;
2428124277
24282 ZigValue *union_field_array = create_const_vals(1);
24278 ZigValue *union_field_array = ira->codegen->pass1_arena->create<ZigValue>();
2428324279 union_field_array->special = ConstValSpecialStatic;
2428424280 union_field_array->type = get_array_type(ira->codegen, type_info_union_field_type, union_field_count, nullptr);
2428524281 union_field_array->data.x_array.special = ConstArraySpecialNone;
24286 union_field_array->data.x_array.data.s_none.elements = create_const_vals(union_field_count);
24282 union_field_array->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(union_field_count);
2428724283
2428824284 init_const_slice(ira->codegen, fields[2], union_field_array, 0, union_field_count, false);
2428924285
......@@ -24296,14 +24292,14 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2429624292 union_field_val->special = ConstValSpecialStatic;
2429724293 union_field_val->type = type_info_union_field_type;
2429824294
24299 ZigValue **inner_fields = alloc_const_vals_ptrs(3);
24295 ZigValue **inner_fields = alloc_const_vals_ptrs(ira->codegen, 3);
2430024296 inner_fields[1]->special = ConstValSpecialStatic;
2430124297 inner_fields[1]->type = get_optional_type(ira->codegen, type_info_enum_field_type);
2430224298
2430324299 if (fields[1]->data.x_optional == nullptr) {
2430424300 inner_fields[1]->data.x_optional = nullptr;
2430524301 } else {
24306 inner_fields[1]->data.x_optional = create_const_vals(1);
24302 inner_fields[1]->data.x_optional = ira->codegen->pass1_arena->create<ZigValue>();
2430724303 make_enum_field_val(ira, inner_fields[1]->data.x_optional, union_field->enum_field, type_info_enum_field_type);
2430824304 }
2430924305
......@@ -24338,11 +24334,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2433824334 break;
2433924335 }
2434024336
24341 result = create_const_vals(1);
24337 result = ira->codegen->pass1_arena->create<ZigValue>();
2434224338 result->special = ConstValSpecialStatic;
2434324339 result->type = ir_type_info_get_type(ira, "Struct", nullptr);
2434424340
24345 ZigValue **fields = alloc_const_vals_ptrs(3);
24341 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 3);
2434624342 result->data.x_struct.fields = fields;
2434724343
2434824344 // layout: ContainerLayout
......@@ -24359,11 +24355,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2435924355 }
2436024356 uint32_t struct_field_count = type_entry->data.structure.src_field_count;
2436124357
24362 ZigValue *struct_field_array = create_const_vals(1);
24358 ZigValue *struct_field_array = ira->codegen->pass1_arena->create<ZigValue>();
2436324359 struct_field_array->special = ConstValSpecialStatic;
2436424360 struct_field_array->type = get_array_type(ira->codegen, type_info_struct_field_type, struct_field_count, nullptr);
2436524361 struct_field_array->data.x_array.special = ConstArraySpecialNone;
24366 struct_field_array->data.x_array.data.s_none.elements = create_const_vals(struct_field_count);
24362 struct_field_array->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(struct_field_count);
2436724363
2436824364 init_const_slice(ira->codegen, fields[1], struct_field_array, 0, struct_field_count, false);
2436924365
......@@ -24374,7 +24370,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2437424370 struct_field_val->special = ConstValSpecialStatic;
2437524371 struct_field_val->type = type_info_struct_field_type;
2437624372
24377 ZigValue **inner_fields = alloc_const_vals_ptrs(4);
24373 ZigValue **inner_fields = alloc_const_vals_ptrs(ira->codegen, 4);
2437824374 inner_fields[1]->special = ConstValSpecialStatic;
2437924375 inner_fields[1]->type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_num_lit_int);
2438024376
......@@ -24387,7 +24383,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2438724383 inner_fields[1]->data.x_optional = nullptr;
2438824384 } else {
2438924385 size_t byte_offset = struct_field->offset;
24390 inner_fields[1]->data.x_optional = create_const_vals(1);
24386 inner_fields[1]->data.x_optional = ira->codegen->pass1_arena->create<ZigValue>();
2439124387 inner_fields[1]->data.x_optional->special = ConstValSpecialStatic;
2439224388 inner_fields[1]->data.x_optional->type = ira->codegen->builtin_types.entry_num_lit_int;
2439324389 bigint_init_unsigned(&inner_fields[1]->data.x_optional->data.x_bigint, byte_offset);
......@@ -24423,11 +24419,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2442324419 }
2442424420 case ZigTypeIdFn:
2442524421 {
24426 result = create_const_vals(1);
24422 result = ira->codegen->pass1_arena->create<ZigValue>();
2442724423 result->special = ConstValSpecialStatic;
2442824424 result->type = ir_type_info_get_type(ira, "Fn", nullptr);
2442924425
24430 ZigValue **fields = alloc_const_vals_ptrs(5);
24426 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 5);
2443124427 result->data.x_struct.fields = fields;
2443224428
2443324429 // calling_convention: TypeInfo.CallingConvention
......@@ -24454,7 +24450,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2445424450 if (type_entry->data.fn.fn_type_id.return_type == nullptr)
2445524451 fields[3]->data.x_optional = nullptr;
2445624452 else {
24457 ZigValue *return_type = create_const_vals(1);
24453 ZigValue *return_type = ira->codegen->pass1_arena->create<ZigValue>();
2445824454 return_type->special = ConstValSpecialStatic;
2445924455 return_type->type = ira->codegen->builtin_types.entry_type;
2446024456 return_type->data.x_type = type_entry->data.fn.fn_type_id.return_type;
......@@ -24468,11 +24464,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2446824464 size_t fn_arg_count = type_entry->data.fn.fn_type_id.param_count -
2446924465 (is_varargs && type_entry->data.fn.fn_type_id.cc != CallingConventionC);
2447024466
24471 ZigValue *fn_arg_array = create_const_vals(1);
24467 ZigValue *fn_arg_array = ira->codegen->pass1_arena->create<ZigValue>();
2447224468 fn_arg_array->special = ConstValSpecialStatic;
2447324469 fn_arg_array->type = get_array_type(ira->codegen, type_info_fn_arg_type, fn_arg_count, nullptr);
2447424470 fn_arg_array->data.x_array.special = ConstArraySpecialNone;
24475 fn_arg_array->data.x_array.data.s_none.elements = create_const_vals(fn_arg_count);
24471 fn_arg_array->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(fn_arg_count);
2447624472
2447724473 init_const_slice(ira->codegen, fields[4], fn_arg_array, 0, fn_arg_count, false);
2447824474
......@@ -24486,7 +24482,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2448624482 bool arg_is_generic = fn_param_info->type == nullptr;
2448724483 if (arg_is_generic) assert(is_generic);
2448824484
24489 ZigValue **inner_fields = alloc_const_vals_ptrs(3);
24485 ZigValue **inner_fields = alloc_const_vals_ptrs(ira->codegen, 3);
2449024486 inner_fields[0]->special = ConstValSpecialStatic;
2449124487 inner_fields[0]->type = ira->codegen->builtin_types.entry_bool;
2449224488 inner_fields[0]->data.x_bool = arg_is_generic;
......@@ -24499,7 +24495,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2449924495 if (arg_is_generic)
2450024496 inner_fields[2]->data.x_optional = nullptr;
2450124497 else {
24502 ZigValue *arg_type = create_const_vals(1);
24498 ZigValue *arg_type = ira->codegen->pass1_arena->create<ZigValue>();
2450324499 arg_type->special = ConstValSpecialStatic;
2450424500 arg_type->type = ira->codegen->builtin_types.entry_type;
2450524501 arg_type->data.x_type = fn_param_info->type;
......@@ -24524,7 +24520,9 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2452424520 break;
2452524521 }
2452624522 case ZigTypeIdFnFrame:
24527 zig_panic("TODO @typeInfo for async function frames");
24523 ir_add_error(ira, source_instr,
24524 buf_sprintf("compiler bug: TODO @typeInfo for async function frames. https://github.com/ziglang/zig/issues/3066"));
24525 return ErrorSemanticAnalyzeFail;
2452824526 }
2452924527
2453024528 assert(result != nullptr);
......@@ -24823,7 +24821,7 @@ static IrInstGen *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstSrcType
2482324821 type_entry->cached_const_name_val = create_const_str_lit(ira->codegen, type_bare_name(type_entry));
2482424822 }
2482524823 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
24826 copy_const_val(result->value, type_entry->cached_const_name_val);
24824 copy_const_val(ira->codegen, result->value, type_entry->cached_const_name_val);
2482724825 return result;
2482824826}
2482924827
......@@ -24855,7 +24853,6 @@ static IrInstGen *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstSrcCImpo
2485524853 }
2485624854 if (type_is_invalid(cimport_result->type))
2485724855 return ira->codegen->invalid_inst_gen;
24858 destroy(result_ptr, "ZigValue");
2485924856
2486024857 ZigPackage *cur_scope_pkg = scope_package(instruction->base.base.scope);
2486124858 Buf *namespace_name = buf_sprintf("%s.cimport:%" ZIG_PRI_usize ":%" ZIG_PRI_usize,
......@@ -25534,11 +25531,11 @@ static IrInstGen *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstSrcToByt
2553425531 return ira->codegen->invalid_inst_gen;
2553525532
2553625533 IrInstGen *result = ir_const(ira, &instruction->base.base, dest_slice_type);
25537 result->value->data.x_struct.fields = alloc_const_vals_ptrs(2);
25534 result->value->data.x_struct.fields = alloc_const_vals_ptrs(ira->codegen, 2);
2553825535
2553925536 ZigValue *ptr_val = result->value->data.x_struct.fields[slice_ptr_index];
2554025537 ZigValue *target_ptr_val = target_val->data.x_struct.fields[slice_ptr_index];
25541 copy_const_val(ptr_val, target_ptr_val);
25538 copy_const_val(ira->codegen, ptr_val, target_ptr_val);
2554225539 ptr_val->type = dest_ptr_type;
2554325540
2554425541 ZigValue *len_val = result->value->data.x_struct.fields[slice_len_index];
......@@ -25825,7 +25822,7 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr
2582525822 expand_undef_array(ira->codegen, b_val);
2582625823
2582725824 IrInstGen *result = ir_const(ira, source_instr, result_type);
25828 result->value->data.x_array.data.s_none.elements = create_const_vals(len_mask);
25825 result->value->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(len_mask);
2582925826 for (uint32_t i = 0; i < mask_val->type->data.vector.len; i += 1) {
2583025827 ZigValue *mask_elem_val = &mask_val->data.x_array.data.s_none.elements[i];
2583125828 ZigValue *result_elem_val = &result->value->data.x_array.data.s_none.elements[i];
......@@ -25838,7 +25835,7 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr
2583825835 ZigValue *src_elem_val = (v >= 0) ?
2583925836 &a->value->data.x_array.data.s_none.elements[v] :
2584025837 &b->value->data.x_array.data.s_none.elements[~v];
25841 copy_const_val(result_elem_val, src_elem_val);
25838 copy_const_val(ira->codegen, result_elem_val, src_elem_val);
2584225839
2584325840 ir_assert(result_elem_val->special == ConstValSpecialStatic, source_instr);
2584425841 }
......@@ -25858,7 +25855,7 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr
2585825855
2585925856 IrInstGen *expand_mask = ir_const(ira, &mask->base,
2586025857 get_vector_type(ira->codegen, len_max, ira->codegen->builtin_types.entry_i32));
25861 expand_mask->value->data.x_array.data.s_none.elements = create_const_vals(len_max);
25858 expand_mask->value->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(len_max);
2586225859 uint32_t i = 0;
2586325860 for (; i < len_min; i += 1)
2586425861 bigint_init_unsigned(&expand_mask->value->data.x_array.data.s_none.elements[i].data.x_bigint, i);
......@@ -25928,9 +25925,9 @@ static IrInstGen *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstSrcSplat *i
2592825925 return ir_const_undef(ira, &instruction->base.base, return_type);
2592925926
2593025927 IrInstGen *result = ir_const(ira, &instruction->base.base, return_type);
25931 result->value->data.x_array.data.s_none.elements = create_const_vals(len_int);
25928 result->value->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(len_int);
2593225929 for (uint32_t i = 0; i < len_int; i += 1) {
25933 copy_const_val(&result->value->data.x_array.data.s_none.elements[i], scalar_val);
25930 copy_const_val(ira->codegen, &result->value->data.x_array.data.s_none.elements[i], scalar_val);
2593425931 }
2593525932 return result;
2593625933 }
......@@ -26068,7 +26065,7 @@ static IrInstGen *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstSrcMemset
2606826065 }
2606926066
2607026067 for (size_t i = start; i < end; i += 1) {
26071 copy_const_val(&dest_elements[i], byte_val);
26068 copy_const_val(ira->codegen, &dest_elements[i], byte_val);
2607226069 }
2607326070
2607426071 return ir_const_void(ira, &instruction->base.base);
......@@ -26244,7 +26241,7 @@ static IrInstGen *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstSrcMemcpy
2624426241 // TODO check for noalias violations - this should be generalized to work for any function
2624526242
2624626243 for (size_t i = 0; i < count; i += 1) {
26247 copy_const_val(&dest_elements[dest_start + i], &src_elements[src_start + i]);
26244 copy_const_val(ira->codegen, &dest_elements[dest_start + i], &src_elements[src_start + i]);
2624826245 }
2624926246
2625026247 return ir_const_void(ira, &instruction->base.base);
......@@ -26528,7 +26525,7 @@ static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *i
2652826525
2652926526 IrInstGen *result = ir_const(ira, &instruction->base.base, return_type);
2653026527 ZigValue *out_val = result->value;
26531 out_val->data.x_struct.fields = alloc_const_vals_ptrs(2);
26528 out_val->data.x_struct.fields = alloc_const_vals_ptrs(ira->codegen, 2);
2653226529
2653326530 ZigValue *ptr_val = out_val->data.x_struct.fields[slice_ptr_index];
2653426531
......@@ -26823,7 +26820,7 @@ static IrInstGen *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstSrcAlign
2682326820 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int);
2682426821 result->value->special = ConstValSpecialLazy;
2682526822
26826 LazyValueAlignOf *lazy_align_of = allocate<LazyValueAlignOf>(1, "LazyValueAlignOf");
26823 LazyValueAlignOf *lazy_align_of = heap::c_allocator.create<LazyValueAlignOf>();
2682726824 lazy_align_of->ira = ira; ira_ref(ira);
2682826825 result->value->data.x_lazy = &lazy_align_of->base;
2682926826 lazy_align_of->base.id = LazyValueIdAlignOf;
......@@ -27149,7 +27146,7 @@ static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInst* source_inst
2714927146 return ira->codegen->invalid_inst_gen;
2715027147
2715127148 if (initializing && err_union_val->special == ConstValSpecialUndef) {
27152 ZigValue *vals = create_const_vals(2);
27149 ZigValue *vals = ira->codegen->pass1_arena->allocate<ZigValue>(2);
2715327150 ZigValue *err_set_val = &vals[0];
2715427151 ZigValue *payload_val = &vals[1];
2715527152
......@@ -27230,7 +27227,7 @@ static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInst* source
2723027227 if (err_union_val == nullptr)
2723127228 return ira->codegen->invalid_inst_gen;
2723227229 if (initializing && err_union_val->special == ConstValSpecialUndef) {
27233 ZigValue *vals = create_const_vals(2);
27230 ZigValue *vals = ira->codegen->pass1_arena->allocate<ZigValue>(2);
2723427231 ZigValue *err_set_val = &vals[0];
2723527232 ZigValue *payload_val = &vals[1];
2723627233
......@@ -27292,7 +27289,7 @@ static IrInstGen *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstSrcFnPro
2729227289 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type);
2729327290 result->value->special = ConstValSpecialLazy;
2729427291
27295 LazyValueFnType *lazy_fn_type = allocate<LazyValueFnType>(1, "LazyValueFnType");
27292 LazyValueFnType *lazy_fn_type = heap::c_allocator.create<LazyValueFnType>();
2729627293 lazy_fn_type->ira = ira; ira_ref(ira);
2729727294 result->value->data.x_lazy = &lazy_fn_type->base;
2729827295 lazy_fn_type->base.id = LazyValueIdFnType;
......@@ -27320,7 +27317,7 @@ static IrInstGen *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstSrcFnPro
2732027317
2732127318 size_t param_count = proto_node->data.fn_proto.params.length;
2732227319 lazy_fn_type->proto_node = proto_node;
27323 lazy_fn_type->param_types = allocate<IrInstGen *>(param_count);
27320 lazy_fn_type->param_types = heap::c_allocator.allocate<IrInstGen *>(param_count);
2732427321
2732527322 for (size_t param_index = 0; param_index < param_count; param_index += 1) {
2732627323 AstNode *param_node = proto_node->data.fn_proto.params.at(param_index);
......@@ -27475,7 +27472,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2747527472 }
2747627473
2747727474 size_t field_prev_uses_count = ira->codegen->errors_by_index.length;
27478 AstNode **field_prev_uses = allocate<AstNode *>(field_prev_uses_count, "AstNode *");
27475 AstNode **field_prev_uses = heap::c_allocator.allocate<AstNode *>(field_prev_uses_count);
2747927476
2748027477 for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) {
2748127478 IrInstSrcCheckSwitchProngsRange *range = &instruction->ranges[range_i];
......@@ -27532,7 +27529,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2753227529 }
2753327530 }
2753427531
27535 deallocate(field_prev_uses, field_prev_uses_count, "AstNode *");
27532 heap::c_allocator.deallocate(field_prev_uses, field_prev_uses_count);
2753627533 } else if (switch_type->id == ZigTypeIdInt) {
2753727534 RangeSet rs = {0};
2753827535 for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) {
......@@ -27725,7 +27722,7 @@ static IrInstGen *ir_align_cast(IrAnalyze *ira, IrInstGen *target, uint32_t alig
2772527722 }
2772627723
2772727724 IrInstGen *result = ir_const(ira, &target->base, result_type);
27728 copy_const_val(result->value, val);
27725 copy_const_val(ira->codegen, result->value, val);
2772927726 result->value->type = result_type;
2773027727 return result;
2773127728 }
......@@ -27821,7 +27818,7 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn
2782127818 InferredStructField *isf = (val->type->id == ZigTypeIdPointer) ?
2782227819 val->type->data.pointer.inferred_struct_field : nullptr;
2782327820 if (isf == nullptr) {
27824 copy_const_val(result->value, val);
27821 copy_const_val(ira->codegen, result->value, val);
2782527822 } else {
2782627823 // The destination value should have x_ptr struct pointing to underlying struct value
2782727824 result->value->data.x_ptr.mut = val->data.x_ptr.mut;
......@@ -27978,7 +27975,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ZigValue *val)
2797827975 while (gen_i < gen_field_count) {
2797927976 size_t big_int_byte_count = val->type->data.structure.host_int_bytes[gen_i];
2798027977 if (big_int_byte_count > child_buf_len) {
27981 child_buf = allocate_nonzero<uint8_t>(big_int_byte_count);
27978 child_buf = heap::c_allocator.allocate_nonzero<uint8_t>(big_int_byte_count);
2798227979 child_buf_len = big_int_byte_count;
2798327980 }
2798427981 BigInt big_int;
......@@ -28041,7 +28038,7 @@ static Error buf_read_value_bytes_array(IrAnalyze *ira, CodeGen *codegen, AstNod
2804128038
2804228039 switch (val->data.x_array.special) {
2804328040 case ConstArraySpecialNone:
28044 val->data.x_array.data.s_none.elements = create_const_vals(len);
28041 val->data.x_array.data.s_none.elements = codegen->pass1_arena->allocate<ZigValue>(len);
2804528042 for (size_t i = 0; i < len; i++) {
2804628043 ZigValue *elem = &val->data.x_array.data.s_none.elements[i];
2804728044 elem->special = ConstValSpecialStatic;
......@@ -28127,7 +28124,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
2812728124 }
2812828125 case ContainerLayoutExtern: {
2812928126 size_t src_field_count = val->type->data.structure.src_field_count;
28130 val->data.x_struct.fields = alloc_const_vals_ptrs(src_field_count);
28127 val->data.x_struct.fields = alloc_const_vals_ptrs(codegen, src_field_count);
2813128128 for (size_t field_i = 0; field_i < src_field_count; field_i += 1) {
2813228129 ZigValue *field_val = val->data.x_struct.fields[field_i];
2813328130 field_val->special = ConstValSpecialStatic;
......@@ -28144,7 +28141,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
2814428141 }
2814528142 case ContainerLayoutPacked: {
2814628143 size_t src_field_count = val->type->data.structure.src_field_count;
28147 val->data.x_struct.fields = alloc_const_vals_ptrs(src_field_count);
28144 val->data.x_struct.fields = alloc_const_vals_ptrs(codegen, src_field_count);
2814828145 size_t gen_field_count = val->type->data.structure.gen_field_count;
2814928146 size_t gen_i = 0;
2815028147 size_t src_i = 0;
......@@ -28156,7 +28153,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
2815628153 while (gen_i < gen_field_count) {
2815728154 size_t big_int_byte_count = val->type->data.structure.host_int_bytes[gen_i];
2815828155 if (big_int_byte_count > child_buf_len) {
28159 child_buf = allocate_nonzero<uint8_t>(big_int_byte_count);
28156 child_buf = heap::c_allocator.allocate_nonzero<uint8_t>(big_int_byte_count);
2816028157 child_buf_len = big_int_byte_count;
2816128158 }
2816228159 BigInt big_int;
......@@ -28266,7 +28263,7 @@ static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrIn
2826628263 return ira->codegen->invalid_inst_gen;
2826728264
2826828265 IrInstGen *result = ir_const(ira, source_instr, dest_type);
28269 uint8_t *buf = allocate_nonzero<uint8_t>(src_size_bytes);
28266 uint8_t *buf = heap::c_allocator.allocate_nonzero<uint8_t>(src_size_bytes);
2827028267 buf_write_value_bytes(ira->codegen, buf, val);
2827128268 if ((err = buf_read_value_bytes(ira, ira->codegen, source_instr->source_node, buf, result->value)))
2827228269 return ira->codegen->invalid_inst_gen;
......@@ -28408,7 +28405,7 @@ static IrInstGen *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstSrcPtrTy
2840828405 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type);
2840928406 result->value->special = ConstValSpecialLazy;
2841028407
28411 LazyValuePtrType *lazy_ptr_type = allocate<LazyValuePtrType>(1, "LazyValuePtrType");
28408 LazyValuePtrType *lazy_ptr_type = heap::c_allocator.create<LazyValuePtrType>();
2841228409 lazy_ptr_type->ira = ira; ira_ref(ira);
2841328410 result->value->data.x_lazy = &lazy_ptr_type->base;
2841428411 lazy_ptr_type->base.id = LazyValueIdPtrType;
......@@ -29107,11 +29104,11 @@ static IrInstGen *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstSrcBswap *i
2910729104 return ir_const_undef(ira, &instruction->base.base, op_type);
2910829105
2910929106 IrInstGen *result = ir_const(ira, &instruction->base.base, op_type);
29110 size_t buf_size = int_type->data.integral.bit_count / 8;
29111 uint8_t *buf = allocate_nonzero<uint8_t>(buf_size);
29107 const size_t buf_size = int_type->data.integral.bit_count / 8;
29108 uint8_t *buf = heap::c_allocator.allocate_nonzero<uint8_t>(buf_size);
2911229109 if (is_vector) {
2911329110 expand_undef_array(ira->codegen, val);
29114 result->value->data.x_array.data.s_none.elements = create_const_vals(op_type->data.vector.len);
29111 result->value->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(op_type->data.vector.len);
2911529112 for (unsigned i = 0; i < op_type->data.vector.len; i += 1) {
2911629113 ZigValue *op_elem_val = &val->data.x_array.data.s_none.elements[i];
2911729114 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, instruction->base.base.source_node,
......@@ -29135,7 +29132,7 @@ static IrInstGen *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstSrcBswap *i
2913529132 bigint_read_twos_complement(&result->value->data.x_bigint, buf, int_type->data.integral.bit_count, false,
2913629133 int_type->data.integral.is_signed);
2913729134 }
29138 free(buf);
29135 heap::c_allocator.deallocate(buf, buf_size);
2913929136 return result;
2914029137 }
2914129138
......@@ -29167,8 +29164,8 @@ static IrInstGen *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstSrcBi
2916729164 IrInstGen *result = ir_const(ira, &instruction->base.base, int_type);
2916829165 size_t num_bits = int_type->data.integral.bit_count;
2916929166 size_t buf_size = (num_bits + 7) / 8;
29170 uint8_t *comptime_buf = allocate_nonzero<uint8_t>(buf_size);
29171 uint8_t *result_buf = allocate_nonzero<uint8_t>(buf_size);
29167 uint8_t *comptime_buf = heap::c_allocator.allocate_nonzero<uint8_t>(buf_size);
29168 uint8_t *result_buf = heap::c_allocator.allocate_nonzero<uint8_t>(buf_size);
2917229169 memset(comptime_buf,0,buf_size);
2917329170 memset(result_buf,0,buf_size);
2917429171
......@@ -29854,7 +29851,7 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutableSrc *old_exec, IrExecutableGen
2985429851 assert(old_exec->first_err_trace_msg == nullptr);
2985529852 assert(expected_type == nullptr || !type_is_invalid(expected_type));
2985629853
29857 IrAnalyze *ira = allocate<IrAnalyze>(1, "IrAnalyze");
29854 IrAnalyze *ira = heap::c_allocator.create<IrAnalyze>();
2985829855 ira->ref_count = 1;
2985929856 old_exec->analysis = ira;
2986029857 ira->codegen = codegen;
src/ir.hpp-2
......@@ -37,6 +37,4 @@ ZigValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ZigValue *const_va
3737void dbg_ir_break(const char *src_file, uint32_t line);
3838void dbg_ir_clear(void);
3939
40void destroy_instruction_gen(IrInstGen *inst);
41
4240#endif
src/link.cpp+19-26
......@@ -650,7 +650,7 @@ static const char *build_libunwind(CodeGen *parent, Stage2ProgressNode *progress
650650 };
651651 ZigList<CFile *> c_source_files = {0};
652652 for (size_t i = 0; i < array_length(unwind_src); i += 1) {
653 CFile *c_file = allocate<CFile>(1);
653 CFile *c_file = heap::c_allocator.create<CFile>();
654654 c_file->source_path = path_from_libunwind(parent, unwind_src[i].path);
655655 switch (unwind_src[i].kind) {
656656 case SrcC:
......@@ -1111,7 +1111,7 @@ static const char *build_musl(CodeGen *parent, Stage2ProgressNode *progress_node
11111111 Buf *full_path = buf_sprintf("%s" OS_SEP "libc" OS_SEP "%s",
11121112 buf_ptr(parent->zig_lib_dir), buf_ptr(src_file));
11131113
1114 CFile *c_file = allocate<CFile>(1);
1114 CFile *c_file = heap::c_allocator.create<CFile>();
11151115 c_file->source_path = buf_ptr(full_path);
11161116
11171117 musl_add_cc_args(parent, c_file, src_kind == MuslSrcO3);
......@@ -1127,7 +1127,7 @@ static const char *build_musl(CodeGen *parent, Stage2ProgressNode *progress_node
11271127}
11281128
11291129static void add_msvcrt_os_dep(CodeGen *parent, CodeGen *child_gen, const char *src_path) {
1130 CFile *c_file = allocate<CFile>(1);
1130 CFile *c_file = heap::c_allocator.create<CFile>();
11311131 c_file->source_path = buf_ptr(buf_sprintf("%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "%s",
11321132 buf_ptr(parent->zig_lib_dir), src_path));
11331133 c_file->args.append("-DHAVE_CONFIG_H");
......@@ -1151,7 +1151,7 @@ static void add_msvcrt_os_dep(CodeGen *parent, CodeGen *child_gen, const char *s
11511151}
11521152
11531153static void add_mingwex_os_dep(CodeGen *parent, CodeGen *child_gen, const char *src_path) {
1154 CFile *c_file = allocate<CFile>(1);
1154 CFile *c_file = heap::c_allocator.create<CFile>();
11551155 c_file->source_path = buf_ptr(buf_sprintf("%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "%s",
11561156 buf_ptr(parent->zig_lib_dir), src_path));
11571157 c_file->args.append("-DHAVE_CONFIG_H");
......@@ -1178,7 +1178,7 @@ static void add_mingwex_os_dep(CodeGen *parent, CodeGen *child_gen, const char *
11781178static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2ProgressNode *progress_node) {
11791179 if (parent->libc == nullptr && parent->zig_target->os == OsWindows) {
11801180 if (strcmp(file, "crt2.o") == 0) {
1181 CFile *c_file = allocate<CFile>(1);
1181 CFile *c_file = heap::c_allocator.create<CFile>();
11821182 c_file->source_path = buf_ptr(buf_sprintf(
11831183 "%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "crt" OS_SEP "crtexe.c", buf_ptr(parent->zig_lib_dir)));
11841184 mingw_add_cc_args(parent, c_file);
......@@ -1190,7 +1190,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2Pr
11901190 //c_file->args.append("-DWPRFLAG=1");
11911191 return build_libc_object(parent, "crt2", c_file, progress_node);
11921192 } else if (strcmp(file, "dllcrt2.o") == 0) {
1193 CFile *c_file = allocate<CFile>(1);
1193 CFile *c_file = heap::c_allocator.create<CFile>();
11941194 c_file->source_path = buf_ptr(buf_sprintf(
11951195 "%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "crt" OS_SEP "crtdll.c", buf_ptr(parent->zig_lib_dir)));
11961196 mingw_add_cc_args(parent, c_file);
......@@ -1231,7 +1231,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2Pr
12311231 "mingw" OS_SEP "crt" OS_SEP "cxa_atexit.c",
12321232 };
12331233 for (size_t i = 0; i < array_length(deps); i += 1) {
1234 CFile *c_file = allocate<CFile>(1);
1234 CFile *c_file = heap::c_allocator.create<CFile>();
12351235 c_file->source_path = path_from_libc(parent, deps[i]);
12361236 c_file->args.append("-DHAVE_CONFIG_H");
12371237 c_file->args.append("-D_SYSCRT=1");
......@@ -1301,7 +1301,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2Pr
13011301 }
13021302 } else if (parent->libc == nullptr && target_is_glibc(parent->zig_target)) {
13031303 if (strcmp(file, "crti.o") == 0) {
1304 CFile *c_file = allocate<CFile>(1);
1304 CFile *c_file = heap::c_allocator.create<CFile>();
13051305 c_file->source_path = glibc_start_asm_path(parent, "crti.S");
13061306 glibc_add_include_dirs(parent, c_file);
13071307 c_file->args.append("-D_LIBC_REENTRANT");
......@@ -1317,7 +1317,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2Pr
13171317 c_file->args.append("-Wa,--noexecstack");
13181318 return build_libc_object(parent, "crti", c_file, progress_node);
13191319 } else if (strcmp(file, "crtn.o") == 0) {
1320 CFile *c_file = allocate<CFile>(1);
1320 CFile *c_file = heap::c_allocator.create<CFile>();
13211321 c_file->source_path = glibc_start_asm_path(parent, "crtn.S");
13221322 glibc_add_include_dirs(parent, c_file);
13231323 c_file->args.append("-D_LIBC_REENTRANT");
......@@ -1328,7 +1328,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2Pr
13281328 c_file->args.append("-Wa,--noexecstack");
13291329 return build_libc_object(parent, "crtn", c_file, progress_node);
13301330 } else if (strcmp(file, "start.os") == 0) {
1331 CFile *c_file = allocate<CFile>(1);
1331 CFile *c_file = heap::c_allocator.create<CFile>();
13321332 c_file->source_path = glibc_start_asm_path(parent, "start.S");
13331333 glibc_add_include_dirs(parent, c_file);
13341334 c_file->args.append("-D_LIBC_REENTRANT");
......@@ -1346,7 +1346,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2Pr
13461346 c_file->args.append("-Wa,--noexecstack");
13471347 return build_libc_object(parent, "start", c_file, progress_node);
13481348 } else if (strcmp(file, "abi-note.o") == 0) {
1349 CFile *c_file = allocate<CFile>(1);
1349 CFile *c_file = heap::c_allocator.create<CFile>();
13501350 c_file->source_path = path_from_libc(parent, "glibc" OS_SEP "csu" OS_SEP "abi-note.S");
13511351 c_file->args.append("-I");
13521352 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "csu"));
......@@ -1369,7 +1369,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2Pr
13691369 } else if (strcmp(file, "libc_nonshared.a") == 0) {
13701370 CodeGen *child_gen = create_child_codegen(parent, nullptr, OutTypeLib, nullptr, "c_nonshared", progress_node);
13711371 {
1372 CFile *c_file = allocate<CFile>(1);
1372 CFile *c_file = heap::c_allocator.create<CFile>();
13731373 c_file->source_path = path_from_libc(parent, "glibc" OS_SEP "csu" OS_SEP "elf-init.c");
13741374 c_file->args.append("-std=gnu11");
13751375 c_file->args.append("-fgnu89-inline");
......@@ -1419,7 +1419,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2Pr
14191419 {"stack_chk_fail_local", "glibc" OS_SEP "debug" OS_SEP "stack_chk_fail_local.c"},
14201420 };
14211421 for (size_t i = 0; i < array_length(deps); i += 1) {
1422 CFile *c_file = allocate<CFile>(1);
1422 CFile *c_file = heap::c_allocator.create<CFile>();
14231423 c_file->source_path = path_from_libc(parent, deps[i].path);
14241424 c_file->args.append("-std=gnu11");
14251425 c_file->args.append("-fgnu89-inline");
......@@ -1451,26 +1451,26 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2Pr
14511451 }
14521452 } else if (parent->libc == nullptr && target_is_musl(parent->zig_target)) {
14531453 if (strcmp(file, "crti.o") == 0) {
1454 CFile *c_file = allocate<CFile>(1);
1454 CFile *c_file = heap::c_allocator.create<CFile>();
14551455 c_file->source_path = musl_start_asm_path(parent, "crti.s");
14561456 musl_add_cc_args(parent, c_file, false);
14571457 c_file->args.append("-Qunused-arguments");
14581458 return build_libc_object(parent, "crti", c_file, progress_node);
14591459 } else if (strcmp(file, "crtn.o") == 0) {
1460 CFile *c_file = allocate<CFile>(1);
1460 CFile *c_file = heap::c_allocator.create<CFile>();
14611461 c_file->source_path = musl_start_asm_path(parent, "crtn.s");
14621462 c_file->args.append("-Qunused-arguments");
14631463 musl_add_cc_args(parent, c_file, false);
14641464 return build_libc_object(parent, "crtn", c_file, progress_node);
14651465 } else if (strcmp(file, "crt1.o") == 0) {
1466 CFile *c_file = allocate<CFile>(1);
1466 CFile *c_file = heap::c_allocator.create<CFile>();
14671467 c_file->source_path = path_from_libc(parent, "musl" OS_SEP "crt" OS_SEP "crt1.c");
14681468 musl_add_cc_args(parent, c_file, false);
14691469 c_file->args.append("-fno-stack-protector");
14701470 c_file->args.append("-DCRT");
14711471 return build_libc_object(parent, "crt1", c_file, progress_node);
14721472 } else if (strcmp(file, "Scrt1.o") == 0) {
1473 CFile *c_file = allocate<CFile>(1);
1473 CFile *c_file = heap::c_allocator.create<CFile>();
14741474 c_file->source_path = path_from_libc(parent, "musl" OS_SEP "crt" OS_SEP "Scrt1.c");
14751475 musl_add_cc_args(parent, c_file, false);
14761476 c_file->args.append("-fPIC");
......@@ -1987,7 +1987,7 @@ static const char *get_def_lib(CodeGen *parent, const char *name, Buf *def_in_fi
19871987 Buf *def_include_dir = buf_sprintf("%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "def-include",
19881988 buf_ptr(parent->zig_lib_dir));
19891989
1990 CacheHash *cache_hash = allocate<CacheHash>(1);
1990 CacheHash *cache_hash = heap::c_allocator.create<CacheHash>();
19911991 cache_init(cache_hash, manifest_dir);
19921992
19931993 cache_buf(cache_hash, compiler_id);
......@@ -2372,7 +2372,7 @@ static void construct_linker_job_coff(LinkJob *lj) {
23722372
23732373 lj->args.append(get_def_lib(g, name, &lib_path));
23742374
2375 free(name);
2375 mem::os::free(name);
23762376 }
23772377}
23782378
......@@ -2647,13 +2647,6 @@ void codegen_link(CodeGen *g) {
26472647 lj.rpath_table.init(4);
26482648 lj.codegen = g;
26492649
2650 if (g->verbose_llvm_ir) {
2651 fprintf(stderr, "\nOptimization:\n");
2652 fprintf(stderr, "---------------\n");
2653 fflush(stderr);
2654 LLVMDumpModule(g->module);
2655 }
2656
26572650 if (g->out_type == OutTypeObj) {
26582651 lj.args.append("-r");
26592652 }
src/list.hpp+2-4
......@@ -13,7 +13,7 @@
1313template<typename T>
1414struct ZigList {
1515 void deinit() {
16 deallocate(items, capacity);
16 heap::c_allocator.deallocate(items, capacity);
1717 }
1818 void append(const T& item) {
1919 ensure_capacity(length + 1);
......@@ -70,7 +70,7 @@ struct ZigList {
7070 better_capacity = better_capacity * 5 / 2 + 8;
7171 } while (better_capacity < new_capacity);
7272
73 items = reallocate_nonzero(items, capacity, better_capacity);
73 items = heap::c_allocator.reallocate_nonzero(items, capacity, better_capacity);
7474 capacity = better_capacity;
7575 }
7676
......@@ -91,5 +91,3 @@ struct ZigList {
9191};
9292
9393#endif
94
95
src/main.cpp+27-21
......@@ -11,12 +11,14 @@
1111#include "compiler.hpp"
1212#include "config.h"
1313#include "error.hpp"
14#include "heap.hpp"
1415#include "os.hpp"
1516#include "target.hpp"
1617#include "libc_installation.hpp"
1718#include "userland.h"
1819#include "glibc.hpp"
1920#include "dump_analysis.hpp"
21#include "mem_profile.hpp"
2022
2123#include <stdio.h>
2224
......@@ -243,21 +245,10 @@ int main_exit(Stage2ProgressNode *root_progress_node, int exit_code) {
243245 if (root_progress_node != nullptr) {
244246 stage2_progress_end(root_progress_node);
245247 }
246#ifdef ZIG_ENABLE_MEM_PROFILE
247 if (mem_report) {
248 memprof_dump_stats(stderr);
249 }
250#endif
251248 return exit_code;
252249}
253250
254int main(int argc, char **argv) {
255 stage2_attach_segfault_handler();
256
257#ifdef ZIG_ENABLE_MEM_PROFILE
258 memprof_init();
259#endif
260
251static int main0(int argc, char **argv) {
261252 char *arg0 = argv[0];
262253 Error err;
263254
......@@ -279,9 +270,6 @@ int main(int argc, char **argv) {
279270 return ZigClang_main(argc, argv);
280271 }
281272
282 // Must be before all os.hpp function calls.
283 os_init();
284
285273 if (argc == 2 && strcmp(argv[1], "id") == 0) {
286274 Buf *compiler_id;
287275 if ((err = get_compiler_id(&compiler_id))) {
......@@ -440,7 +428,7 @@ int main(int argc, char **argv) {
440428 bool enable_doc_generation = false;
441429 bool disable_bin_generation = false;
442430 const char *cache_dir = nullptr;
443 CliPkg *cur_pkg = allocate<CliPkg>(1);
431 CliPkg *cur_pkg = heap::c_allocator.create<CliPkg>();
444432 BuildMode build_mode = BuildModeDebug;
445433 ZigList<const char *> test_exec_args = {0};
446434 int runtime_args_start = -1;
......@@ -636,6 +624,7 @@ int main(int argc, char **argv) {
636624 } else if (strcmp(arg, "-fmem-report") == 0) {
637625#ifdef ZIG_ENABLE_MEM_PROFILE
638626 mem_report = true;
627 mem::report_print = true;
639628#else
640629 fprintf(stderr, "-fmem-report requires configuring with -DZIG_ENABLE_MEM_PROFILE=ON\n");
641630 return print_error_usage(arg0);
......@@ -696,7 +685,7 @@ int main(int argc, char **argv) {
696685 fprintf(stderr, "Expected 2 arguments after --pkg-begin\n");
697686 return print_error_usage(arg0);
698687 }
699 CliPkg *new_cur_pkg = allocate<CliPkg>(1);
688 CliPkg *new_cur_pkg = heap::c_allocator.create<CliPkg>();
700689 i += 1;
701690 new_cur_pkg->name = argv[i];
702691 i += 1;
......@@ -811,7 +800,7 @@ int main(int argc, char **argv) {
811800 } else if (strcmp(arg, "--object") == 0) {
812801 objects.append(argv[i]);
813802 } else if (strcmp(arg, "--c-source") == 0) {
814 CFile *c_file = allocate<CFile>(1);
803 CFile *c_file = heap::c_allocator.create<CFile>();
815804 for (;;) {
816805 if (argv[i][0] == '-') {
817806 c_file->args.append(argv[i]);
......@@ -991,7 +980,7 @@ int main(int argc, char **argv) {
991980 }
992981 }
993982 if (target_is_glibc(&target)) {
994 target.glibc_version = allocate<ZigGLibCVersion>(1);
983 target.glibc_version = heap::c_allocator.create<ZigGLibCVersion>();
995984
996985 if (target_glibc != nullptr) {
997986 if ((err = target_parse_glibc_version(target.glibc_version, target_glibc))) {
......@@ -1139,7 +1128,7 @@ int main(int argc, char **argv) {
11391128 }
11401129 ZigLibCInstallation *libc = nullptr;
11411130 if (libc_txt != nullptr) {
1142 libc = allocate<ZigLibCInstallation>(1);
1131 libc = heap::c_allocator.create<ZigLibCInstallation>();
11431132 if ((err = zig_libc_parse(libc, buf_create_from_str(libc_txt), &target, true))) {
11441133 fprintf(stderr, "Unable to parse --libc text file: %s\n", err_str(err));
11451134 return main_exit(root_progress_node, EXIT_FAILURE);
......@@ -1270,7 +1259,8 @@ int main(int argc, char **argv) {
12701259
12711260 if (cmd == CmdRun) {
12721261#ifdef ZIG_ENABLE_MEM_PROFILE
1273 memprof_dump_stats(stderr);
1262 if (mem::report_print)
1263 mem::print_report();
12741264#endif
12751265
12761266 const char *exec_path = buf_ptr(&g->output_file_path);
......@@ -1385,4 +1375,20 @@ int main(int argc, char **argv) {
13851375 case CmdNone:
13861376 return print_full_usage(arg0, stderr, EXIT_FAILURE);
13871377 }
1378 zig_unreachable();
1379}
1380
1381int main(int argc, char **argv) {
1382 stage2_attach_segfault_handler();
1383 os_init();
1384 mem::init();
1385
1386 auto result = main0(argc, argv);
1387
1388#ifdef ZIG_ENABLE_MEM_PROFILE
1389 if (mem::report_print)
1390 mem::intern_counters.print_report();
1391#endif
1392 mem::deinit();
1393 return result;
13881394}
src/mem.cpp created+37
......@@ -0,0 +1,37 @@
1/*
2 * Copyright (c) 2020 Andrew Kelley
3 *
4 * This file is part of zig, which is MIT licensed.
5 * See http://opensource.org/licenses/MIT
6 */
7
8#include "config.h"
9#include "mem.hpp"
10#include "mem_profile.hpp"
11#include "heap.hpp"
12
13namespace mem {
14
15void init() {
16 heap::bootstrap_allocator_state.init("heap::bootstrap_allocator");
17 heap::c_allocator_state.init("heap::c_allocator");
18}
19
20void deinit() {
21 heap::c_allocator_state.deinit();
22 heap::bootstrap_allocator_state.deinit();
23}
24
25#ifdef ZIG_ENABLE_MEM_PROFILE
26void print_report(FILE *file) {
27 heap::c_allocator_state.print_report(file);
28 intern_counters.print_report(file);
29}
30#endif
31
32#ifdef ZIG_ENABLE_MEM_PROFILE
33bool report_print = false;
34FILE *report_file{nullptr};
35#endif
36
37} // namespace mem
src/mem.hpp created+149
......@@ -0,0 +1,149 @@
1/*
2 * Copyright (c) 2020 Andrew Kelley
3 *
4 * This file is part of zig, which is MIT licensed.
5 * See http://opensource.org/licenses/MIT
6 */
7
8#ifndef ZIG_MEM_HPP
9#define ZIG_MEM_HPP
10
11#include <stdint.h>
12#include <stdio.h>
13#include <stdlib.h>
14
15#include "config.h"
16#include "util_base.hpp"
17#include "mem_type_info.hpp"
18
19//
20// -- Memory Allocation General Notes --
21//
22// `heap::c_allocator` is the preferred general allocator.
23//
24// `heap::bootstrap_allocator` is an implementation detail for use
25// by allocators themselves when incidental heap may be required for
26// profiling and statistics. It breaks the infinite recursion cycle.
27//
28// `mem::os` contains a raw wrapper for system malloc API used in
29// preference to calling ::{malloc, free, calloc, realloc} directly.
30// This isolates usage and helps with audits:
31//
32// mem::os::malloc
33// mem::os::free
34// mem::os::calloc
35// mem::os::realloc
36//
37namespace mem {
38
39// initialize mem module before any use
40void init();
41
42// deinitialize mem module to free memory and print report
43void deinit();
44
45// isolate system/libc allocators
46namespace os {
47
48ATTRIBUTE_RETURNS_NOALIAS
49inline void *malloc(size_t size) {
50#ifndef NDEBUG
51 // make behavior when size == 0 portable
52 if (size == 0)
53 return nullptr;
54#endif
55 auto ptr = ::malloc(size);
56 if (ptr == nullptr)
57 zig_panic("allocation failed");
58 return ptr;
59}
60
61inline void free(void *ptr) {
62 ::free(ptr);
63}
64
65ATTRIBUTE_RETURNS_NOALIAS
66inline void *calloc(size_t count, size_t size) {
67#ifndef NDEBUG
68 // make behavior when size == 0 portable
69 if (count == 0 || size == 0)
70 return nullptr;
71#endif
72 auto ptr = ::calloc(count, size);
73 if (ptr == nullptr)
74 zig_panic("allocation failed");
75 return ptr;
76}
77
78inline void *realloc(void *old_ptr, size_t size) {
79#ifndef NDEBUG
80 // make behavior when size == 0 portable
81 if (old_ptr == nullptr && size == 0)
82 return nullptr;
83#endif
84 auto ptr = ::realloc(old_ptr, size);
85 if (ptr == nullptr)
86 zig_panic("allocation failed");
87 return ptr;
88}
89
90} // namespace os
91
92struct Allocator {
93 virtual void destruct(Allocator *allocator) = 0;
94
95 template <typename T> ATTRIBUTE_RETURNS_NOALIAS
96 T *allocate(size_t count) {
97 return reinterpret_cast<T *>(this->internal_allocate(TypeInfo::make<T>(), count));
98 }
99
100 template <typename T> ATTRIBUTE_RETURNS_NOALIAS
101 T *allocate_nonzero(size_t count) {
102 return reinterpret_cast<T *>(this->internal_allocate_nonzero(TypeInfo::make<T>(), count));
103 }
104
105 template <typename T>
106 T *reallocate(T *old_ptr, size_t old_count, size_t new_count) {
107 return reinterpret_cast<T *>(this->internal_reallocate(TypeInfo::make<T>(), old_ptr, old_count, new_count));
108 }
109
110 template <typename T>
111 T *reallocate_nonzero(T *old_ptr, size_t old_count, size_t new_count) {
112 return reinterpret_cast<T *>(this->internal_reallocate_nonzero(TypeInfo::make<T>(), old_ptr, old_count, new_count));
113 }
114
115 template<typename T>
116 void deallocate(T *ptr, size_t count) {
117 this->internal_deallocate(TypeInfo::make<T>(), ptr, count);
118 }
119
120 template<typename T>
121 T *create() {
122 return reinterpret_cast<T *>(this->internal_allocate(TypeInfo::make<T>(), 1));
123 }
124
125 template<typename T>
126 void destroy(T *ptr) {
127 this->internal_deallocate(TypeInfo::make<T>(), ptr, 1);
128 }
129
130protected:
131 ATTRIBUTE_RETURNS_NOALIAS virtual void *internal_allocate(const TypeInfo &info, size_t count) = 0;
132 ATTRIBUTE_RETURNS_NOALIAS virtual void *internal_allocate_nonzero(const TypeInfo &info, size_t count) = 0;
133 virtual void *internal_reallocate(const TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) = 0;
134 virtual void *internal_reallocate_nonzero(const TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) = 0;
135 virtual void internal_deallocate(const TypeInfo &info, void *ptr, size_t count) = 0;
136};
137
138#ifdef ZIG_ENABLE_MEM_PROFILE
139void print_report(FILE *file = nullptr);
140
141// global memory report flag
142extern bool report_print;
143// global memory report default destination
144extern FILE *report_file;
145#endif
146
147} // namespace mem
148
149#endif
src/mem_hash_map.hpp created+244
......@@ -0,0 +1,244 @@
1/*
2 * Copyright (c) 2015 Andrew Kelley
3 *
4 * This file is part of zig, which is MIT licensed.
5 * See http://opensource.org/licenses/MIT
6 */
7
8#ifndef ZIG_MEM_HASH_MAP_HPP
9#define ZIG_MEM_HASH_MAP_HPP
10
11#include "mem.hpp"
12
13namespace mem {
14
15template<typename K, typename V, uint32_t (*HashFunction)(K key), bool (*EqualFn)(K a, K b)>
16class HashMap {
17public:
18 void init(Allocator& allocator, int capacity) {
19 init_capacity(allocator, capacity);
20 }
21 void deinit(Allocator& allocator) {
22 allocator.deallocate(_entries, _capacity);
23 }
24
25 struct Entry {
26 K key;
27 V value;
28 bool used;
29 int distance_from_start_index;
30 };
31
32 void clear() {
33 for (int i = 0; i < _capacity; i += 1) {
34 _entries[i].used = false;
35 }
36 _size = 0;
37 _max_distance_from_start_index = 0;
38 _modification_count += 1;
39 }
40
41 int size() const {
42 return _size;
43 }
44
45 void put(Allocator& allocator, const K &key, const V &value) {
46 _modification_count += 1;
47 internal_put(key, value);
48
49 // if we get too full (60%), double the capacity
50 if (_size * 5 >= _capacity * 3) {
51 Entry *old_entries = _entries;
52 int old_capacity = _capacity;
53 init_capacity(allocator, _capacity * 2);
54 // dump all of the old elements into the new table
55 for (int i = 0; i < old_capacity; i += 1) {
56 Entry *old_entry = &old_entries[i];
57 if (old_entry->used)
58 internal_put(old_entry->key, old_entry->value);
59 }
60 allocator.deallocate(old_entries, old_capacity);
61 }
62 }
63
64 Entry *put_unique(Allocator& allocator, const K &key, const V &value) {
65 // TODO make this more efficient
66 Entry *entry = internal_get(key);
67 if (entry)
68 return entry;
69 put(allocator, key, value);
70 return nullptr;
71 }
72
73 const V &get(const K &key) const {
74 Entry *entry = internal_get(key);
75 if (!entry)
76 zig_panic("key not found");
77 return entry->value;
78 }
79
80 Entry *maybe_get(const K &key) const {
81 return internal_get(key);
82 }
83
84 void maybe_remove(const K &key) {
85 if (maybe_get(key)) {
86 remove(key);
87 }
88 }
89
90 void remove(const K &key) {
91 _modification_count += 1;
92 int start_index = key_to_index(key);
93 for (int roll_over = 0; roll_over <= _max_distance_from_start_index; roll_over += 1) {
94 int index = (start_index + roll_over) % _capacity;
95 Entry *entry = &_entries[index];
96
97 if (!entry->used)
98 zig_panic("key not found");
99
100 if (!EqualFn(entry->key, key))
101 continue;
102
103 for (; roll_over < _capacity; roll_over += 1) {
104 int next_index = (start_index + roll_over + 1) % _capacity;
105 Entry *next_entry = &_entries[next_index];
106 if (!next_entry->used || next_entry->distance_from_start_index == 0) {
107 entry->used = false;
108 _size -= 1;
109 return;
110 }
111 *entry = *next_entry;
112 entry->distance_from_start_index -= 1;
113 entry = next_entry;
114 }
115 zig_panic("shifting everything in the table");
116 }
117 zig_panic("key not found");
118 }
119
120 class Iterator {
121 public:
122 Entry *next() {
123 if (_inital_modification_count != _table->_modification_count)
124 zig_panic("concurrent modification");
125 if (_count >= _table->size())
126 return NULL;
127 for (; _index < _table->_capacity; _index += 1) {
128 Entry *entry = &_table->_entries[_index];
129 if (entry->used) {
130 _index += 1;
131 _count += 1;
132 return entry;
133 }
134 }
135 zig_panic("no next item");
136 }
137
138 private:
139 const HashMap * _table;
140 // how many items have we returned
141 int _count = 0;
142 // iterator through the entry array
143 int _index = 0;
144 // used to detect concurrent modification
145 uint32_t _inital_modification_count;
146 Iterator(const HashMap * table) :
147 _table(table), _inital_modification_count(table->_modification_count) {
148 }
149 friend HashMap;
150 };
151
152 // you must not modify the underlying HashMap while this iterator is still in use
153 Iterator entry_iterator() const {
154 return Iterator(this);
155 }
156
157private:
158 Entry *_entries;
159 int _capacity;
160 int _size;
161 int _max_distance_from_start_index;
162 // this is used to detect bugs where a hashtable is edited while an iterator is running.
163 uint32_t _modification_count;
164
165 void init_capacity(Allocator& allocator, int capacity) {
166 _capacity = capacity;
167 _entries = allocator.allocate<Entry>(_capacity);
168 _size = 0;
169 _max_distance_from_start_index = 0;
170 for (int i = 0; i < _capacity; i += 1) {
171 _entries[i].used = false;
172 }
173 }
174
175 void internal_put(K key, V value) {
176 int start_index = key_to_index(key);
177 for (int roll_over = 0, distance_from_start_index = 0;
178 roll_over < _capacity; roll_over += 1, distance_from_start_index += 1)
179 {
180 int index = (start_index + roll_over) % _capacity;
181 Entry *entry = &_entries[index];
182
183 if (entry->used && !EqualFn(entry->key, key)) {
184 if (entry->distance_from_start_index < distance_from_start_index) {
185 // robin hood to the rescue
186 Entry tmp = *entry;
187 if (distance_from_start_index > _max_distance_from_start_index)
188 _max_distance_from_start_index = distance_from_start_index;
189 *entry = {
190 key,
191 value,
192 true,
193 distance_from_start_index,
194 };
195 key = tmp.key;
196 value = tmp.value;
197 distance_from_start_index = tmp.distance_from_start_index;
198 }
199 continue;
200 }
201
202 if (!entry->used) {
203 // adding an entry. otherwise overwriting old value with
204 // same key
205 _size += 1;
206 }
207
208 if (distance_from_start_index > _max_distance_from_start_index)
209 _max_distance_from_start_index = distance_from_start_index;
210 *entry = {
211 key,
212 value,
213 true,
214 distance_from_start_index,
215 };
216 return;
217 }
218 zig_panic("put into a full HashMap");
219 }
220
221
222 Entry *internal_get(const K &key) const {
223 int start_index = key_to_index(key);
224 for (int roll_over = 0; roll_over <= _max_distance_from_start_index; roll_over += 1) {
225 int index = (start_index + roll_over) % _capacity;
226 Entry *entry = &_entries[index];
227
228 if (!entry->used)
229 return NULL;
230
231 if (EqualFn(entry->key, key))
232 return entry;
233 }
234 return NULL;
235 }
236
237 int key_to_index(const K &key) const {
238 return (int)(HashFunction(key) % ((uint32_t)_capacity));
239 }
240};
241
242} // namespace mem
243
244#endif
src/mem_list.hpp created+101
......@@ -0,0 +1,101 @@
1/*
2 * Copyright (c) 2015 Andrew Kelley
3 *
4 * This file is part of zig, which is MIT licensed.
5 * See http://opensource.org/licenses/MIT
6 */
7
8#ifndef ZIG_MEM_LIST_HPP
9#define ZIG_MEM_LIST_HPP
10
11#include "mem.hpp"
12
13namespace mem {
14
15template<typename T>
16struct List {
17 void deinit(Allocator& allocator) {
18 allocator.deallocate<T>(items, capacity);
19 }
20
21 void append(Allocator& allocator, const T& item) {
22 ensure_capacity(allocator, length + 1);
23 items[length++] = item;
24 }
25
26 // remember that the pointer to this item is invalid after you
27 // modify the length of the list
28 const T & at(size_t index) const {
29 assert(index != SIZE_MAX);
30 assert(index < length);
31 return items[index];
32 }
33
34 T & at(size_t index) {
35 assert(index != SIZE_MAX);
36 assert(index < length);
37 return items[index];
38 }
39
40 T pop() {
41 assert(length >= 1);
42 return items[--length];
43 }
44
45 T *add_one() {
46 resize(length + 1);
47 return &last();
48 }
49
50 const T & last() const {
51 assert(length >= 1);
52 return items[length - 1];
53 }
54
55 T & last() {
56 assert(length >= 1);
57 return items[length - 1];
58 }
59
60 void resize(Allocator& allocator, size_t new_length) {
61 assert(new_length != SIZE_MAX);
62 ensure_capacity(allocator, new_length);
63 length = new_length;
64 }
65
66 void clear() {
67 length = 0;
68 }
69
70 void ensure_capacity(Allocator& allocator, size_t new_capacity) {
71 if (capacity >= new_capacity)
72 return;
73
74 size_t better_capacity = capacity;
75 do {
76 better_capacity = better_capacity * 5 / 2 + 8;
77 } while (better_capacity < new_capacity);
78
79 items = allocator.reallocate_nonzero<T>(items, capacity, better_capacity);
80 capacity = better_capacity;
81 }
82
83 T swap_remove(size_t index) {
84 if (length - 1 == index) return pop();
85
86 assert(index != SIZE_MAX);
87 assert(index < length);
88
89 T old_item = items[index];
90 items[index] = pop();
91 return old_item;
92 }
93
94 T *items{nullptr};
95 size_t length{0};
96 size_t capacity{0};
97};
98
99} // namespace mem
100
101#endif
src/mem_profile.cpp created+181
......@@ -0,0 +1,181 @@
1/*
2 * Copyright (c) 2020 Andrew Kelley
3 *
4 * This file is part of zig, which is MIT licensed.
5 * See http://opensource.org/licenses/MIT
6 */
7
8#include "config.h"
9
10#ifdef ZIG_ENABLE_MEM_PROFILE
11
12#include "mem.hpp"
13#include "mem_list.hpp"
14#include "mem_profile.hpp"
15#include "heap.hpp"
16
17namespace mem {
18
19void Profile::init(const char *name, const char *kind) {
20 this->name = name;
21 this->kind = kind;
22 this->usage_table.init(heap::bootstrap_allocator, 1024);
23}
24
25void Profile::deinit() {
26 assert(this->name != nullptr);
27 if (mem::report_print)
28 this->print_report();
29 this->usage_table.deinit(heap::bootstrap_allocator);
30 this->name = nullptr;
31}
32
33void Profile::record_alloc(const TypeInfo &info, size_t count) {
34 if (count == 0) return;
35 auto existing_entry = this->usage_table.put_unique(
36 heap::bootstrap_allocator,
37 UsageKey{info.name_ptr, info.name_len},
38 Entry{info, 1, count, 0, 0} );
39 if (existing_entry != nullptr) {
40 assert(existing_entry->value.info.size == info.size); // allocated name does not match type
41 existing_entry->value.alloc.calls += 1;
42 existing_entry->value.alloc.objects += count;
43 }
44}
45
46void Profile::record_dealloc(const TypeInfo &info, size_t count) {
47 if (count == 0) return;
48 auto existing_entry = this->usage_table.maybe_get(UsageKey{info.name_ptr, info.name_len});
49 if (existing_entry == nullptr) {
50 fprintf(stderr, "deallocated name '");
51 for (size_t i = 0; i < info.name_len; ++i)
52 fputc(info.name_ptr[i], stderr);
53 zig_panic("' (size %zu) not found in allocated table; compromised memory usage stats", info.size);
54 }
55 if (existing_entry->value.info.size != info.size) {
56 fprintf(stderr, "deallocated name '");
57 for (size_t i = 0; i < info.name_len; ++i)
58 fputc(info.name_ptr[i], stderr);
59 zig_panic("' does not match expected type size %zu", info.size);
60 }
61 assert(existing_entry->value.alloc.calls - existing_entry->value.dealloc.calls > 0);
62 assert(existing_entry->value.alloc.objects - existing_entry->value.dealloc.objects >= count);
63 existing_entry->value.dealloc.calls += 1;
64 existing_entry->value.dealloc.objects += count;
65}
66
67static size_t entry_remain_total_bytes(const Profile::Entry *entry) {
68 return (entry->alloc.objects - entry->dealloc.objects) * entry->info.size;
69}
70
71static int entry_compare(const void *a, const void *b) {
72 size_t total_a = entry_remain_total_bytes(*reinterpret_cast<Profile::Entry *const *>(a));
73 size_t total_b = entry_remain_total_bytes(*reinterpret_cast<Profile::Entry *const *>(b));
74 if (total_a > total_b)
75 return -1;
76 if (total_a < total_b)
77 return 1;
78 return 0;
79};
80
81void Profile::print_report(FILE *file) {
82 if (!file) {
83 file = report_file;
84 if (!file)
85 file = stderr;
86 }
87 fprintf(file, "\n--- MEMORY PROFILE REPORT [%s]: %s ---\n", this->kind, this->name);
88
89 List<const Entry *> list;
90 auto it = this->usage_table.entry_iterator();
91 for (;;) {
92 auto entry = it.next();
93 if (!entry)
94 break;
95 list.append(heap::bootstrap_allocator, &entry->value);
96 }
97
98 qsort(list.items, list.length, sizeof(const Entry *), entry_compare);
99
100 size_t total_bytes_alloc = 0;
101 size_t total_bytes_dealloc = 0;
102
103 size_t total_calls_alloc = 0;
104 size_t total_calls_dealloc = 0;
105
106 for (size_t i = 0; i < list.length; i += 1) {
107 const Entry *entry = list.at(i);
108 fprintf(file, " ");
109 for (size_t j = 0; j < entry->info.name_len; ++j)
110 fputc(entry->info.name_ptr[j], file);
111 fprintf(file, ": %zu bytes each", entry->info.size);
112
113 fprintf(file, ", alloc{ %zu calls, %zu objects, total ", entry->alloc.calls, entry->alloc.objects);
114 const auto alloc_num_bytes = entry->alloc.objects * entry->info.size;
115 zig_pretty_print_bytes(file, alloc_num_bytes);
116
117 fprintf(file, " }, dealloc{ %zu calls, %zu objects, total ", entry->dealloc.calls, entry->dealloc.objects);
118 const auto dealloc_num_bytes = entry->dealloc.objects * entry->info.size;
119 zig_pretty_print_bytes(file, dealloc_num_bytes);
120
121 fprintf(file, " }, remain{ %zu calls, %zu objects, total ",
122 entry->alloc.calls - entry->dealloc.calls,
123 entry->alloc.objects - entry->dealloc.objects );
124 const auto remain_num_bytes = alloc_num_bytes - dealloc_num_bytes;
125 zig_pretty_print_bytes(file, remain_num_bytes);
126
127 fprintf(file, " }\n");
128
129 total_bytes_alloc += alloc_num_bytes;
130 total_bytes_dealloc += dealloc_num_bytes;
131
132 total_calls_alloc += entry->alloc.calls;
133 total_calls_dealloc += entry->dealloc.calls;
134 }
135
136 fprintf(file, "\n Total bytes allocated: ");
137 zig_pretty_print_bytes(file, total_bytes_alloc);
138 fprintf(file, ", deallocated: ");
139 zig_pretty_print_bytes(file, total_bytes_dealloc);
140 fprintf(file, ", remaining: ");
141 zig_pretty_print_bytes(file, total_bytes_alloc - total_bytes_dealloc);
142
143 fprintf(file, "\n Total calls alloc: %zu, dealloc: %zu, remain: %zu\n",
144 total_calls_alloc, total_calls_dealloc, (total_calls_alloc - total_calls_dealloc));
145
146 list.deinit(heap::bootstrap_allocator);
147}
148
149uint32_t Profile::usage_hash(UsageKey key) {
150 // FNV 32-bit hash
151 uint32_t h = 2166136261;
152 for (size_t i = 0; i < key.name_len; ++i) {
153 h = h ^ key.name_ptr[i];
154 h = h * 16777619;
155 }
156 return h;
157}
158
159bool Profile::usage_equal(UsageKey a, UsageKey b) {
160 return memcmp(a.name_ptr, b.name_ptr, a.name_len > b.name_len ? a.name_len : b.name_len) == 0;
161}
162
163void InternCounters::print_report(FILE *file) {
164 if (!file) {
165 file = report_file;
166 if (!file)
167 file = stderr;
168 }
169 fprintf(file, "\n--- IR INTERNING REPORT ---\n");
170 fprintf(file, " undefined: interned %zu times\n", intern_counters.x_undefined);
171 fprintf(file, " void: interned %zu times\n", intern_counters.x_void);
172 fprintf(file, " null: interned %zu times\n", intern_counters.x_null);
173 fprintf(file, " unreachable: interned %zu times\n", intern_counters.x_unreachable);
174 fprintf(file, " zero_byte: interned %zu times\n", intern_counters.zero_byte);
175}
176
177InternCounters intern_counters;
178
179} // namespace mem
180
181#endif
src/mem_profile.hpp created+71
......@@ -0,0 +1,71 @@
1/*
2 * Copyright (c) 2020 Andrew Kelley
3 *
4 * This file is part of zig, which is MIT licensed.
5 * See http://opensource.org/licenses/MIT
6 */
7
8#ifndef ZIG_MEM_PROFILE_HPP
9#define ZIG_MEM_PROFILE_HPP
10
11#include "config.h"
12
13#ifdef ZIG_ENABLE_MEM_PROFILE
14
15#include <stdio.h>
16
17#include "mem.hpp"
18#include "mem_hash_map.hpp"
19#include "util.hpp"
20
21namespace mem {
22
23struct Profile {
24 void init(const char *name, const char *kind);
25 void deinit();
26
27 void record_alloc(const TypeInfo &info, size_t count);
28 void record_dealloc(const TypeInfo &info, size_t count);
29
30 void print_report(FILE *file = nullptr);
31
32 struct Entry {
33 TypeInfo info;
34
35 struct Use {
36 size_t calls;
37 size_t objects;
38 } alloc, dealloc;
39 };
40
41private:
42 const char *name;
43 const char *kind;
44
45 struct UsageKey {
46 const char *name_ptr;
47 size_t name_len;
48 };
49
50 static uint32_t usage_hash(UsageKey key);
51 static bool usage_equal(UsageKey a, UsageKey b);
52
53 HashMap<UsageKey, Entry, usage_hash, usage_equal> usage_table;
54};
55
56struct InternCounters {
57 size_t x_undefined;
58 size_t x_void;
59 size_t x_null;
60 size_t x_unreachable;
61 size_t zero_byte;
62
63 void print_report(FILE *file = nullptr);
64};
65
66extern InternCounters intern_counters;
67
68} // namespace mem
69
70#endif
71#endif
src/mem_type_info.hpp created+136
......@@ -0,0 +1,136 @@
1/*
2 * Copyright (c) 2020 Andrew Kelley
3 *
4 * This file is part of zig, which is MIT licensed.
5 * See http://opensource.org/licenses/MIT
6 */
7
8#ifndef ZIG_MEM_TYPE_INFO_HPP
9#define ZIG_MEM_TYPE_INFO_HPP
10
11#include "config.h"
12
13#ifndef ZIG_TYPE_INFO_IMPLEMENTATION
14# ifdef ZIG_ENABLE_MEM_PROFILE
15# define ZIG_TYPE_INFO_IMPLEMENTATION 1
16# else
17# define ZIG_TYPE_INFO_IMPLEMENTATION 0
18# endif
19#endif
20
21namespace mem {
22
23#if ZIG_TYPE_INFO_IMPLEMENTATION == 0
24
25struct TypeInfo {
26 size_t size;
27 size_t alignment;
28
29 template <typename T>
30 static constexpr TypeInfo make() {
31 return {sizeof(T), alignof(T)};
32 }
33};
34
35#elif ZIG_TYPE_INFO_IMPLEMENTATION == 1
36
37//
38// A non-portable way to get a human-readable type-name compatible with
39// non-RTTI C++ compiler mode; eg. `-fno-rtti`.
40//
41// Minimum requirements are c++11 and a compiler that has a constant for the
42// current function's decorated name whereby a template-type name can be
43// computed. eg. `__PRETTY_FUNCTION__` or `__FUNCSIG__`.
44//
45// given the following snippet:
46//
47// | #include <stdio.h>
48// |
49// | struct Top {};
50// | namespace mynamespace {
51// | using custom = unsigned int;
52// | struct Foo {
53// | struct Bar {};
54// | };
55// | };
56// |
57// | template <typename T>
58// | void foobar() {
59// | #ifdef _MSC_VER
60// | fprintf(stderr, "--> %s\n", __FUNCSIG__);
61// | #else
62// | fprintf(stderr, "--> %s\n", __PRETTY_FUNCTION__);
63// | #endif
64// | }
65// |
66// | int main() {
67// | foobar<Top>();
68// | foobar<unsigned int>();
69// | foobar<mynamespace::custom>();
70// | foobar<mynamespace::Foo*>();
71// | foobar<mynamespace::Foo::Bar*>();
72// | }
73//
74// gcc 9.2.0 produces:
75// --> void foobar() [with T = Top]
76// --> void foobar() [with T = unsigned int]
77// --> void foobar() [with T = unsigned int]
78// --> void foobar() [with T = mynamespace::Foo*]
79// --> void foobar() [with T = mynamespace::Foo::Bar*]
80//
81// xcode 11.3.1/clang produces:
82// --> void foobar() [T = Top]
83// --> void foobar() [T = unsigned int]
84// --> void foobar() [T = unsigned int]
85// --> void foobar() [T = mynamespace::Foo *]
86// --> void foobar() [T = mynamespace::Foo::Bar *]
87//
88// VStudio 2019 16.5.0/msvc produces:
89// --> void __cdecl foobar<struct Top>(void)
90// --> void __cdecl foobar<unsigned int>(void)
91// --> void __cdecl foobar<unsigned int>(void)
92// --> void __cdecl foobar<structmynamespace::Foo*>(void)
93// --> void __cdecl foobar<structmynamespace::Foo::Bar*>(void)
94//
95struct TypeInfo {
96 const char *name_ptr;
97 size_t name_len;
98 size_t size;
99 size_t alignment;
100
101 static constexpr TypeInfo to_type_info(const char *str, size_t start, size_t end, size_t size, size_t alignment) {
102 return TypeInfo{str + start, end - start, size, alignment};
103 }
104
105 static constexpr size_t index_of(const char *str, char c) {
106 return *str == c ? 0 : 1 + index_of(str + 1, c);
107 }
108
109 template <typename T>
110 static constexpr const char *decorated_name() {
111#ifdef _MSC_VER
112 return __FUNCSIG__;
113#else
114 return __PRETTY_FUNCTION__;
115#endif
116 }
117
118 static constexpr TypeInfo extract(const char *decorated, size_t size, size_t alignment) {
119#ifdef _MSC_VER
120 return to_type_info(decorated, index_of(decorated, '<') + 1, index_of(decorated, '>'), size, alignment);
121#else
122 return to_type_info(decorated, index_of(decorated, '=') + 2, index_of(decorated, ']'), size, alignment);
123#endif
124 }
125
126 template <typename T>
127 static constexpr TypeInfo make() {
128 return TypeInfo::extract(TypeInfo::decorated_name<T>(), sizeof(T), alignof(T));
129 }
130};
131
132#endif // ZIG_TYPE_INFO_IMPLEMENTATION
133
134} // namespace mem
135
136#endif
src/memory_profiling.cpp deleted-150
......@@ -1,150 +0,0 @@
1#include "memory_profiling.hpp"
2#include "hash_map.hpp"
3#include "list.hpp"
4#include "util.hpp"
5#include <string.h>
6
7#ifdef ZIG_ENABLE_MEM_PROFILE
8
9MemprofInternCount memprof_intern_count;
10
11static bool str_eql_str(const char *a, const char *b) {
12 return strcmp(a, b) == 0;
13}
14
15static uint32_t str_hash(const char *s) {
16 // FNV 32-bit hash
17 uint32_t h = 2166136261;
18 for (; *s; s += 1) {
19 h = h ^ *s;
20 h = h * 16777619;
21 }
22 return h;
23}
24
25struct CountAndSize {
26 size_t item_count;
27 size_t type_size;
28};
29
30ZigList<const char *> unknown_names = {};
31HashMap<const char *, CountAndSize, str_hash, str_eql_str> usage_table = {};
32bool table_active = false;
33
34static const char *get_default_name(const char *name_or_null, size_t type_size) {
35 if (name_or_null != nullptr) return name_or_null;
36 if (type_size >= unknown_names.length) {
37 table_active = false;
38 while (type_size >= unknown_names.length) {
39 unknown_names.append(nullptr);
40 }
41 table_active = true;
42 }
43 if (unknown_names.at(type_size) == nullptr) {
44 char buf[100];
45 sprintf(buf, "Unknown_%zu%c", type_size, 0);
46 unknown_names.at(type_size) = strdup(buf);
47 }
48 return unknown_names.at(type_size);
49}
50
51void memprof_alloc(const char *name, size_t count, size_t type_size) {
52 if (!table_active) return;
53 if (count == 0) return;
54 // temporarily disable during table put
55 table_active = false;
56 name = get_default_name(name, type_size);
57 auto existing_entry = usage_table.put_unique(name, {count, type_size});
58 if (existing_entry != nullptr) {
59 assert(existing_entry->value.type_size == type_size); // allocated name does not match type
60 existing_entry->value.item_count += count;
61 }
62 table_active = true;
63}
64
65void memprof_dealloc(const char *name, size_t count, size_t type_size) {
66 if (!table_active) return;
67 if (count == 0) return;
68 name = get_default_name(name, type_size);
69 auto existing_entry = usage_table.maybe_get(name);
70 if (existing_entry == nullptr) {
71 zig_panic("deallocated name '%s' (size %zu) not found in allocated table; compromised memory usage stats",
72 name, type_size);
73 }
74 if (existing_entry->value.type_size != type_size) {
75 zig_panic("deallocated name '%s' does not match expected type size %zu", name, type_size);
76 }
77 existing_entry->value.item_count -= count;
78}
79
80void memprof_init(void) {
81 usage_table.init(1024);
82 table_active = true;
83}
84
85struct MemItem {
86 const char *type_name;
87 CountAndSize count_and_size;
88};
89
90static size_t get_bytes(const MemItem *item) {
91 return item->count_and_size.item_count * item->count_and_size.type_size;
92}
93
94static int compare_bytes_desc(const void *a, const void *b) {
95 size_t size_a = get_bytes((const MemItem *)(a));
96 size_t size_b = get_bytes((const MemItem *)(b));
97 if (size_a > size_b)
98 return -1;
99 if (size_a < size_b)
100 return 1;
101 return 0;
102}
103
104void memprof_dump_stats(FILE *file) {
105 assert(table_active);
106 // disable modifications from this function
107 table_active = false;
108
109 ZigList<MemItem> list = {};
110
111 auto it = usage_table.entry_iterator();
112 for (;;) {
113 auto *entry = it.next();
114 if (!entry)
115 break;
116
117 list.append({entry->key, entry->value});
118 }
119
120 qsort(list.items, list.length, sizeof(MemItem), compare_bytes_desc);
121
122 size_t total_bytes_used = 0;
123
124 for (size_t i = 0; i < list.length; i += 1) {
125 const MemItem *item = &list.at(i);
126 fprintf(file, "%s: %zu items, %zu bytes each, total ", item->type_name,
127 item->count_and_size.item_count, item->count_and_size.type_size);
128 size_t bytes = get_bytes(item);
129 zig_pretty_print_bytes(file, bytes);
130 fprintf(file, "\n");
131
132 total_bytes_used += bytes;
133 }
134
135 fprintf(stderr, "Total bytes used: ");
136 zig_pretty_print_bytes(file, total_bytes_used);
137 fprintf(file, "\n");
138
139 list.deinit();
140 table_active = true;
141
142 fprintf(stderr, "\n");
143 fprintf(stderr, "undefined: interned %zu times\n", memprof_intern_count.x_undefined);
144 fprintf(stderr, "void: interned %zu times\n", memprof_intern_count.x_void);
145 fprintf(stderr, "null: interned %zu times\n", memprof_intern_count.x_null);
146 fprintf(stderr, "unreachable: interned %zu times\n", memprof_intern_count.x_unreachable);
147 fprintf(stderr, "zero_byte: interned %zu times\n", memprof_intern_count.zero_byte);
148}
149
150#endif
src/memory_profiling.hpp deleted-31
......@@ -1,31 +0,0 @@
1/*
2 * Copyright (c) 2019 Andrew Kelley
3 *
4 * This file is part of zig, which is MIT licensed.
5 * See http://opensource.org/licenses/MIT
6 */
7
8#ifndef ZIG_MEMORY_PROFILING_HPP
9#define ZIG_MEMORY_PROFILING_HPP
10
11#include "config.h"
12
13#include <stddef.h>
14#include <stdio.h>
15
16struct MemprofInternCount {
17 size_t x_undefined;
18 size_t x_void;
19 size_t x_null;
20 size_t x_unreachable;
21 size_t zero_byte;
22};
23extern MemprofInternCount memprof_intern_count;
24
25void memprof_init(void);
26
27void memprof_alloc(const char *name, size_t item_count, size_t type_size);
28void memprof_dealloc(const char *name, size_t item_count, size_t type_size);
29
30void memprof_dump_stats(FILE *file);
31#endif
src/os.cpp+7-7
......@@ -107,7 +107,7 @@ static void populate_termination(Termination *term, int status) {
107107}
108108
109109static void os_spawn_process_posix(ZigList<const char *> &args, Termination *term) {
110 const char **argv = allocate<const char *>(args.length + 1);
110 const char **argv = heap::c_allocator.allocate<const char *>(args.length + 1);
111111 for (size_t i = 0; i < args.length; i += 1) {
112112 argv[i] = args.at(i);
113113 }
......@@ -688,7 +688,7 @@ static Buf os_path_resolve_posix(Buf **paths_ptr, size_t paths_len) {
688688
689689 if (have_abs) {
690690 result_len = max_size;
691 result_ptr = allocate_nonzero<uint8_t>(result_len);
691 result_ptr = heap::c_allocator.allocate_nonzero<uint8_t>(result_len);
692692 } else {
693693 Buf cwd = BUF_INIT;
694694 int err;
......@@ -696,7 +696,7 @@ static Buf os_path_resolve_posix(Buf **paths_ptr, size_t paths_len) {
696696 zig_panic("get cwd failed");
697697 }
698698 result_len = max_size + buf_len(&cwd) + 1;
699 result_ptr = allocate_nonzero<uint8_t>(result_len);
699 result_ptr = heap::c_allocator.allocate_nonzero<uint8_t>(result_len);
700700 memcpy(result_ptr, buf_ptr(&cwd), buf_len(&cwd));
701701 result_index += buf_len(&cwd);
702702 }
......@@ -816,7 +816,7 @@ static Error os_exec_process_posix(ZigList<const char *> &args,
816816 if (dup2(stderr_pipe[1], STDERR_FILENO) == -1)
817817 zig_panic("dup2 failed");
818818
819 const char **argv = allocate<const char *>(args.length + 1);
819 const char **argv = heap::c_allocator.allocate<const char *>(args.length + 1);
820820 argv[args.length] = nullptr;
821821 for (size_t i = 0; i < args.length; i += 1) {
822822 argv[i] = args.at(i);
......@@ -1134,7 +1134,7 @@ static bool is_stderr_cyg_pty(void) {
11341134 if (stderr_handle == INVALID_HANDLE_VALUE)
11351135 return false;
11361136
1137 int size = sizeof(FILE_NAME_INFO) + sizeof(WCHAR) * MAX_PATH;
1137 const int size = sizeof(FILE_NAME_INFO) + sizeof(WCHAR) * MAX_PATH;
11381138 FILE_NAME_INFO *nameinfo;
11391139 WCHAR *p = NULL;
11401140
......@@ -1142,7 +1142,7 @@ static bool is_stderr_cyg_pty(void) {
11421142 if (GetFileType(stderr_handle) != FILE_TYPE_PIPE) {
11431143 return 0;
11441144 }
1145 nameinfo = (FILE_NAME_INFO *)allocate<char>(size);
1145 nameinfo = reinterpret_cast<FILE_NAME_INFO *>(heap::c_allocator.allocate<char>(size));
11461146 if (nameinfo == NULL) {
11471147 return 0;
11481148 }
......@@ -1179,7 +1179,7 @@ static bool is_stderr_cyg_pty(void) {
11791179 }
11801180 }
11811181 }
1182 free(nameinfo);
1182 heap::c_allocator.deallocate(reinterpret_cast<char *>(nameinfo), size);
11831183 return (p != NULL);
11841184}
11851185#endif
src/parser.cpp+3-3
......@@ -147,7 +147,7 @@ static void ast_invalid_token_error(ParseContext *pc, Token *token) {
147147}
148148
149149static AstNode *ast_create_node_no_line_info(ParseContext *pc, NodeType type) {
150 AstNode *node = allocate<AstNode>(1, "AstNode");
150 AstNode *node = heap::c_allocator.create<AstNode>();
151151 node->type = type;
152152 node->owner = pc->owner;
153153 return node;
......@@ -1966,7 +1966,7 @@ static AsmOutput *ast_parse_asm_output_item(ParseContext *pc) {
19661966
19671967 expect_token(pc, TokenIdRParen);
19681968
1969 AsmOutput *res = allocate<AsmOutput>(1);
1969 AsmOutput *res = heap::c_allocator.create<AsmOutput>();
19701970 res->asm_symbolic_name = token_buf(sym_name);
19711971 res->constraint = token_buf(str);
19721972 res->variable_name = token_buf(var_name);
......@@ -2003,7 +2003,7 @@ static AsmInput *ast_parse_asm_input_item(ParseContext *pc) {
20032003 AstNode *expr = ast_expect(pc, ast_parse_expr);
20042004 expect_token(pc, TokenIdRParen);
20052005
2006 AsmInput *res = allocate<AsmInput>(1);
2006 AsmInput *res = heap::c_allocator.create<AsmInput>();
20072007 res->asm_symbolic_name = token_buf(sym_name);
20082008 res->constraint = token_buf(constraint);
20092009 res->expr = expr;
src/target.cpp+1-1
......@@ -524,7 +524,7 @@ void get_native_target(ZigTarget *target) {
524524 target->abi = target_default_abi(target->arch, target->os);
525525 }
526526 if (target_is_glibc(target)) {
527 target->glibc_version = allocate<ZigGLibCVersion>(1);
527 target->glibc_version = heap::c_allocator.create<ZigGLibCVersion>();
528528 target_init_default_glibc_version(target);
529529#ifdef ZIG_OS_LINUX
530530 Error err;
src/tokenizer.cpp+2-2
......@@ -397,10 +397,10 @@ static void invalid_char_error(Tokenize *t, uint8_t c) {
397397void tokenize(Buf *buf, Tokenization *out) {
398398 Tokenize t = {0};
399399 t.out = out;
400 t.tokens = out->tokens = allocate<ZigList<Token>>(1);
400 t.tokens = out->tokens = heap::c_allocator.create<ZigList<Token>>();
401401 t.buf = buf;
402402
403 out->line_offsets = allocate<ZigList<size_t>>(1);
403 out->line_offsets = heap::c_allocator.create<ZigList<size_t>>();
404404 out->line_offsets->append(0);
405405
406406 // Skip the UTF-8 BOM if present
src/userland.cpp+2-2
......@@ -101,7 +101,7 @@ Error stage2_cpu_features_parse(struct Stage2CpuFeatures **out, const char *zig_
101101 const char *cpu_name, const char *cpu_features)
102102{
103103 if (zig_triple == nullptr) {
104 Stage2CpuFeatures *result = allocate<Stage2CpuFeatures>(1, "Stage2CpuFeatures");
104 Stage2CpuFeatures *result = heap::c_allocator.create<Stage2CpuFeatures>();
105105 result->llvm_cpu_name = ZigLLVMGetHostCPUName();
106106 result->llvm_cpu_features = ZigLLVMGetNativeFeatures();
107107 result->builtin_str = "arch.getBaselineCpuFeatures();\n";
......@@ -110,7 +110,7 @@ Error stage2_cpu_features_parse(struct Stage2CpuFeatures **out, const char *zig_
110110 return ErrorNone;
111111 }
112112 if (cpu_name == nullptr && cpu_features == nullptr) {
113 Stage2CpuFeatures *result = allocate<Stage2CpuFeatures>(1, "Stage2CpuFeatures");
113 Stage2CpuFeatures *result = heap::c_allocator.create<Stage2CpuFeatures>();
114114 result->builtin_str = "arch.getBaselineCpuFeatures();\n";
115115 result->cache_hash = "\n\n";
116116 *out = result;
src/util.hpp+5-127
......@@ -8,69 +8,19 @@
88#ifndef ZIG_UTIL_HPP
99#define ZIG_UTIL_HPP
1010
11#include "memory_profiling.hpp"
12
1311#include <stdlib.h>
1412#include <stdint.h>
1513#include <string.h>
16#include <assert.h>
1714#include <ctype.h>
1815
1916#if defined(_MSC_VER)
20
2117#include <intrin.h>
22
23#define ATTRIBUTE_COLD __declspec(noinline)
24#define ATTRIBUTE_PRINTF(a, b)
25#define ATTRIBUTE_RETURNS_NOALIAS __declspec(restrict)
26#define ATTRIBUTE_NORETURN __declspec(noreturn)
27#define ATTRIBUTE_MUST_USE
28
29#define BREAKPOINT __debugbreak()
30
31#else
32
33#define ATTRIBUTE_COLD __attribute__((cold))
34#define ATTRIBUTE_PRINTF(a, b) __attribute__((format(printf, a, b)))
35#define ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__))
36#define ATTRIBUTE_NORETURN __attribute__((noreturn))
37#define ATTRIBUTE_MUST_USE __attribute__((warn_unused_result))
38
39#if defined(__MINGW32__) || defined(__MINGW64__)
40#define BREAKPOINT __debugbreak()
41#elif defined(__i386__) || defined(__x86_64__)
42#define BREAKPOINT __asm__ volatile("int $0x03");
43#elif defined(__clang__)
44#define BREAKPOINT __builtin_debugtrap()
45#elif defined(__GNUC__)
46#define BREAKPOINT __builtin_trap()
47#else
48#include <signal.h>
49#define BREAKPOINT raise(SIGTRAP)
50#endif
51
52#endif
53
54ATTRIBUTE_COLD
55ATTRIBUTE_NORETURN
56ATTRIBUTE_PRINTF(1, 2)
57void zig_panic(const char *format, ...);
58
59static inline void zig_assert(bool ok, const char *file, int line, const char *func) {
60 if (!ok) {
61 zig_panic("Assertion failed at %s:%d in %s. This is a bug in the Zig compiler.", file, line, func);
62 }
63}
64
65#ifdef _WIN32
66#define __func__ __FUNCTION__
6718#endif
6819
69#define zig_unreachable() zig_panic("Unreachable at %s:%d in %s. This is a bug in the Zig compiler.", __FILE__, __LINE__, __func__)
70
71// Assertions in stage1 are always on, and they call zig @panic.
72#undef assert
73#define assert(ok) zig_assert(ok, __FILE__, __LINE__, __func__)
20#include "config.h"
21#include "util_base.hpp"
22#include "heap.hpp"
23#include "mem.hpp"
7424
7525#if defined(_MSC_VER)
7626static inline int clzll(unsigned long long mask) {
......@@ -107,78 +57,6 @@ static inline int ctzll(unsigned long long mask) {
10757#define ctzll(x) __builtin_ctzll(x)
10858#endif
10959
110
111template<typename T>
112ATTRIBUTE_RETURNS_NOALIAS static inline T *allocate_nonzero(size_t count, const char *name = nullptr) {
113#ifdef ZIG_ENABLE_MEM_PROFILE
114 memprof_alloc(name, count, sizeof(T));
115#endif
116#ifndef NDEBUG
117 // make behavior when size == 0 portable
118 if (count == 0)
119 return nullptr;
120#endif
121 T *ptr = reinterpret_cast<T*>(malloc(count * sizeof(T)));
122 if (!ptr)
123 zig_panic("allocation failed");
124 return ptr;
125}
126
127template<typename T>
128ATTRIBUTE_RETURNS_NOALIAS static inline T *allocate(size_t count, const char *name = nullptr) {
129#ifdef ZIG_ENABLE_MEM_PROFILE
130 memprof_alloc(name, count, sizeof(T));
131#endif
132#ifndef NDEBUG
133 // make behavior when size == 0 portable
134 if (count == 0)
135 return nullptr;
136#endif
137 T *ptr = reinterpret_cast<T*>(calloc(count, sizeof(T)));
138 if (!ptr)
139 zig_panic("allocation failed");
140 return ptr;
141}
142
143template<typename T>
144static inline T *reallocate(T *old, size_t old_count, size_t new_count, const char *name = nullptr) {
145 T *ptr = reallocate_nonzero(old, old_count, new_count);
146 if (new_count > old_count) {
147 memset(&ptr[old_count], 0, (new_count - old_count) * sizeof(T));
148 }
149 return ptr;
150}
151
152template<typename T>
153static inline T *reallocate_nonzero(T *old, size_t old_count, size_t new_count, const char *name = nullptr) {
154#ifdef ZIG_ENABLE_MEM_PROFILE
155 memprof_dealloc(name, old_count, sizeof(T));
156 memprof_alloc(name, new_count, sizeof(T));
157#endif
158#ifndef NDEBUG
159 // make behavior when size == 0 portable
160 if (new_count == 0 && old == nullptr)
161 return nullptr;
162#endif
163 T *ptr = reinterpret_cast<T*>(realloc(old, new_count * sizeof(T)));
164 if (!ptr)
165 zig_panic("allocation failed");
166 return ptr;
167}
168
169template<typename T>
170static inline void deallocate(T *old, size_t count, const char *name = nullptr) {
171#ifdef ZIG_ENABLE_MEM_PROFILE
172 memprof_dealloc(name, count, sizeof(T));
173#endif
174 free(old);
175}
176
177template<typename T>
178static inline void destroy(T *old, const char *name = nullptr) {
179 return deallocate(old, 1, name);
180}
181
18260template <typename T, size_t n>
18361constexpr size_t array_length(const T (&)[n]) {
18462 return n;
......@@ -293,7 +171,7 @@ struct Slice {
293171 }
294172
295173 static inline Slice<T> alloc(size_t n) {
296 return {allocate_nonzero<T>(n), n};
174 return {heap::c_allocator.allocate_nonzero<T>(n), n};
297175 }
298176};
299177
src/util_base.hpp created+67
......@@ -0,0 +1,67 @@
1/*
2 * Copyright (c) 2015 Andrew Kelley
3 *
4 * This file is part of zig, which is MIT licensed.
5 * See http://opensource.org/licenses/MIT
6 */
7
8#ifndef ZIG_UTIL_BASE_HPP
9#define ZIG_UTIL_BASE_HPP
10
11#include <assert.h>
12
13#if defined(_MSC_VER)
14
15#define ATTRIBUTE_COLD __declspec(noinline)
16#define ATTRIBUTE_PRINTF(a, b)
17#define ATTRIBUTE_RETURNS_NOALIAS __declspec(restrict)
18#define ATTRIBUTE_NORETURN __declspec(noreturn)
19#define ATTRIBUTE_MUST_USE
20
21#define BREAKPOINT __debugbreak()
22
23#else
24
25#define ATTRIBUTE_COLD __attribute__((cold))
26#define ATTRIBUTE_PRINTF(a, b) __attribute__((format(printf, a, b)))
27#define ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__))
28#define ATTRIBUTE_NORETURN __attribute__((noreturn))
29#define ATTRIBUTE_MUST_USE __attribute__((warn_unused_result))
30
31#if defined(__MINGW32__) || defined(__MINGW64__)
32#define BREAKPOINT __debugbreak()
33#elif defined(__i386__) || defined(__x86_64__)
34#define BREAKPOINT __asm__ volatile("int $0x03");
35#elif defined(__clang__)
36#define BREAKPOINT __builtin_debugtrap()
37#elif defined(__GNUC__)
38#define BREAKPOINT __builtin_trap()
39#else
40#include <signal.h>
41#define BREAKPOINT raise(SIGTRAP)
42#endif
43
44#endif
45
46ATTRIBUTE_COLD
47ATTRIBUTE_NORETURN
48ATTRIBUTE_PRINTF(1, 2)
49void zig_panic(const char *format, ...);
50
51static inline void zig_assert(bool ok, const char *file, int line, const char *func) {
52 if (!ok) {
53 zig_panic("Assertion failed at %s:%d in %s. This is a bug in the Zig compiler.", file, line, func);
54 }
55}
56
57#ifdef _WIN32
58#define __func__ __FUNCTION__
59#endif
60
61#define zig_unreachable() zig_panic("Unreachable at %s:%d in %s. This is a bug in the Zig compiler.", __FILE__, __LINE__, __func__)
62
63// Assertions in stage1 are always on, and they call zig @panic.
64#undef assert
65#define assert(ok) zig_assert(ok, __FILE__, __LINE__, __func__)
66
67#endif
test/compile_errors.zig+16
......@@ -3,6 +3,22 @@ const builtin = @import("builtin");
33const Target = @import("std").Target;
44
55pub fn addCases(cases: *tests.CompileErrorContext) void {
6 cases.addTest("duplicate field in anonymous struct literal",
7 \\export fn entry() void {
8 \\ const anon = .{
9 \\ .inner = .{
10 \\ .a = .{
11 \\ .something = "text",
12 \\ },
13 \\ .a = .{},
14 \\ },
15 \\ };
16 \\}
17 , &[_][]const u8{
18 "tmp.zig:7:13: error: duplicate field",
19 "tmp.zig:4:13: note: other field here",
20 });
21
622 cases.addTest("type mismatch in C prototype with varargs",
723 \\const fn_ty = ?fn ([*c]u8, ...) callconv(.C) void;
824 \\extern fn fn_decl(fmt: [*:0]u8, ...) void;
test/stage1/behavior/atomics.zig+4-4
......@@ -146,10 +146,10 @@ fn testAtomicStore() void {
146146}
147147
148148test "atomicrmw with floats" {
149 if (builtin.arch == .aarch64 or
150 builtin.arch == .arm or
151 builtin.arch == .riscv64)
152 return;
149 if (builtin.arch == .aarch64 or builtin.arch == .arm or builtin.arch == .riscv64) {
150 // https://github.com/ziglang/zig/issues/4457
151 return error.SkipZigTest;
152 }
153153 testAtomicRmwFloat();
154154}
155155
test/stage1/behavior/bugs/1851.zig+2-3
......@@ -6,10 +6,9 @@ test "allocation and looping over 3-byte integer" {
66 expect(@sizeOf([1]u24) == 4);
77 expect(@alignOf(u24) == 4);
88 expect(@alignOf([1]u24) == 4);
9 var buffer: [100]u8 = undefined;
10 const a = &std.heap.FixedBufferAllocator.init(&buffer).allocator;
119
12 var x = a.alloc(u24, 2) catch unreachable;
10 var x = try std.testing.allocator.alloc(u24, 2);
11 defer std.testing.allocator.free(x);
1312 expect(x.len == 2);
1413 x[0] = 0xFFFFFF;
1514 x[1] = 0xFFFFFF;
test/stage1/behavior/cast.zig+27
......@@ -764,3 +764,30 @@ test "variable initialization uses result locations properly with regards to the
764764 const x: i32 = if (b) 1 else 2;
765765 expect(x == 1);
766766}
767
768test "cast between [*c]T and ?[*:0]T on fn parameter" {
769 const S = struct {
770 const Handler = ?extern fn ([*c]const u8) void;
771 fn addCallback(handler: Handler) void {}
772
773 fn myCallback(cstr: ?[*:0]const u8) callconv(.C) void {}
774
775 fn doTheTest() void {
776 addCallback(myCallback);
777 }
778 };
779 S.doTheTest();
780}
781
782test "cast between C pointer with different but compatible types" {
783 const S = struct {
784 fn foo(arg: [*]c_ushort) u16 {
785 return arg[0];
786 }
787 fn doTheTest() void {
788 var x = [_]u16{ 4, 2, 1, 3 };
789 expect(foo(@ptrCast([*]u16, &x)) == 4);
790 }
791 };
792 S.doTheTest();
793}
test/stage1/behavior/vector.zig+27
......@@ -1,6 +1,7 @@
11const std = @import("std");
22const mem = std.mem;
33const expect = std.testing.expect;
4const expectEqual = std.testing.expectEqual;
45const builtin = @import("builtin");
56
67test "implicit cast vector to array - bool" {
......@@ -250,3 +251,29 @@ test "initialize vector which is a struct field" {
250251 S.doTheTest();
251252 comptime S.doTheTest();
252253}
254
255test "vector comparison operators" {
256 const S = struct {
257 fn doTheTest() void {
258 {
259 const v1: @Vector(4, bool) = [_]bool{ true, false, true, false };
260 const v2: @Vector(4, bool) = [_]bool{ false, true, false, true };
261 expectEqual(@splat(4, true), v1 == v1);
262 expectEqual(@splat(4, false), v1 == v2);
263 expectEqual(@splat(4, true), v1 != v2);
264 expectEqual(@splat(4, false), v2 != v2);
265 }
266 {
267 const v1 = @splat(4, @as(u32, 0xc0ffeeee));
268 const v2: @Vector(4, c_uint) = v1;
269 const v3 = @splat(4, @as(u32, 0xdeadbeef));
270 expectEqual(@splat(4, true), v1 == v2);
271 expectEqual(@splat(4, false), v1 == v3);
272 expectEqual(@splat(4, true), v1 != v3);
273 expectEqual(@splat(4, false), v1 != v2);
274 }
275 }
276 };
277 S.doTheTest();
278 comptime S.doTheTest();
279}
test/translate_c.zig+12
......@@ -621,9 +621,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
621621 cases.add("float suffixes",
622622 \\#define foo 3.14f
623623 \\#define bar 16.e-2l
624 \\#define FOO 0.12345
625 \\#define BAR .12345
624626 , &[_][]const u8{
625627 "pub const foo = @as(f32, 3.14);",
626628 "pub const bar = @as(c_longdouble, 16.e-2);",
629 "pub const FOO = 0.12345;",
630 "pub const BAR = 0.12345;",
627631 });
628632
629633 cases.add("comments",
......@@ -1358,12 +1362,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
13581362 cases.add("basic macro function",
13591363 \\extern int c;
13601364 \\#define BASIC(c) (c*2)
1365 \\#define FOO(L,b) (L + b)
13611366 , &[_][]const u8{
13621367 \\pub extern var c: c_int;
13631368 ,
13641369 \\pub inline fn BASIC(c_1: var) @TypeOf(c_1 * 2) {
13651370 \\ return c_1 * 2;
13661371 \\}
1372 ,
1373 \\pub inline fn FOO(L: var, b: var) @TypeOf(L + b) {
1374 \\ return L + b;
1375 \\}
13671376 });
13681377
13691378 cases.add("macro defines string literal with hex",
......@@ -2529,10 +2538,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
25292538
25302539 cases.add("macro cast",
25312540 \\#define FOO(bar) baz((void *)(baz))
2541 \\#define BAR (void*) a
25322542 , &[_][]const u8{
25332543 \\pub inline fn FOO(bar: var) @TypeOf(baz(if (@typeId(@TypeOf(baz)) == .Pointer) @ptrCast(*c_void, baz) else if (@typeId(@TypeOf(baz)) == .Int) @intToPtr(*c_void, baz) else @as(*c_void, baz))) {
25342544 \\ return baz(if (@typeId(@TypeOf(baz)) == .Pointer) @ptrCast(*c_void, baz) else if (@typeId(@TypeOf(baz)) == .Int) @intToPtr(*c_void, baz) else @as(*c_void, baz));
25352545 \\}
2546 ,
2547 \\pub const BAR = if (@typeId(@TypeOf(a)) == .Pointer) @ptrCast(*c_void, a) else if (@typeId(@TypeOf(a)) == .Int) @intToPtr(*c_void, a) else @as(*c_void, a);
25362548 });
25372549
25382550 cases.add("macro conditional operator",