Commit graph

7436 commits

Author SHA1 Message Date
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
5a6666db55
all: update for panic.unwrapError and panic.call signature changes 2025-01-24 22:33:23 +00: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
mlugg
7774287fdc
tests: enable stack trace tests for x86_64-selfhosted
Allows the stack trace tests to be additionally compiled and run with
`.use_llvm = false, .use_lld = false` depending on the host target. This
is currently enabled for x86_64 targets emitting ELF.

Self-hosted backends emit slightly different DWARF info to the LLVM
backend, so the checking logic (and the tests themselves) had to be
tweaked slightly to support both backends at once.
2025-01-23 23:22:13 +00: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
Matthew Lugg
61fe307d0f
Merge pull request #22571 from mlugg/various-fixes-again
compiler: a few fixes
2025-01-22 16:47:45 +00:00
Jacob Young
d4b6a53327 x86_64: implement error return traces 2025-01-22 03:44:13 -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
BratishkaErik
941677e083
std.Build: add addLibrary function (#22554)
Acts as a replacement for `addSharedLibrary` and `addStaticLibrary`, but
linking mode can be changed more easily in build.zig, for example:

In library:
```zig
const linkage = b.option(std.builtin.LinkMode, "linkage", "Link mode for a foo_bar library") orelse .static; // or other default

const lib = b.addLibrary(.{
    .linkage = linkage,
    .name = "foo_bar",
    .root_module = mod,
});
```

In consumer:
```zig
const dep_foo_bar = b.dependency("foo_bar", .{
    .target = target,
    .optimize = optimize,
    .linkage = .static // or dynamic
});

mod.linkLibrary(dep_foor_bar.artifact("foo_bar"));
```

It also matches nicely with `linkLibrary` name.

Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
2025-01-22 02:29:21 +00:00
Andrew Kelley
b31a2c9555
Merge pull request #22541 from ziglang/pipeline
Compilation pipeline: spawn Jobs earlier that produce linker inputs
2025-01-21 14:27:05 -05:00
Jacob Young
d652dd0658 x86_64: rewrite @abs for scalar floats 2025-01-21 06:39:24 -05:00
Andrew Kelley
f5485a52bc reject crti.o/crtn.o, embrace the future
crti.o/crtn.o is a legacy strategy for calling constructor functions
upon object loading that has been superseded by the
init_array/fini_array mechanism.

Zig code depends on neither, since the language intentionally has no way
to initialize data at runtime, but alas the Zig linker still must
support this feature since popular languages depend on it.

Anyway, the way it works is that crti.o has the machine code prelude of
two functions called _init and _fini, each in their own section with the
respective name. crtn.o has the machine code instructions comprising the
exitlude for each function. In between, objects use the .init and .fini
link section to populate the function body.

This function is then expected to be called upon object initialization
and deinitialization.

This mechanism is depended on by libc, for example musl and glibc, but
only for older ISAs. By the time the libcs gained support for newer
ISAs, they had moved on to the init_array/fini_array mechanism instead.

For the Zig linker, we are trying to move the linker towards
order-independent objects which is incompatible with the legacy
crti/crtn mechanism.

Therefore, this commit drops support entirely for crti/crtn mechanism,
which is necessary since the other commits in this branch make it
nondeterministic in which order the libc objects and the other link
inputs are sent to the linker.

The linker is still expected to produce a deterministic output, however,
by ignoring object input order for the purposes of symbol resolution.
2025-01-20 20:59:52 -08:00
mlugg
0ec6b2dd88 compiler: simplify generic functions, fix issues with inline calls
The original motivation here was to fix regressions caused by #22414.
However, while working on this, I ended up discussing a language
simplification with Andrew, which changes things a little from how they
worked before #22414.

The main user-facing change here is that any reference to a prior
function parameter, even if potentially comptime-known at the usage
site or even not analyzed, now makes a function generic. This applies
even if the parameter being referenced is not a `comptime` parameter,
since it could still be populated when performing an inline call. This
is a breaking language change.

The detection of this is done in AstGen; when evaluating a parameter
type or return type, we track whether it referenced any prior parameter,
and if so, we mark this type as being "generic" in ZIR. This will cause
Sema to not evaluate it until the time of instantiation or inline call.

A lovely consequence of this from an implementation perspective is that
it eliminates the need for most of the "generic poison" system. In
particular, `error.GenericPoison` is now completely unnecessary, because
we identify generic expressions earlier in the pipeline; this simplifies
the compiler and avoids redundant work. This also entirely eliminates
the concept of the "generic poison value". The only remnant of this
system is the "generic poison type" (`Type.generic_poison` and
`InternPool.Index.generic_poison_type`). This type is used in two
places:

* During semantic analysis, to represent an unknown result type.
* When storing generic function types, to represent a generic parameter/return type.

It's possible that these use cases should instead use `.none`, but I
leave that investigation to a future adventurer.

One last thing. Prior to #22414, inline calls were a little inefficient,
because they re-evaluated even non-generic parameter types whenever they
were called. Changing this behavior is what ultimately led to #22538.
Well, because the new logic will mark a type expression as generic if
there is any change its resolved type could differ in an inline call,
this redundant work is unnecessary! So, this is another way in which the
new design reduces redundant work and complexity.

Resolves: #22494
Resolves: #22532
Resolves: #22538
2025-01-21 02:41:42 +00:00
Andrew Kelley
216e0f3730
Merge pull request #22548 from mlugg/fix-broken-pipe
Wait for reported spawn success or failure before trying to write to the stdio pipe in the build runner.

Hopefully fixes `error.BrokenPipe` failures
2025-01-20 21:40:04 -05:00
mlugg
8bcb578507 Sema: fix is_non_null_ptr handling for runtime-known pointers
We can still often determine a comptime result based on the type, even
if the pointer is runtime-known.

Also, we previously used load -> is non null instead of AIR
`is_non_null_ptr` if the pointer is comptime-known, but that's a bad
heuristic. Instead, we should check for the pointer to be
comptime-known, *and* for the load to be comptime-known, and only in
that case should we call `Sema.analyzeIsNonNull`.

Resolves: #22556
2025-01-21 00:33:32 +00:00
Jacob Young
b9198b708f x86_64: rewrite @abs 2025-01-20 14:47:07 -05:00
Alex Rønne Petersen
d5db02728c
Merge pull request #22530 from alexrp/omit-unwind-tables
Fix building the standard library without CFI directives
2025-01-20 07:24:12 +01:00
mlugg
b8e568504e
std.Build: extend test_runner option to specify whether runner uses std.zig.Server
The previous logic here was trying to assume that custom test runners
never used `std.zig.Server` to communicate with the build runner;
however, it was flawed, because modifying the `test_runner` field on
`Step.Compile` would not update this flag. That might have been
intentional (allowing a way for the user to specify a custom test runner
which *does* use the compiler server protocol), but if so, it was a
flawed API, since it was too easy to update one field without updating
the other.

Instead, bundle these two pieces of state into a new type
`std.Build.Step.Compile.TestRunner`. When passing a custom test runner,
you are now *provided* to specify whether it is a "simple" runner, or
whether it uses the compiler server protocol.

This is a breaking change, but is unlikely to affect many people, since
custom test runners are seldom used in the wild.
2025-01-20 00:14:58 +00:00
Alex Rønne Petersen
45bb4f955c
test: Add a standalone test for omitting CFI directives. 2025-01-19 02:15:30 +01:00
mlugg
3b6e5ba490
Sema: don't try to initialize global union pointer at comptime
Resolves: #19832
2025-01-18 14:30:06 +00:00
mlugg
f7b9f84df2
incremental: fix enum resolution bugs 2025-01-18 14:30:06 +00:00
Jacob Young
8c8dfb35f3 x86_64: fix crashes compiling the compiler and tests 2025-01-16 20:47:30 -05:00
Jacob Young
c3d33440f0 x86_64: pass more behavior tests 2025-01-16 20:47:30 -05:00
Jacob Young
666d76d85c x86_64: implement load and store 2025-01-16 20:47:30 -05:00
Jacob Young
63730441d0 x86_64: implement union access 2025-01-16 20:47:30 -05:00
Jacob Young
3240adfa16 x86_64: implement pointer addition and subtraction 2025-01-16 20:47:30 -05:00
Jacob Young
0d9079f466 x86_64: implement element access 2025-01-16 20:47:30 -05:00
Jacob Young
e5d5a8bc4e x86_64: implement switch jump tables 2025-01-16 20:42:08 -05:00
Jacob Young
ac1a975f9b x86_64: implement clz and not 2025-01-16 20:42:08 -05:00
Jacob Young
a1828ebcda x86_64: demolish the old 2025-01-16 20:42:08 -05:00
Jacob Young
73a42953c9 x86_64: 2 means better 2025-01-16 20:42:08 -05:00
Jacob Young
b9c4400776 x86_64: implement fallback for pcmpeqq 2025-01-16 20:42:08 -05:00
Jacob Young
c4b93555b0 x86_64: testing 2025-01-16 20:42:08 -05:00
Jacob Young
257054a146 Revert "disable flaky incremental compilation tests"
This reverts commit 133abdeda2 but keeps
the tests disabled for the wasm target, which is the only configuration
that seems to fail, even though the error looks like a frontend error.
2025-01-16 20:02:49 -05:00
Matthew Lugg
4d8c24c6c5
Merge pull request #22505 from mlugg/easier-modify-builtin
std.builtin.Type renames, and make it easier to modify std.builtin
2025-01-16 22:20:02 +00:00
Andrew Kelley
133abdeda2 disable flaky incremental compilation tests
tracking issue #22510
2025-01-16 13:13:11 -08:00
mlugg
9804cc8bc6
all: update to std.builtin.Type.{Pointer,Array,StructField} field renames 2025-01-16 12:49:58 +00:00
mlugg
d00e05f186
all: update to std.builtin.Type.Pointer.Size field renames
This was done by regex substitution with `sed`. I then manually went
over the entire diff and fixed any incorrect changes.

This diff also changes a lot of `callconv(.C)` to `callconv(.c)`, since
my regex happened to also trigger here. I opted to leave these changes
in, since they *are* a correct migration, even if they're not the one I
was trying to do!
2025-01-16 12:46:29 +00:00
Andrew Kelley
24bdb42a23 test/link/wasm/shared-memory: update to better linker behavior
now it's smarter about omitting tls stuff if there end up being no
TLS data sections
2025-01-15 19:44:20 -08:00
Andrew Kelley
744bb5d16a wasm linker: change rules about symbol visibility
export by default means export, as expected. if you want hidden
visibility then use hidden visibility.
2025-01-15 18:31:44 -08:00
Andrew Kelley
9dd6efb7e4 wasm linker: fix TLS data segments
fix calculation of alignment and size

include __tls_align and __tls_size globals along with __tls_base

include them only if the TLS segment is emitted

add missing reloc logic for memory_addr_tls_sleb

fix name of data segments to include only the prefix
2025-01-15 18:17:37 -08:00
Andrew Kelley
204e689bdb tests: remove dead code 2025-01-15 15:11:37 -08:00
Andrew Kelley
42602dc96b test/link/wasm/export-data: update expected behavior
Object being linked has neither functions nor globals named "foo" or
"bar" and so these names correctly fail to be exported when creating an
executable.
2025-01-15 15:11:37 -08:00
Andrew Kelley
50d053f31c test/wasm/infer-features: update to expected behavior
I intentionally simplified the target features functionality to use the
target features that are explicitly specified to the linker and ignore
the "tooling conventions"

this makes the wasm linker behave the same as ELF, COFF, and MachO.
2025-01-15 15:11:37 -08:00
Andrew Kelley
ec5fc6a2a8 test/link/wasm/function-table: delete bad test
this tests for importing a function table, but the example source does
not try to use an imported table, so it's a useless check. it's unclear
what the behavior is even supposed to do in this case.

the other two cases are left alone.
2025-01-15 15:11:37 -08:00
Andrew Kelley
ae119e395a test/link/wasm/segment: delete bad test
- doesn't run the exe
- checks for data segment named .rodata which is not a thing
- checks for data segment named .bss which is not needed
2025-01-15 15:11:37 -08:00
Andrew Kelley
c565191f30 test/link/wasm/type: remove redundant tests
This test passes now, but let's not run it for the other optimization
modes since they don't affect linker behavior.
2025-01-15 15:11:36 -08:00
Andrew Kelley
9143575ec3 test/wasm/export: delete redundant tests
the other optimization modes don't affect linking
2025-01-15 15:11:36 -08:00