Commit Graph
12562 Commits
Author SHA1 Message Date
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
mlugg 7a7d0225d9 Sema: detect invalid field stores in tuple initialization
This bug was exposed by the previous commit, since array_init is now
used for tuple parameters.
2023-08-10 10:00:37 +01:00
mlugg f2c8fa769a Sema: refactor generic calls to interleave argument analysis and parameter type resolution
AstGen provides all function call arguments with a result location,
referenced through the call instruction index. The idea is that this
should be the parameter type, but for `anytype` parameters, we use
generic poison, which is required to be handled correctly.

Previously, generic instantiations and inline calls worked by evaluating
all args in advance, before resolving generic parameter types. This
means any generic parameter (not just `anytype` ones) had generic poison
result types. This caused missing result locations in some cases.

Additionally, the generic instantiation logic caused `zirParam` to
analyze the argument types a second time before coercion. This meant
that for nominal types (struct/enum/etc), a *new* type was created,
distinct to the result type which was previously forwarded to the
argument expression.

This commit fixes both of these issues. Generic parameter type
resolution is now interleaved with argument analysis, so that we don't
have unnecessary generic poison types, and generic instantiation logic
now handles parameters itself rather than falling through to the
standard zirParam logic, so avoids duplicating the types.

Resolves: #16566
Resolves: #16258
Resolves: #16753
2023-08-10 10:00:26 +01:00
mluggandAli Chraghi 93e53d1e00 compiler: fix crash on invalid result type for @splat
This introduces a new ZIR instruction, `vec_elem_type`.

Co-Authored-By: Ali Chraghi <alichraghi@proton.me>
Resolves: #16567
2023-08-09 19:46:58 +01:00
mlugg 6917a8c258 AstGen: handle ty result location for struct and array init correctly
Well, this was a journey!

The original issue I was trying to fix is covered by the new behavior
test in array.zig: in essence, `ty` and `coerced_ty` result locations
were not correctly propagated.

While fixing this, I noticed a similar bug in struct inits: the type was
propagated to *fields* fine, but the actual struct init was
unnecessarily anonymous, which could lead to unnecessary copies. Note
that the behavior test added in struct.zig was already passing - the bug
here didn't change any easy-to-test behavior - but I figured I'd add it
anyway.

This is a little harder than it seems, because the result type may not
itself be an array/struct type: it could be an optional / error union
wrapper. A new ZIR instruction is introduced to unwrap these.

This is also made a little tricky by the fact that it's possible for
result types to be unknown at the time of semantic analysis (due to
`anytype` parameters), leading to generic poison. In these cases, we
must essentially downgrade to an anonymous initialization.

Fixing these issues exposed *another* bug, related to type resolution in
Sema. That issue is now tracked by #16603. As a temporary workaround for
this bug, a few result locations for builtin function operands have been
disabled in AstGen. This is technically a breaking change, but it's very
minor: I doubt it'll cause any breakage in the wild.
2023-08-09 19:46:55 +01:00
Zachary Raineri 0461a64a93 change uses of std.builtin.Mode to OptimizeMode (#16745)
std.builtin.Mode is deprecated.
2023-08-09 14:39:34 -04:00
Jacob Young 57470e833e Module: implement span for .call_arg of a @call
Closes #16750
2023-08-09 10:09:17 -04:00
Jacob Young 736df27663 Sema: use the correct decl for generic argument source locations
Closes #16746
2023-08-09 10:09:01 -04:00
Jacob Young 9630379a8e Sema: fix generic method argument source locations 2023-08-09 10:09:01 -04:00
Jacob Young c4848694d2 llvm: enable even without libllvm linked 2023-08-09 05:47:13 -04:00
Jacob Young 66084b6c3f Sema: remove validateRunTimeType
This function does not seem to differ in any interesting way from
`!typeRequiresComptime`, other than the `is_extern` param which is only
used in one place, and some differences did not seem correct anyway.

My reasoning for changing opaque types to be comptime-only is that
`explainWhyTypeIsComptime` is quite happy to explain why they are. :D
2023-08-09 05:46:44 -04:00
Jacob Young 3e1dd93bb2 llvm: force strip without libllvm to avoid unimplemented behavior
Also fix deinit bugs.
2023-08-08 23:32:40 -04:00
Jacob Young 53bea0f7e4 llvm: remove dependence on llvm data layout alignment
by just using the zig alignment and letting llvm promote it as desired
2023-08-08 22:09:44 -04:00
Jacob Young 35cd56a369 llvm: fix alias issues 2023-08-08 21:32:50 -04:00
Jacob Young 2bdd180c6f llvm: finish converting globals 2023-08-08 21:32:50 -04:00
Jacob Young 2499d8fb73 Builder: fix enough bugs to pass the behavior tests
without using any information from the LLVM API
2023-08-08 21:32:50 -04:00
Jacob Young a66cd54f94 llvm: cleanup even more unused LLVM API bindings 2023-08-08 21:32:50 -04:00
Jacob Young a0cb03ed99 llvm: finish converting instructions 2023-08-08 21:32:50 -04:00
Jacob Young 49cc1bff08 llvm: finish converting intrinsics 2023-08-08 21:32:50 -04:00
Jacob Young 6577f52614 llvm: convert vector reduction intrinsics
Scratch that thing I said about one pass. :)
2023-08-08 21:32:50 -04:00
Jacob Young e1efd4d3c2 Builder: simplify intrinsic table
This format removes back-references allowing it to be parsed in a single
pass.  It also reduces the number of kinds, simplifying the code.
2023-08-08 21:32:50 -04:00
Jacob Young 5b79f08ee8 llvm: finish converting attributes to use Builder and the C LLVM API 2023-08-08 21:32:50 -04:00
Jacob Young b63d9745b5 llvm: convert intrinsics to using Builder 2023-08-08 21:32:50 -04:00
Jacob Young 3ebf8ce970 Builder: fix builtin pseudo-instruction dumping 2023-08-08 21:32:50 -04:00
Jacob Young f938404a45 Builder: fix attribute spacing 2023-08-08 21:32:50 -04:00
Zachary Raineri 49244dc0ca std: remove some unused imports (#16710) 2023-08-06 15:18:50 -04:00
Jacob Young 1c7798a3cd Merge pull request #16705 from antlilja/builder-intrinsics
Implement more intrinsics in new LLVM IR builder API and remove uses of LLVM owns API
2023-08-05 23:05:02 -04:00
Robin Voetter 68f84964b3 llvm: add const addrspace cast 2023-08-05 17:11:57 -07:00
antlilja e149f1e1de Use new LLVM IR builder API in bit op lowering 2023-08-06 01:46:57 +02:00
antlilja 86f61a9d26 Implement bitop intrinsics in new LLVM IR builder
* llvm.bitreverse
* llvm.bswap
* llvm.ctpop
* llvm.ctlz
* llvm.cttz
2023-08-06 01:46:57 +02:00
antlilja 2b4ac7c6b3 Use new LLVM builder API in buildFloatOP 2023-08-06 01:46:56 +02:00
antlilja 63dcffdf9f Implement fp intrinsics in new LLVM IR builder
Intrinsics implemented
* llvm.ceil
* llvm.cos
* llvm.exp
* llvm.exp2
* llvm.fabs
* llvm.floor
* llvm.log
* llvm.log10
* llvm.log2
* llvm.round
* llvm.sin
* llvm.trunc
* llvm.fma
2023-08-06 01:46:51 +02:00
Jacob Young b8c9d5ae98 cbe: don't emit traps in naked functions
Closes #16680
2023-08-05 16:44:56 -07:00
Jacob Young a91a8df679 Sema: fix issues passing an invalid type to a generic method
Closes #16601
2023-08-05 11:21:50 -07:00
Jeremy Volkman 516eb33442 Fix typo: headerpat -> headerpad 2023-08-04 09:20:45 +02:00
Jakub Konka f96d773d98 macho: append syslibroot to search dirs when resolving libSystem 2023-08-03 09:52:15 -07:00
Andrew Kelley 72fb58f107 CLI: fix a typo that made static/dynamic do the opposite 2023-08-03 09:52:15 -07:00
Andrew Kelley 4923e64199 Compilation: detect sysroot from libc installation 2023-08-03 09:52:15 -07:00
Andrew Kelley 4089f96def darwin: pass -iframework to clang for system frameworks 2023-08-03 09:52:15 -07:00
Andrew Kelley 9dd9aa49a5 Compilation: fix incorrect non-optional assumption 2023-08-03 09:52:15 -07:00
Andrew Kelley 7360927afe CLI: add native paths only if ABI is also native 2023-08-03 09:52:15 -07:00
Andrew Kelley e582a3642b std.zig.system.darwin: fix redundant names 2023-08-03 09:52:15 -07:00
Andrew Kelley da91ef5c28 zig libc: restore functionality on macOS
Regressed in 2006add849.

References to native_darwin_sdk are no longer kept in the frontend.
Instead the darwin SDK is detected as part of NativePaths and as part of
LibCInstallation.
2023-08-03 09:52:15 -07:00
Andrew Kelley c94bbebb91 std.zig.system.NativePaths: simplify and integrate with Darwin SDK 2023-08-03 09:52:15 -07:00