zig/test
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
..
behavior compiler: simplify generic functions, fix issues with inline calls 2025-01-21 02:41:42 +00:00
c_abi std.Target: Replace isARM() with isArmOrThumb() and rename it to isArm(). 2024-11-03 09:29:30 +01:00
c_import std: update std.builtin.Type fields to follow naming conventions 2024-08-28 08:39:59 +01:00
cases compiler: simplify generic functions, fix issues with inline calls 2025-01-21 02:41:42 +00:00
incremental incremental: fix enum resolution bugs 2025-01-18 14:30:06 +00:00
link test/link/wasm/shared-memory: update to better linker behavior 2025-01-15 19:44:20 -08:00
src Dwarf: emit debug info for extern globals 2025-01-12 23:40:57 -05:00
standalone Merge pull request #22548 from mlugg/fix-broken-pipe 2025-01-20 21:40:04 -05:00
assemble_and_link.zig migrate from std.Target.current to @import("builtin").target 2021-10-04 23:48:55 -07:00
behavior.zig x86_64: testing 2025-01-16 20:42:08 -05:00
c_import.zig c_import: extract behavior tests that use @cImport 2024-02-20 18:44:43 +01:00
cases.zig remove test/cbe.zig 2024-03-28 15:24:01 +02:00
compare_output.zig compiler: remove anonymous struct types, unify all tuples 2024-10-31 20:42:53 +00:00
compile_errors.zig Sema: rewrite semantic analysis of function calls 2025-01-09 06:46:47 +00:00
gen_h.zig all: zig fmt and rename "@XToY" to "@YFromX" 2023-06-19 12:34:42 -07:00
llvm_targets.zig std.Target: Remove Os.Tag.bridgeos. 2024-12-03 20:43:15 +01:00
nvptx.zig test: Set emit_bin=false for all nvptx tests. 2024-11-24 22:11:17 +01:00
run_translated_c.zig remove hard tabs from source code 2024-07-31 16:57:42 -07:00
stack_traces.zig test/stack_traces.zig: add err union switch case 2024-01-18 15:10:32 +11:00
tests.zig build: respect -Duse-llvm option when doing behavior tests 2025-01-15 15:11:36 -08:00
translate_c.zig test: update for CallingConvention changes 2024-10-19 19:15:23 +01:00