12605 Commits

Author SHA1 Message Date
Jacob Young
70e0d8170f Sema: cleanup @as invasion 2023-08-28 17:25:39 -04:00
mlugg
b8e6c42688 compiler: provide result type for @memset value
Resolves: #16986
2023-08-28 12:33:36 -07:00
mlugg
8d036d1d78 Sema: allow cast builtins on vectors
The following cast builtins did not previously work on vectors, and have
been made to:

* `@floatCast`
* `@ptrFromInt`
* `@intFromPtr`
* `@floatFromInt`
* `@intFromFloat`
* `@intFromBool`

Resolves: #16267
2023-08-28 12:32:02 -07:00
Jacob Young
c6024691cf Sema: implement reference trace with called from here notes
Closes #15124
2023-08-28 12:28:25 -07:00
Jay Petacat
ff61c42879 std: Rename TailQueue to DoublyLinkedList
`TailQueue` was implemented as a doubly-linked list, but named after an
abstract data type. This was inconsistent with `SinglyLinkedList`, which
can be used to implement an abstract data type, but is still named after
the implementation. Renaming `TailQueue` to `DoublyLinkedList` improves
consistency between the two type names, and should help discoverability.

`TailQueue` is now a deprecated alias of `DoublyLinkedList`.

Related to issues #1629 and #8233.
2023-08-27 20:57:46 -07:00
riverbl
87557b37c6 Replace @panic with unreachable, add test
Replace `@panic` with `unreachable` in stage2 wasm `@divFloor` implementation

Add test for division and remainder operations for stage2 wasm
2023-08-23 20:34:59 +01:00
riverbl
383e6ffc7b Implement @mod and fix bugs with divFloor for wasm
Implement lowering code for `@mod` on integers in the stage2 wasm backend

Fix invalid wasm being produced for `@divFloor` on signed integers by the stage2 wasm backend
2023-08-23 16:52:30 +01:00
Andrew Kelley
6780a6bbfa wasm backend: delete dead code in lowerConstant 2023-08-22 19:02:58 -07:00
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
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
Jacob Young
4ac20f69ac Revert "llvm: fix bootstrap"
This reverts commit ea72fea1a4e2bc8309c211308f49f7f2c38507be.
2023-08-20 12:40:34 -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
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
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
510802d25e comp: forward -iframework/-iframeworkwithsysroot paths to the backend 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
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
Jakub Konka
01836c7bbe comp: make --verbose-cc actually thread-safe 2023-08-16 18:04:10 -07: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
Jakub Konka
787e755a2f macho: tie FDEs and unwind records to all symbol aliases
This is in particular very important to the Zig language which
allows exporting the same symbol under different names. For instance,
it is possible to have a case such that:

```
...
4258 T _foo
4258 T _bar
...
```

In this case we need to keep track of both symbol names when resolving
FDEs and unwind records.
2023-08-16 12:07:37 +02:00
Evan Haas
49cb1683ff translate-c: Use canonical type of field for flexible array definition
This prevents incorrectly casting an ElaboratedType to ArrayType
if the flexible field is a typedef'ed zero-length array

Fixes #16838
2023-08-15 23:59:07 -07:00
Evan Haas
bdf5739c0a translate-c: Flexible array members must be the last field in a struct
Previously any zero-length or incomplete array within a struct was treated
as a flexible array member.
2023-08-15 23:59:07 -07:00
mlugg
083ee8e0e2
InternPool: preserve indices of builtin types when resolved
Some builtin types have a special InternPool index (e.g.
`.type_info_type`) so that AstGen can refer to them before semantic
analysis. Unfortunately, this previously led to a second index existing
to refer to the type once it was resolved, complicating Sema by having
the concept of an "unresolved" type index.

This change makes Sema modify these InternPool indices in-place to
contain the expanded representation when resolved. The analysis of the
corresponding decls is caught in `Module.semaDecl`, and a field is set
on Sema telling it which index to place struct/union/enum types at. This
system could break if `std.builtin` contained complex decls which
evaluate multiple struct types, but this will be caught by the
assertions in `InternPool.resolveBuiltinType`.

The AstGen result types which were disabled in 6917a8c have been
re-enabled.

Resolves: #16603
2023-08-15 11:45:23 +01:00
mlugg
6e2eb208aa
Sema: queue type resolution whem emitting array_elem_val
This type not being resolved was a bug which was being triggered by the
next commit.
2023-08-15 11:42:25 +01:00
Xavier Bouchoux
f7b82ed416 objcopy: fix typo
fixes aecc15391a4c37a4504d29cb7e3179990b180773
the usual last 'harmless' cosmetic ajustement before commit strikes again...
2023-08-15 02:52:38 -07:00
mlugg
8f3ccbbe36 Sema: provide source location when analyzing panic handler
The panic handler decl_val was previously given a `unneeded` source
location, which was then added to the reference trace, resulting in a
crash if the source location was used in the reference trace. This
commit makes two trivial changes:

* Don't add unneeded source locations to the ref table (panic in debug, silently ignore in release)
* Pass a real source location when analyzing the panic handler
2023-08-14 11:43:21 -07:00
Krzysztof Wolicki
197d9a9eb3 Autodoc: remove assumption that slice's lhs is always a declRef 2023-08-14 15:44:21 +02:00
Jacob Young
1c5c3f499a cmake: fix auto-detection of various host targets
Closes #16800
2023-08-13 11:26:10 -07:00
Andre Herbst
014d88ef65 libunwind: Remove include for libcxx as its also done in upstream llvm repo 2023-08-12 13:47:09 -07:00
Andrew Kelley
6b06a696df
Merge pull request #16788 from xxxbxxx/objcopy-step
build/ObjCopy: strip debug info to a separate elf file
2023-08-12 10:30:32 -07:00
Xavier Bouchoux
aecc15391a objcpy: preserve the mode when striping an elf file.
+ clean some @as()
2023-08-12 09:54:20 +02:00
Jacob Young
09b0070e87 AstGen: cleanup @as invasion 2023-08-12 02:22:46 -04:00
Jacob Young
41575fa868 AstGen: fix src loc for invalid switch expression rls coercions 2023-08-12 02:22:26 -04:00
Jacob Young
ce7acf1296 AstGen: fix src loc for invalid coercion in breaks 2023-08-12 01:57:15 -04:00
Jacob Young
2b5bd56a67 AstGen: fix src loc for invalid coercions in tuple literals 2023-08-12 01:57:11 -04:00
Jacob Young
ffc116de78 AstGen: fix src loc for invalid if expression rls coercions
Closes #12509
2023-08-12 01:57:07 -04:00
mlugg
5e0107fbce Sema: remove redundant addConstant functions
After ff37ccd, interned values are trivial to convert to Air refs, using
`Air.internedToRef`. This made functions like `Sema.addConstant` effectively
redundant. This commit removes `Sema.addConstant` and `Sema.addType`, replacing
them with direct usages of `Air.internedToRef`.

Additionally, a new helper `Module.undefValue` is added, and the following
functions are moved into Module:
* `Sema.addConstUndef` -> `Module.undefRef`
* `Sema.addUnsignedInt` -> `Module.intRef` (now also works for signed types)

The general pattern here is that any `Module.xyzValue` helper may also have a
corresponding `Module.xyzRef` helper, which just wraps the call in
`Air.internedToRef`.
2023-08-11 11:02:24 -07:00
Jacob Young
8b9161179d Sema: avoid deleting runtime side-effects in comptime initializers
Closes #16744
2023-08-11 11:01:47 -07:00
Xavier Bouchoux
77dd64b5f4 Sema: fix coerceArrayLike() for vectors with padding
as explainded at https://llvm.org/docs/LangRef.html#vector-type :

"In general vector elements are laid out in memory in the same way as array types.
Such an analogy works fine as long as the vector elements are byte sized.
However, when the elements of the vector aren’t byte sized it gets a bit more complicated.
One way to describe the layout is by describing what happens when a vector such
as <N x iM> is bitcasted to an integer type with N*M bits, and then following the
rules for storing such an integer to memory."

"When <N*M> isn’t evenly divisible by the byte size the exact memory layout
is unspecified (just like it is for an integral type of the same size)."
2023-08-10 16:10:59 -07:00
Andrew Kelley
b820d5df79
Merge pull request #16747 from jacobly0/llvm-wo-libllvm
llvm: enable the backend even when not linked to llvm
2023-08-10 12:02:57 -07:00
mlugg
f32b9bc776
Sema: add references to generic instantiations
This makes the reference trace appear for generic calls where it
previously did not.

Resolves: #16725
2023-08-10 10:00:37 +01:00