diff --git a/doc/langref.html.in b/doc/langref.html.in index dbdeb0fb42..edafc82ab8 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -9363,7 +9363,7 @@ pub fn main() !void { Finally, if none of the above apply, you need a general purpose allocator. Zig's general purpose allocator is available as a function that takes a {#link|comptime#} {#link|struct#} of configuration options and returns a type. - Generally, you will set up one {#syntax#}std.heap.GeneralPurposeAllocator#{endsyntax#} in + Generally, you will set up one {#syntax#}std.heap.GeneralPurposeAllocator{#endsyntax#} in your main function, and then pass it or sub-allocators around to various parts of your application. diff --git a/lib/std/heap/general_purpose_allocator.zig b/lib/std/heap/general_purpose_allocator.zig index 5369560356..27f2d10586 100644 --- a/lib/std/heap/general_purpose_allocator.zig +++ b/lib/std/heap/general_purpose_allocator.zig @@ -102,8 +102,22 @@ const StackTrace = std.builtin.StackTrace; /// Integer type for pointing to slots in a small allocation const SlotIndex = std.meta.Int(false, math.log2(page_size) + 1); -// WebAssembly doesn't support stack tracing yet. -const default_stack_trace_frames: usize = if (std.Target.current.cpu.arch.isWasm()) 0 else 4; +const sys_can_stack_trace = switch (std.Target.current.cpu.arch) { + // Observed to go into an infinite loop. + // TODO: Make this work. + .mips, + .mipsel, + => false, + + // `@returnAddress()` in LLVM 10 gives + // "Non-Emscripten WebAssembly hasn't implemented __builtin_return_address". + .wasm32, + .wasm64, + => std.Target.current.os.tag == .emscripten, + + else => true, +}; +const default_stack_trace_frames: usize = if (sys_can_stack_trace) 4 else 0; pub const Config = struct { /// Number of stack frames to capture.