Commit Graph

1590 Commits

Author SHA1 Message Date
mlugg 9eda6ccefc InternPool: use separate key for slices
This change eliminates some problematic recursive logic in InternPool,
and provides a safer API.
2024-02-02 11:02:03 +00:00
Veikka Tuominen 7d75c3d3b8 llvm: ensure returned undef is 0xaa bytes when runtime safety is enabled
Closes #13178
2024-01-29 17:35:07 -08:00
Andrew Kelley f4f8036ec0 Merge pull request #18729 from Vexu/fixes
Fix some generic{Reader,Writer} related issues
2024-01-29 13:07:37 -08:00
Veikka Tuominen f93a36c091 llvm: revert bad array access optimization
Closes #18723
2024-01-29 08:43:27 -08:00
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
Jacob Young 047d6d996e cbe: fix non-msvc externs and exports
Closes #17817
2024-01-03 02:52:25 -05:00
Jacob Young 98b633ff17 Reapply "Merge pull request #17824 from kcbanner/fixup_msvc_fmax"
This reverts commit 2b58978360.
2024-01-03 02:41:21 -05: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
Andrew Kelley 2b58978360 Revert "Merge pull request #17824 from kcbanner/fixup_msvc_fmax"
This reverts commit 7161ed79c4, reversing
changes made to 3f2a65594e.

Unfortunately, this sat in the PR queue too long and the merge broke the
zig1.wasm bootstrap process.
2024-01-01 17:49:57 -07:00
Andrew Kelley 7161ed79c4 Merge pull request #17824 from kcbanner/fixup_msvc_fmax
cbe: add a system for avoiding collisions with C compiler intrinsics
2024-01-01 15:36:16 -08: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
Robin Voetter decff51238 spirv: structured control flow 2023-11-24 17:50:11 +01:00
Robin Voetter b4b1c4df64 spirv: add -fstructured-cfg option
This enables the compiler to generate a structured cfg even in opencl,
even if it is not strictly required by the SPIR-V Kernel specification.
2023-11-24 11:40:18 +01:00
Robin Voetter cb026c5d59 spirv: always emit mask constants even if no bits are set
A parameter like this is not always optional, even if that is
usually implied. SPIR-V tools fail to parse a module with an
OpLoopMerge instruction where the loop control parameter is
left out.
2023-11-24 01:11:15 +01:00
Robin Voetter 255737ea57 spirv: fix memory leak in SpvModule 2023-11-24 01:11:14 +01:00
mlugg b355893438 compiler: correct unnecessary uses of 'var' 2023-11-19 11:11:49 +00: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
Andrew Kelley 63e5476450 Merge pull request #17963 from jacobly0/workaround/16392
llvm: workaround SROA misoptimizations in LLVM
2023-11-11 05:08:36 -05:00
Jacob Young ae8992629c BitcodeReader: followup cleanup 2023-11-10 22:35:35 -05:00
Jacob Young 59375b3c22 llvm: workaround SROA misoptimizations in LLVM
Workaround #16392
2023-11-10 15:46:42 -05:00
Jacob Young 10f4486c0b Compilation: forward clang diagnostics to error bundles 2023-11-09 16:43:12 -05:00
kcbanner 35c86984a6 cbe: support rendering union values that have no defined tag type
This was regressed in d657b6c0e2, when
the comptime memory model for unions was changed to allow them to have
no defined tag type.
2023-11-07 00:49:39 +00:00
kcbanner 26dabbf301 cbe: handle underscore prexfix on macos, don't mangle extern function names 2023-11-05 20:34:13 -05:00
kcbanner 192e9a315d cbe: add DeclVisibility and zig_extern_mangled to handle exporting mangled symbols under a different name 2023-11-05 20:34:13 -05:00
kcbanner ce293c982e cbe: avoid collisions with builtins and intrinsics
Changes:
- Add `isMangledIdent` to determine if `fmtIdent` would make any edits to the identifier
- Any function that has a mangled identifier is referred to using the mangled identifer
  within the current file, but if it is exported the first export will be with the non-mangled name.
- Add `zig_import` to import a symbol under a different name
- Add a level of indirection to float function names. Now, they are referred to as
  `zig_float_fn_<float type>_<operation>`. The definitions in zig.h are wrapped
  with `zig_import` to import the symbol under the real name.

The specific problem that sparked this change was the combination of
`zig_libc_name_f80(name) __##name##x` with the input `fma`, resulting
in `__fmax`, which is a new intrinsic in recent versions of cl.exe.

With the above changes in place, compiler_rt can output the following:

```
static zig_weak_linkage_fn zig_f80 zig_e___fmax(zig_f80, zig_f80, zig_f80);
zig_export(zig_weak_linkage_fn zig_f80 zig_e___fmax(zig_f80, zig_f80, zig_f80), __fmax, "__fmax");
```

Within compiler_rt, `zig_e___fmax` is used to refer to the function, but consumers
will import `__fmax`, which maps to their `zig_float_fn_f80_fma` definition from zig.h.
2023-11-05 20:34:13 -05:00
Jacob Young 13b1e10b8f cbe: fix @bitCast warnings 2023-10-31 21:37:40 -04: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
Andrew Kelley cbcef2d806 C backend: remove some @as 2023-10-25 19:57:02 -07:00