Commit Graph

13589 Commits

Author SHA1 Message Date
Andrew Kelley 46af8bd2ba resinator: use ArrayList instead of BoundedArray
In this case it improved maintainability because magic number `4` is no
longer repeated 3 times, and there is no longer a redundant branch in
the loop.
2023-11-22 11:33:34 -07:00
Andrew Kelley d5e21a4f1a std: remove meta.trait
In general, I don't like the idea of std.meta.trait, and so I am
providing some guidance by deleting the entire namespace from the
standard library and compiler codebase.

My main criticism is that it's overcomplicated machinery that bloats
compile times and is ultimately unnecessary given the existence of Zig's
strong type system and reference traces.

Users who want this can create a third party package that provides this
functionality.

closes #18051
2023-11-22 13:24:27 -05:00
Andrew Kelley 54d196bb30 Merge pull request #18057 from Vexu/fixes
Fix bad error location on field init with field access
2023-11-21 15:12:03 -05:00
Andrew Kelley be6f76655f Merge pull request #18055 from ziglang/zig-init 2023-11-21 11:59:24 -05:00
Garrett 40b8c993f5 translate-c: skip blank macros when translating defines 2023-11-21 13:54:46 +00:00
Carl Åstholm 8bf4b3c611 translate-c: translate 80/128-bit long double literals 2023-11-21 14:14:01 +02:00
Veikka Tuominen d63298da65 InternPool: handle funcZirBodyInst for func_coerced
Closes #18039
2023-11-21 13:59:14 +02:00
Veikka Tuominen a947f97331 Sema: fix bad error location on field init with field access
Closes #14753
2023-11-21 13:59:14 +02:00
Bogdan Romanyuk 583afd6f0c value: update isDeclRef for anonymous declarations 2023-11-21 13:21:32 +02:00
Andrew Kelley 9f363cd679 zig init: also create a build.zig.zon 2023-11-20 23:30:51 -07:00
Andrew Kelley f645022d16 merge zig init-exe and zig init-lib into zig init
Instead of `zig init-lib` and `zig init-exe`, now there is only
`zig init`, which initializes any of the template files that do not
already exist, and makes a package that contains both an executable and
a static library. The idea is that the user can delete whatever they
don't want. In fact, I think even more things should be added to the
build.zig template.
2023-11-20 23:01:45 -07:00
mlugg ff838d8631 translate-c: work around unnecessary uses of 'var' 2023-11-19 11:11:50 +00:00
mlugg 3c585730f2 AstGen: preserve result type in comptime block 2023-11-19 11:11:50 +00:00
mlugg b355893438 compiler: correct unnecessary uses of 'var' 2023-11-19 11:11:49 +00:00
mlugg 172c2797bd link: fix MachO boundary symbol resolution 2023-11-19 11:11:49 +00:00
mlugg baabc6013e compiler: add error for unnecessary use of 'var'
When a local variable is never used as an lvalue, we can determine that
`const` would be sufficient for this variable, so emit an error in this
case. More sophisticated checking is unfortunately not possible with
Zig's current analysis model, since whether an lvalue is actually
mutated depends on semantic analysis, in which some code paths may not
be analyzed, so attempting to determine this would result in false
positive compile errors.

It's worth noting that an unfortunate consequence of this is that any
field call `a.b()` will allow `a` to be `var`, even if `b` does not take
a pointer as its first parameter - this is again a necessary compromise
because the parameter type is not known until semantic analysis.

Also update `translate-c` to not trigger these errors. This is done by
replacing the `_ = @TypeOf(x)` emitted with `_ = &x` - the reference
there means that the local is permitted to be `var`. A similar strategy
will be used to prevent compile errors in the behavior tests, where we
sometimes want to force a value to be runtime-known.

Resolves: #224
2023-11-19 09:55:07 +00:00
dweiller 325e0f5f0e test: check compile errors when compilation has no errors 2023-11-19 00:12:43 +02:00
Curtis Tate Wilkinson 7b99189f19 Add struct declaration location to empty root struct field member error 2023-11-18 12:03:10 +00:00
Jakub Konka 91329ce944 std.macho: fix LoadCommandIterator to work with underaligned data 2023-11-17 20:49:32 +01:00
Veikka Tuominen 5f86414019 Merge pull request #18006 from Vexu/aro-translate-c
Sync Aro dependency & translate-c progress
2023-11-17 09:02:11 +02:00
Veikka Tuominen acebf05be9 aro-translate-c: update to upstream changes 2023-11-17 09:01:25 +02:00
David 673a1efa22 Sema: include sentinel in type of pointer-to-array ptr field
Resolves: #18007
2023-11-16 16:08:30 +00:00
David 941090d94f Move duplicate field detection for struct init expressions into AstGen
Partially addresses #17916.
2023-11-16 14:38:16 +00:00
Krzysztof Wolicki acf9de376d Sema: Add error for non-power of 2 field alignment when reifying Unions, Structs, Pointers 2023-11-16 10:19:54 +02:00
Jakub Konka 6e4d7362ce elf: fix emitting start/stop synthetic symbols 2023-11-15 19:20:03 +01:00
Jakub Konka d771c0a7a1 elf: create .got.plt unconditionally 2023-11-15 19:07:09 +01:00
Jakub Konka 6f3bbd5eaa elf: we were writing too many symbols in the symtab 2023-11-15 19:00:13 +01:00
Jakub Konka 760ce69734 elf: actually write synthetic globals to output symtab 2023-11-15 15:07:09 +01:00
Veikka Tuominen c327489d21 aro-translate-c: start work on translating statements 2023-11-15 10:51:26 +02:00
Veikka Tuominen a15feeb694 aro-translate-c: translate function types 2023-11-15 10:50:45 +02:00
Jacob Young 0c6cb8d8c8 x86_64: actually track state during @divFloor of i128
Closes #17998
2023-11-14 22:50:05 -05:00
Jakub Konka 6fd1c64f23 Merge pull request #17978 from ziglang/elf-x86-tls
x86_64+elf: TLS support
2023-11-14 22:09:15 +01:00
Jakub Konka 4adb8f786f elf: do not pointlessly store zerofill data for TLVs 2023-11-14 16:51:25 +01:00
Jakub Konka e883907431 coff: revert .rdata to be read-only again 2023-11-13 23:23:06 +01:00
Jakub Konka 028bfdbca3 coff: mark dirty any reloc target at [addr,..) inclusive 2023-11-13 23:07:21 +01:00
Michael Dusan 569182dbb2 compilation: forbid PIE for dynamic libraries
but allow for { .exe, .o, .a }.

closes #17928
2023-11-13 20:30:57 +01:00
Jakub Konka 8c748d5fd7 elf: setting offset to maxInt for non-allocated non-incremental sections is bad 2023-11-13 17:57:57 +01:00
Andrew Kelley 91b897ef58 rework memory management of Module.Namespace hash maps
The motivating problem here was a memory leak in the hash maps of
Module.Namespace.

The commit deletes more of the legacy incremental compilation
implementation. It had things like use of orderedRemove and trying to do
too much OOP-style creation and deletion of objects.

Instead, this commit iterates over all the namespaces on Module deinit
and calls deinit on the hash map fields. This logic is much simpler to
reason about.

Similarly, change global inline assembly to an array hash map since
iterating over the values is a primary use of it, and clean up the
remaining values on Module deinit, solving another memory leak.

After this there are no more memory leaks remaining when using the
x86 backend in a libc-less compiler.
2023-11-12 23:21:21 -05:00
kcbanner 53500a5768 sema: fixup underflows during struct / ptr array init when using -fstrip 2023-11-12 18:22:57 -05:00
Jacob Young 80b73e3e8f x86_64: resolve tlv references on first use and spill to the stack
This avoids any arbitrary memory operand possibly clobbering rax and
sometime rdi with no warning.
2023-11-12 18:12:41 -05:00
Jakub Konka 3d3153c58e x86_64: use .rax for local exec as prescribed by the spec 2023-11-12 18:12:41 -05:00
Jakub Konka c6833e6273 x86_64: remove unreachable Elf prong 2023-11-12 18:12:41 -05:00
Jakub Konka 575c29e5c4 elf: set symbol flags such as needs_zig_got in ZigObject 2023-11-12 18:12:41 -05:00
Jakub Konka 412519dd49 x86_64: seems like we will need to keep track of rax and reserve rax+rdi for TLS 2023-11-12 18:12:41 -05:00
Jakub Konka 0dab319e86 elf: dump PLT entries 2023-11-12 18:12:41 -05:00
Jakub Konka 984c598590 x86_64: emit TLS local dynamic model when PIC 2023-11-12 18:12:41 -05:00
Jakub Konka 51efee2cb6 elf: fix allocating local TLS symbols 2023-11-12 18:12:41 -05:00
Jakub Konka 1afc6917f5 x86_64: get something going for the local exec model 2023-11-12 18:12:41 -05:00
Jakub Konka b48baeeebb elf: fix typo in initial section offsets 2023-11-12 18:12:41 -05:00
Jakub Konka aa0fbbcb39 elf: check for empty relocs buffers in ZigObject before emitting section 2023-11-12 18:12:40 -05:00