0
Fork 0
mirror of https://codeberg.org/ziglang/zig synced 2026-11-18 07:05:05 +00:00
zig/lib/std/debug.zig

2630 lines
102 KiB

2019-05-26 13:17:34 -04:00
2019-05-24 22:52:07 -04:00
2019-05-26 13:17:34 -04:00
2016-08-17 20:11:04 -07:00
2019-05-26 13:17:34 -04:00
2020-05-05 05:14:22 -06:00
2020-05-05 05:14:22 -06:00
2019-05-27 02:16:05 -04:00
2023-07-11 01:06:41 -04:00
2020-05-05 05:14:22 -06:00
2022-10-07 21:24:44 +03:30
2019-05-26 13:17:34 -04:00
2019-05-26 13:17:34 -04:00
2019-05-26 13:17:34 -04:00
2019-05-26 13:17:34 -04:00
2019-05-26 13:17:34 -04:00
2019-05-26 13:17:34 -04:00
2019-05-26 13:17:34 -04:00
2020-05-05 05:14:22 -06:00
2019-05-27 02:16:05 -04:00
2019-07-16 01:48:47 +02:00
2018-02-28 21:19:51 -05:00
2020-05-05 05:14:22 -06:00
2021-06-19 21:10:22 -04:00
2018-01-14 10:19:21 -05:00
2018-12-02 18:54:04 -05:00
2018-12-02 18:54:04 -05:00
2018-12-02 18:54:04 -05:00
compiler: preserve result type information through address-of operator This commit introduces the new `ref_coerced_ty` result type into AstGen. This represents a expression which we want to treat as an lvalue, and the pointer will be coerced to a given type. This change gives known result types to many expressions, in particular struct and array initializations. This allows certain casts to work which previously required explicitly specifying types via `@as`. It also eliminates our dependence on anonymous struct types for expressions of the form `&.{ ... }` - this paves the way for #16865, and also results in less Sema magic happening for such initializations, also leading to potentially better runtime code. As part of these changes, this commit also implements #17194 by disallowing RLS on explicitly-typed struct and array initializations. Apologies for linking these changes - it seemed rather pointless to try and separate them, since they both make big changes to struct and array initializations in AstGen. The rationale for this change can be found in the proposal - in essence, performing RLS whilst maintaining the semantics of the intermediary type is a very difficult problem to solve. This allowed the problematic `coerce_result_ptr` ZIR instruction to be completely eliminated, which in turn also simplified the logic for inferred allocations in Sema - thanks to this, we almost break even on line count! In doing this, the ZIR instructions surrounding these initializations have been restructured - some have been added and removed, and others renamed for clarity (and their semantics changed slightly). In order to optimize ZIR tag count, the `struct_init_anon_ref` and `array_init_anon_ref` instructions have been removed in favour of using `ref` on a standard anonymous value initialization, since these instructions are now virtually never used. Lastly, it's worth noting that this commit introduces a slightly strange source of generic poison types: in the expression `@as(*anyopaque, &x)`, the sub-expression `x` has a generic poison result type, despite no generic code being involved. This turns out to be a logical choice, because we don't know the result type for `x`, and the generic poison type represents precisely this case, providing the semantics we need. Resolves: #16512 Resolves: #17194
2023-09-18 14:49:18 +01:00
2018-12-02 18:54:04 -05:00
2018-07-29 23:25:40 -04:00
2018-12-02 18:54:04 -05:00
2021-02-05 00:28:07 +07:00
2020-05-13 16:21:15 +01:00
2018-12-02 18:54:04 -05:00
2018-12-02 18:54:04 -05:00
2018-12-02 18:54:04 -05:00
2023-07-11 01:06:41 -04:00
2023-07-11 01:06:41 -04:00
2023-07-11 01:06:41 -04:00
2021-02-05 00:28:07 +07:00
2018-12-02 18:54:04 -05:00
2018-07-29 23:25:40 -04:00
2018-12-02 18:54:04 -05:00
2022-10-07 21:24:44 +03:30
2018-01-14 10:19:21 -05:00
2018-09-12 14:26:21 -04:00
2018-09-12 14:26:21 -04:00
2020-02-22 11:51:45 +01:00
2020-02-21 12:11:04 +01:00
2020-02-20 20:48:54 +01:00
2020-02-09 11:55:43 +01:00
2020-02-22 12:44:21 +01:00
2020-02-22 12:44:21 +01:00
2020-05-05 05:14:22 -06:00
2020-05-05 05:14:22 -06:00
2020-10-11 08:23:36 +00:00
2020-10-12 14:29:43 +05:30
2020-02-09 11:55:43 +01:00
2020-02-10 13:18:28 +01:00
2020-05-05 05:14:22 -06:00
2023-05-04 01:35:43 -04:00
2023-05-04 01:35:43 -04:00
2023-05-04 01:35:43 -04:00
2020-02-18 13:06:17 +01:00
2020-05-05 05:14:22 -06:00
2023-05-04 01:35:43 -04:00
2020-02-20 20:18:51 +01:00
2023-05-04 01:35:43 -04:00
2023-05-04 01:35:43 -04:00
2023-06-25 02:47:48 -04:00
2023-05-04 01:35:43 -04:00
2023-05-04 01:35:43 -04:00
2018-08-25 03:07:37 -04:00
2021-06-10 18:20:18 +01:00
2020-05-29 16:39:47 -04:00
2020-02-20 20:18:51 +01:00
2020-02-22 11:51:45 +01:00
2023-05-23 15:33:12 +03:30
2020-02-22 11:51:45 +01:00
2020-02-18 12:37:25 +01:00
2020-02-20 20:18:51 +01:00
2020-02-22 11:51:45 +01:00
2017-04-24 12:01:19 -04:00
2017-04-24 12:01:19 -04:00
2017-04-24 12:01:19 -04:00
2017-04-24 12:01:19 -04:00
2017-04-24 12:01:19 -04:00
2020-06-08 16:33:35 -04:00
2021-06-19 21:10:22 -04:00
2020-05-29 16:39:47 -04:00
2020-05-05 05:14:22 -06:00
2020-02-20 20:18:51 +01:00
2020-02-20 20:18:51 +01:00
2020-02-20 20:18:51 +01:00
2020-02-09 11:55:43 +01:00
2020-02-22 11:51:45 +01:00
2020-02-09 11:55:43 +01:00
2020-02-09 11:55:43 +01:00
2020-02-22 11:51:45 +01:00
2020-02-09 11:55:43 +01:00
2020-02-09 11:55:43 +01:00
2020-02-09 11:55:43 +01:00
2020-02-09 11:55:43 +01:00
2020-02-22 11:51:45 +01:00
2020-02-22 11:51:45 +01:00
2020-02-09 11:55:43 +01:00
2020-02-22 11:51:45 +01:00
2020-02-11 09:40:21 +01:00
2020-02-11 09:40:21 +01:00
2020-02-18 12:37:25 +01:00
2020-02-18 12:37:25 +01:00
2020-02-11 09:40:21 +01:00
2020-02-18 12:37:25 +01:00
2020-02-20 20:48:54 +01:00
2020-02-11 09:40:21 +01:00
2020-02-22 11:51:45 +01:00
2020-02-18 12:37:25 +01:00
2020-02-22 11:51:45 +01:00
2020-02-10 13:18:28 +01:00
2020-02-22 12:44:21 +01:00
2020-02-10 13:18:28 +01:00
2020-02-20 20:48:54 +01:00
2020-02-10 13:18:28 +01:00
2020-02-22 11:51:45 +01:00
2020-02-18 12:37:25 +01:00
2020-02-18 12:37:25 +01:00
2020-02-09 11:55:43 +01:00
2020-02-18 12:37:25 +01:00
2021-06-19 21:10:22 -04:00
2020-02-18 12:37:25 +01:00
2020-02-18 12:37:25 +01:00
2020-02-18 12:37:25 +01:00
2020-02-18 12:37:25 +01:00
2023-06-25 02:47:48 -04:00
2023-06-25 02:47:48 -04:00
2020-02-18 12:37:25 +01:00
2020-02-18 12:37:25 +01:00
2020-02-20 20:48:54 +01:00
2020-02-20 20:18:51 +01:00
2020-02-18 12:37:25 +01:00
2020-02-09 11:55:43 +01:00
reimplement std.HashMap * breaking changes to the API. Some of the weird decisions from before are changed to what would be more expected. - `get` returns `?V`, use `getEntry` for the old API. - `put` returns `!void`, use `fetchPut` for the old API. * HashMap now has a comptime parameter of whether to store hashes with entries. AutoHashMap has heuristics on whether to set this parameter. For example, for integers, it is false, since equality checking is cheap, but for strings, it is true, since equality checking is probably expensive. * The implementation has a separate array for entry_index / distance_from_start_index. Entries no longer has holes; it is an ArrayList, and iteration is simpler and more cache coherent. This is inspired by Python's new dictionaries. * HashMap is separated into an "unmanaged" and a "managed" API. The unmanaged API is where the actual implementation is; the managed API wraps it and provides a more convenient API, storing the allocator. * Memory usage: When there are less than or equal to 8 entries, HashMap now incurs only a single pointer-size integer as overhead, opposed to using an ArrayList. * Since the entries array is separate from the indexes array, the holes in the indexes array take up less room than the holes in the entries array otherwise would. However the entries array also allocates additional capacity for appending into the array. * HashMap now maintains insertion order. Deletion performs a "swap remove". It's now possible to modify the HashMap while iterating.
2020-07-03 23:57:24 +00:00
2020-02-09 11:55:43 +01:00
2020-02-22 11:51:45 +01:00
2020-02-09 11:55:43 +01:00
2020-02-20 20:18:51 +01:00
2020-02-09 11:55:43 +01:00
2020-02-22 12:44:21 +01:00
2020-02-09 11:55:43 +01:00
2021-06-19 21:10:22 -04:00
2020-02-09 11:55:43 +01:00
2020-10-12 14:29:43 +05:30
2020-02-11 09:40:21 +01:00
2020-02-22 11:51:45 +01:00
2020-02-22 11:51:45 +01:00
2020-05-29 16:39:47 -04:00
2020-02-22 11:51:45 +01:00
2020-02-22 11:51:45 +01:00
2020-02-22 11:51:45 +01:00
2020-02-22 11:51:45 +01:00
2020-02-22 11:51:45 +01:00
2020-02-22 11:51:45 +01:00
2020-02-22 11:51:45 +01:00
2020-02-22 11:51:45 +01:00
2020-02-22 11:51:45 +01:00
2020-05-05 05:14:22 -06:00
2020-02-22 11:51:45 +01:00
2020-02-22 11:51:45 +01:00
2020-02-22 11:51:45 +01:00
2019-05-26 13:17:34 -04:00
2020-02-10 13:18:28 +01:00
2020-02-22 12:05:50 +01:00
2020-02-22 12:05:50 +01:00
2020-02-22 12:05:50 +01:00
2020-02-22 12:05:50 +01:00
2020-02-22 12:05:50 +01:00
2020-02-22 12:05:50 +01:00
2020-02-22 12:05:50 +01:00
2020-02-22 12:05:50 +01:00
2020-02-09 11:55:43 +01:00
2020-02-21 12:11:04 +01:00
2020-02-21 12:11:04 +01:00
2020-02-21 12:11:04 +01:00
2020-02-09 11:55:43 +01:00
2016-12-18 19:40:26 -05:00
2023-05-04 01:35:43 -04:00
2023-06-25 02:47:48 -04:00
improvements targeted at improving async functions * Reuse bytes of async function frames when non-async functions make `noasync` calls. This prevents explosive stack growth. * Zig now passes a stack size argument to the linker when linking ELF binaries. Linux ignores this value, but it is available as a program header called GNU_STACK. I prototyped some code that memory maps extra space to the stack using this program header, but there was still a problem when accessing stack memory very far down. Stack probing is needed or not working or something. I also prototyped using `@newStackCall` to call main and that does work around the issue but it also brings its own issues. That code is commented out for now in std/special/start.zig. I'm on a plane with no Internet, but I plan to consult with the musl community for advice when I get a chance. * Added `noasync` to a bunch of function calls in std.debug. It's very messy but it's a workaround that makes stack traces functional with evented I/O enabled. Eventually these will be cleaned up as the root bugs are found and fixed. Programs built in blocking mode are unaffected. * Lowered the default stack size of std.io.InStream (for the async version) to 1 MiB instead of 4. Until we figure out how to get choosing a stack size working (see 2nd bullet point above), 4 MiB tends to cause segfaults due to stack size running out, or usage of stack memory too far apart, or something like that. * Default thread stack size is bumped from 8 MiB to 16 to match the size we give for the main thread. It's planned to eventually remove this hard coded value and have Zig able to determine this value during semantic analysis, with call graph analysis and function pointer annotations and extern function annotations.
2019-09-11 20:22:49 -04:00
2020-01-29 23:15:17 +02:00
improvements targeted at improving async functions * Reuse bytes of async function frames when non-async functions make `noasync` calls. This prevents explosive stack growth. * Zig now passes a stack size argument to the linker when linking ELF binaries. Linux ignores this value, but it is available as a program header called GNU_STACK. I prototyped some code that memory maps extra space to the stack using this program header, but there was still a problem when accessing stack memory very far down. Stack probing is needed or not working or something. I also prototyped using `@newStackCall` to call main and that does work around the issue but it also brings its own issues. That code is commented out for now in std/special/start.zig. I'm on a plane with no Internet, but I plan to consult with the musl community for advice when I get a chance. * Added `noasync` to a bunch of function calls in std.debug. It's very messy but it's a workaround that makes stack traces functional with evented I/O enabled. Eventually these will be cleaned up as the root bugs are found and fixed. Programs built in blocking mode are unaffected. * Lowered the default stack size of std.io.InStream (for the async version) to 1 MiB instead of 4. Until we figure out how to get choosing a stack size working (see 2nd bullet point above), 4 MiB tends to cause segfaults due to stack size running out, or usage of stack memory too far apart, or something like that. * Default thread stack size is bumped from 8 MiB to 16 to match the size we give for the main thread. It's planned to eventually remove this hard coded value and have Zig able to determine this value during semantic analysis, with call graph analysis and function pointer annotations and extern function annotations.
2019-09-11 20:22:49 -04:00
2019-09-25 18:17:29 +03:00
2019-09-25 18:17:29 +03:00
improvements targeted at improving async functions * Reuse bytes of async function frames when non-async functions make `noasync` calls. This prevents explosive stack growth. * Zig now passes a stack size argument to the linker when linking ELF binaries. Linux ignores this value, but it is available as a program header called GNU_STACK. I prototyped some code that memory maps extra space to the stack using this program header, but there was still a problem when accessing stack memory very far down. Stack probing is needed or not working or something. I also prototyped using `@newStackCall` to call main and that does work around the issue but it also brings its own issues. That code is commented out for now in std/special/start.zig. I'm on a plane with no Internet, but I plan to consult with the musl community for advice when I get a chance. * Added `noasync` to a bunch of function calls in std.debug. It's very messy but it's a workaround that makes stack traces functional with evented I/O enabled. Eventually these will be cleaned up as the root bugs are found and fixed. Programs built in blocking mode are unaffected. * Lowered the default stack size of std.io.InStream (for the async version) to 1 MiB instead of 4. Until we figure out how to get choosing a stack size working (see 2nd bullet point above), 4 MiB tends to cause segfaults due to stack size running out, or usage of stack memory too far apart, or something like that. * Default thread stack size is bumped from 8 MiB to 16 to match the size we give for the main thread. It's planned to eventually remove this hard coded value and have Zig able to determine this value during semantic analysis, with call graph analysis and function pointer annotations and extern function annotations.
2019-09-11 20:22:49 -04:00
2022-04-21 10:14:23 +02:00
2022-04-21 10:14:23 +02:00
2022-04-21 10:14:23 +02:00
2022-04-21 10:14:23 +02:00