1004 Commits

Author SHA1 Message Date
Veikka Tuominen
78e982f7c3 llvm: fix alignment of array ptr when bitcasting vector
Closes #17996
2024-01-29 13:51:57 +02:00
ocrap7
1ce12db5c8 Skip all dbg instructions 2024-01-16 15:01:42 -08:00
Jacob Young
03ed3f56cf Sema: fix @extern decls
Closes #18550
2024-01-15 07:39:05 +01:00
Andrew Kelley
30688c341b LLVM: fix lowering of extern anyopaque
closes #18461
2024-01-11 01:00:49 -08:00
Veikka Tuominen
faeb0ef032 llvm: optional slices cannot be passed in parts when they allowzero
Closes #18428
2024-01-08 06:57:06 +02:00
Andrew Kelley
0be97b5ae3 fix population of builtin.zig not making the parent dir 2024-01-01 17:51:20 -07:00
Andrew Kelley
2047a6b82d fix remaining compile errors except one 2024-01-01 17:51:20 -07:00
Andrew Kelley
638db680f4 move dll_export_fns and rdynamic to Compilation.Config 2024-01-01 17:51:20 -07:00
Andrew Kelley
b54ad93175 update codegen.llvm references to bin_file.options 2024-01-01 17:51:19 -07:00
Andrew Kelley
2596f5d925 update bin_file.options references in Sema
mainly pertaining to error return tracing
2024-01-01 17:51:19 -07:00
Andrew Kelley
c49957dbe8 fix a round of compile errors caused by this branch 2024-01-01 17:51:19 -07:00
Andrew Kelley
f54471b54c compiler: miscellaneous branch progress
implement builtin.zig file population for all modules rather than
assuming there is only one global builtin.zig module.

move some fields from link.File to Compilation
move some fields from Module to Compilation

compute debug_format in global Compilation config resolution

wire up C compilation to the concept of owner modules

make whole cache mode call link.File.createEmpty() instead of
link.File.open()
2024-01-01 17:51:19 -07:00
Andrew Kelley
33cdf33b95 compiler: update many references to bin_file.options 2024-01-01 17:51:19 -07:00
Andrew Kelley
b162c3c820 update bin_file.options references in Module (Zcu) 2024-01-01 17:51:19 -07:00
Andrew Kelley
f5ddef1e45 update references to module (to be renamed to zcu) 2024-01-01 17:51:19 -07:00
Andrew Kelley
0789e91eeb linkers: update references to "options" field 2024-01-01 17:51:19 -07:00
Andrew Kelley
9a48a5ab07 compiler: update references to single_threaded 2024-01-01 17:51:19 -07:00
Andrew Kelley
2bef0715c7 move a large chunk of linker logic away from "options"
These options are only supposed to be provided to the initialization
functions, resolved, and then computed values stored in the appropriate
place (base struct or the object-format-specific structs).

Many more to go...
2024-01-01 17:51:18 -07:00
Andrew Kelley
12de7e3472 WIP: move many global settings to become per-Module
Much of the logic from Compilation.create() is extracted into
Compilation.Config.resolve() which accepts many optional settings and
produces concrete settings. This separate step is needed by API users of
Compilation so that they can pass the resolved global settings to the
Module creation function, which itself needs to resolve per-Module
settings.

Since the target and other things are no longer global settings, I did
not want them stored in link.File (in the `options` field). That options
field was already a kludge; those options should be resolved into
concrete settings. This commit also starts to work on that, deleting
link.Options, moving the fields into Compilation and
ObjectFormat-specific structs instead. Some fields were ephemeral and
should not have been stored at all, such as symbol_size_hint.

The link.File object of Compilation is now a `?*link.File` and `null`
when -fno-emit-bin is passed. It is now arena-allocated along with
Compilation itself, avoiding some messy cleanup code that was there
before.

On the command line, it is now possible to configure the standard
library itself by using `--mod std` just like any other module. This
meant that the CLI needed to create the standard library module rather
than having Compilation create it.

There are a lot of changes in this commit and it's still not done. I
didn't realize how quickly this changeset was going to balloon out of
control, and there are still many lines that need to be changed before
it even compiles successfully.

* introduce std.Build.Cache.HashHelper.oneShot
* add error_tracing to std.Build.Module
* extract build.zig file generation into src/Builtin.zig
* each CSourceFile and RcSourceFile now has a Module owner, which
  determines some of the C compiler flags.
2024-01-01 17:51:18 -07:00
Jacob Young
3f2a65594e Compilation: cleanup hashmap usage 2024-01-01 13:38:30 -08:00
Stefan Su
42ddf592dd
use casted_rhs instead of rhs so icmp works correctly for airShlSat 2023-12-22 14:51:41 +00:00
Jacob Young
daf91ed8d1 Air: use typesafe Air.Inst.Index
I need some indices for a thing...
2023-12-03 02:05:06 -08:00
Meghan Denny
2549de80b2 move Module.Decl.Index and Module.Namespace.Index to InternPool 2023-11-26 02:24:40 -05:00
Techatrix
18608223ef convert toType and toValue to Type.fromInterned and Value.fromInterned 2023-11-25 04:09:53 -05:00
Andrew Kelley
91b897ef58 rework memory management of Module.Namespace hash maps
The motivating problem here was a memory leak in the hash maps of
Module.Namespace.

The commit deletes more of the legacy incremental compilation
implementation. It had things like use of orderedRemove and trying to do
too much OOP-style creation and deletion of objects.

Instead, this commit iterates over all the namespaces on Module deinit
and calls deinit on the hash map fields. This logic is much simpler to
reason about.

Similarly, change global inline assembly to an array hash map since
iterating over the values is a primary use of it, and clean up the
remaining values on Module deinit, solving another memory leak.

After this there are no more memory leaks remaining when using the
x86 backend in a libc-less compiler.
2023-11-12 23:21:21 -05:00
Jacob Young
59375b3c22 llvm: workaround SROA misoptimizations in LLVM
Workaround #16392
2023-11-10 15:46:42 -05:00
Andrew Kelley
3fc6fc6812 std.builtin.Endian: make the tags lower case
Let's take this breaking change opportunity to fix the style of this
enum.
2023-10-31 21:37:35 -04:00
Andrew Kelley
4bc88dd116 link: support exporting constant values without a Decl
The main motivating change here is to prevent the creation of a fake
Decl object by the frontend in order to `@export()` a value.

Instead, `link.updateDeclExports` is renamed to `link.updateExports` and
accepts a tagged union which can be either a Decl.Index or a
InternPool.Index.
2023-10-26 20:32:16 -07:00
mlugg
20bb81166f
InternPool: remove runtime_value representation
The main goal of this commit is to remove the `runtime_value` field from
`InternPool.Key` (and its associated representation), but there are a
few dominos. Specifically, this mostly eliminates the "maybe runtime"
concept from value resolution in Sema: so some resolution functions like
`resolveMaybeUndefValAllowVariablesMaybeRuntime` are gone. This required
a small change to struct/union/array initializers, to no longer
use `runtime_value` if a field was a `variable` - I'm not convinced this
case was even reachable, as `variable` should only ever exist as the
trivial value of a global runtime `var` decl.

Now, the only case in which a `Sema.resolveMaybeUndefVal`-esque function
can return the `variable` key is `resolveMaybeUndefValAllowVariables`,
which is directly called from `Sema.resolveInstValueAllowVariables`
(previously `Sema.resolveInstValue`), which is only used for resolving
the value of a Decl from `Module.semaDecl`.

While changing these functions, I also slightly reordered and
restructured some of them, and updated their doc comments.
2023-10-24 14:28:33 +01:00
Andrew Kelley
94d61ce964
Merge pull request #17651 from Vexu/error-limit
Make distinct error limit configurable (attempt #2)
2023-10-23 03:19:03 -04:00
Veikka Tuominen
9d9e22e716 remove uses of non-configurable err_int 2023-10-22 14:29:26 +03:00
Andrew Kelley
7bab406c79 InternPool: store alignment of anon decls
Commit 5393e56500d499753dbc39704c0161b47d1e4d5c has a flaw pointed out
by @mlugg: the `ty` field of pointer values changes when comptime values
are pointer-casted. This commit introduces a new encoding which
additionally stores the "original pointer type" which is used to store
the alignment of the anonymous decl, and potentially other information
in the future such as section and pointer address space. However, this
new encoding is only used when the original pointer type differs from
the casted pointer type in a meaningful way.

I was able to make the LLVM backend and the C backend lower anonymous
decls with the appropriate alignment, however I will need some help
figuring out how to do this for the backends that lower anonymous decls
via src/codegen.zig and the wasm backend.
2023-10-21 21:38:41 -04:00
Andrew Kelley
ecfb18286a migrate make_ptr_const to new anonymous decl mechanism
Instead of creating Module.Decl objects, directly create InternPool
pointer values using the anon_decl Addr encoding.

The LLVM backend needed code to notice the alignment of the pointer and
lower accordingly. The other backends likely need a similar change.
2023-10-21 21:38:41 -04:00
Robin Voetter
ab701c3d37
spirv: anon decl refs 2023-10-15 13:59:24 +02:00
Andrew Kelley
ab4d6bf468 LLVM: work around @floatFromInt bug
see #17381
2023-10-14 00:33:46 -07:00
Andrew Kelley
69dc1a6bb2 llvm: fix incorrect file paths in debug info
The previous code incorrectly added `sub_path` twice.

Also for the compilation unit, it was passing empty string to realpath,
resulting in the error handling codepath being used.

closes #17482
2023-10-13 03:07:50 -07:00
Andrew Kelley
aaf46187ab
Merge pull request #17391 from xxxbxxx/load-i4
codegen/llvm: truncate padding bits when loading a non-byte-sized value
2023-10-09 22:06:49 -07:00
Andrew Kelley
35d81c99c0 more fixes related to previous commits Package/Module API 2023-10-08 16:54:31 -07:00
Andrew Kelley
f708c5fafc CLI: finish updating module API usage
Finish the work started in 4c4fb839972f66f55aa44fc0aca5f80b0608c731.
Now the compiler compiles again.

Wire up dependency tree fetching code in the CLI for `zig build`.
Everything is hooked up except for `createDependenciesModule` is not yet
implemented.
2023-10-08 16:54:31 -07:00
Xavier Bouchoux
40528b8a93 codegen/llvm: add workarounds to loadTruncate() for llvm codegen bugs
for wasm, as a heuritic, only enable truncation for values smaller than 32bits.
 -> the bug is no longer triggered in most use cases (or at least the test suite...)

as for powerpc, adding a redundant `and mask` produces working code.
2023-10-08 11:37:49 +02:00
Xavier Bouchoux
370662c565 codegen/llvm: truncate padding bits when loading a non-byte-sized value 2023-10-08 11:37:49 +02:00
Jacob Young
6bb10c7271 llvm: fix load of packed struct that was initialized through pointers 2023-10-08 11:37:49 +02:00
Jakub Konka
8b4e3b6aee comp: add support for -fdata-sections 2023-10-04 11:21:56 -07:00
Andrew Kelley
c0b5512544 compiler: start handling anonymous decls differently
Instead of explicitly creating a `Module.Decl` object for each anonymous
declaration, each `InternPool.Index` value is implicitly understood to
be an anonymous declaration when encountered by backend codegen.

The memory management strategy for these anonymous decls then becomes to
garbage collect them along with standard InternPool garbage.

In the interest of a smooth transition, this commit only implements this
new scheme for string literals and leaves all the previous mechanisms in
place.
2023-10-03 12:12:50 -07:00
ocrap7
c933a7c58c llvm: remove extra copy of wrapped payloads 2023-10-03 11:16:11 -07:00
Andrew Kelley
5c3393dc2e
Merge pull request #17375 from xxxbxxx/packed-struct
codegen: fix field offsets in packed structs
2023-10-03 11:13:40 -07:00
Andrew Kelley
7733894761
Merge pull request #17341 from rzezeski/illumos-updates
Illumos/Solaris updates
2023-10-03 11:04:41 -07:00
Xavier Bouchoux
405705cb76 codegen: fix byte-aligned field offsets in unaligned nested packed structs 2023-10-03 05:34:19 +00:00
Xavier Bouchoux
62d178e91a codegen: fix field offsets in packed structs
* add nested packed struct/union behavior tests
 * use ptr_info.packed_offset rather than trying to duplicate the logic from Sema.structFieldPtrByIndex()
 * use the container_ptr_info.packed_offset to account for non-aligned nested structs.
 * dedup type.packedStructFieldBitOffset() and module.structPackedFieldBitOffset()
2023-10-03 06:39:20 +02:00
Stephen Gregoratto
285970982a Add illumos OS tag
- Adds `illumos` to the `Target.Os.Tag` enum. A new function,
  `isSolarish` has been added that returns true if the tag is either
  Solaris or Illumos. This matches the naming convention found in Rust's
  `libc` crate[1].
- Add the tag wherever `.solaris` is being checked against.
- Check for the C pre-processor macro `__illumos__` in CMake to set the
  proper target tuple. Illumos distros patch their compilers to have
  this in the "built-in" set (verified with `echo | cc -dM -E -`).

  Alternatively you could check the output of `uname -o`.

Right now, both Solaris and Illumos import from `c/solaris.zig`. In the
future it may be worth putting the shared ABI bits in a base file, and
mixing that in with specific `c/solaris.zig`/`c/illumos.zig` files.

[1]: 6e02a329a2/src/unix/solarish
2023-10-02 15:31:49 -06:00