14361 Commits

Author SHA1 Message Date
mlugg
36d0afbf28
Autodoc: handle more direct int value Refs 2024-03-01 06:11:47 +00:00
mlugg
408a08708f
Autodoc: do not rely on redundant block within function body 2024-03-01 01:20:50 +00:00
mlugg
321045cf33
codegen: handle dbg_var scoping correctly after eliding more ZIR blocks
Since we now elide more ZIR blocks in AstGen, care must be taken in
codegen to introduce lexical scopes for every body, not just `block`s.

Also, elide a few unnecessary AIR blocks in Sema.
2024-02-29 23:38:18 +00:00
mlugg
f51d9ab892
Sema: simplify and clarify analyzeBodyInner and wrapper functions
The signature and variants of Sema's main loop have evolved over time to
what was a quite confusing state of affairs. This commit makes minor
changes to how `analyzeBodyInner` works, and restructures/renames the
wrapper functions, adding doc comments to clarify their purposes. The
most notable change is that `analyzeBodyInner` now returns
`CompileError!void`; inline breaks are now all communicated via
`error.ComptimeBreak`.
2024-02-29 23:38:18 +00:00
antlilja
147beec7da LLVM Builder: Fix emission of enum debug enumerator info bitcode 2024-02-29 12:02:13 -08:00
Luuk de Gram
202ed7330f
fix memory leaks 2024-02-29 15:52:43 +01:00
Luuk de Gram
196ba706a0
wasm: gc fixes and re-enable linker tests
Certain symbols were left unmarked, meaning they would not be emit into
the final binary incorrectly. We now mark the synthetic symbols to ensure
they are emit as they are already created under the circumstance they're
needed for. This also re-enables disabled tests that were left disabled
in a previous merge conflict.
Lastly, this adds the shared-memory test to the test harnass as it was
previously forgotten and therefore regressed.
2024-02-29 15:24:08 +01:00
Luuk de Gram
5ba5a2c133
wasm: integrate linker errors with Compilation
Rather than using the logger, we now emit proper 'compiler'-errors just
like the ELF and MachO linkers with notes. We now also support emitting
multiple errors before quiting the linking process in certain phases,
such as symbol resolution. This means we will print all symbols which
were resolved incorrectly, rather than the first one we encounter.
2024-02-29 15:24:07 +01:00
Luuk de Gram
5ef8321338
wasm: make symbol indexes a non-exhaustive enum
This introduces some type safety so we cannot accidently give an atom
index as a symbol index. This also means we do not have to store any
optionals and therefore allow for memory optimizations. Lastly, we can
now always simply access the symbol index of an atom, rather than having
to call `getSymbolIndex` as it is easy to forget.
2024-02-29 15:24:07 +01:00
Luuk de Gram
c99ef23862
wasm: consolidate flushModule and linkWithZld
We now use a single function to use the in-house WebAssembly linker
rather than wasm-ld. For both incremental compilation and traditional
linking we use the same codepath.
2024-02-29 15:24:04 +01:00
Luuk de Gram
5aec88fa41
wasm: correctly generate relocations for type index
Previously we could directly write the type index because we used the
index that was known in the final binary. However, as we now process
the Zig module as its own relocatable object file, we must ensure to
generate a relocation for type indexes. This also ensures that we can
later link the relocatable object file as a standalone also.

This also fixes generating indirect function table entries for ZigObject
as it now correctly points to the relocation symbol index rather than
the symbol index that owns the relocation.
2024-02-29 15:23:05 +01:00
Luuk de Gram
5a0f2af7e4
wasm: reimplement Zig errors in linker 2024-02-29 15:23:04 +01:00
Luuk de Gram
c153f94c89
wasm: ensure unique function indexes
We cannot keep function indexes as maxInt(u32) due to functions being
dedupliated when they point to the same function. For this reason we now
use a regular arraylist which will have new functions appended to, and
when deleted, its index is appended to the free list, allowing us to
re-use slots in the function list.
2024-02-29 15:23:04 +01:00
Luuk de Gram
fde8c2f41a
wasm: reimplement deleteDeclExport
Removes the symbol from the decl's list of exports, marks it as dead,
as well as appends it to the symbol free list. Also removes it from
the list of global symbols as all exports are global.

In the future we should perhaps use a map for the export list to prevent
linear lookups. But this requires a benchmark as having more than 1
export for the same decl is very rare.
2024-02-29 15:23:04 +01:00
Luuk de Gram
8f96e7eec1
wasm: re-implement updateExports
We now correctly create a symbol for each exported decl with its export-
name. The symbol points to the same linker-object. We store a map from
decl to all of its exports so we can update exports if it already exists
rather than infinitely create new exports.
2024-02-29 15:23:04 +01:00
Luuk de Gram
a028b10b9f
wasm: update freeDecl and finishDecl
We now parse the decls right away into atoms and allocate the
corresponding linker-object, such as segment and function, rather than
waiting until `flushModule`.
2024-02-29 15:23:04 +01:00
Luuk de Gram
4d14374a66
wasm: Move createFunction to ZigObject
This function was previously only called by the backend which generates
a synthetical function that is not represented by any AIR or Zig code.
For this reason, the ownership is moved to the zig-object and stored
there so it can be linked with the other object files without the driver
having to specialize it.
2024-02-29 15:23:04 +01:00
Luuk de Gram
0a030d6598
wasm: Use File.Index for symbol locations
Rather than using the optional, we now directly use `File.Index` which
can already represent an unknown file due to its `.null` value. This
means we do not pay for the memory cost.

This type of index is now used for:
- SymbolLoc
- Key of the functions map
- InitFunc

Now we can simply pass things like atom.file, object.file, loc.file etc
whenever we need to access its representing object file which makes it
a lot easier.
2024-02-29 15:23:03 +01:00
Luuk de Gram
94f3a18c88
wasm: Add File abstraction 2024-02-29 15:23:03 +01:00
Luuk de Gram
cbc8d33062
wasm: fix symbol resolution and atom processing 2024-02-29 15:23:03 +01:00
Luuk de Gram
143e9599d6
wasm: use File abstraction instead of object
When merging sections we now make use of the `File` abstraction so all
objects such as globals, functions, imports, etc are also merged from
the `ZigObject` module. This allows us to use a singular way to perform
each link action without having to check the kind of the file.
The logic is mostly handled in the abstract file module, unless its
complexity warrants the handling within the corresponding module itself.
2024-02-29 15:23:03 +01:00
Luuk de Gram
12505c6d3d
wasm: store File.Index on the Atom
Also, consolidate the creation of Atoms so they all use `createAtom`.
2024-02-29 15:23:03 +01:00
Luuk de Gram
f6896ef218
wasm: create linking objects in correct module
CodeGen will create linking objects such as symbols, function types, etc
in ZigObject, rather than in the linker driver where the final result
will be stored. They will end up in the linker driver module during
the `flush` phase instead.

This must mean we must call functions such as `addOrGetFuncType` in the
correct namespace or else it will be created in the incorrect list and
therefore return incorrect indexes.
2024-02-29 15:23:03 +01:00
Luuk de Gram
9b3c8fd3a8
wasm: initialize a ZigObject when required
When we have a ZigCompileUnit and don't use LLVM, we initialize the
ZigObject which will encapsulate the Zig Module as an object file in-
memory. During initialization we also create symbols which the object
will need such as the stack pointer.
2024-02-29 15:23:02 +01:00
Luuk de Gram
e54177e852
wasm: move incremental Dwarf info into ZigObject 2024-02-29 15:23:02 +01:00
Luuk de Gram
ba0e84a411
wasm: move Zig module-linkage to ZigObject
Rather than specializing the linker-driver to be able to handle objects
generated by a ZCU, we store all data in-memory in ZigObject. ZigObject
acts more like a regular object file which will allow us to treat it
as us. This will make linking much more simple, but will also reduce
the complexity of incremental-linking as we can simply update ZigObject
and relink it.
2024-02-29 15:22:58 +01:00
Andrew Kelley
f7d095d372 use hash.addListOfBytes where applicable 2024-02-28 20:38:24 -07:00
Andrew Kelley
30688f33a4 add missing export symbol names to whole mode wasm cache hash
Fixes false positive cache hit.
2024-02-28 20:38:24 -07:00
Andrew Kelley
f5aad47287
Merge pull request #19122 from ziglang/lazy-aro
make aro-based translate-c lazily built from source
2024-02-28 18:21:30 -08:00
Jacob Young
69df00f657
Merge pull request #19115 from antlilja/llvm-misc
LLVM: Miscellaneous improvements to Builder
2024-02-29 01:03:58 +01:00
Andrew Kelley
240d0b68f6 make aro-based translate-c lazily built from source
Part of #19063.

Primarily, this moves Aro from deps/ to lib/compiler/ so that it can be
lazily compiled from source. src/aro_translate_c.zig is moved to
lib/compiler/aro_translate_c.zig and some of Zig CLI logic moved to a
main() function there.

aro_translate_c.zig becomes the "common" import for clang-based
translate-c.

Not all of the compiler was able to be detangled from Aro, however, so
it still, for now, remains being compiled with the main compiler
sources due to the clang-based translate-c depending on it. Once
aro-based translate-c achieves feature parity with the clang-based
translate-c implementation, the clang-based one can be removed from Zig.

Aro made it unnecessarily difficult to depend on with these .def files
and all these Zig module requirements. I looked at the .def files and
made these observations:

- The canonical source is llvm .def files.
- Therefore there is an update process to sync with llvm that involves
  regenerating the .def files in Aro.
- Therefore you might as well just regenerate the .zig files directly
  and check those into Aro.
- Also with a small amount of tinkering, the file size on disk of these
  generated .zig files can be made many times smaller, without
  compromising type safety in the usage of the data.

This would make things much easier on Zig as downstream project,
particularly we could remove those pesky stubs when bootstrapping.

I have gone ahead with these changes since they unblock me and I will
have a chat with Vexu to see what he thinks.
2024-02-28 13:21:05 -07:00
antlilja
5c2e463ecd LLVM: Don't create a debug lexical block when inlining 2024-02-28 14:46:43 +01:00
antlilja
40f99862e1 Builder: Implement StrtabString and use it for Global names 2024-02-28 14:46:43 +01:00
antlilja
826c6c0ec6 LLVM: Implement more efficient blob writing 2024-02-28 14:46:43 +01:00
Andrew Kelley
420b7713d4 CLI: strip lazy built commands by default
Saves a lot of time since we use -OReleaseFast.
Disabled when ZIG_DEBUG_CMD=1 is passed.
2024-02-27 22:55:00 -07:00
Andrew Kelley
a4380a30f5 move zig libc command to be lazily built
part of #19063

This is a prerequisite for doing the same for Resinator.
2024-02-27 22:55:00 -07:00
Andrew Kelley
6f7354a041
Merge pull request #19102 from ziglang/decouple-zir
JIT `zig fmt` and `zig reduce`
2024-02-27 11:03:08 -08:00
Luuk de Gram
27f589dea1
Merge pull request #18538 from Pangoraw/wasm_vector_abi
wasm: allow non-int vectors
2024-02-27 18:42:12 +01:00
Andrew Kelley
97f2a8b5cb introduce ZIG_DEBUG_CMD to choose debug mode
for lazily built commands such as `zig fmt` and `zig reduce`. Useful if
you want to test a patch to them.
2024-02-26 23:48:56 -07:00
Andrew Kelley
1a01151a4e back out the build_runner.zig moving change
I'd like to move this file but to do so requires a zig1.wasm update, so
I'll choose a more opportune moment to make this change.
2024-02-26 23:44:01 -07:00
Andrew Kelley
dfe430e9f4 move lazily compiled source files to lib/compiler/ 2024-02-26 23:43:56 -07:00
Andrew Kelley
0157e1196c compiler: JIT zig reduce
See #19063
2024-02-26 23:43:42 -07:00
Andrew Kelley
d661f0f35b compiler: JIT zig fmt
See #19063
2024-02-26 22:26:19 -07:00
Andrew Kelley
b116063e02 move AstGen to std.zig.AstGen
Part of an effort to ship more of the compiler in source form.
2024-02-26 21:51:19 -07:00
Andrew Kelley
a2e87aba66 rearrange std.zig
This frees up std.zig.fmt to be used for the implementation of `zig
fmt`.
2024-02-26 21:35:33 -07:00
Andrew Kelley
7b37bc771b move Zir to std.zig.Zir
Part of an effort to ship more of the compiler in source form.
2024-02-26 21:35:30 -07:00
Andrew Kelley
5f3b21a5b6 Zir: decouple from InternPool
Note that the correctness of these enum tag values is still protected
by the comptime logic at the top of Zcu (currently src/Module.zig).
2024-02-26 21:35:30 -07:00
Andrew Kelley
f7143e18e3 move Zcu.LazySrcLoc to std.zig.LazySrcLoc
Part of an effort to ship more of the compiler in source form.
2024-02-26 21:35:30 -07:00
Matthew Lugg
8775d8bbce
Merge pull request #19062 from mlugg/dbg-var-blocks
compiler: decide dbg_var scoping based on AIR blocks
2024-02-27 03:25:04 +00:00
John Schmidt
f803761e13 Fix tuple default values
- Add default values to the list of comptime-known elements in
  `zirValidatePtrArrayInit`
- In `structFieldValueComptime`, only assert `haveFieldInits` if we
  enter the`fieldIsComptime` branch (otherwise they are not needed).
2024-02-26 17:03:20 -08:00