Commit Graph

29636 Commits

Author SHA1 Message Date
mlugg
2f0f1efa6f
compiler: type.zig -> Type.zig 2024-07-04 21:01:42 +01:00
mlugg
ded5c759f8
Zcu: store LazySrcLoc in error messages
This change modifies `Zcu.ErrorMsg` to store a `Zcu.LazySrcLoc` rather
than a `Zcu.SrcLoc`. Everything else is dominoes.

The reason for this change is incremental compilation. If a failed
`AnalUnit` is up-to-date on an update, we want to re-use the old error
messages. However, the file containing the error location may have been
modified, and `SrcLoc` cannot survive such a modification. `LazySrcLoc`
is designed to be correct across incremental updates. Therefore, we
defer source location resolution until `Compilation` gathers the compile
errors into the `ErrorBundle`.
2024-07-04 21:01:41 +01:00
mlugg
089bbd6588
Zcu: rework reference traces
Previously, `reference_table` mapped from a `Decl` being referenced to
the `Decl` that performed the reference. This is convenient for
constructing error messages, but problematic for incremental
compilation. This is because on an incremental update, we want to
efficiently remove all references triggered by an `AnalUnit` which is
being re-analyzed.

For this reason, `reference_table` now maps the other way: from the
`AnalUnit` *performing* the reference, to the `AnalUnit` whose analysis
was triggered. As a general rule, any call to any of the following
functions should be preceded by a call to `Sema.addReferenceEntry`:

* `Zcu.ensureDeclAnalyzed`
* `Sema.ensureDeclAnalyzed`
* `Zcu.ensureFuncBodyAnalyzed`
* `Zcu.ensureFuncBodyAnalysisQueued`

This is not just important for error messages, but also more
fundamentally for incremental compilation. When an incremental update
occurs, we must determine whether any `AnalUnit` has become
unreferenced: in this case, we should ignore its associated error
messages, and perhaps even remove it from the binary. For this reason,
we no longer store only one reference to every `AnalUnit`, but every
reference. At the end of an update, `Zcu.resolveReferences` will
construct the reverse mapping, and as such identify which `AnalUnit`s
are still referenced. The current implementation doesn't quite do what
we need for incremental compilation here, but the framework is in place.

Note that `Zcu.resolveReferences` does constitute a non-trivial amount
of work on every incremental update. However, for incremental
compilation, this work -- which will effectively be a graph traversal
over all `AnalUnit` references -- seems strictly necessary. At the
moment, this work is only done if the `Zcu` has any errors, when
collecting them into the final `ErrorBundle`.

An unsolved problem here is how to represent inline function calls in
the reference trace. If `foo` performs an inline call to `bar` which
references `qux`, then ideally, `bar` would be shown on the reference
trace between `foo` and `qux`, but this is not currently the case. The
solution here is probably for `Zcu.Reference` to store information about
the source locations of active inline calls betweeen the referencer and
its reference.
2024-07-04 21:01:41 +01:00
mlugg
5f03c02505
Zcu: key compile errors on AnalUnit where appropriate
This change seeks to more appropriately model the way semantic analysis
works by drawing a more clear line between errors emitted by analyzing a
`Decl` (in future a `Cau`) and errors emitted by analyzing a runtime
function.

This does change a few compile errors surrounding compile logs by adding
more "also here" notes. The new notes are more technically correct, but
perhaps not so helpful. They're not doing enough harm for me to put
extensive thought into this for now.
2024-07-04 21:01:41 +01:00
mlugg
7e552dc1e9
Zcu: rework exports
This commit reworks our representation of exported Decls and values in
Zcu to be memory-optimized and trivially serialized.

All exports are now stored in the `all_exports` array on `Zcu`. An
`AnalUnit` which performs an export (either through an `export`
annotation or by containing an analyzed `@export`) gains an entry into
`single_exports` if it performs only one export, or `multi_exports` if
it performs multiple.

We no longer store a persistent mapping from a `Decl`/value to all
exports of that entity; this state is not necessary for the majority of
the pipeline. Instead, we construct it in `Zcu.processExports`, just
before flush. This does not affect the algorithmic complexity of
`processExports`, since this function already iterates all exports in
the `Zcu`.

The elimination of `decl_exports` and `value_exports` led to a few
non-trivial backend changes. The LLVM backend has been wrangled into a
more reasonable state in general regarding exports and externs. The C
backend is currently disabled in this commit, because its support for
`export` was quite broken, and that was exposed by this work -- I'm
hoping @jacobly0 will be able to pick this up!
2024-07-04 21:01:41 +01:00
mlugg
bc8cd13598
compiler: rename AnalSubject to AnalUnit
I meant to call it this originally, I just got mixed up -- sorry!
2024-07-04 21:01:40 +01:00
Jonathan Marler
d9f1a952b8 build: fix WriteFile and addCSourceFiles not adding LazyPath deps
Adds a missing call to addLazyPathDependenciesOnly in
std.Build.Module.addCSourceFiles.  Also fixes an issue in
std.Build.Step.WriteFile where it wasn't updating all the GeneratedFile
instances for every directory.  To fix the second issue, I removed
all the GeneratedFile instances and now all files/directories reference
the steps main GeneratedFile via sub paths.
2024-07-04 13:34:17 -04:00
Ryan Liptak
b67caf72e3 Add behavior test: including the sentinel when dereferencing a string literal
This test would have failed in the past, but this has been fixed sometime in the last year. Closes #15944
2024-07-04 16:02:27 +03:00
Andrew Kelley
768b17755e
Merge pull request #19615 from ianic/tar_diagnostic
std.tar: add strip components error to diagnostics
2024-07-03 21:29:04 -04:00
antlilja
efb00c20ee LLVM Builder: Pass correct argument to ensureUnusedMetadataCapacity
The trail_len was being multiplied by the size of the type before
2024-07-03 16:45:05 -04:00
Krzysztof Wolicki
4870e002f2 Compilation: pass libc include directories when compiling assembly_with_cpp 2024-07-03 15:37:49 -04:00
Techatrix
8f7b50e2c4 json: respect duplicate_field_behavior in std.json.Value.jsonParse 2024-07-03 15:34:59 -04:00
Igor Anić
e0350859bb use unreachable keyword for unreachable code path 2024-07-03 12:12:53 -07:00
Igor Anić
035c1b6522 std.tar: add strip components error to diagnostics
This was the only kind of error which was raised in pipeToFileSystem and
not added to Diagnostics.
Shell tar silently ignores paths which are stripped out when used with
`--strip-components` switch. This enables that same behavior, errors
will be collected in diagnostics but caller is free to ignore that type
of diagnostics errors.
Enables use case where caller knows structure of the tar file and want
to extract only some deeply nested folders ignoring upper files/folders.

Fixes: #17620 by giving caller options:
- not provide diagnostic and get errors
- provide diagnostics and analyze errors
- provide diagnostics and ignore errors
2024-07-03 12:12:50 -07:00
Michael Bradshaw
fe66a12a23 Rename nonSIMDCall* to nonSimdCall* 2024-07-03 19:00:17 +01:00
Michael Bradshaw
21cad3e09f Rename MAX_NAME_BYTES to max_name_bytes 2024-07-03 17:42:09 +01:00
Nikita
e1d4cf67ca Add two new io_uring flags to linux.zig 2024-07-03 05:28:55 -04:00
cryptocode
cb182432b0 [std.c] Add eventfd and dup3 functions to FreeBSD
The eventfd system call and dup3 library call have been available
since FreeBSD 13 and 10 respectively, and are thus available in
all [FreeBSD releases not deemed EOL](<https://endoflife.date/freebsd>)

The lack of these were discovered when porting a terminal emulator
to FreeBSD. It would be nice to have them included in Zig's stdlib.
2024-07-03 05:27:21 -04:00
Pat Tullmann
a31fe8aa3e glibc headers: arc4random* functions added in glibc 2.36
Here's the glibc v2.36 announcment noting the addition of arc4random,
arc4random_buf and arc4random_uniform:

  https://sourceware.org/git/?p=glibc.git;a=blob;f=NEWS;h=8420a65cd06874ee09518366b8fba746a557212a;hb=6f4e0fcfa2d2b0915816a3a3a1d48b4763a7dee2

Tested with the testcase from the bug.  I get a compile-time error when
building against older glibc (instead of a linker error), and no errors
(as before) when compiling against v2.36 or later.  And the glibc_compat
regression tests pass.

Fix #20426
2024-07-03 02:57:24 -04:00
wooster0
5e3bad3556 Make 0e.0 and 0xp0 not crash
This fixes those sequences of characters crashing.
2024-07-03 02:53:37 -04:00
Luuk de Gram
1905137d0b
Merge pull request #20438 from pavelverigo/stage2-wasm-default-signextend
stage2-wasm: store signed integers with extended sign bit + minor changes
2024-07-02 17:58:01 +02:00
Michael Bradshaw
02b3d5b58a Rename isASCII to isAscii 2024-07-02 16:31:15 +02:00
Pavel Verigo
1a951b49af stage2-wasm: not op for <= 128 bits ints 2024-07-02 15:02:59 +02:00
Pavel Verigo
5a9495002f stage2-wasm: Zcu renaming 2024-07-02 15:02:59 +02:00
Pavel Verigo
4b9d327f12 stage2-wasm: sign extend strategy 2024-07-02 15:02:59 +02:00
David Rubin
e4447c54ea add ppc64 reloc definitions 2024-07-02 08:59:10 +02:00
Andrew Kelley
da7c48324b CI: update macOS runner to 12
Apple has already dropped support for macOS 11.
GitHub Actions is dropping macOS 11 support now.
The Zig project is also dropping macOS 11 support now.
2024-07-02 02:04:10 -04:00
Andrew Kelley
fed8d9054c
Merge pull request #19267 from PanSashko/compile-dup-mod
Fix adding module arguments for Step.Compile
2024-07-02 01:10:34 -04:00
Sashko
8ef24461a0 DynLib: fix a typo in DynLib.openZ 2024-07-01 19:44:20 -04:00
Andrew Kelley
8db1490b8a update test build script to latest API 2024-07-01 16:38:02 -07:00
Sashko
a717ac0340 Add a standalone test to cover the duplicate module bug 2024-07-01 16:36:39 -07:00
Sashko
604a332e21 Extract getZigArgs function in std.Build.Step.Compile 2024-07-01 16:36:13 -07:00
Wayne Wu
cb308ba3ac
langref: correct test runner path 2024-06-27 19:37:44 +00:00
Jakub Konka
1e3fb48256
Merge pull request #20428 from ziglang/macho-tsan
macho: support TSAN
2024-06-27 06:35:53 +02:00
Matthew Lugg
a016ca6170
Merge pull request #20424 from mlugg/the-great-decl-split
Dismantle Decl a little bit more
2024-06-27 00:14:03 +01:00
Jakub Konka
766e281a72 macho: set allow_shlib_undefined to true when TSAN was requested 2024-06-26 22:01:00 +02:00
Jakub Konka
e9309036b2 macho: print libtsan ref when dumping argv 2024-06-26 08:43:46 +02:00
Jakub Konka
6e78642d51 macho: link in TSAN if requested 2024-06-26 07:38:36 +02:00
mlugg
4cb5318088
InternPool: rename Depender to AnalSubject
This is essentially just a rename. I also changed the representation of
`AnalSubject` to use a `packed struct` rather than a non-exhaustive
enum, but that change is relatively trivial.
2024-06-26 05:28:04 +01:00
mlugg
5b523d0469
Zir: make src_line absolute for declaration instructions
We need special logic for updating line numbers anyway, so it's fine to
just use absolute numbers here. This eliminates a field from `Decl`.
2024-06-26 05:28:03 +01:00
Pavel Verigo
3e9ab6aa7b stage2-wasm: abs 128 bit 2024-06-24 20:50:39 +02:00
Bogdan Romanyuk
ab4c461b76
std.mem.zeroes: explicit compile error for @Type(.EnumLiteral) 2024-06-24 00:43:09 +00:00
Alex Rønne Petersen
1ede3af9f6 std.zig.target: Remove armeb-windows-gnu and aarch64_be-windows-gnu.
This doesn't actually exist; Windows on Arm only runs on little endian. MinGW
also doesn't work for these targets at all.
2024-06-23 19:53:52 -04:00
David Rubin
e73ae94b36 riscv: remove deprecated Module usages 2024-06-23 15:26:14 +01:00
Frank Denis
f3655fd07d
std.crypto.chacha: fix typo in XChaChaIETF.stream() (#20399)
Thanks to @r4gus for reporting this.

Fixes #20398
2024-06-23 13:20:18 +00:00
Bram
5f58956264 std: Extended type checks for Thread startFn return type 2024-06-23 04:35:00 +01:00
Sean
f1b6f1aeb3
std.meta.hasUniqueRepresentation: Handle optional pointers correctly (#20366)
std.meta.hasUniqueRepresentation should now return true for non-slice optional pointers. Additional checks were added to the test to reflect this.
2024-06-23 03:33:45 +00:00
Michael Bradshaw
642093e04b Rename *[UI]LEB128 functions to *[UI]leb128 2024-06-23 04:30:12 +01:00
Andrew Kelley
0fcd59eada rename src/Module.zig to src/Zcu.zig
This patch is a pure rename plus only changing the file path in
`@import` sites, so it is expected to not create version control
conflicts, even when rebasing.
2024-06-22 22:59:56 -04:00
Pavel Verigo
6026bbd0ad stage2-wasm: fix div and rem 2024-06-22 21:35:36 +02:00