14411 Commits

Author SHA1 Message Date
Ryan Liptak
52de2802c4 Lazily compile the zig rc subcommand and use it during zig build-exe
This moves .rc/.manifest compilation out of the main Zig binary, contributing towards #19063

Also:
- Make resinator use Aro as its preprocessor instead of clang
- Sync resinator with upstream
2024-03-11 05:06:16 -07:00
Andrew Kelley
1397341540 add missing field to module creation
Fixes a merge conflict with one of mlugg's recent branches.
2024-03-10 18:22:53 -07:00
Andrew Kelley
6b8c7540a8 fix 32 bit compilation 2024-03-10 17:51:07 -07:00
Andrew Kelley
8b70e4f2c9 autodocs: fix root name and missing dir close 2024-03-10 17:51:07 -07:00
Andrew Kelley
261094ca85 -femit-docs: create main.wasm artifact 2024-03-10 17:51:07 -07:00
Andrew Kelley
ffd53a459e -femit-docs: creating sources.tar
It's always a good day when you get to use File.writeFileAll 😎
2024-03-10 17:51:07 -07:00
Andrew Kelley
91260459e3 frontend: skeleton for creating autodocs
This time, unlike the old implementation, it properly does autodoc
generation during the compilation pipeline, saving time.
2024-03-10 17:51:06 -07:00
Andrew Kelley
33f3443243 add zig std subcommand 2024-03-10 17:51:06 -07:00
Andrew Kelley
356e653f9b better to use AST than ZIR for doc generation 2024-03-10 17:51:05 -07:00
Jakub Konka
c1bda06c14
Merge pull request #19225 from ziglang/elf-aarch64
elf: port aarch64 support from zld
2024-03-10 15:32:58 +01:00
Jakub Konka
2cdbad6f10 elf+aarch64: handle PREL64 reloc 2024-03-09 19:34:34 +01:00
Jakub Konka
229468b7a9 elf+aarch64: fix 32bit build 2024-03-09 18:55:52 +01:00
mlugg
e2cbbd0c26 Sema: perform codegen for anon decl created by @extern
This fixes a bug where, at least with the LLVM backend, `@extern` calls
which had the same name as a normal `extern` in the same Zcu would
result in the `@extern` incorrectly suffixing the identifier `.2`.
Usually, the LLVM backend has a system to change the generated globals
to "collapse" them all together, but it only works if `updateDecl` is
called!
2024-03-09 04:52:06 +00:00
Jakub Konka
859f9a22c4 elf+aarch64: implement basic thunk support 2024-03-08 22:46:18 +01:00
Jakub Konka
7c5ddb6ae4 elf+aarch64: handle PREL32 reloc 2024-03-08 22:46:18 +01:00
Jakub Konka
47100bd40a elf+aarch64: handle TLS GD model 2024-03-08 22:46:18 +01:00
Jakub Konka
b343103567 elf+aarch64: handle gottp and .tls_common 2024-03-08 22:46:18 +01:00
Jakub Konka
7258d143e3 elf+aarch64: fix incorrectly emitted TLSDESC relocs 2024-03-08 22:46:17 +01:00
Jakub Konka
b5642b4f85 elf+aarch64: set _GLOBAL_OFFSET_TABLE_ to .got section 2024-03-08 22:46:17 +01:00
Jakub Konka
d9069cbe2c elf+aarch64: relax TLSDESC for executables 2024-03-08 22:46:17 +01:00
Jakub Konka
310cef0972 elf+aarch64: handle TLSDESC non-relaxed 2024-03-08 22:46:17 +01:00
Jakub Konka
109d2321b0 link: refactor common aarch64 helpers 2024-03-08 22:46:17 +01:00
Jakub Konka
c1dbf01aa3 elf+aarch64: resolve TLS LE model 2024-03-08 22:46:17 +01:00
Jakub Konka
69f9f359dd elf+aarch64: use correctly offset tp address 2024-03-08 22:46:17 +01:00
Jakub Konka
0af5d2e9b6 elf+aarch64: implement .plt.got 2024-03-08 22:46:17 +01:00
Jakub Konka
1cf45fb209 elf+aarch64: implement enough to link dynamically with gcc as the driver 2024-03-08 22:46:17 +01:00
mlugg
f3227598eb Sema: reset block error return trace index between cases
Resolves: #19210
2024-03-08 07:30:32 -08:00
Andrew Kelley
97aa5f7b8a
Merge pull request #19190 from mlugg/struct-equivalence
compiler: namespace type equivalence based on AST node + captures
2024-03-07 18:41:45 -08:00
mlugg
38331b1cab
Package.Module: actually set File.path_digest for builtin modules 2024-03-07 06:26:25 +00:00
Dillen Meijboom
377ecc6afb feat: add support for --enable-new-dtags and --disable-new-dtags 2024-03-06 17:52:05 -08:00
mlugg
b41a0b4768
Package.Module: deduplicate identical builtin modules
Previously, when multiple modules had builtin modules with identical
sources, two distinct `Module`s and `File`s were created pointing at the
same file path. This led to a bug later in the frontend. These modules
are now deduplicated with a simple hashmap on the builtin source.
2024-03-06 21:26:39 +00:00
mlugg
4c05a9a892
Sema: do not destroy enum type if field analysis fails 2024-03-06 21:26:38 +00:00
mlugg
e043fe474f
Fix incorrectly resolved merge conflicts
To be honest, I can't be bothered to figure out which commits these
changes should be in.
2024-03-06 21:26:38 +00:00
mlugg
2c4ac44f25
compiler: treat decl_val/decl_ref of potentially generic decls as captures
This fixes an issue with the implementation of #18816. Consider the
following code:

```zig
pub fn Wrap(comptime T: type) type {
    return struct {
        pub const T1 = T;
        inner: struct { x: T1 },
    };
}
```

Previously, the type of `inner` was not considered to be "capturing" any
value, as `T1` is a decl. However, since it is declared within a generic
function, this decl reference depends on the context, and thus should be
treated as a capture.

AstGen has been augmented to tunnel references to decls through closure
when the decl was declared in a potentially-generic context (i.e. within
a function).
2024-03-06 21:26:38 +00:00
mlugg
d0c022f734
compiler: namespace type equivalence based on AST node + captures
This implements the accepted proposal #18816. Namespace-owning types
(struct, enum, union, opaque) are no longer unique whenever analysed;
instead, their identity is determined based on their AST node and the
set of values they capture.

Reified types (`@Type`) are deduplicated based on the structure of the
type created. For instance, if two structs are created by the same
reification with identical fields, layout, etc, they will be the same
type.

This commit does not produce a working compiler; the next commit, adding
captures for decl references, is necessary. It felt appropriate to split
this up.

Resolves: #18816
2024-03-06 21:26:37 +00:00
mlugg
8ec6f730ef
compiler: represent captures directly in InternPool
These were previously associated with the type's namespace, but we need
to store them directly in the InternPool for #18816.
2024-03-06 21:26:37 +00:00
mlugg
975b859377
InternPool: create specialized functions for loading namespace types
Namespace types (`struct`, `enum`, `union`, `opaque`) do not use
structural equality - equivalence is based on their Decl index (and soon
will change to AST node + captures). However, we previously stored all
other information in the corresponding `InternPool.Key` anyway. For
logical consistency, it makes sense to have the key only be the true key
(that is, the Decl index) and to load all other data through another
function. This introduces those functions, by the name of
`loadStructType` etc. It's a big diff, but most of it is no-brainer
changes.

In future, it might be nice to eliminate a bunch of the loaded state in
favour of accessor functions on the `LoadedXyzType` types (like how we
have `LoadedUnionType.size()`), but that can be explored at a later
date.
2024-03-06 21:26:37 +00:00
mlugg
a6ca20b9a1
compiler: change representation of closures
This changes the representation of closures in Zir and Sema. Rather than
a pair of instructions `closure_capture` and `closure_get`, the system
now works as follows:

* Each ZIR type declaration (`struct_decl` etc) contains a list of
  captures in the form of ZIR indices (or, for efficiency, direct
  references to parent captures). This is an ordered list; indexes into
  it are used to refer to captured values.
* The `extended(closure_get)` ZIR instruction refers to a value in this
  list via a 16-bit index (limiting this index to 16 bits allows us to
  store this in `extended`).
* `Module.Namespace` has a new field `captures` which contains the list
  of values captured in a given namespace. This is initialized based on
  the ZIR capture list whenever a type declaration is analyzed.

This change eliminates `CaptureScope` from semantic analysis, which is a
nice simplification; but the main motivation here is that this change is
a prerequisite for #18816.
2024-03-06 21:26:37 +00:00
garrison hinson-hasty
1e67f50211
Sema: fix compiler crash @ptrCasting optional slice 2024-03-05 18:55:21 +00:00
Meghan Denny
7d41a5cbcf cli: add --rpath and -R linker arg aliases 2024-03-05 10:39:55 -08:00
Ryan Liptak
469643940c Use the global cache dir for the manifests of generated mingw .libs
Fixes a mismatch where the manifests would be written to the local cache dir, but the .def/.lib files themselves would be written to the global cache dir. This meant that if you cleared your global cache, your local cache would still think that the .lib files existed in the cache and it'd lead to 'No such file or directory' errors at linktime.

This mismatch was introduced in the stage1 -> stage2 transition of this code.
2024-03-04 05:36:01 -08:00
Andrew Kelley
90c1a2c41a
Merge pull request #19152 from antlilja/llvm-broken-debug
LLVM: Fail to emit if LLVM encounters broken debug info
2024-03-02 21:43:39 -08:00
Andrew Kelley
33de937fd9 move zig objcopy command to be lazily built
part of #19063
2024-03-02 21:22:45 -08:00
Jacob Young
aa688567f5 Air: replace .dbg_inline_* with .dbg_inline_block
This prevents the possibility of not emitting a `.dbg_inline_end`
instruction and reduces the allocation requirements of the backends.

Closes #19093
2024-03-02 21:19:34 -08:00
antlilja
282b398f6d Add comment explaining LLVM bug and linking tracking issue 2024-03-03 02:28:24 +01:00
antlilja
d345068ec2 LLVM: Fail to emit if LLVM encounters broken debug info 2024-03-02 20:53:06 +01:00
antlilja
e2345f006f LLVM: Add enableBrokenDebugInfoCheck and getBrokenDebugInfo
These functions allows the caller to find out wether the context
encounters broken debug info or not.
2024-03-02 20:53:06 +01:00
Matthew Lugg
9d500bda2d
Merge pull request #19117 from mlugg/dbg-var-blocks
Major ZIR size optimizations & small cleanups in Sema
2024-03-02 04:52:19 +00:00
Jacob Young
b60fc16b4f compiler: audit debug mode checks
* Introduce `-Ddebug-extensions` for enabling compiler debug helpers
 * Replace safety mode checks with `std.debug.runtime_safety`
 * Replace debugger helper checks with `!builtin.strip_debug_info`

Sometimes, you just have to debug optimized compilers...
2024-03-01 17:42:54 -08:00
Jakub Konka
9e402704e2 macho: correctly find N_GSYM symbols when parsing symbol stabs
In `ld -r` mode, the linker will emit `N_GSYM` for any defined
external symbols as well as private externals. In the former case,
the thing is easy since `N_EXT` bit will be set in the nlist's type.
In the latter however we will encounter a local symbol with `N_PEXT`
bit set (non-extern, but was private external) which we also need
to include when resolving symbol stabs.

The major change in the logic for parsing symbol stabs per input
object file is that we no longer try to force-resolve a `N_GSYM`
as a global symbol. This was a mistake since every symbol stab
always describes a symbol defined within the parsed input object file.
We then work out if we should forward `N_GSYM` in the output symtab
after we have resolved all symbols, but never before - intel we lack
when initially parsing symbol stabs. Therefore, we simply record
which symbol has a debug symbol stab, and work out its precise type
when emitting output symtab after symbol resolution has been done.
2024-03-01 10:18:10 +01:00