| author | |
| committer | |
| log | 7360be19a461175d1a50dfb1d7c086bcc650b3c1 |
| tree | e2c3d5c04b48c4c14597e9ffc1cd4b6152067756 |
| parent | 84bf7a6701d5f51a8307736d310d4049c9158921 |
In main, now this allocator is chosen by default when compiling without
libc in ReleaseFast or ReleaseSmall, and not targeting WebAssembly.4 files changed, 23 insertions(+), 22 deletions(-)
bootstrap.c+1-1| ... | ... | @@ -139,7 +139,7 @@ int main(int argc, char **argv) { |
| 139 | 139 | "pub const enable_tracy = false;\n" |
| 140 | 140 | "pub const value_tracing = false;\n" |
| 141 | 141 | "pub const skip_non_native = false;\n" |
| 142 | "pub const force_gpa = false;\n" | |
| 142 | "pub const debug_gpa = false;\n" | |
| 143 | 143 | "pub const dev = .core;\n" |
| 144 | 144 | "pub const value_interpret_mode = .direct;\n" |
| 145 | 145 | , zig_version); |
build.zig+3-3| ... | ... | @@ -171,7 +171,7 @@ pub fn build(b: *std.Build) !void { |
| 171 | 171 | const tracy_callstack = b.option(bool, "tracy-callstack", "Include callstack information with Tracy data. Does nothing if -Dtracy is not provided") orelse (tracy != null); |
| 172 | 172 | const tracy_allocation = b.option(bool, "tracy-allocation", "Include allocation information with Tracy data. Does nothing if -Dtracy is not provided") orelse (tracy != null); |
| 173 | 173 | const tracy_callstack_depth: u32 = b.option(u32, "tracy-callstack-depth", "Declare callstack depth for Tracy data. Does nothing if -Dtracy_callstack is not provided") orelse 10; |
| 174 | const force_gpa = b.option(bool, "force-gpa", "Force the compiler to use GeneralPurposeAllocator") orelse false; | |
| 174 | const debug_gpa = b.option(bool, "debug-allocator", "Force the compiler to use DebugAllocator") orelse false; | |
| 175 | 175 | const link_libc = b.option(bool, "force-link-libc", "Force self-hosted compiler to link libc") orelse (enable_llvm or only_c); |
| 176 | 176 | const sanitize_thread = b.option(bool, "sanitize-thread", "Enable thread-sanitization") orelse false; |
| 177 | 177 | const strip = b.option(bool, "strip", "Omit debug information"); |
| ... | ... | @@ -233,7 +233,7 @@ pub fn build(b: *std.Build) !void { |
| 233 | 233 | exe_options.addOption(bool, "llvm_has_csky", llvm_has_csky); |
| 234 | 234 | exe_options.addOption(bool, "llvm_has_arc", llvm_has_arc); |
| 235 | 235 | exe_options.addOption(bool, "llvm_has_xtensa", llvm_has_xtensa); |
| 236 | exe_options.addOption(bool, "force_gpa", force_gpa); | |
| 236 | exe_options.addOption(bool, "debug_gpa", debug_gpa); | |
| 237 | 237 | exe_options.addOption(DevEnv, "dev", b.option(DevEnv, "dev", "Build a compiler with a reduced feature set for development of specific features") orelse if (only_c) .bootstrap else .full); |
| 238 | 238 | exe_options.addOption(ValueInterpretMode, "value_interpret_mode", value_interpret_mode); |
| 239 | 239 | |
| ... | ... | @@ -608,7 +608,7 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void { |
| 608 | 608 | |
| 609 | 609 | exe_options.addOption(u32, "mem_leak_frames", 0); |
| 610 | 610 | exe_options.addOption(bool, "have_llvm", false); |
| 611 | exe_options.addOption(bool, "force_gpa", false); | |
| 611 | exe_options.addOption(bool, "debug_gpa", false); | |
| 612 | 612 | exe_options.addOption([:0]const u8, "version", version); |
| 613 | 613 | exe_options.addOption(std.SemanticVersion, "semver", semver); |
| 614 | 614 | exe_options.addOption(bool, "enable_debug_extensions", false); |
src/main.zig+18-17| ... | ... | @@ -171,30 +171,31 @@ pub fn log( |
| 171 | 171 | std.debug.print(prefix1 ++ prefix2 ++ format ++ "\n", args); |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{ | |
| 174 | var debug_allocator: std.heap.DebugAllocator(.{ | |
| 175 | 175 | .stack_trace_frames = build_options.mem_leak_frames, |
| 176 | }){}; | |
| 176 | }) = .init; | |
| 177 | 177 | |
| 178 | 178 | pub fn main() anyerror!void { |
| 179 | 179 | crash_report.initialize(); |
| 180 | 180 | |
| 181 | const use_gpa = (build_options.force_gpa or !builtin.link_libc) and native_os != .wasi; | |
| 182 | const gpa = gpa: { | |
| 183 | if (native_os == .wasi) { | |
| 184 | break :gpa std.heap.wasm_allocator; | |
| 185 | } | |
| 186 | if (use_gpa) { | |
| 187 | break :gpa general_purpose_allocator.allocator(); | |
| 188 | } | |
| 189 | // We would prefer to use raw libc allocator here, but cannot | |
| 190 | // use it if it won't support the alignment we need. | |
| 191 | if (@alignOf(std.c.max_align_t) < @max(@alignOf(i128), std.atomic.cache_line)) { | |
| 192 | break :gpa std.heap.c_allocator; | |
| 181 | const gpa, const is_debug = gpa: { | |
| 182 | if (build_options.debug_gpa) break :gpa .{ debug_allocator.allocator(), true }; | |
| 183 | if (native_os == .wasi) break :gpa .{ std.heap.wasm_allocator, false }; | |
| 184 | if (builtin.link_libc) { | |
| 185 | // We would prefer to use raw libc allocator here, but cannot use | |
| 186 | // it if it won't support the alignment we need. | |
| 187 | if (@alignOf(std.c.max_align_t) < @max(@alignOf(i128), std.atomic.cache_line)) { | |
| 188 | break :gpa .{ std.heap.c_allocator, false }; | |
| 189 | } | |
| 190 | break :gpa .{ std.heap.raw_c_allocator, false }; | |
| 193 | 191 | } |
| 194 | break :gpa std.heap.raw_c_allocator; | |
| 192 | break :gpa switch (builtin.mode) { | |
| 193 | .Debug, .ReleaseSafe => .{ debug_allocator.allocator(), true }, | |
| 194 | .ReleaseFast, .ReleaseSmall => .{ std.heap.smp_allocator, false }, | |
| 195 | }; | |
| 195 | 196 | }; |
| 196 | defer if (use_gpa) { | |
| 197 | _ = general_purpose_allocator.deinit(); | |
| 197 | defer if (is_debug) { | |
| 198 | _ = debug_allocator.deinit(); | |
| 198 | 199 | }; |
| 199 | 200 | var arena_instance = std.heap.ArenaAllocator.init(gpa); |
| 200 | 201 | defer arena_instance.deinit(); |
stage1/config.zig.in+1-1| ... | ... | @@ -11,6 +11,6 @@ pub const enable_link_snapshots = false; |
| 11 | 11 | pub const enable_tracy = false; |
| 12 | 12 | pub const value_tracing = false; |
| 13 | 13 | pub const skip_non_native = false; |
| 14 | pub const force_gpa = false; | |
| 14 | pub const debug_gpa = false; | |
| 15 | 15 | pub const dev = .core; |
| 16 | 16 | pub const value_interpret_mode = .direct; |