aboutsummaryrefslogtreecommitdiff
path: root/src/codegen.zig
AgeCommit message (Collapse)Author
2023-11-12x86_64: resolve tlv references on first use and spill to the stackJacob Young
This avoids any arbitrary memory operand possibly clobbering rax and sometime rdi with no warning.
2023-11-12elf: set symbol flags such as needs_zig_got in ZigObjectJakub Konka
2023-11-04Merge pull request #17844 from ziglang/elf-objectJakub Konka
elf: handle emitting relocatables and static libraries - humble beginnings
2023-11-04elf: postpone creation of .got.zig entry until code emitJakub Konka
2023-11-04elf: make sure we never emit .got.zig relocs when linking object filesJakub Konka
2023-11-03x86_64: fix std test failuresJacob Young
2023-10-30elf: move incremental codegen bits into ZigObject.zigJakub Konka
2023-10-30elf: rename ZigModule to ZigObjectJakub Konka
2023-10-30coff: implement enough of extern handling to pass comptime export testsJakub Konka
2023-10-30macho: implement enough of extern handling to pass comptime export testsJakub Konka
2023-10-28x86_64: no more load/lea_symbol weirdnessJakub Konka
2023-10-28elf: set needs_got on generated extern varsJakub Konka
2023-10-28x86_64: rename load/lea_memory to load/lea_symbolJakub Konka
2023-10-28x86_64: do not hardcode memory passed by Elf linkerJakub Konka
2023-10-25x86_64: pass more testsJacob Young
* 128-bit integer multiplication with overflow * more instruction encodings used by std inline asm * implement the `try_ptr` air instruction * follow correct stack frame abi * enable full panic handler * enable stack traces
2023-10-24InternPool: remove runtime_value representationmlugg
The main goal of this commit is to remove the `runtime_value` field from `InternPool.Key` (and its associated representation), but there are a few dominos. Specifically, this mostly eliminates the "maybe runtime" concept from value resolution in Sema: so some resolution functions like `resolveMaybeUndefValAllowVariablesMaybeRuntime` are gone. This required a small change to struct/union/array initializers, to no longer use `runtime_value` if a field was a `variable` - I'm not convinced this case was even reachable, as `variable` should only ever exist as the trivial value of a global runtime `var` decl. Now, the only case in which a `Sema.resolveMaybeUndefVal`-esque function can return the `variable` key is `resolveMaybeUndefValAllowVariables`, which is directly called from `Sema.resolveInstValueAllowVariables` (previously `Sema.resolveInstValue`), which is only used for resolving the value of a Decl from `Module.semaDecl`. While changing these functions, I also slightly reordered and restructured some of them, and updated their doc comments.
2023-10-23Merge pull request #17651 from Vexu/error-limitAndrew Kelley
Make distinct error limit configurable (attempt #2)
2023-10-22Revert "Revert "Merge pull request #17637 from jacobly0/x86_64-test-std""Jacob Young
This reverts commit 6f0198cadbe29294f2bf3153a27beebd64377566.
2023-10-22Revert "Merge pull request #17637 from jacobly0/x86_64-test-std"Andrew Kelley
This reverts commit 0c99ba1eab63865592bb084feb271cd4e4b0357e, reversing changes made to 5f92b070bf284f1493b1b5d433dd3adde2f46727. This caused a CI failure when it landed in master branch due to a 128-bit `@byteSwap` in std.mem.
2023-10-22Merge pull request #17637 from jacobly0/x86_64-test-stdJacob Young
x86_64: start to enable `test-std` and `test-compiler-rt` testing
2023-10-22remove uses of non-configurable `err_int`Veikka Tuominen
2023-10-21codegen: implement lowering aligned anon declsJacob Young
2023-10-21InternPool: store alignment of anon declsAndrew Kelley
Commit 5393e56500d499753dbc39704c0161b47d1e4d5c has a flaw pointed out by @mlugg: the `ty` field of pointer values changes when comptime values are pointer-casted. This commit introduces a new encoding which additionally stores the "original pointer type" which is used to store the alignment of the anonymous decl, and potentially other information in the future such as section and pointer address space. However, this new encoding is only used when the original pointer type differs from the casted pointer type in a meaningful way. I was able to make the LLVM backend and the C backend lower anonymous decls with the appropriate alignment, however I will need some help figuring out how to do this for the backends that lower anonymous decls via src/codegen.zig and the wasm backend.
2023-10-21x86_64: disable difficult std tests and hack around more zero-bit typesJacob Young
2023-10-16codegen: refactor .actual_got into .extern_gotJakub Konka
2023-10-16codegen+elf: check if extern is a variable refJakub Konka
2023-10-16codegen+elf: lower imported data refsJakub Konka
2023-10-16x86_64: add -fPIC support targeting ELFJakub Konka
2023-10-16elf: create new synthetic section ZigGotSectionJakub Konka
2023-10-05plan9: refactor debug infoJacob Young
The main goal is to stop depending on `emit.lower.target`.
2023-10-03codegen: separate getAnonDeclVAddr into lowerAnonDecl and the formerJakub Konka
Implement the stub for Elf. I believe that separating the concerns, namely, having an interface function that is responsible for signalling the linker to lower the anon decl only, and a separate function to obtain the decl's vaddr is preferable since it allows us to handle codegen errors in a simpler way.
2023-10-03link: stub out getAnonDeclVAddrAndrew Kelley
2023-10-03compiler: start handling anonymous decls differentlyAndrew Kelley
Instead of explicitly creating a `Module.Decl` object for each anonymous declaration, each `InternPool.Index` value is implicitly understood to be an anonymous declaration when encountered by backend codegen. The memory management strategy for these anonymous decls then becomes to garbage collect them along with standard InternPool garbage. In the interest of a smooth transition, this commit only implements this new scheme for string literals and leaves all the previous mechanisms in place.
2023-09-23codegen/sema: handle unions with unknown tags in more placeskcbanner
2023-09-23sema: rework the comptime representation of comptime unionskcbanner
When the tag is not known, it's set to `.none`. In this case, the value is either an array of bytes (for extern unions) or an integer (for packed unions).
2023-09-23sema: add support for unions in readFromMemory and writeToMemorykcbanner
2023-09-21compiler: fix compilation for 32-bit targetsAndrew Kelley
2023-09-21compiler: move struct types into InternPool properAndrew Kelley
Structs were previously using `SegmentedList` to be given indexes, but were not actually backed by the InternPool arrays. After this, the only remaining uses of `SegmentedList` in the compiler are `Module.Decl` and `Module.Namespace`. Once those last two are migrated to become backed by InternPool arrays as well, we can introduce state serialization via writing these arrays to disk all at once. Unfortunately there are a lot of source code locations that touch the struct type API, so this commit is still work-in-progress. Once I get it compiling and passing the test suite, I can provide some interesting data points such as how it affected the InternPool memory size and performance comparison against master branch. I also couldn't resist migrating over a bunch of alignment API over to use the log2 Alignment type rather than a mismash of u32 and u64 byte units with 0 meaning something implicitly different and special at every location. Turns out you can do all the math you need directly on the log2 representation of alignments.
2023-09-13elf: do not store Symbol's index in SymbolJakub Konka
2023-09-13Merge pull request #17113 from ziglang/elf-linkerJakub Konka
elf: upstream zld/ELF functionality, part 1
2023-09-12InternPool: prevent anon struct UAF bugs with type safetyAndrew Kelley
Instead of using actual slices for InternPool.Key.AnonStructType, this commit changes to use Slice types instead, which store a long-lived index rather than a pointer. This is a follow-up to 7ef1eb1c27754cb0349fdc10db1f02ff2dddd99b.
2023-09-12elf: add simplistic reloc scanning mechanismJakub Konka
2023-09-08elf: store GOT index in symbol extra array; use GotSection for GOTJakub Konka
2023-09-06elf: make everything upside down - track by Symbol.Index rather than Atom.IndexJakub Konka
2023-09-04elf: simplify accessors to symbols, atoms, etcJakub Konka
2023-08-22compiler: move unions into InternPoolAndrew Kelley
There are a couple concepts here worth understanding: Key.UnionType - This type is available *before* resolving the union's fields. The enum tag type, number of fields, and field names, field types, and field alignments are not available with this. InternPool.UnionType - This one can be obtained from the above type with `InternPool.loadUnionType` which asserts that the union's enum tag type has been resolved. This one has all the information available. Additionally: * ZIR: Turn an unused bit into `any_aligned_fields` flag to help semantic analysis know whether a union has explicit alignment on any fields (usually not). * Sema: delete `resolveTypeRequiresComptime` which had the same type signature and near-duplicate logic to `typeRequiresComptime`. - Make opaque types not report comptime-only (this was inconsistent between the two implementations of this function). * Implement accepted proposal #12556 which is a breaking change.
2023-07-31Fix integer overflow in field padding calculationantlilja
The old code was iterating and generating symbols for fields in their declared order instead of the memory optimized order while getting offsets in the memory optimized order.
2023-07-21codegen: writer().writeByteNTimes -> appendNTimesr00ster91
Both ways do the same thing but I think the compiler might have an easier time optimizing `appendNTimes` because it does less things/the path is shorter. I have not done any benchmarking at runtime but have compared the instruction count of both ways a little here: https://zig.godbolt.org/z/vr193W9oj `b` (`appendNTimes`) is ~103 instructions while `a` (`writer().writeByteNTimes`) is ~117 instructions. And looking at the implementation of `writeByteNTimes`, it only seems to buffer up 256 bytes before doing another `writeAll` which for `std.ArrayList` probably means another allocation, whereas when directly using `appendNTimes`, the entire exact additional capacity required is known from the start. Either way, this would be more consistent anyway.
2023-07-18rework generic function callsAndrew Kelley
Abridged summary: * Move `Module.Fn` into `InternPool`. * Delete a lot of confusing and problematic `Sema` logic related to generic function calls. This commit removes `Module.Fn` and replaces it with two new `InternPool.Tag` values: * `func_decl` - corresponding to a function declared in the source code. This one contains line/column numbers, zir_body_inst, etc. * `func_instance` - one for each monomorphization of a generic function. Contains a reference to the `func_decl` from whence the instantiation came, along with the `comptime` parameter values (or types in the case of `anytype`) Since `InternPool` provides deduplication on these values, these fields are now deleted from `Module`: * `monomorphed_func_keys` * `monomorphed_funcs` * `align_stack_fns` Instead of these, Sema logic for generic function instantiation now unconditionally evaluates the function prototype expression for every generic callsite. This is technically required in order for type coercions to work. The previous code had some dubious, probably wrong hacks to make things work, such as `hashUncoerced`. I'm not 100% sure how we were able to eliminate that function and still pass all the behavior tests, but I'm pretty sure things were still broken without doing type coercion for every generic function call argument. After the function prototype is evaluated, it produces a deduplicated `func_instance` `InternPool.Index` which can then be used for the generic function call. Some other nice things made by this simplification are the removal of `comptime_args_fn_inst` and `preallocated_new_func` from `Sema`, and the messy logic associated with them. I have not yet been able to measure the perf of this against master branch. On one hand, it reduces memory usage and pointer chasing of the most heavily used `InternPool` Tag - function bodies - but on the other hand, it does evaluate function prototype expressions more than before. We will soon find out.
2023-06-25x86_64: add missing padding to global unionsJacob Young