zig/src
mlugg 0ec6b2dd88 compiler: simplify generic functions, fix issues with inline calls
The original motivation here was to fix regressions caused by #22414.
However, while working on this, I ended up discussing a language
simplification with Andrew, which changes things a little from how they
worked before #22414.

The main user-facing change here is that any reference to a prior
function parameter, even if potentially comptime-known at the usage
site or even not analyzed, now makes a function generic. This applies
even if the parameter being referenced is not a `comptime` parameter,
since it could still be populated when performing an inline call. This
is a breaking language change.

The detection of this is done in AstGen; when evaluating a parameter
type or return type, we track whether it referenced any prior parameter,
and if so, we mark this type as being "generic" in ZIR. This will cause
Sema to not evaluate it until the time of instantiation or inline call.

A lovely consequence of this from an implementation perspective is that
it eliminates the need for most of the "generic poison" system. In
particular, `error.GenericPoison` is now completely unnecessary, because
we identify generic expressions earlier in the pipeline; this simplifies
the compiler and avoids redundant work. This also entirely eliminates
the concept of the "generic poison value". The only remnant of this
system is the "generic poison type" (`Type.generic_poison` and
`InternPool.Index.generic_poison_type`). This type is used in two
places:

* During semantic analysis, to represent an unknown result type.
* When storing generic function types, to represent a generic parameter/return type.

It's possible that these use cases should instead use `.none`, but I
leave that investigation to a future adventurer.

One last thing. Prior to #22414, inline calls were a little inefficient,
because they re-evaluated even non-generic parameter types whenever they
were called. Changing this behavior is what ultimately led to #22538.
Well, because the new logic will mark a type expression as generic if
there is any change its resolved type could differ in an inline call,
this redundant work is unnecessary! So, this is another way in which the
new design reduces redundant work and complexity.

Resolves: #22494
Resolves: #22532
Resolves: #22538
2025-01-21 02:41:42 +00:00
..
Air compiler: simplify generic functions, fix issues with inline calls 2025-01-21 02:41:42 +00:00
arch compiler: simplify generic functions, fix issues with inline calls 2025-01-21 02:41:42 +00:00
codegen compiler: simplify generic functions, fix issues with inline calls 2025-01-21 02:41:42 +00:00
Compilation Added support for thin lto 2025-01-05 18:08:11 +01:00
link macho linker: adjust symbol priority 2025-01-17 15:12:01 -08:00
Liveness dwarf: fix stepping through an inline loop containing one statement 2024-11-24 17:28:12 -05:00
Package compiler: Fix @import("builtin").unwind_tables logic. 2025-01-18 14:57:41 +01:00
Sema compiler: analyze type and value of global declaration separately 2024-12-24 02:18:41 +00:00
Zcu compiler: simplify generic functions, fix issues with inline calls 2025-01-21 02:41:42 +00:00
Air.zig compiler: simplify generic functions, fix issues with inline calls 2025-01-21 02:41:42 +00:00
Builtin.zig compiler: Improve the handling of unwind table levels. 2024-12-11 00:10:15 +01:00
clang.zig all: update to std.builtin.Type.Pointer.Size field renames 2025-01-16 12:46:29 +00:00
clang_options.zig zig cc: honor all -m and -mno- CPU feature flags 2021-11-26 19:59:33 -07:00
clang_options_data.zig compiler: Improve the handling of unwind table levels. 2024-12-11 00:10:15 +01:00
codegen.zig compiler: simplify generic functions, fix issues with inline calls 2025-01-21 02:41:42 +00:00
Compilation.zig x86_64: rewrite 2025-01-16 20:42:07 -05:00
crash_report.zig all: update to std.builtin.Type.Pointer.Size field renames 2025-01-16 12:46:29 +00:00
DarwinPosixSpawn.zig std.c.darwin.posix_spawn: fix signature 2024-12-16 14:53:54 +00:00
dev.zig x86_64: implement clz and not 2025-01-16 20:42:08 -05:00
fmt.zig compiler: introduce ZonGen and make ast-check run it for ZON inputs 2024-12-16 17:02:35 +00:00
glibc.zig implement the prelink phase in the frontend 2025-01-15 15:11:36 -08:00
InternPool.zig compiler: simplify generic functions, fix issues with inline calls 2025-01-21 02:41:42 +00:00
introspect.zig Fix handling of empty XDG environment variables 2024-08-19 23:30:14 -07:00
libcxx.zig compiler: Improve the handling of unwind table levels. 2024-12-11 00:10:15 +01:00
libtsan.zig tsan: Handle more Apple targets when picking library name. 2024-11-05 22:41:09 +01:00
libunwind.zig libunwind: Build C files with -fexceptions. 2025-01-18 13:15:58 +01:00
link.zig fix merge conflicts with updating line numbers 2025-01-15 15:11:36 -08:00
Liveness.zig x86_64: implement switch jump tables 2025-01-16 20:42:08 -05:00
main.zig x86_64: fix crashes compiling the compiler and tests 2025-01-16 20:47:30 -05:00
mingw.zig mingw: Add upstream RtlSecureZeroMemory implementation. 2025-01-14 05:31:14 +01:00
musl.zig remove memcpy and memmove from bundled libcs 2025-01-17 12:34:15 -08:00
mutable_value.zig all: update to std.builtin.Type.Pointer.Size field renames 2025-01-16 12:46:29 +00:00
Package.zig fetch: filter unpack errors 2024-04-09 15:00:21 +02:00
print_air.zig x86_64: rewrite 2025-01-16 20:42:07 -05:00
print_env.zig std: update std.builtin.Type fields to follow naming conventions 2024-08-28 08:39:59 +01:00
print_targets.zig move zig libc command to be lazily built 2024-02-27 22:55:00 -07:00
print_value.zig compiler: simplify generic functions, fix issues with inline calls 2025-01-21 02:41:42 +00:00
print_zir.zig compiler: simplify generic functions, fix issues with inline calls 2025-01-21 02:41:42 +00:00
print_zoir.zig compiler: introduce ZonGen and make ast-check run it for ZON inputs 2024-12-16 17:02:35 +00:00
RangeSet.zig sema: rework type resolution to use Zcu when possible 2024-08-25 15:16:42 -07:00
register_manager.zig x86_64: fix crashes compiling the compiler and tests 2025-01-16 20:47:30 -05:00
Sema.zig compiler: simplify generic functions, fix issues with inline calls 2025-01-21 02:41:42 +00:00
target.zig x86_64: enable struct field reordering 2025-01-18 16:14:51 -05:00
ThreadSafeQueue.zig link.flushTaskQueue: move safety lock 2024-10-23 16:27:39 -07:00
tracy.zig Add build option to set tracy-callstack-depth in build.zig (#21990) 2024-11-29 12:13:06 -08:00
translate_c.zig all: update to std.builtin.Type.Pointer.Size field renames 2025-01-16 12:46:29 +00:00
Type.zig compiler: simplify generic functions, fix issues with inline calls 2025-01-21 02:41:42 +00:00
Value.zig compiler: simplify generic functions, fix issues with inline calls 2025-01-21 02:41:42 +00:00
wasi_libc.zig remove memcpy and memmove from bundled libcs 2025-01-17 12:34:15 -08:00
Zcu.zig compiler: simplify generic functions, fix issues with inline calls 2025-01-21 02:41:42 +00:00
zig_clang.cpp zig_clang: Update to Clang 19. 2024-09-19 18:20:20 -07:00
zig_clang.h zig_clang: Update to Clang 19. 2024-09-19 18:20:20 -07:00
zig_clang_cc1_main.cpp compiler: Update LLVM/Clang driver files to LLVM/Clang 19. 2024-09-19 18:20:20 -07:00
zig_clang_cc1as_main.cpp compiler: Update LLVM/Clang driver files to LLVM/Clang 19. 2024-09-19 18:20:20 -07:00
zig_clang_driver.cpp compiler: Update LLVM/Clang driver files to LLVM/Clang 19. 2024-09-19 18:20:20 -07:00
zig_llvm-ar.cpp compiler: Update LLVM/Clang driver files to LLVM/Clang 19. 2024-09-19 18:20:20 -07:00
zig_llvm.cpp zig_llvm: Reduce our exposure to LLVM API breakage. 2024-10-31 01:27:22 +01:00
zig_llvm.h zig_llvm: Reduce our exposure to LLVM API breakage. 2024-10-31 01:27:22 +01:00