25531 Commits

Author SHA1 Message Date
Andrew Kelley
ada0010471 compiler: move unions into InternPool
There are a couple concepts here worth understanding:

Key.UnionType - This type is available *before* resolving the union's
fields. The enum tag type, number of fields, and field names, field
types, and field alignments are not available with this.

InternPool.UnionType - This one can be obtained from the above type with
`InternPool.loadUnionType` which asserts that the union's enum tag type
has been resolved. This one has all the information available.

Additionally:

* ZIR: Turn an unused bit into `any_aligned_fields` flag to help
  semantic analysis know whether a union has explicit alignment on any
  fields (usually not).
* Sema: delete `resolveTypeRequiresComptime` which had the same type
  signature and near-duplicate logic to `typeRequiresComptime`.
  - Make opaque types not report comptime-only (this was inconsistent
    between the two implementations of this function).
* Implement accepted proposal #12556 which is a breaking change.
2023-08-22 13:54:14 -07:00
mlugg
6a5463951f Sema: disallow C pointer to slice coercion
Resolves: #16719
2023-08-21 11:31:22 -07:00
mlugg
82c8e45a7e Sema: check @memset operand provides length
Resolves: #16698
2023-08-21 11:30:20 -07:00
Carl Åstholm
60fc18bd1c compiler_rt: fix f80 comparisons
This corrects comparisons between negative numbers.
2023-08-21 11:26:25 -07:00
Gregory Mullen
f74e10cd47 Update default stack frames for general_purpose_allocator.zig
Created from a conversation with  @andrewrk on irc: Memory leaks when using ArrayList can be inconvenient to debug when the stack frame size is 4 because the entirety of the printed frame is within zig stdlib, and not in the users calling stack. Increasing this to 6 for Debug builds, gives 2 frames of user code. I increased the frame size for tests as well by the equivalent factor, but I'm unconvinced that's actually desirable.
2023-08-21 11:22:22 -07:00
Jakub Konka
8e96be0088
Merge pull request #16888 from ziglang/macho-frameworks
compiler: resolve framework paths in the frontend
2023-08-21 11:01:11 +02:00
mlugg
283afb50b5 AstGen: disallow '-0' integer literal
The intent here is ambiguous: this resolves to the comptime_int '0', but
it's likely the user meant to use a floating-point literal.

Resolves: #16890
2023-08-21 11:47:31 +03:00
Jakub Konka
b73ef34289 frontend: directly pass resolved frameworks container to the linker
We can infer the framework name from the included resolved framework
path.

Fix hash implementation, and bump linker hash value from 9 to 10.
2023-08-21 08:07:44 +02:00
Andrew Kelley
411462e1cd
Merge pull request #16875 from mlugg/astgen-rl-pass
AstGen: add result location analysis pass
2023-08-20 15:38:36 -07:00
Jacob Young
4ac20f69ac Revert "llvm: fix bootstrap"
This reverts commit ea72fea1a4e2bc8309c211308f49f7f2c38507be.
2023-08-20 12:40:34 -07:00
mlugg
3e1b676ac1
stage1: update zig1
This is necessary due to the CBE fixes in the previous commit.

Signed-off-by: Andrew Kelley <andrew@ziglang.org>
2023-08-20 12:40:10 -07:00
mlugg
7a85ad151d cbe: elide block result allocation for 0-bit types
This logic already existed for the void type, but is also necessary for
other 0-bit types. Without it, we try to alloc a local for a 0-bit type
which gets translated to a local of type `void` which C doesn't like.
2023-08-20 11:58:14 -07:00
mlugg
51f6438e07 AstRlAnnotate: work around upstream LLVM bug
This is a workaround for an LLVM bug causing compiler crashes for
certain targets, and can be reverted once a fix for that lands.

Tracked by #16876.
2023-08-20 11:58:14 -07:00
mlugg
321961d860 AstGen: add result location analysis pass
The main motivation for this change is eliminating the `block_ptr`
result location and corresponding `store_to_block_ptr` ZIR instruction.
This is achieved through a simple pass over the AST before AstGen which
determines, for AST nodes which have a choice on whether to provide a
result location, which choice to make, based on whether the result
pointer is consumed non-trivially.

This eliminates so much logic from AstGen that we almost break even on
line count! AstGen no longer has to worry about instruction rewriting
based on whether or not a result location was consumed: it always knows
what to do ahead of time, which simplifies a *lot* of logic. This also
incidentally fixes a few random AstGen bugs related to result location
handling, leading to the changes in `test/` and `lib/std/`.

This opens the door to future RLS improvements by making them much
easier to implement correctly, and fixes many bugs. Most ZIR is made
more compact after this commit, mainly due to not having redundant
`store_to_block_ptr` instructions lying around, but also due to a few
bugs in the old system which are implicitly fixed here.
2023-08-20 11:58:14 -07:00
Jakub Konka
4793dafa04 frontend: move framework path resolution from the linker to frontend 2023-08-20 10:43:20 +02:00
Jakub Konka
e687c87d69 macho: we no longer need to resolve framework dirs against sysroot 2023-08-20 08:37:44 +02:00
Ryan Liptak
020105d0dd Cache: Fix findPrefix when paths are slightly out of the ordinary
This makes Cache.findPrefix/findPrefixResolved use `std.fs.path.relative` instead of `std.mem.startsWith` when checking if a file is within a prefix. This fixes multiple edge cases around prefix detection:

- If a prefix path ended with a path separator, then the first character of the 'sub_path' would get cut off because the previous implementation assumed it was a path separator. Example: prefix: `/foo/`, file_path: `/foo/abc.txt` would see that they both start with `/foo/` and then slice starting from one byte past the common prefix, ending up with `bc.txt` instead of the expected `abc.txt`
- If a prefix contained double path separators after any component, then the `startsWith` check would erroneously fail. Example: prefix: `/foo//bar`, file_path: `/foo/bar/abc.txt` would not see that abc.txt is a sub path of the prefix `/foo//bar`
- On Windows, case insensitivity was not respected at all, instead the UTF-8 bytes were compared directly

This fixes all of the things in the above list (and possibly more).
2023-08-19 22:32:24 -07:00
Ryan Liptak
a11cdb6a34 os.realpathW: Reduce the number of OpenFile calls for directories
Same as a190582b26a82f96da7488eff37e9676cdb937bc but for os.realpathW instead of fs.Dir.realpathW
2023-08-19 22:29:46 -07:00
Andrew Kelley
4c97919e8e
Merge pull request #16885 from squeek502/windows-selfExePath-symlink
`fs.selfExePath`: Make the Windows implementation follow symlinks
2023-08-19 21:24:36 -07:00
Ryan Liptak
47343f9bcf Add self_exe_symlink standalone test
Tests that fs.selfExePath follows symlinks by comparing it to the path of the File returned from fs.openSelfExe
2023-08-19 17:48:19 -07:00
Ryan Liptak
2c2ecd624a fs.selfExePath: Make the Windows implementation follow symlinks
Before, selfExePath would be the path of the symlink on Windows instead of the path of what the symlink points to.

This deprecates fs.selfExePathW since it does not provide a separate use-case over selfExePath (before, the W version could return [:0]u16 directly)

Fixes #16670
2023-08-19 17:48:18 -07:00
Jakub Konka
ddf5859c22 macos: add <paths.h> header to Zig shipped libc 2023-08-19 14:23:00 +02:00
Ryan Liptak
e078324dbe Add NetworkNotFound to ReadLinkError
This matches how other filesystem functions were made to handle BAD_NETWORK_PATH/BAD_NETWORK_NAME in https://github.com/ziglang/zig/pull/16568. ReadLink was the odd one out, but that is no longer the case.
2023-08-18 18:07:16 -07:00
Andrew Kelley
84b4b6bffa
Merge pull request #16818 from ziglang/damn-sysroot
build: do not emit `-iwithsysroot`/`-iframeworkwithsysroot` implicitly
2023-08-18 18:06:20 -07:00
Ryan Liptak
3dd439030c fs tests: Use 127.0.0.1 instead of localhost as the server in UNC transformation
In theory, localhost could be mapped to a different address via the LMHOSTS file, so using 127.0.0.1 should remove that potential wrinkle and allow the drive-absolute -> UNC transformation to work on any(?) setup.

Also print the error name to ensure it gets printed in CI (aarch64-windows ReleaseSmall seemed not to print the error in the last intermittent UNC failure)
2023-08-18 12:21:54 -07:00
Jakub Konka
583914126f build: -Denable-ios-sdk implies -Denable-macos-sdk 2023-08-18 12:05:13 +02:00
Jakub Konka
f4afc6525b standalone: add iOS smoke test - test ability to target iOS with Zig 2023-08-18 11:58:11 +02:00
Jakub Konka
517a2c7caf build: add build test check for availability of IOS SDK on the host 2023-08-18 11:57:12 +02:00
Jakub Konka
1e899b8769 check-object: dump contents of LC_BUILD_VERSION and LC_VERSION_MIN_* cmds 2023-08-18 11:56:14 +02:00
Jakub Konka
274400c57d macho: add helper for accessing tools array in LC_BUILD_VERSION cmd 2023-08-18 11:55:29 +02:00
Jakub Konka
71cc2e6759 build: merge FrameworkDir into IncludeDir 2023-08-18 08:08:24 +02:00
Lewis Gaul
387b0ac4f1
Make NaNs quiet by default and other NaN tidy-up (#16826)
* Generalise NaN handling and make std.math.nan() give quiet NaNs

* Address uses of std.math.qnan_* and std.math.nan_* consts

* Comment out failing test due to issues with signalling NaN

* Fix issue in c_builtins.zig where we need qnan_u32
2023-08-18 02:07:49 -04:00
Jakub Konka
23b4a2b8e1 build: disambiguate system framework path (-iframework) from framework path (-F) 2023-08-18 08:00:40 +02:00
Jakub Konka
510802d25e comp: forward -iframework/-iframeworkwithsysroot paths to the backend 2023-08-18 08:00:40 +02:00
Jakub Konka
6a4b29a58f build: remove spurious -iframework flag; use getPath2 for framework path resolution 2023-08-18 08:00:40 +02:00
Jakub Konka
5e945f813c build: do not emit -iwithsysroot/-iframeworkwithsysroot implicitly
Prior to this change, we would unconditionally emit any system include path/framework
path as `-iwithsysroot`/`-iframeworkwithsysroot` if the sysroot was
set which can lead to unexpected build failures. Now, calls to
`b.addSystemIncludePath` and `b.addFrameworkPath` will always emit
search paths as `-isystem`/`-iframework`. As a result, it is now up to
the user to correctly concat the search paths with the sysroot when
and where desired.

If there is a need for emitting `-iwithsysroot`/`-iframeworkwithsysroot`
I would advise adding explicit hooks such as `addSystemIncludePathWithSysroot`
and `addFrameworkPathWithSysroot`.
2023-08-18 08:00:40 +02:00
Jakub Konka
6a9fd55809 cc: disambiguate includes with sysroot in ClangSearchSanitizer
This noninvasive change improves warning messages for mixing up
paths between `-iwithsysroot` and `-iframeworkwithsysroot`.
2023-08-18 08:00:40 +02:00
Andrew Kelley
7ef1eb1c27 InternPool: safer enum API
The key changes in this commit are:

```diff
-        names: []const NullTerminatedString,
+        names: NullTerminatedString.Slice,
-        values: []const Index,
+        values: Index.Slice,
```

Which eliminates the slices from `InternPool.Key.EnumType` and replaces
them with structs that contain `start` and `len` indexes. This makes the
lifetime of `EnumType` change from expiring with updates to InternPool,
to expiring when the InternPool is garbage-collected, which is currently
never.

This is gearing up for a larger change I started working on locally
which moves union types into InternPool.

As a bonus, I fixed some unnecessary instances of `@as`.
2023-08-17 18:16:03 -07:00
Andrew Kelley
8c1329b222
Merge pull request #16847 from squeek502/fs-fixes
`std.fs`: Improve tests and fix some bugs that were uncovered
2023-08-17 12:15:51 -07:00
Andrew Kelley
5ae5dc507b
Merge pull request #16824 from mikdusan/bsd
de-bitrot the BSDs
2023-08-17 12:14:30 -07:00
Michael Dusan
e288c54699
std.debug: openbsd does not have getcontext 2023-08-17 10:55:39 -04:00
Ian Johnson
f3f554b9b8
std.json: avoid stale pointers when parsing Value (#16864)
Closes #16861

Using `alloc_if_needed` when parsing a `Value` allows receiving a token
which points to the buffer of the underlying `Reader`. This token will
no longer be valid after the `Reader`'s buffer is refilled, which will
happen with large values. Using `alloc_always` avoids this issue by
ensuring the returned tokens always own their data independently of the
underlying buffer.
2023-08-17 07:52:46 -04:00
Ian Johnson
5395c2786a Autodoc: fix guide path resolution
The previous logic was using `root_src_directory` both in constructing
the resolved path and as the root when opening the resolved path, which
effectively duplicates those path components in the final path.
2023-08-17 12:38:53 +02:00
Ryan Liptak
2b44961a20 Fix ntToWin32Namespace and friends on big endian architectures 2023-08-17 00:59:19 -07:00
Ryan Liptak
8c8f3cbd43 fs tests: Update some testing.expect calls to use the more specific expect functions 2023-08-17 00:59:19 -07:00
Ryan Liptak
8f5f1ff25a fs tests: Test multiple different path types in most tests
(which path types will depend on which the target supports)
2023-08-17 00:59:19 -07:00
mlugg
000aa30086 std.Build: check for native CPU when serializing CrossTarget
When using `std.Build.dependency` with target options, dependencies
would sometimes get targets which are equivalent but have distinct
names, e.g. `native` vs `native-native`. This is a somewhat broad issue,
and it's unclear how to fix it more generally - perhaps we should
special-case CrossTarget in options passing, or maybe targets should
have a canonical name which we guarantee to use everywhere aside from
raw user input.

However, this commit fixes the most egregious issue, which was an active
blocker to using the package manager for some users. This was caused by
the CPU changing from `native` to a specific descriptor (e.g.
`skylake+sgx`), which then changed the behavior of `zigTriple`.

Resolves: #16856
2023-08-16 18:05:18 -07:00
Jakub Konka
01836c7bbe comp: make --verbose-cc actually thread-safe 2023-08-16 18:04:10 -07:00
Nitin Prakash
f1992a39a5
langref: minor documentation fixes to addCSourceFile (#16785) 2023-08-16 15:35:58 -04:00
Jakub Konka
fd830b146d
Merge pull request #16852 from ziglang/issue-16751
macho: tie FDEs and unwind records to all symbol aliases, not just the first global
2023-08-16 15:21:46 +02:00