Commit graph

10511 commits

Author SHA1 Message Date
mlugg
24babde746
std.mem.asBytes: fix footgun when passing non-single pointer
I was just bitten by this footgun, where I actually wanted
`sliceAsBytes` but unintentionally used `asBytes`, which in practice
ignored all but the first element. Just add a comptime assertion to
trigger a compile error in this case.
2024-10-31 20:42:53 +00:00
mlugg
d11bbde5f9
compiler: remove anonymous struct types, unify all tuples
This commit reworks how anonymous struct literals and tuples work.

Previously, an untyped anonymous struct literal
(e.g. `const x = .{ .a = 123 }`) was given an "anonymous struct type",
which is a special kind of struct which coerces using structural
equivalence. This mechanism was a holdover from before we used
RLS / result types as the primary mechanism of type inference. This
commit changes the language so that the type assigned here is a "normal"
struct type. It uses a form of equivalence based on the AST node and the
type's structure, much like a reified (`@Type`) type.

Additionally, tuples have been simplified. The distinction between
"simple" and "complex" tuple types is eliminated. All tuples, even those
explicitly declared using `struct { ... }` syntax, use structural
equivalence, and do not undergo staged type resolution. Tuples are very
restricted: they cannot have non-`auto` layouts, cannot have aligned
fields, and cannot have default values with the exception of `comptime`
fields. Tuples currently do not have optimized layout, but this can be
changed in the future.

This change simplifies the language, and fixes some problematic
coercions through pointers which led to unintuitive behavior.

Resolves: #16865
2024-10-31 20:42:53 +00:00
Archit Gupta
a916bc7fdd std.fs.File: Fix metadata error check on Linux
On Linux, File.metadata calls the statx syscall directly. As such, the
return value is the error code. Previously, it handled the error with
`posix.errno`, which when libc is linked, treats the return value as a
value set to -1 if there is an error with the error code in errno. If
libc wasn't linked, it would be handled correctly.

In the Linux with libc linked case, this would cause the error result to
always be treated as success (err val != -1), even when an error
occurred.
2024-10-31 14:02:42 +01:00
Simon Ekström
17a87d7341
std.fmt: Fix compile error in Parser.peek() (#20532) 2024-10-30 07:45:23 +00:00
Mario Nachbaur
4661705a0e
std.debug: watchOS: fixes for ilp32 ABI (#21765)
Xcode requires target arm64_32 (aarch64-watchos-ilp32) in order to
build code for Apple Watches. This commit fixes compilation errors
that appear when compiling with that target.
2024-10-29 22:12:57 +01:00
Robin Voetter
3450809e3d
Merge pull request #21826 from Snektron/spirv-vulkan
spirv: vulkan setup
2024-10-29 19:58:51 +01:00
Julian Noble
a03ab9ee01
std.os.windows.WriteFile: Map ERROR_NO_DATA to error.BrokenPipe instead of ERROR_BROKEN_PIPE (#21811)
It appears that ReadFile returns ERROR_BROKEN_PIPE for a broken pipe, but WriteFile returns ERROR_NO_DATA.

Co-authored-by: Alex Rønne Petersen <alex@alexrp.com>
2024-10-29 15:10:19 +01:00
JonathanHallstrom
5ce17ecfa7 remove unnecessary cast 2024-10-29 01:48:13 +01:00
Bruno Franca dos Reis
cdd8e82f0a
closes #21824 (#21832) 2024-10-28 14:54:02 +00:00
Alex Rønne Petersen
4c336705b9
Merge pull request #21807 from Rexicon226/riscv-interupt
implement new interrupt calling conventions in the llvm backend
2024-10-28 13:51:11 +01:00
David Rubin
6415ff29d7 remove needs_mem_loc
This field isn't used anymore and was related to old RLS
2024-10-28 08:17:31 +00:00
Robin Voetter
9b42bc1ce5
spirv: start.zig support for vulkan
* Use builtin.zig_backend instead of builtin.cpu.arch, the latter
  does not yet compile under VK.
* Don't call regular _start for either opencl or vulkan. We might
  even want to disable these completely.
2024-10-27 14:20:52 +01:00
Alex Rønne Petersen
059f18855f
std.Target: Make DynamicLinker.standard() much stricter.
Its semantics are now documented in terms of DynamicLinker.kind(os.tag).

The idea here is two-fold:

* The term "standard" actually means something; we shouldn't return a valid
  dynamic linker path for a triple for which it hasn't *actually* been
  standardized. That's just incorrect. For example, previously, this function
  would happily return a path for x86_64-linux-androideabi, csky-macos-gnu, or
  aarch64-hurd-msvc, and other such obvious nonsense.
* Callers that use the return value from this function to do host probing (such
  as std.zig.system.detectAbiAndDynamicLinker()) can now do so with greater
  confidence because DynamicLinker.standard() will eagerly reject nonsensical
  target triples.
2024-10-26 22:00:49 +02:00
Alex Rønne Petersen
8818dc6213
std.zig.system: Fix detectAbiAndDynamicLinker() for non-Linux/Hurd ELF hosts.
Since we exclude Abi.none from the list of ABIs to be tested, it means that
Abi.gnu, which happens to be the first in the list, always gets picked for hosts
where the dynamic linker path does not depend on the ABI component of the
triple. Such hosts include all the BSDs, Haiku, Serenity, Solaris, etc.

To fix this, use DynamicLinker.kind() to determine whether this whole exercise
even makes sense. If it doesn't, as is the case on every OS other than Linux and
Hurd, we'll just fall back to Abi.default() which will try to pick a sensible
default based on the arch and OS components. This detection logic still has
plenty of room for improvement, but is at least a notable step up from
confusingly detecting Abi.gnu ~everywhere.

Closes #9089.
2024-10-26 22:00:49 +02:00
Alex Rønne Petersen
27c85e5969
std.Target: Remove hasDynamicLinker() in favor of DynamicLinker.kind().
hasDynamicLinker() was just kind of lying in the case of Darwin platforms for
the benefit of std.zig.system.detectAbiAndDynamicLinker(). A better name would
have been hasElfDynamicLinker() or something. It also got the answer wrong for a
bunch of platforms that don't actually use ELF. Anyway, this was clearly the
wrong layer to do this at, so remove this function and instead use
DynamicLinker.kind() + an isDarwin() check in detectAbiAndDynamicLinker().
2024-10-26 22:00:49 +02:00
Alex Rønne Petersen
f02d25d883
std.Target: Implement DynamicLinker.kind() function.
This helps callers of DynamicLinker.standard() make informed decisions about
the usefulness of the returned value.
2024-10-26 22:00:49 +02:00
Alex Rønne Petersen
79717740bd
std.Target: Pick better baseline CPU models for darwin and ps4/ps5 on x86_64.
These are sourced from getX86TargetCPU() in Clang.
2024-10-26 21:59:59 +02:00
Alex Rønne Petersen
ea987faa85
std.Target: Use explicit baseline CPU models for bpf, m68k, msp430, and xcore.
This makes no difference presently, but if LLVM ever starts modeling features
for these, we would not get them by default for our baseline if we use the
generic model.
2024-10-26 21:59:59 +02:00
Alex Rønne Petersen
e26b64a87d
std.Target: Use mips32r2/mips64r2 as the baseline CPU models for mips/mips64.
This matches Clang's defaults. That also means these CPU models tend to get more
testing, so they're a safer baseline choice. Anecdotally, the oldest MIPS
hardware that I've seen anyone run Zig on was also r2.
2024-10-26 21:59:59 +02:00
Alex Rønne Petersen
385f586605
std.Target: Use sm_52 as the baseline CPU model for nvptx.
This matches Clang's default.
2024-10-26 21:59:59 +02:00
Alex Rønne Petersen
2d22cc9f61
std.Target: Use gfx906 as the baseline CPU model for amdgcn.
This matches Clang's default.
2024-10-26 21:59:59 +02:00
Alex Rønne Petersen
5b7eba95ba
std.Target: Use gfx600 as the generic CPU model for amdgcn.
This is the first model that was actually in the GCN family.
2024-10-26 21:59:59 +02:00
Alex Rønne Petersen
51dc4b0549
std.Target: Use ppc64 as the generic CPU model for powerpc64le.
ppc64le remains the baseline CPU model. Note that there's nothing about little
endian, 64-bit PowerPC that requires the features in the ppc64le model; the
reason it exists is that 64-bit PowerPC wasn't really used in little endian mode
prior to those features being commonplace. That makes the ppc64le model a good
baseline model, but not the right choice for a generic model.
2024-10-26 21:59:59 +02:00
Alex Rønne Petersen
8062bdba9a
std.Target: Use avr1 as the generic CPU model for avr.
avr2 remains the baseline CPU model.
2024-10-26 21:59:58 +02:00
Alex Rønne Petersen
c50fb58307
std.Target: Use v11 as the baseline CPU model for lanai. 2024-10-26 21:59:58 +02:00
Alex Rønne Petersen
73b4cb6314
std.Target: Use ck810 as the baseline CPU model for csky. 2024-10-26 21:59:58 +02:00
Alex Rønne Petersen
8282f3be96
std.Target: Add doc comments for Cpu.Arch.generic() and baseline(). 2024-10-26 21:59:58 +02:00
Nelson Crosby
b1361f237a Fix up Linux xattr syscalls
fgetxattr now doesn't accidentally call lgetxattr,
and argument types are more consistent.
2024-10-26 13:53:07 +02:00
David Rubin
b122b9fbe0
remove default field for RiscvInterruptOptions.Mode 2024-10-25 20:00:43 -07:00
Andrew Kelley
b8795b4d02
Merge pull request #21795 from ziglang/kqueue-watch
Build Runner: Implement File System Watching for kqueue
2024-10-25 04:00:26 -07:00
Linus Groh
5769592cdd std.os.uefi: Fix calling convention build error
```
std/os/uefi/protocol/simple_text_input.zig:10:63: error: no field named 'Win64' in enum '@typeInfo(builtin.CallingConvention).@"union".tag_type.?'
std/builtin.zig:169:31: note: enum declared here
std/os/uefi/protocol/simple_text_output.zig:9:64: error: no field named 'Win64' in enum '@typeInfo(builtin.CallingConvention).@"union".tag_type.?'
std/builtin.zig:169:31: note: enum declared here
std/os/uefi/tables/runtime_services.zig:26:86: error: no field named 'Win64' in enum '@typeInfo(builtin.CallingConvention).@"union".tag_type.?'
std/builtin.zig:169:31: note: enum declared here
```
2024-10-25 10:45:55 +02:00
Andrew Kelley
cc671a2d40 std.Build.Watch: implement removing watches for kqueue 2024-10-24 23:31:56 -07:00
Andrew Kelley
8819d8b061 std.Build.Watch: limit to one switch on os tag
DRY
2024-10-24 16:29:02 -07:00
Andrew Kelley
7a46ba73ce implement --watch for kqueue
it doesn't detect and remove no longer watched things yet

it also isn't aware of any file names reported by kqueue. I'm unsure if
that functionality exists.
2024-10-24 16:24:56 -07:00
Andrew Kelley
ba71079837 combine codegen work queue and linker task queue
these tasks have some shared data dependencies so they cannot be done
simultaneously. Future work should untangle these data dependencies so
that more can be done in parallel.

for now this commit ensures correctness by making linker input parsing
and codegen tasks part of the same queue.
2024-10-23 16:27:39 -07:00
Andrew Kelley
3f6b6b1bcd revert macos target version bump 2024-10-23 16:27:38 -07:00
Andrew Kelley
c2898c436f branch fixes 2024-10-23 16:27:38 -07:00
Andrew Kelley
e567abb339 rework linker inputs
* Compilation.objects changes to Compilation.link_inputs which stores
  objects, archives, windows resources, shared objects, and strings
  intended to be put directly into the dynamic section. Order is now
  preserved between all of these kinds of linker inputs. If it is
  determined the order does not matter for a particular kind of linker
  input, that item should be moved to a different array.
* rename system_libs to windows_libs
* untangle library lookup from CLI types
* when doing library lookup, instead of using access syscalls, go ahead
  and open the files and keep the handles around for passing to the
  cache system and the linker.
* during library lookup and cache file hashing, use positioned reads to
  avoid affecting the file seek position.
* library directories are opened in the CLI and converted to Directory
  objects, warnings emitted for those that cannot be opened.
2024-10-23 16:27:38 -07:00
Andrew Kelley
4706ec81d4 introduce a CLI flag to enable .so scripts; default off
The compiler defaults this value to off so that users whose system
shared libraries are all ELF files don't have to pay the cost of
checking every file to find out if it is a text file instead.

When a GNU ld script is encountered, the error message instructs users
about the CLI flag that will immediately solve their problem.
2024-10-23 16:27:38 -07:00
Andrew Kelley
a4cc344aa0 std.Build.Step.Compile: add a way to expect an error message
other than a compile error, specifically
2024-10-23 16:27:38 -07:00
Andrew Kelley
33d07f4b6e
Merge pull request #21779 from ziglang/avoid-data-races
link.MachO: remove buggy multi-threading
2024-10-23 16:27:09 -07:00
Andrew Kelley
78f643c46d
Merge pull request #21758 from kcbanner/dll_storage_class
Add `is_dll_import` to @extern, to support `__declspec(dllimport)` with the MSVC ABI
2024-10-23 15:35:54 -07:00
Andrew Kelley
d210f733f8 std.Progress: fix data race
In end(), the freelist pointer is owned so the bare store would be ok.
However, there is a load in start() that can happen at the same time, if
another start() and end() pair grabs that same index.

I don't think this fixes #21663 actually because even if the data race
corrupts the value for `next`, the cmpxchg protects the value from being
stored there.
2024-10-23 13:47:44 -07:00
Matthew Lugg
6bf52b0505
Merge pull request #21697 from mlugg/callconv
Replace `std.builtin.CallingConvention` with a tagged union, eliminating `@setAlignStack`
2024-10-23 16:48:33 +01:00
kcbanner
b87fa93500 Change ExternOptions.dll_storage_class to is_dll_import
It wouldn't make sense to have passe `.export` here, and that was
in fact a compile error - so simply make this a bool instead.
2024-10-22 12:41:35 -04:00
kcbanner
ee25757245 Add support for specifying dll_storage_class in @extern 2024-10-22 12:41:35 -04:00
Mario Nachbaur
9f84f7f921 watchOS: add os to aarch64 architecture
Needed for creating libraries that run both on
physical Apple Watches and the watchOS simulator.
2024-10-21 09:24:24 +02:00
mlugg
830230176d
std: update uses of .Inline callconv 2024-10-19 19:21:33 +01:00
mlugg
bde68fdebc
std.Target: correct C callconv on hardfloat ARM 2024-10-19 19:21:32 +01:00
mlugg
ed862b05ae
std.builtin.CallingConvention: remove deprecated RISC-V privilege mode
See b6cade0703
2024-10-19 19:21:32 +01:00