zig build -Dskip-install-lib-files
Measurements taken on:
- Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
- 0.10.0-dev.2381+39ebfedd2
| const std = @import("std"); | |
| var gpa_instance: std.heap.GeneralPurposeAllocator(.{}) = .{}; | |
| const global_allocator = gpa_instance.allocator(); | |
| const S = struct { | |
| comptime gpa: std.mem.Allocator = global_allocator, | |
| x: i32, | |
| }; |
| 0000000000328360 <buildOutputType>: | |
| 328360: 55 push rbp | |
| 328361: 48 89 e5 mov rbp,rsp | |
| 328364: 41 57 push r15 | |
| 328366: 41 56 push r14 | |
| 328368: 41 55 push r13 | |
| 32836a: 41 54 push r12 | |
| 32836c: 53 push rbx | |
| 32836d: 48 83 e4 e0 and rsp,0xffffffffffffffe0 | |
| 328371: 48 81 ec 60 5f 00 00 sub rsp,0x5f60 |
| --- a/src/Zir.zig | |
| +++ b/src/Zir.zig | |
| /// Trailing: | |
| /// 0. lib_name: u32, // null terminated string index, if has_lib_name is set | |
| - /// 1. cc: Ref, // if has_cc is set | |
| - /// 2. align: Ref, // if has_align is set | |
| - /// 3. return_type: Index // for each ret_body_len | |
| - /// 4. body: Index // for each body_len | |
| - /// 5. src_locs: Func.SrcLocs // if body_len != 0 | |
| - pub const ExtendedFunc = struct { |
| [nix-shell:~/Downloads/zig/build]$ ./zig fmt --ast-check ../src/ ../lib/std/ | |
| as_node: 571082 | |
| dbg_stmt: 325704 | |
| int: 266542 | |
| extended: 212003 | |
| param_type: 185337 | |
| int_big: 177048 | |
| call: 138602 | |
| field_call_bind: 105334 | |
| decl_val: 99774 |
| map: std.AutoHashMapUnmanaged(void, void), | |
| items: std.MultiArrayList(Item), | |
| extra: std.ArrayListUnmanaged(u32), | |
| strings: std.ArrayListUnmanaged(u8), | |
| const InternArena = @This(); | |
| const std = @import("std"); | |
| const Allocator = std.mem.Allocator; | |
| const KeyAdapter = struct { |
| export fn entry() bool { | |
| doTheTest() catch return false; | |
| return true; | |
| } | |
| fn doTheTest() !void { | |
| var x1: u8 = 42; | |
| const t1 = .{ x1, 56, 54 }; | |
| var arr1: [3]u8 = t1; | |
| _ = arr1[0]; |
| [14:41:12] <waddlesplash> Zig seems cool but you don't seem to be about the RAII that we love so much :-p | |
| [14:47:25] <andrewrk> anyway I won't come in here trying to convince anyone to switch languages or coding styles :) | |
| [14:47:44] <waddlesplash> in Haiku ... C++ virtual inheritance and RAII objects mean that the code can much more clearly communicate what it is trying to do at the same time it is actually doing it | |
| [14:48:02] <andrewrk> I do think that there is a misunderstanding that we don't care about RAII principles in zig though. I mean yeah you have to manually `defer cleanup();` but the coding model is the same | |
| [14:48:15] <waddlesplash> but what happens if you decide you don't want to clean something up? | |
| [14:48:21] <waddlesplash> for instance we have a very common paradigm in Haiku: | |
| [14:49:35] <waddlesplash> thing* whatever = allocate_memory_or_something(); | |
| [14:49:35] <waddlesplash> MemoryDeleter<thing> whateverDeleter(whatever); | |
| [14:49:36] <waddlesplash> if (error) return error; /* whatever is delete |
I have an object file created by LLVM:
$ readelf -s test.o
Symbol table '.symtab' contains 8 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
1: 0000000000000000 0 FILE LOCAL DEFAULT ABS test
2: 0000000000000010 22 FUNC LOCAL DEFAULT 2 start.callMain2
| const std = @import("std"); | |
| const expect = std.testing.expect; | |
| test "example" { | |
| var x: usize = 0; | |
| x += checkSize(i32); | |
| x += checkSize(bool); | |
| try expect(x == 5); | |
| } |