16860 Commits

Author SHA1 Message Date
achan1989
f82d7e87a3
main: better error message if the global cache dir is unusable
Fixes #19400
2025-01-30 14:10:17 +01:00
Jacob Young
e4c049e410 x86_64: rewrite comparisons 2025-01-29 22:00:08 -08:00
mlugg
107b65ec5d Sema: explain why we tried to call an extern fn at comptime
I recently saw a user hit the "comptime call of extern function" error,
and get confused because they didn't know why the scope was `comptime`.
So, use `explainWhyBlockIsComptime` on this and related errors to add
all the relevant notes.

The added test case shows the motivating situation.
2025-01-29 18:43:24 +00:00
Frank Denis
e60072635e
Add libdl shims from wasi-libc 2025-01-29 12:48:56 +01:00
Frank Denis
8a8da49b52
Re-add lazy preopen changes 2025-01-29 11:54:08 +01:00
Frank Denis
3f4c43b0aa
Update wasi-libc to d03829489904d38c624f6de9983190f1e5e7c9c5 2025-01-29 11:54:02 +01:00
zhylmzr
308ba80597 fix(cc): make link and preprocessor logic to be more consistent with
clang's behavior.

1. `zig cc main.c -o /dev/null` shouldn't emit a.out
2. `zig cc -E main.c` and `zig cc -E main -o -` should output to stdout
2025-01-29 10:48:36 +01:00
mlugg
71d16106ad Sema: @memcpy changes
* The langspec definition of `@memcpy` has been changed so that the
  source and destination element types must be in-memory coercible,
  allowing all such calls to be raw copying operations, not actually
  applying any coercions.
* Implement aliasing check for comptime `@memcpy`; a compile error will
  now be emitted if the arguments alias.
* Implement more efficient comptime `@memcpy` by loading and storing a
  whole array at once, similar to how `@memset` is implemented.
2025-01-29 06:35:22 +00:00
Andrew Kelley
37037b269e frontend: use main Compilation code_model when building libxx
as well as libtsan, libunwind, and libc files
2025-01-27 17:07:56 -08:00
Andrew Kelley
eed3b9567d
Merge pull request #22610 from jacobly0/x86_64-rewrite
x86_64: rewrite `@min`/`@max` for scalar floats
2025-01-27 11:47:52 -08:00
Carter Snook
2043e8ae05
main: classify empty environment variables as unset
This matches existing well-specified conventions for e.g. NO_COLOR.

Closes #22380.
2025-01-27 17:53:32 +01:00
Will Lillis
672bc8141f
fix: Only suggest try on destructure of error union if payload type can be destructured (#21510) 2025-01-26 19:38:07 +01:00
Jacob Young
654da648b3 x86_64: rewrite @min/@max for float vectors 2025-01-26 09:51:07 -05:00
Jacob Young
0c890bb9a4 x86_64: rewrite @min/@max for scalar floats 2025-01-26 06:58:37 -05:00
Matthew Lugg
3767b08039
Merge pull request #22602 from mlugg/incr-embedfile
incremental: handle `@embedFile`
2025-01-26 01:41:56 +00:00
Andrew Kelley
8fa47bb904
Merge pull request #22230 from alexrp/lto-stuff
Disable LTO by default + some LTO fixes
2025-01-25 13:17:25 -08:00
Andrew Kelley
d0d5ca2b6c
Merge pull request #22581 from jacobly0/x86_64-rewrite
x86_64: rewrite `@abs` on floats
2025-01-25 07:30:45 -08:00
Alex Rønne Petersen
b60e39fe8f
Compilation: Disable LTO by default.
LLD has too many LTO bugs, and we're dropping the LLD dependency soon anyway.
2025-01-25 14:59:02 +01:00
Alex Rønne Petersen
9f116d38b8
libtsan: Build with unwind tables like upstream. 2025-01-25 14:58:55 +01:00
Alex Rønne Petersen
46a1a15861
Compilation: Remove the _tls_index hack for MinGW.
No longer needed since we disable LTO for mingw32.
2025-01-25 14:58:44 +01:00
Alex Rønne Petersen
1e8b82f6b4
compiler: Rework LTO settings for some Zig-provided libraries.
* compiler-rt and mingw32 have both run into LLD bugs, and LLVM disables LTO for
  its compiler-rt, so disable LTO for these.
* While we haven't run into any bugs in it, LLVM disables LTO for its libtsan,
  so follow suit just to be safe.
* Allow LTO for libfuzzer as LLVM does.
2025-01-25 14:57:33 +01:00
Alex Rønne Petersen
afe2fed34d
link: Set machine and float ABI when invoking ld.lld and lld-link.
If this isn't done, LTO can completely miscompile the input bitcode modules for
certain targets where we need to explicitly set these ABIs (because LLVM's
defaults are bad).
2025-01-25 14:57:33 +01:00
Alex Rønne Petersen
cd8c92fc40
compiler: Explicitly specify ABI for arm, mips, and powerpc when talking to LLVM.
See 652c5151429e279f70396ee601416c87a70c1bec. Better to avoid relying on default
LLVM behavior going forward.
2025-01-25 14:56:59 +01:00
Alex Rønne Petersen
b95081209a
compiler: Explicitly specify loongarch ABI when talking to LLVM.
Necessary because of: dc665fa5f5
2025-01-25 14:56:59 +01:00
mlugg
f47b8de2ad
incremental: handle @embedFile
Uses of `@embedFile` register dependencies on the corresponding
`Zcu.EmbedFile`. At the start of every update, we iterate all embedded
files and update them if necessary, and invalidate the dependencies if
they changed.

In order to properly integrate with the lazy analysis model, failed
embed files are now reported by the `AnalUnit` which actually used
`@embedFile`; the filesystem error is stored in the `Zcu.EmbedFile`.

An incremental test is added covering incremental updates to embedded
files, and I have verified locally that dependency invalidation is
working correctly.
2025-01-25 06:07:08 +00:00
Matthew Lugg
8ba3812eee
Merge pull request #22594 from mlugg/panic-stuff
compiler: yet more panic handler changes
2025-01-25 04:10:55 +00:00
Jacob Young
c7433212d1 x86_64: rewrite scalar and vector int @min and @max 2025-01-24 21:02:32 -05:00
Jacob Young
7701cfa032 x86_64: mitigate miscomp during switch dispatch 2025-01-24 20:56:11 -05:00
Jacob Young
ba82d6e83e x86_64: fix typo and lower optimized insts 2025-01-24 20:56:11 -05:00
Jacob Young
b1fa89439a x86_64: rewrite float vector @abs and equality comparisons 2025-01-24 20:56:11 -05:00
Jacob Young
ae3d95fc8d x86_64: rewrite scalar float equality comparisons 2025-01-24 20:56:11 -05:00
mlugg
b6726913d3
Zcu: remove null_stack_trace
The new simplifications to the panic handler have eliminated the need
for this piece of memoized state.
2025-01-24 22:33:23 +00:00
mlugg
5a6666db55
all: update for panic.unwrapError and panic.call signature changes 2025-01-24 22:33:23 +00:00
mlugg
b0a8931690
Sema: prepare to remove ?*StackTrace argument from unwrapError and call
Now that we propagate the error return trace to all `callconv(.auto)`
functions, passing it explicitly to panic handlers is redundant.
2025-01-24 20:50:20 +00:00
Andrew Kelley
3e174ee1ac frontend: fix data race with mingw crt files 2025-01-24 12:22:00 -08:00
Andrew Kelley
d3f4e9d4ac Compilation pipeline: repeat failed prelink tasks
and remove faulty assertion. When a prelink task fails, the
completed_prelink_tasks counter will not decrement.

A future improvement will be needed to make the pipeline fully robust
and handle failed prelink tasks, followed by updates in which those
tasks succeed, and compilation proceeds like normal.

Currently if a prelink task fails, the Compilation will be left in a
state unrecoverable by an incremental update.
2025-01-24 12:22:00 -08:00
mlugg
83991efe10
compiler: yet more panic handler changes
* `std.builtin.Panic` -> `std.builtin.panic`, because it is a namespace.
* `root.Panic` -> `root.panic` for the same reason. There are type
  checks so that we still allow the legacy `pub fn panic` strategy in
  the 0.14.0 release.
* `std.debug.SimplePanic` -> `std.debug.simple_panic`, same reason.
* `std.debug.NoPanic` -> `std.debug.no_panic`, same reason.
* `std.debug.FormattedPanic` is now a function `std.debug.FullPanic`
  which takes as input a `panicFn` and returns a namespace with all the
  panic functions. This handles the incredibly common case of just
  wanting to override how the message is printed, whilst keeping nice
  formatted panics.
* Remove `std.builtin.panic.messages`; now, every safety panic has its
  own function. This reduces binary bloat, as calls to these functions
  no longer need to prepare any arguments (aside from the error return
  trace).
* Remove some legacy declarations, since a zig1.wasm update has
  happened. Most of these were related to the panic handler, but a quick
  grep for "zig1" brought up a couple more results too.

Also, add some missing type checks to Sema.

Resolves: #22584

formatted -> full
2025-01-24 19:29:51 +00:00
Alex Rønne Petersen
41185d297f
Package.Module: Make create() fall back on options.global.root_optimize_mode.
As is done for root_strip and root_error_tracing.
2025-01-23 23:22:38 +00:00
Alex Rønne Petersen
ef4d7f01a5
compiler: Fix computation of Compilation.Config.any_unwind_tables.
This moves the default value logic to Package.Module.create() instead and makes
it so that Compilation.Config.any_unwind_tables is computed similarly to
any_sanitize_thread, any_fuzz, etc. It turns out that for any_unwind_tables, we
only actually care if unwind tables are enabled at all, not at what level.
2025-01-23 23:22:38 +00:00
Alex Rønne Petersen
b46a40ff1d
compiler: Handle --no-eh-frame-hdr as a regular zig build-* flag too.
For some reason we accepted --eh-frame-hdr, but not --no-eh-frame-hdr, despite
accepting the latter as a -Wl linker flag.
2025-01-23 23:22:38 +00:00
Alex Rønne Petersen
d916954bee
Merge pull request #22098 from alexrp/wasm-generic-baseline
`std.Target`: Use `lime1` as wasm baseline model and `mvp` as generic model
2025-01-23 18:41:11 +01:00
Alex Rønne Petersen
68c6a88770
link.Wasm.Feature: Make fromCpuFeature() and toCpuFeature() less cute.
This is more verbose, but at least we now get a compile error instead of UB when
a new feature is added to std.Target.wasm.Feature but not to link.Wasm.Feature.
2025-01-22 21:18:15 +01:00
Alex Rønne Petersen
ea1502974d
wasm: Add a nontrapping_bulk_memory_len0 feature.
This will mainly be used when targeting our wasm2c implementation which has no
problem with zero-length bulk memory operations, as a non-standard extension.
2025-01-22 20:56:28 +01:00
Matthew Lugg
0e815c652d
Merge pull request #22572 from jacobly0/new-error-trace
compiler: include error trace in all functions, implement for x86_64 backend
2025-01-22 16:48:27 +00:00
Jacob Young
d4b6a53327 x86_64: implement error return traces 2025-01-22 03:44:13 -05:00
mlugg
1bce01de97 compiler: pass error return traces everywhere 2025-01-22 02:22:56 -05:00
mlugg
e864c38cc3
Sema: fix crash when inline loop condition is not comptime-known 2025-01-22 04:18:43 +00:00
mlugg
8470b6ea37
Zcu: fix switch prong source location resolution
Resolves: #22343
2025-01-22 04:11:02 +00:00
Alex Rønne Petersen
280ced66eb
std.Target: Define and use lime1 as the baseline CPU model for WebAssembly.
See: https://github.com/WebAssembly/tool-conventions/pull/235

This is not *quite* using the same features as the spec'd lime1 model because
LLVM 19 doesn't have the level of feature granularity that we need for that.
This will be fixed once we upgrade to LLVM 20.

Part of #21818.
2025-01-22 03:01:05 +01:00
Alex Rønne Petersen
e800ea0fdd
wasm: Add a check for zero length around uses of memory.copy/memory.fill.
Apparently the WebAssembly spec requires these instructions to trap if the
computed memory access could be out of bounds, even if the length is zero.
Really a rather bizarre design choice.
2025-01-22 03:01:02 +01:00