Commit Graph

29669 Commits

Author SHA1 Message Date
Jacob Young
49b25475ad InternPool: remove usage of data with simple indices
This allows them to be atomically replaced.
2024-07-07 22:59:52 -04:00
Jacob Young
383cffbfae InternPool: temporarily disable multi-threaded behavior
This reduces the cost of the new data structure until the multi-threaded
behavior is actually used.
2024-07-07 22:59:52 -04:00
Jacob Young
92ddb959a7 InternPool: implement and use thread-safe list for items 2024-07-07 22:59:52 -04:00
Jacob Young
8293ff94cf InternPool: implement and use thread-safe list for strings 2024-07-07 22:59:52 -04:00
Jacob Young
3e1b190fe6 InternPool: replace garbage with an arena
This was just a badly implemented arena anyway.
2024-07-07 22:59:52 -04:00
Jacob Young
c8b9364b30 InternPool: use thread-safe hash map for strings 2024-07-07 22:59:52 -04:00
Jacob Young
cda716ecc4 InternPool: implement thread-safe hash map 2024-07-07 22:59:52 -04:00
Jacob Young
ca02266157 Zcu: pass PerThread to intern pool string functions 2024-07-07 22:59:52 -04:00
Jacob Young
525f341f33 Zcu: introduce PerThread and pass to all the functions 2024-07-07 22:59:52 -04:00
Shun Sakai
8f20e81b88
std.crypto.pwhash: Add recommended parameters (#20527)
These parameters according to the OWASP cheat sheet.
2024-07-07 20:18:33 +00:00
Erik Arvstedt
c40708a2ce cmake/findllvm: fix incorrect lib dir setup for zig2
Line `link_directories("${CMAKE_PREFIX_PATH}/lib")` was evaluated as
`link_directories("/lib")` in the default case of `CMAKE_PREFIX_PATH`
being empty.
This caused cmake to add `-L/lib -Wl,-rpath,/lib` to the zig2
build flags.

This could result in errors on systems where libraries set via
`CMAKE_LIBRARY_PATH` had conflicting versions in `/lib`:
- `-L/lib` could cause linking zig2 to fail
- `-Wl,-rpath,/lib` adds `/lib` as the first entry of the zig2 `RPATH`.
  This could cause running zig2 (to build zig3) to fail.

In case of conflicting lib dirs, cmake emitted this warning, which is
now fixed:
```
Cannot generate a safe runtime search path for target zig2 because files in
  some directories may conflict with libraries in implicit directories:

    runtime library [libclang-cpp.so.18.1] in /nix/store/...-clang-18.1.5-lib/lib may be hidden by files in:
      /lib
```
2024-07-06 14:29:03 -04:00
Andrew Kelley
bf588f67d8 build system: add docs to LinkSystemLibraryOptions 2024-07-05 11:34:13 -07:00
Linus Groh
b3afba8a70 std.c: Add setlocale() 2024-07-05 04:45:44 -04:00
Alex Rønne Petersen
0d7aa1b637 std.Target: Use arch8 as the baseline CPU model for s390x.
Fixes #9442.
2024-07-05 01:52:18 -04:00
Andrew Kelley
0f8561d099
Merge pull request #20487 from ziglang/incremental-serialization
Zcu: extract serializable state from File
2024-07-04 23:13:22 -04:00
Andrew Kelley
74346b0f79 frontend: TrackedInst stores FileIndex instead of path digest
The purpose of using path digest was to reference a file in a
serializable manner. Now that there is a stable index associated with
files, it is a superior way to accomplish that goal, since removes one
layer of indirection, and makes TrackedInst 8 bytes instead of 20.

The saved Zig Compiler State file for "hello world" goes from 1.3M to
1.2M with this change.
2024-07-04 17:56:01 -07:00
Andrew Kelley
30ec43a6c7 Zcu: extract permanent state from File
Primarily, this commit removes 2 fields from File, relying on the data
being stored in the `files` field, with the key as the path digest, and
the value as the struct decl corresponding to the File. This table is
serialized into the compiler state that survives between incremental
updates.

Meanwhile, the File struct remains ephemeral data that can be
reconstructed the first time it is needed by the compiler process, as
well as operated on by independent worker threads.

A key outcome of this commit is that there is now a stable index that
can be used to refer to a File. This will be needed when serializing
error messages to survive incremental compilation updates.
2024-07-04 17:51:35 -07:00
Andrew Kelley
7ed2fbd755 std.Build.Cache: add binToHex function
reduces need for API users to rely on formatted printing, even though
that's how it is currently implemented.
2024-07-04 17:12:45 -07:00
Andrew Kelley
29512f0edd Compilation: don't give len=0 bufs to pwritev
The OS returns EFAULT for undefined pointers, even when len=0.
2024-07-04 17:12:45 -07:00
Andrew Kelley
cac7e5afc7 add std.debug.assertReadable
Useful when trying to figure out whether a slice is valid memory.
2024-07-04 17:12:45 -07:00
Andrew Kelley
790b8428a2
Merge pull request #20494 from mlugg/the-great-decl-split
refactors ad infinitum
2024-07-04 20:12:05 -04:00
Jakub Konka
de61540c2d
Merge pull request #20496 from ziglang/macos-tsan 2024-07-05 00:33:46 +02:00
Jakub Konka
d2cace58bd Compilation: rename tsan_static_lib to tsan_lib 2024-07-04 22:09:57 +02:00
Jakub Konka
e42e12dbbf tsan: fix wording in comments 2024-07-04 22:03:31 +02:00
mlugg
cda6f552d5
cbe: don't mark exported values/Decls as extern 2024-07-04 21:01:43 +01:00
mlugg
a5d5c097f5
Sema: add missing references 2024-07-04 21:01:42 +01:00
mlugg
eae9aa800e
std: avoid references that trigger compile errors
Note that the `_ = Address` statements in tests previously were a nop,
and now actually check that the type is valid. However, on WASI, the
type is *not* valid.
2024-07-04 21:01:42 +01:00
Jacob Young
00da182e68
cbe: fix for export changes 2024-07-04 21:01:42 +01:00
mlugg
0e5335aaf5
compiler: rework type resolution, fully resolve all types
I'm so sorry.

This commit was just meant to be making all types fully resolve by
queueing resolution at the moment of their creation. Unfortunately, a
lot of dominoes ended up falling. Here's what happened:

* I added a work queue job to fully resolve a type.
* I realised that from here we could eliminate `Sema.types_to_resolve`
  if we made function codegen a separate job. This is desirable for
  simplicity of both spec and implementation.
* This led to a new AIR traversal to detect whether any required type is
  unresolved. If a type in the AIR failed to resolve, then we can't run
  codegen.
* Because full type resolution now occurs by the work queue job, a bug
  was exposed whereby error messages for type resolution were associated
  with the wrong `Decl`, resulting in duplicate error messages when the
  type was also resolved "by" its owner `Decl` (which really *all*
  resolution should be done on).
* A correct fix for this requires using a different `Sema` when
  performing type resolution: we need a `Sema` owned by the type. Also
  note that this fix is necessary for incremental compilation.
* This means a whole bunch of functions no longer need to take `Sema`s.
  * First-order effects: `resolveTypeFields`, `resolveTypeLayout`, etc
  * Second-order effects: `Type.abiAlignmentAdvanced`, `Value.orderAgainstZeroAdvanced`, etc

The end result of this is, in short, a more correct compiler and a
simpler language specification. This regressed a few error notes in the
test cases, but nothing that seems worth blocking this change.

Oh, also, I ripped out the old code in `test/src/Cases.zig` which
introduced a dependency on `Compilation`. This dependency was
problematic at best, and this code has been unused for a while. When we
re-enable incremental test cases, we must rewrite their executor to use
the compiler server protocol.
2024-07-04 21:01:42 +01:00
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
Jakub Konka
6756aaccf1 macho: do not save rpaths globally in the driver 2024-07-04 22:01:19 +02: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
Jakub Konka
76c3b6b794 tsan: add workaround for TSAN Apple bug
Addresses TSAN bug on Apple platforms by always setting the headerpad
size to a non-zero value when building the TSAN dylib.
2024-07-04 07:33:00 +02:00
Jakub Konka
c9d19ebb7a macho: link dynamic TSAN lib 2024-07-04 07:33:00 +02:00
Jakub Konka
1cfc364785 tsan: build dynamic library on Apple platforms 2024-07-04 07:33:00 +02: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