mirror of
https://github.com/ziglang/zig.git
synced 2026-01-15 03:45:22 +00:00
The idea here is that there are two ways we can reference a function at runtime:
* Through a direct call, i.e. where the function is comptime-known
* Through a function pointer
This means we can easily perform a form of rudimentary escape analysis
on functions. If we ever see a `decl_ref` or `ref` of a function, we
have a function pointer, which could "leak" into runtime code, so we
emit the function; but for a plain `decl_val`, there's no need to.
This change means that `comptime { _ = f; }` no longer forces a function
to be emitted, which was used for some things (mainly tests). These use
sites have been replaced with `_ = &f;`, which still triggers analysis
of the function body, since you're taking a pointer to the function.
Resolves: #6256
Resolves: #15353
14 lines
297 B
Zig
14 lines
297 B
Zig
fn foo() [:0]u8 {
|
|
var x: []u8 = undefined;
|
|
return x;
|
|
}
|
|
comptime { _ = &foo; }
|
|
|
|
// error
|
|
// backend=stage2
|
|
// target=native
|
|
//
|
|
// :3:12: error: expected type '[:0]u8', found '[]u8'
|
|
// :3:12: note: destination pointer requires '0' sentinel
|
|
// :1:10: note: function return type declared here
|