aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/fn.zig
AgeCommit message (Collapse)Author
2025-09-23forbid trivial local address returned from functions (#25333)Andrew Kelley
progress towards #25312
2025-09-20add behavior test: return undefined pointer from functionAndrew Kelley
This clarifies that it is legal to return an invalid pointer from a function, provided that such pointer is not dereferenced. This matches current status quo of the language. Any change to this should be a proposal that argues for different semantics. It is also legal in C to return a pointer to a local. The C backend lowers such thing directly, so the corresponding warning in C must be disabled (`-Wno-return-stack-address`).
2025-07-22aarch64: add new from scratch self-hosted backendJacob Young
2025-07-11Remove numerous things deprecated during the 0.14 release cycleLinus Groh
Basically everything that has a direct replacement or no uses left. Notable omissions: - std.ArrayHashMap: Too much fallout, needs a separate cleanup. - std.debug.runtime_safety: Too much fallout. - std.heap.GeneralPurposeAllocator: Lots of references to it remain, not a simple find and replace as "debug allocator" is not equivalent to "general purpose allocator". - std.io.Reader: Is being reworked at the moment. - std.unicode.utf8Decode(): No replacement, needs a new API first. - Manifest backwards compat options: Removal would break test data used by TestFetchBuilder. - panic handler needs to be a namespace: Many tests still rely on it being a function, needs a separate cleanup.
2025-06-16rename spirv backend nameAli Cheraghi
`stage2_spirv64` -> `stage2_spirv`
2025-05-31Legalize: implement scalarization of binary operationsJacob Young
2025-03-24Sema: fix in-memory coercion of functions introducing new generic parametersmlugg
While it is not allowed for a function coercion to change whether a function is generic, it *is* okay to make existing concrete parameters of a generic function also generic, or vice versa. Either of these cases implies that the result is a generic function, so comptime type checks will happen when the function is ultimately called. Resolves: #21099
2025-02-24test: skip failing tests with spirv-vulkanAli Cheraghi
2025-02-06behavior: add test for old bugmlugg
Resolves: #18435
2025-01-21compiler: simplify generic functions, fix issues with inline callsmlugg
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-16all: update to `std.builtin.Type.Pointer.Size` field renamesmlugg
This was done by regex substitution with `sed`. I then manually went over the entire diff and fixed any incorrect changes. This diff also changes a lot of `callconv(.C)` to `callconv(.c)`, since my regex happened to also trigger here. I opted to leave these changes in, since they *are* a correct migration, even if they're not the one I was trying to do!
2024-12-18compiler: disallow `callconv` etc from depending on function parametersmlugg
Resolves: #22261
2024-12-08cbe: prevent tautological-compare warnings in generated codeJacob Young
2024-12-08AstGen: correctly deduplicate `ref` of `param` and `alloc_inferred`mlugg
Both of these instructions were previously under a special case in `rvalue` which resulted in every reference to such an instruction adding a new `ref` instruction. This had the effect that, for instance, `&a != &a` for parameters. Deduplicating these `ref` instructions was problematic for different reasons. For `alloc_inferred`, the problem was that it's not valid to `ref` the alloc until the allocation has been resolved (`resolve_inferred_alloc`), but `AstGen.appendBodyWithFixups` would place the `ref` directly after the `alloc_inferred`. This is solved by bringing `resolve_inferred_alloc` in line with `make_ptr_const` by having it *return* the final pointer, rather than modifying `sema.inst_map` of the original `alloc_inferred`. That way, the `ref` refers to the `resolve_inferred_alloc` instruction, so is placed immediately after it, avoiding this issue. For `param`, the problem is a bit trickier: `param` instructions live in a body which must contain only `param` instructions, then a `func{,_inferred,_fancy}`, then a `break_inline`. Moreover, `param` instructions may be referenced not only by the function body, but also by other parameters, the return type expression, etc. Each of these bodies requires separate `ref` instructions. This is solved by pulling entries out of `ref_table` after evaluating each component of the function declaration, and appending the refs later on when actually putting the bodies together. This gives way to another issue: if you write `fn f(x: T) @TypeOf(x.foo())`, then since `x.foo()` takes a reference to `x`, this `ref` instruction is now in a comptime context (outside of the `@TypeOf` ZIR body), so emits a compile error. This is solved by loosening the rules around `ref` instructions; because they are not side-effecting, it is okay to allow `ref` of runtime values at comptime, resulting in a runtime-known value in a comptime scope. We already apply this mechanism in some cases; for instance, it's why `runtime_array.len` works in a `comptime` context. In future, we will want to give similar treatment to many operations in Sema: in general, it's fine to apply runtime operations at comptime provided they don't have side effects! Resolves: #22140
2024-09-12Replace deprecated default initializations with decl literalsLinus Groh
2024-08-28std: update `std.builtin.Type` fields to follow naming conventionsmlugg
The compiler actually doesn't need any functional changes for this: Sema does reification based on the tag indices of `std.builtin.Type` already! So, no zig1.wasm update is necessary. This change is necessary to disallow name clashes between fields and decls on a type, which is a prerequisite of #9938.
2024-08-15elf: fix up riscv for `.got.zig` rewriteDavid Rubin
2024-07-26riscv: update tests and fix reuse bugDavid Rubin
2024-07-26riscv: implement more operatorsDavid Rubin
we can run `std.debug.print` now, with both run-time strings and integers!
2024-06-13riscv: implement optional logicDavid Rubin
2024-06-13riscv: add `airAggregateInit` for arraysDavid Rubin
2024-06-13riscv: first sign of floats!David Rubin
2024-06-13riscv: `std.fmt.format` runningDavid Rubin
- implements `airSlice`, `airBitAnd`, `airBitOr`, `airShr`. - got a basic design going for the `airErrorName` but for some reason it simply returns empty bytes. will investigate further. - only generating `.got.zig` entries when not compiling an object or shared library - reduced the total amount of ops a mnemonic can have to 3, simplifying the logic
2024-06-13riscv: arbitrary sized arraysDavid Rubin
2024-05-11riscv: finally fix bug + `airAggregateInit`David Rubin
i just hadn't realized that I placed the `riscv_start` branch in the non-simplified starts
2024-05-11riscv: by-value structs + `@min`David Rubin
2024-05-11riscv: math progressDavid Rubin
2024-05-11riscv: add stage2_riscv to test matrix and bypass failing testsDavid Rubin
2024-04-13cbe: fix optional codegenJacob Young
Also reduce ctype pool string memory usage, remove self assignments, and enable more warnings.
2024-04-07Sema: fix runtime call of inline fn with comptime-known comptime-only ret typeCarl Åstholm
2024-04-06spirv: enable passing testsRobin Voetter
2024-02-06x86_64+macho: pass more behavior testsJakub Konka
2024-01-19do not enforce function parameters to be marked comptime if only called at ↵Meghan Denny
comptime
2024-01-15test/behavior: replace all 'comptime expect' with 'comptime assert'dweiller
2023-11-19test: update behavior to silence 'var is never mutated' errorsmlugg
2023-10-29x86_64: fix compiler rt test failuresJacob Young
2023-10-27categorize fn ptr behavior testAndrew Kelley
move a function pointer test from bugs/xxx.zig to fn.zig
2023-10-22Revert "Revert "Merge pull request #17637 from jacobly0/x86_64-test-std""Jacob Young
This reverts commit 6f0198cadbe29294f2bf3153a27beebd64377566.
2023-10-22Revert "Merge pull request #17637 from jacobly0/x86_64-test-std"Andrew Kelley
This reverts commit 0c99ba1eab63865592bb084feb271cd4e4b0357e, reversing changes made to 5f92b070bf284f1493b1b5d433dd3adde2f46727. This caused a CI failure when it landed in master branch due to a 128-bit `@byteSwap` in std.mem.
2023-10-21x86_64: fix crashesJacob Young
2023-10-15spirv: update failing / passing testsRobin Voetter
Some tests are now failing due to debug info changes, some tests now pass due to improved compiler functionality.
2023-09-23spirv: enable passing testsRobin Voetter
2023-09-23spirv: disable failing testsRobin Voetter
2023-07-31std: cleanup asm usageJacob Young
After fixing some issues with inline assembly in the C backend, the std cleanups have the side effect of making these functions compatible with the backend, allowing it to be used on linux without linking libc.
2023-06-24all: migrate code to new cast builtin syntaxmlugg
Most of this migration was performed automatically with `zig fmt`. There were a few exceptions which I had to manually fix: * `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten * `@truncate`'s fixup is incorrect for vectors * Test cases are not formatted, and their error locations change
2023-06-20Type: remove arbitrary restrictions on param and return typesJacob Young
Opaque and `noreturn` makes sense since they don't represent real values, but `null` and `undefined` are perfectly normal comptime-only values. Closes #16088
2023-06-13all: replace `comptime try` with `try comptime`Eric Joldasov
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-05-20spirv: ptr_elem_valRobin Voetter
Implements the ptr_elem_val air tag. Implementation is unified with ptr_elem_ptr.
2023-05-20spirv: more passing testsRobin Voetter
2023-05-15x86_64: implement calling function referencesJacob Young