Commit Graph

27415 Commits

Author SHA1 Message Date
Abhinav Gupta
d3a163f868
build/LazyPath: Add dirname (#18371)
Adds a variant to the LazyPath union representing a parent directory
of a generated path.

```zig
const LazyPath = union(enum) {
    generated_dirname: struct {
        generated: *const GeneratedFile,
        up: usize,
    },
    // ...
}
```

These can be constructed with the new method:

```zig
pub fn dirname(self: LazyPath) LazyPath
```

For the cases where the LazyPath is already known
(`.path`, `.cwd_relative`, and `dependency`)
this is evaluated right away.
For dirnames of generated files and their dirnames,
this is evaluated at getPath time.

dirname calls can be chained, but for safety,
they are not allowed to escape outside a root
defined for each case:

- path: This is relative to the build root,
  so dirname can't escape outside the build root.
- generated: Can't escape the zig-cache.
- cwd_relative: This can be a relative or absolute path.
  If relative, can't escape the current directory,
  and if absolute, can't go beyond root (/).
- dependency: Can't escape the dependency's root directory.

Testing:
I've included a standalone case for many of the happy cases.
I couldn't find an easy way to test the negatives, though,
because tests cannot yet expect panics.
2024-01-04 18:47:28 -05:00
Carl Åstholm
501a2350ab sema: Prevent reifying non-empty union with empty tag type 2024-01-04 22:38:31 +02:00
xdBronch
15f7a477d0 fallback to zigs DynLib when static linking musl 2024-01-04 18:02:45 +02:00
xdBronch
6ebeb85abd speed up sliceTo when end == sentinel 2024-01-04 17:54:56 +02:00
Anubhab Ghosh
d525c59808 Enable gnu_f16_abi on x86_64 2024-01-04 17:41:30 +02:00
Ryan Liptak
0527cab71b Use std.fs.path.relative for @import and @embedFile sub paths
Fixes edge cases where the `startsWith` that was used previously would return a false positive on a resolved path like `foo.zig` when the resolved root was `foo`. Before this commit, such a path would be treated as a sub path of 'foo' with a resolved sub file path of 'zig' (and the `.` would be assumed to be a path separator). After this commit, `foo.zig` will be correctly treated as outside of the root of `foo`.

Closes #18355
2024-01-04 17:34:34 +02:00
Andrew Kelley
9a16085093
Merge pull request #18376 from amp-59/shl_exact_comptime_int_to_shl
Sema: Updated `zirShl` to compute `shl_exact` with `comptime_int` LHS using `shl`
2024-01-04 04:19:26 -08:00
Andrew Kelley
537e2808e0 build system: fix missing step dependencies on lib
When depending on a module that depends on a static library, there was a
missing step dependency on the static library, which caused a compile
error due to missing header file.

This fixes the problem by adding the proper step dependencies.

Reviewing this code, I'm starting to wonder if it might be simpler to
have Module instances create dummy Step objects to better model
dependencies and dependees, rather than trying to maintain this graph
without an actual node. That would be an improvement for a future
commit.
2024-01-04 03:44:26 -08:00
Andrew Kelley
fc79b22a98
Merge pull request #17431 from castholm/expectEqual
Update `std.testing.expectEqual` and friends to use peer type resolution
2024-01-03 23:55:59 -08:00
Andrew Kelley
52ebba6bdf @shlExact fixups
* Add clarification in langref
* move test case to behavior tests
2024-01-04 00:44:44 -07:00
amp-59
10016e0368 Sema: fix crash compiling @shlExact
Updated `zirShl`, to compute `shl_exact` with `comptime_int` LHS operand
like `shl`, and added test case for `@shlExact` with `comptime_int` LHS
operand.
2024-01-04 00:10:41 -07:00
Krzysztof Wolicki
ecd520f661 Fix std.Build.findProgram 2024-01-03 18:18:48 -08:00
Andrew Kelley
2ac315c245 compiler: fix build runner not added to cache hash
Closes #18438
2024-01-03 17:36:54 -08:00
Andrew Kelley
f64205b445
Merge pull request #18262 from ziglang/fix-18259
std.Build.Step.Run: fix depfile support
2024-01-03 13:23:40 -08:00
Andrew Kelley
ce480dedbb
Merge pull request #18403 from FnControlOption/parse
std.zig: Miscellaneous cleanup
2024-01-03 13:10:26 -08:00
Andrew Kelley
a9337bef2d
Merge pull request #18431 from jacobly0/cbe-extern
cbe: fix non-msvc externs and exports
2024-01-03 12:57:01 -08:00
Carl Åstholm
85869f8225 Correct expected/actual parameter order of some assertions 2024-01-03 21:20:49 +01:00
Carl Åstholm
d7b36503ca Remove some @as coercions from assertions
These are some spurious fixes to help illustrate the improved ergonomics of the `expectEqual` change. It is by no means complete.
2024-01-03 21:20:48 +01:00
Carl Åstholm
4c1da0912a Fix compile errors from the expectEqual change 2024-01-03 21:20:48 +01:00
Carl Åstholm
e5994f5f57 Update std.testing.expectEqual and friends to use peer type resolution
This commit changes the type of the second parameter to `anytype`, which should make it easier to pass literals to these functions. This change shouldn't *silently* break existing code (the assertions themselves should retain the same behavior as before) but it may result in some new compile errors when struct/union/array literals or builtins like `@bitCast` are used for the second argument. These compile errors can be fixed by explicitly coercing these expressions to the correct type using `@as`.
2024-01-03 21:20:48 +01:00
Karl Böhlmark
9a56228c2b
doc: Fix typos in bpf docs 2024-01-03 12:34:10 +02:00
xdBronch
d03649ec2f add missing resolveStructFieldInits 2024-01-03 11:05:25 +02:00
Jacob Young
047d6d996e cbe: fix non-msvc externs and exports
Closes #17817
2024-01-03 02:52:25 -05:00
Jacob Young
98b633ff17 Reapply "Merge pull request #17824 from kcbanner/fixup_msvc_fmax"
This reverts commit 2b58978360.
2024-01-03 02:41:21 -05:00
amp-59
ca4ee9ae73
Sema: Added logic to avoid unchecked operations calling preparePanicId (#18416)
Fixes #18415
2024-01-03 02:34:24 -05:00
Andrew Kelley
60958d135f std.Build.Step.Compile: fix passing wrong Builder to getPath
This resulted in an error building a transitive module dependency.
2024-01-02 18:22:11 -07:00
Andrew Kelley
289ae45c1b
Merge pull request #18160 from ziglang/std-build-module
Move many settings from being per-Compilation to being per-Module
2024-01-02 14:11:27 -08:00
PanSashko
c89bb3e141 Fix std.enums.values
Current implementation fails to handle the following enum

```zig
const E = enum {
  X,
  pub const X = 1;
}
```

because `@field(type, name)` prefers declarations over enum fields.
2024-01-02 20:28:55 +02:00
Meghan Denny
e19219fa0e std.ComptimeStringMap: allow getting kv index 2024-01-02 17:40:30 +02:00
Veikka Tuominen
d9d840a33a
Merge pull request #18410 from dweiller/by-length-slice-bug
sema: add compile error for OOB by-length slice of array
2024-01-02 17:37:21 +02:00
sammy j
a04d433094 add support for lists when parsing user args 2024-01-02 17:35:11 +02:00
Loris Cro
65878c16ee std.Build.Step.Run: fix depfile support 2024-01-02 11:54:32 +01:00
arbrk1
024540de15
Liveness: fix branch operands becoming aliased 2024-01-02 12:08:26 +02:00
Samuel Nevarez
25a556107c langref: order comment to align with code example 2024-01-02 12:06:59 +02:00
Andrew Kelley
c546ddb3ed disable standalone coff_dwarf test on aarch64-windows
See tracking issue #18427
2024-01-01 19:49:08 -07:00
Andrew Kelley
2b63ba31e9 add standalone test for depending on the main module 2024-01-01 19:49:08 -07:00
Andrew Kelley
d5c1e7f7b1 link: accept the update arena in flush
This branch introduced an arena allocator for temporary allocations in
Compilation.update. Almost every implementation of flush() inside the
linker code was already creating a local arena that had the lifetime of
the function call. This commit passes the update arena so that all those
local ones can be deleted, resulting in slightly more efficient memory
usage with every compilation update.

While at it, this commit also removes the Compilation parameter from the
linker flush function API since a reference to the Compilation is now
already stored in `link.File`.
2024-01-01 19:49:08 -07:00
Andrew Kelley
eae6d45cde CLI: introduce global -I args for C include paths
This isn't technically needed since per-module -I args can suffice, but
this can produce very long CLI invocations when several --mod args are
combined with --search-prefix args since the -I args have to be repeated
for each module.

This is a partial revert of ecbe8bbf2df2ed4d473efbc32e0b6d7091fba76f.
2024-01-01 19:49:08 -07:00
Andrew Kelley
7cec11a66b CI: update windows scripts to new CLI module syntax 2024-01-01 19:49:08 -07:00
Andrew Kelley
7fb9f58f85 Compilation: rename before flush during whole cache mode
The linker needs to know the file system path of output in the flush
function because file paths inside the build artifacts reference each
other. Fixes a regression introduced in this branch.
2024-01-01 19:49:08 -07:00
Andrew Kelley
6b2709616e frontend: ignore AccessDenied when writing builtin.zig
This issue already existed in master branch, however, the more
aggressive caching of builtin.zig in this branch made it happen more
often. I added doc comments to AtomicFile to explain when this problem
can occur.

For the compiler's use case, error.AccessDenied can be simply swallowed
because it means the destination file already exists and there is
nothing else to do besides proceed with the AtomicFile cleanup.

I never solved the mystery of why the log statements weren't printing
but those are temporary debugging instruments anyway, and I am already
too many yaks deep to whip out another razor.

closes #14978
2024-01-01 19:49:08 -07:00
Andrew Kelley
a89d6878d2 Compilation: fix cache hash of incremental builds
Without this commit, unrelated test builds using incremental cache mode
(self-hosted, no lld) would end up using the same cache namespace, which
is undesireable since concurrent builds will clobber each other's work.

This happened because of passing the root module to
addModuleToCacheHash. In the case of a test build, the root module
actually does not connect to the rest of the import table. Instead, the
main module needs to be passed, which has "root" in its import table.

The other call to addModuleTableToCacheHash which is in
addNonIncrementalStuffToCacheManifest already correctly passes the main
module.

In the future, I think this problem can be fully addressed by obtaining
an advisory lock on the output binary file. However, even in that case,
it is still valuable to make different compilations use different cache
namespaces lest unrelated compilations suffer from pointless thrashing
rather than being independently edited.
2024-01-01 19:49:08 -07:00
Andrew Kelley
e22102dfc6 Compilation: make create() take an arena allocator
Instead of making its own inside create. 10 out of 10 calls to create()
had already an arena in scope, so this commit means that 10 instances of
Compilation now reuse an existing arena with the same lifetime rather
than creating a redundant one.

In other words, this very slightly optimizes initialization of the
frontend in terms of memory allocation.
2024-01-01 19:49:08 -07:00
Andrew Kelley
c2cc1b3792 frontend: add logging to help troubleshoot builtin.zig write failures 2024-01-01 19:49:08 -07:00
Andrew Kelley
96b4eeab55 std: disable failing test on macos
See tracking issue https://github.com/ziglang/zig/issues/18395
2024-01-01 19:49:08 -07:00
Andrew Kelley
668c0cdeda compiler: Compilation.Config: trivial refactor 2024-01-01 19:49:08 -07:00
Andrew Kelley
751ff043d7 fix stack_iterator test build script
When I updated this build script to the new API, I incorrectly
translated the logic for setting unwind_tables. This commit fixes it.
2024-01-01 19:49:08 -07:00
Andrew Kelley
196ddf010c frontend: fix populateTestFunctions accessing the wrong module
The test runner reads the list of test function pointers from its own
builtin module, which is the root_mod, not main_mod.
2024-01-01 19:49:08 -07:00
Andrew Kelley
8fa4496909 std.Build.Step.Compile: fix search prefix lowering
Instead of adding -I and -L flags at the end of the CLI, they need to be
added for every module, after the module-specific flags.
2024-01-01 19:49:08 -07:00
Andrew Kelley
b8674910d4 restore -fno-emit-bin -femit-llvm-ir functionality
Now, link.File will always be null when -fno-emit-bin is specified, and
in the case that LLVM artifacts are still required, the Zcu instance has
an LlvmObject.
2024-01-01 19:49:08 -07:00