16860 Commits

Author SHA1 Message Date
Andrew Kelley
a70307e7ff CLI: add unit test and improve sanitizeExampleName 2025-02-26 11:42:03 -08:00
Andrew Kelley
eff1716b6c Package: update unit tests to new API 2025-02-26 11:42:03 -08:00
Andrew Kelley
7cedc01b7e zig init: sanitize generated name
Adhere to the new rules: 32 byte limit + must be a valid bare zig
identifier
2025-02-26 11:42:03 -08:00
Andrew Kelley
d6a88ed74d introduce package id and redo hash format again
Introduces the `id` field to `build.zig.zon`.

Together with name, this represents a globally unique package
identifier. This field should be initialized with a 16-bit random number
when the package is first created, and then *never change*. This allows
Zig to unambiguously detect when one package is an updated version of
another.

When forking a Zig project, this id should be regenerated with a new
random number if the upstream project is still maintained. Otherwise,
the fork is *hostile*, attempting to take control over the original
project's identity.

`0x0000` is invalid because it obviously means a random number wasn't
used.

`0xffff` is reserved to represent "naked" packages.

Tracking issue #14288

Additionally:

* Fix bad path in error messages regarding build.zig.zon file.
* Manifest validates that `name` and `version` field of build.zig.zon
  are maximum 32 bytes.
* Introduce error for root package to not switch to enum literal for
  name.
* Introduce error for root package to omit `id`.
* Update init template to generate `id`
* Update init template to populate `minimum_zig_version`.
* New package hash format changes:
  - name and version limited to 32 bytes via error rather than truncation
  - truncate sha256 to 192 bits rather than 40 bits
  - include the package id

This means that, given only the package hashes for a complete dependency
tree, it is possible to perform version selection and know the final
size on disk, without doing any fetching whatsoever. This prevents
wasted bandwidth since package versions not selected do not need to be
fetched.
2025-02-26 11:42:03 -08:00
Andrew Kelley
9763dd2901 Package.Manifest: enforce maximum version string length of 32 2025-02-26 11:42:03 -08:00
Andrew Kelley
76e8b297b1 Package.Manifest: enforce name limit of 32 2025-02-26 11:42:03 -08:00
Andrew Kelley
a57b0a0f2f fix generated hash of by-path dependencies
This branch regressed from master by switching to binary rather than hex
digest, allowing null bytes to end up in identifiers in the zig file.

This commit fixes it by changing the "hash" to be literally equal to the
sub_path (with a prefix '/' to indicate "global") if it can fit. If it
is too long then it is actually hashed, and that value used instead.
2025-02-26 11:42:03 -08:00
Andrew Kelley
e03bc7ac78 require package names to be valid zig identifiers 2025-02-26 11:42:03 -08:00
Andrew Kelley
12355cfb4c Package: new hash format
legacy format is also supported.

closes #20178
2025-02-26 11:42:03 -08:00
Andrew Kelley
f74a856d84 reword deprecated error slightly
"found" -> "reached" to match "reached unreachable code"
2025-02-26 14:41:33 -05:00
Andrew Kelley
c5aa680c88 don't inherit allowed deprecation from parent modules
Inheriting allow-deprecation from parent modules doesn't make too much
sense, so instead make them default to disallow unless otherwise
specified. This allows build system to avoid redundant
`-fno-allow-deprecated` args.

This makes the generated CLIs smaller, and makes zig1.wasm update not
needed.

Also represented `is_root` differently (moved to field of graph).
2025-02-26 14:41:33 -05:00
Loris Cro
466fa311b1 @deprecated: optimize sema implementation
mlugg suggested a better way of implementing analysis of an istruction
that cannot be referenced by other instructions.
2025-02-26 14:41:33 -05:00
Loris Cro
c75fdd96d2 @deprecated: add tests 2025-02-26 14:41:33 -05:00
Loris Cro
fff8eff2bd initial implementation of @deprecated 2025-02-26 14:41:33 -05:00
Ali Cheraghi
8957b27074 Compilation: disable ubsan_rt for spirv target 2025-02-26 14:39:30 -05:00
Andrew Kelley
c45dcd013b
Merge pull request #22488 from Rexicon226/ubsan-rt
implement a ubsan runtime for better error messages
2025-02-26 03:08:36 -05:00
mlugg
84da520c44
Sema: remove legacy coercion
This was meant to be removed in #21817, but was somehow missed.
2025-02-26 00:17:09 +00:00
mlugg
e0a955afb3 x86_64: use ZON for encodings 2025-02-25 22:32:00 +00:00
mlugg
de8a1211c1 Zcu: correctly resolve references to test bodies
Resolves: #21569
Resolves: #22912
2025-02-25 22:29:02 +00:00
Robin Voetter
d856763aca
Merge pull request #22937 from alichraghi/ali_spv
spirv: make test suite working again
2025-02-25 20:27:37 +01:00
Andrew Kelley
e18c7f9cca ubsan: don't create ubsan in every static lib by default
Problem here is if zig is asked to create multiple static libraries, it
will build the runtime multiple times and then they will conflict.
Instead we want to build the runtime exactly once.
2025-02-25 11:22:33 -08:00
David Rubin
35b9db3b15 correct some bugs 2025-02-25 11:22:33 -08:00
David Rubin
931178494f Compilation: correct when to include ubsan 2025-02-25 11:22:33 -08:00
David Rubin
14178475e3 main: add -f{no-}ubsan-rt to the usage text 2025-02-25 11:22:33 -08:00
David Rubin
2d4574aafb Compilation: always import ubsan if a ZCU exists
Unlike `compiler-rt`, `ubsan` uses the standard library quite a lot.
Using a similar approach to how `compiler-rt` is handled today, where it's
compiled into its own object and then linked would be sub-optimal as we'd
be introducing a lot of code bloat.

This approach always "imports" `ubsan` if the ZCU, if it exists. If it doesn't
such as the case where we're compiling only C code, then we have no choice other
than to compile it down to an object and link. There's still a tiny optimization
we can do in that case, which is when compiling to a static library, there's no
need to construct an archive with a single object. We'd only go back and parse out
ubsan from the archive later in the pipeline. So we compile it to an object instead
and link that to the static library.

TLDR;
- `zig build-exe foo.c` -> build `libubsan.a` and links
- `zig build-obj foo.c` -> doesn't build anything, just emits references to ubsan runtime
- `zig build-lib foo.c -static` -> build `ubsan.o` and link it
- `zig build-exe foo.zig bar.c` -> import `ubsan-rt` into the ZCU
- `zig build-obj foo.zig bar.c` -> import `ubsan-rt` into the ZCU
- `zig build-lib foo.zig bar.c` -> import `ubsan-rt` into the ZCU
2025-02-25 11:22:33 -08:00
David Rubin
95720f007b move libubsan to lib/ and integrate it into -fubsan-rt 2025-02-25 11:22:33 -08:00
David Rubin
c27b7973c9 Compilation: use the minimal runtime in ReleaseSafe 2025-02-25 11:22:33 -08:00
David Rubin
5e0073c898 ubsan: add a basic runtime 2025-02-25 11:22:33 -08:00
Andrew Kelley
466ce48e4c link.MachO.UnwindInfo: reproduce lld's comment
it explains why zero is used instead of saturation
2025-02-25 11:18:42 -08:00
Alex Rønne Petersen
743623bc54 link.MachO.UnwindInfo: Handle u24 overflow for CU records pointing to DWARF.
Closes #23010.
2025-02-25 11:13:00 -08:00
Alex Rønne Petersen
bedf806672
Merge pull request #22999 from alexrp/mingw-update 2025-02-25 12:54:55 +01:00
Robin Voetter
fe5a78691f
spirv: get rid of function_types cache
This deep hash map doesn't work
2025-02-24 20:58:13 +01:00
Ali Cheraghi
94af47d28c
spirv: do not generate unnecessary forward pointer
Co-authored-by: Robin Voetter <robin@voetter.nl>
2025-02-24 19:12:38 +01:00
Ali Cheraghi
a0eec9ce9e
spirv: replace some unreachables with compile errors 2025-02-24 19:12:33 +01:00
Alex Rønne Petersen
8afe928b6e
mingw: Update MinGW-w64 sources to 3839e21b08807479a31d5a9764666f82ae2f0356. 2025-02-24 12:01:07 +01:00
Alex Rønne Petersen
ecc76348e6
Merge pull request #22154 from alexrp/disable-intrinsics
compiler: Implement `@disableIntrinsics()` builtin function.
2025-02-24 08:25:23 +01:00
Alex Rønne Petersen
76558f8c6b llvm: Fix C ABI integer promotion for loongarch64.
It appears to just be a 1:1 copy of riscv64, including the super weird sign
extension quirk for u32.

Contributes to #21671.
2025-02-24 06:07:05 +01:00
mlugg
5e20e9b449 Sema: allow @ptrCast of slices changing the length
Also, refactor `Sema.ptrCastFull` to not be a horrifying hellscape.
2025-02-23 08:28:58 +00:00
Jacob Young
220f80e71d Dwarf: fix lowering of comptime-only optional pointer null values
Closes #22974
2025-02-22 22:47:32 -05:00
David Rubin
84aac8b6c7 Type: resolve union tag type before checking for runtime bits 2025-02-22 22:22:55 -05:00
Alex Rønne Petersen
e11ac02662
cbe: Implement support for -fno-builtin and @disableIntrinsics(). 2025-02-23 04:08:58 +01:00
Alex Rønne Petersen
6ba785584a
compiler: Implement @disableIntrinsics() builtin function.
Closes #21833.
Closes #22110.
2025-02-23 04:08:56 +01:00
Andrew Kelley
eb3c7f5706 zig build fmt 2025-02-22 17:09:20 -08:00
Andrew Kelley
c0c911bfa7 zig fmt: fix invalid alignment on frees 2025-02-22 17:09:20 -08:00
87flowers
855445f18e arch/sparc64/CodeGen: Fix indentation in realStackOffset 2025-02-22 17:09:20 -08:00
Alex Rønne Petersen
5e203e157b
Merge pull request #22903 from alexrp/llvm-nobuiltin-memcpy-inline
`llvm`: Use inline variants of `memcpy`/`memset` intrinsics when using `-fno-builtin`
2025-02-23 00:51:40 +01:00
Pavel Verigo
b25d93e7d9 stage2-wasm: implement switch_dispatch + handle > 32 bit integers in switches
Updated solution is future proof for arbitary size integer handling for both strategies .br_table lowering if switch case is dense, .br_if base jump table if values are too sparse.
2025-02-22 18:34:00 -05:00
Andrew Kelley
61b69a418d
Merge pull request #22659 from ifreund/linker-script-fix
link: fix ambiguous names in linker scripts
2025-02-22 18:18:24 -05:00
Alex Rønne Petersen
21eb757497
llvm: Use inline variants of memcpy/memset intrinsics when using -fno-builtin.
This is a correctness issue: When -fno-builtin is used, we must assume that we
could be compiling the memcpy/memset implementations, so generating calls to
them is problematic.
2025-02-22 15:06:40 +01:00
Alex Rønne Petersen
41b179ca09
llvm.Builder: Update some intrinsic definitions for LLVM 19. 2025-02-22 15:06:37 +01:00