0
Fork 0
mirror of https://codeberg.org/ziglang/zig synced 2026-11-18 07:05:05 +00:00
zig/lib/std
Andrew Kelley aef3e534f5 stage2: *WIP*: rework ZIR memory layout; overhaul source locations
The memory layout for ZIR instructions is completely reworked. See
zir.zig for those changes. Some new types:

 * `zir.Code`: a "finished" set of ZIR instructions. Instead of allocating
   each instruction independently, there is now a Tag and 8 bytes of
   data available for all ZIR instructions. Small instructions fit
   within these 8 bytes; larger ones use 4 bytes for an index into
   `extra`. There is also `string_bytes` so that we can have 4 byte
   references to strings. `zir.Inst.Tag` describes how to interpret
   those 8 bytes of data.
   - This is shared by all `Block` scopes.

 * `Module.WipZirCode`: represents an in-progress `zir.Code`. In this
   structure, the arrays are mutable, and get resized as we add/delete
   things. There is extra state to keep track of things. This struct is
   stored on the stack. Once it is finished, it produces an immutable
   `zir.Code`, which will remain on the heap for the duration of a
   function's existence.
   - This is shared by all `GenZir` scopes.

 * `Sema`: represents in-progress semantic analysis of a `zir.Code`.
   This data is stored on the stack and is shared among all `Block`
   scopes. It is now the main "self" argument to everything in the file
   that was previously named `zir_sema.zig`.
   Additionally, I moved some logic that was in `Module` into here.

`Module.Fn` now stores its parameter names inside the `zir.Code`,
instead of inside ZIR instructions. When the TZIR memory layout
reworking time comes, codegen will be able to reference this data
directly instead of duplicating it.

astgen.zig is (so far) almost entirely untouched, but nearly all of it
will need to be reworked to adhere to this new memory layout structure.

I have no benchmarks to report yet, as I am still working through
compile errors and fixing various things that I broke in this branch.

Overhaul of Source Locations:

Previously we used `usize` everywhere to mean byte offset, but sometimes
also mean other stuff. This was error prone and also made us do
unnecessary work, and store unnecessary bytes in memory.

Now there are more types involved into source locations, and more ways
to describe a source location.

 * AllErrors.Message: embrace the assumption that files always have less
   than 2 << 32 bytes.
 * SrcLoc gets more complicated, to model more complicated source
   locations.
 * Introduce LazySrcLoc, which can model interesting source locations
   with very little stored state. Useful for avoiding doing unnecessary
   work when no compile errors occur.

Also, previously, we had `src: usize` on every ZIR instruction. This is
no longer the case. Each instruction now determines whether it even cares
about source location, and if so, how that source location is stored.
This requires more careful work inside `Sema`, but it results in fewer
bytes stored on the heap, without compromising accuracy and power of
compile error messages.

Miscellaneous:

 * std.zig: string literals have more helpful result values for
   reporting errors. There is now a lower level API and a higher level
   API.
   - side note: I noticed that the string literal logic needs some love.
     There is some unnecessarily hacky code there.
 * cut & pasted some TZIR logic that was in zir.zig to ir.zig. This
   probably broke stuff and needs to get fixed.
 * Removed type/Enum.zig, type/Union.zig, and type/Struct.zig. I don't
   think this quite how this code will be organized. Need some more
   careful planning about how to implement structs, unions, enums. They
   need to be independent Decls, just like a top level function.
History 2021-03-16 00:03:22 -07:00
..
atomic std: Swap arguments in Thread.spawn 2021-02-28 14:03:19 +01:00
build Merge pull request #7763 from kivikakk/zig-elf-parse 2021-03-04 11:56:31 -08:00
c translate-c: fix c tokenizer giving invalid tokens 2021-03-03 11:33:14 -08:00
compress Convert inline fn to callconv(.Inline) everywhere 2021-02-10 20:06:12 -07:00
crypto Use a unified error set for std/crypto/* 2021-03-14 20:51:31 +01:00
event std: Swap arguments in Thread.spawn 2021-02-28 14:03:19 +01:00
fmt Reject bare +/- input when parsing floats 2021-03-05 13:11:20 +01:00
fs zig fmt the std lib 2021-03-01 20:04:28 -07:00
hash Convert inline fn to callconv(.Inline) everywhere 2021-02-10 20:06:12 -07:00
heap std.GeneralPurposeAllocator: logging improvements 2021-01-30 20:15:26 -07:00
io make std.c.getErrno() return same type as _errno() aka c_int 2021-03-12 15:04:36 +01:00
json HashMap.put returns !void, not a !bool 2021-02-27 13:11:47 +02:00
math replace ArrayList.shrinkAndFree by ArrayList.shrinkRetainingCapacity 2021-02-21 11:56:14 +02:00
mem std: Clear old memory on free 2021-02-25 22:20:30 +02:00
meta zig fmt the std lib 2021-02-24 21:29:23 -07:00
net std: Swap arguments in Thread.spawn 2021-02-28 14:03:19 +01:00
os std: Replace testing fns for floating-point values 2021-03-14 17:23:47 -04:00
rand std: disable a couple tests on windows 2021-01-02 12:21:19 -07:00
special std/special: init-exe,lib make import(std) its own decl (#8160) 2021-03-05 19:13:05 -08:00
target target: map zig ppc32 → llvm ppc 2021-02-04 14:22:38 -08:00
testing Year++ 2020-12-31 15:45:24 -08:00
Thread std: Swap arguments in Thread.spawn 2021-02-28 14:03:19 +01:00
time Year++ 2020-12-31 15:45:24 -08:00
unicode Reduce use of deprecated IO types 2021-01-07 23:48:58 -08:00
valgrind Year++ 2020-12-31 15:45:24 -08:00
zig stage2: *WIP*: rework ZIR memory layout; overhaul source locations 2021-03-16 00:03:22 -07:00
array_hash_map.zig zig fmt the std lib 2021-02-24 21:29:23 -07:00
array_list.zig Remove deprecated stream aliases 2021-01-08 16:54:56 -05:00
ascii.zig std.ascii: add lessThanIgnoreCase and orderIgnoreCase 2021-02-27 01:21:01 -07:00
atomic.zig Year++ 2020-12-31 15:45:24 -08:00
base64.zig zig fmt the std lib 2021-02-24 21:29:23 -07:00
bit_set.zig zig fmt the std lib 2021-03-01 20:04:28 -07:00
buf_map.zig Year++ 2020-12-31 15:45:24 -08:00
buf_set.zig HashMap.put returns !void, not a !bool 2021-02-27 13:11:47 +02:00
build.zig HashMap.put returns !void, not a !bool 2021-02-27 13:11:47 +02:00
builtin.zig stage1: switch from inline fn to callconv(.Inline) 2021-02-10 20:06:13 -07:00
c.zig std: support optional getaddrinfo arguments 2021-03-16 01:10:32 +01:00
child_process.zig Reduce use of deprecated IO types 2021-01-07 23:48:58 -08:00
coff.zig zig fmt the std lib 2021-02-24 21:29:23 -07:00
compress.zig std: Update test "" to test where it makes sense 2021-01-22 15:46:58 +01:00
comptime_string_map.zig Year++ 2020-12-31 15:45:24 -08:00
crypto.zig Use a unified error set for std/crypto/* 2021-03-14 20:51:31 +01:00
cstr.zig Year++ 2020-12-31 15:45:24 -08:00
debug.zig Merge pull request #7946 from koachan/sparc64-framefixes 2021-03-01 19:10:36 -08:00
dwarf.zig zig fmt the std lib 2021-02-24 21:29:23 -07:00
dwarf_bits.zig Year++ 2020-12-31 15:45:24 -08:00
dynamic_library.zig Year++ 2020-12-31 15:45:24 -08:00
elf.zig elf: make EM non-exhaustive 2021-03-11 10:09:51 +11:00
event.zig Year++ 2020-12-31 15:45:24 -08:00
fifo.zig std.fifo.LinearFifo - Expose reader and writer type. 2021-02-22 00:22:46 +02:00
fmt.zig Implement fmtDuration using Formatter (#8137) 2021-03-07 15:00:15 +02:00
fs.zig initial support for haiku sync update 2021-02-25 16:41:42 -07:00
hash.zig Year++ 2020-12-31 15:45:24 -08:00
hash_map.zig stage2 cbe: non pointer optionals 2021-03-08 00:33:56 +02:00
heap.zig Year++ 2020-12-31 15:45:24 -08:00
io.zig std: remove io.AutoIndentingStream 2021-02-16 23:20:46 +01:00
json.zig HashMap.put returns !void, not a !bool 2021-02-27 13:11:47 +02:00
leb128.zig Year++ 2020-12-31 15:45:24 -08:00
linked_list.zig Fix off-by-one error in SinglyLinkedList.len() and add associated tests 2021-01-04 14:03:21 -08:00
log.zig zig fmt the std lib 2021-02-24 21:29:23 -07:00
macho.zig macho: add arm64 relocation type enum 2021-01-26 08:11:31 +01:00
math.zig zig fmt the std lib 2021-03-01 20:04:28 -07:00
mem.zig std: Prevent null pointer deref in mem.len{,Z} 2021-03-07 14:58:45 +02:00
meta.zig add tests 2021-03-05 21:21:23 +01:00
multi_array_list.zig std: Handle empty MultiArrayList in items() 2021-03-12 00:17:35 +01:00
net.zig replace ArrayList.shrinkAndFree by ArrayList.shrinkRetainingCapacity 2021-02-21 11:56:14 +02:00
once.zig std: Swap arguments in Thread.spawn 2021-02-28 14:03:19 +01:00
os.zig make std.c.getErrno() return same type as _errno() aka c_int 2021-03-12 15:04:36 +01:00
packed_int_array.zig Add workaround in PackedIntArray .initAllTo for #7635 2021-01-02 01:10:47 +11:00
pdb.zig Don't read more bytes than exist in MsfStream (#7839) 2021-02-01 15:27:39 -05:00
priority_queue.zig HashMap.put returns !void, not a !bool 2021-02-27 13:11:47 +02:00
process.zig initial support for haiku continue clean up 2021-02-25 16:41:42 -07:00
Progress.zig std: Use more common escape sequences in Progress 2021-03-12 19:31:59 -05:00
rand.zig std: Update test "" to test where it makes sense 2021-01-22 15:46:58 +01:00
SemanticVersion.zig Move fmt.testFmt to testing.expectFmt 2021-01-12 18:13:29 -08:00
sort.zig Fix example code in comments for asc and desc 2021-01-06 15:53:53 -08:00
start.zig Convert inline fn to callconv(.Inline) everywhere 2021-02-10 20:06:12 -07:00
start_windows_tls.zig Year++ 2020-12-31 15:45:24 -08:00
std.zig Add some bit set variants 2021-03-01 18:52:15 -08:00
target.zig haiku: minor fixups 2021-02-25 16:54:32 -07:00
testing.zig std: Replace testing fns for floating-point values 2021-03-14 17:23:47 -04:00
Thread.zig make std.c.getErrno() return same type as _errno() aka c_int 2021-03-12 15:04:36 +01:00
time.zig Year++ 2020-12-31 15:45:24 -08:00
unicode.zig Year++ 2020-12-31 15:45:24 -08:00
valgrind.zig std: Update test "" to test where it makes sense 2021-01-22 15:46:58 +01:00
wasm.zig Ensure function indices are correct and fix a memory leak 2021-02-05 18:06:25 +01:00
zig.zig stage2: *WIP*: rework ZIR memory layout; overhaul source locations 2021-03-16 00:03:22 -07:00