Comments (4)
inline functions can call themselves with #167 and the compiler will complain if there are too many backwards branches.
However, if an inline function calls itself in the generated (post-evaluated) function, then there should be an error.
from zig.
This is actually a really hard problem. We want to catch things like indirect recursion with inline functions, but sometimes indirect recursion is fine, if it terminates.
LLVM handles this by ignoring the alwaysinline attribute when it can't do the inlining.
We can duplicate LLVM's analysis and logic, or we can try to reach back into the module post-optimization and discover if inlining failed.
from zig.
I added a compile error for when an inline function cannot be inlined. It looks at the post-optimization module and sees if the function got inlined. However there are these harder, unsolved problems:
- There is no
note:
pointing to the cause of why the function cannot be inlined. - There are cases when debug mode and release mode are different, because LLVM optimizations can do crazy stuff like figure out that indirect recursion is tail called and change it to a loop:
export fn foo() {
bar();
}
inline fn bar() {
quux();
baz();
}
inline fn baz() {
quux();
bar();
}
extern fn quux();
In debug mode this gives error: unable to inline function
but in release mode, it ends up figuring out this:
; Function Attrs: nounwind
define void @foo() local_unnamed_addr #0 !dbg !16 {
Entry:
br label %tailrecurse.i
tailrecurse.i: ; preds = %tailrecurse.i, %Entry
tail call void @quux() #0, !dbg !22
tail call void @quux() #0, !dbg !27
br label %tailrecurse.i, !dbg !31
}
- We don't have a way to figure out if callsite inlining worked.
Moving this to another milestone to deal with.
from zig.
zig version
0.6.0+d4d509090
fn number() !void {
_ = try @import("std").fmt.parseFloat(f64, &[_]u8{ 1, 2, 3, 4, 5 });
}
test "parseFloat" {
_ = number;
}
gives:
..\lib\zig\std\fmt\parse_float.zig:55:5: error: unable to inline function
inline fn shiftLeft1(d: *Z96, s: Z96) void {
^
..\lib\zig\std\fmt\parse_float.zig:62:5: error: unable to inline function
inline fn add(d: *Z96, s: Z96) void {
^
..\lib\zig\std\fmt\parse_float.zig:48:5: error: unable to inline function
inline fn shiftRight1(d: *Z96, s: Z96) void {
^
calling number
works, but in my real code I do call the function (in some other function) and still get the same error.
from zig.
Related Issues (20)
- zig cc --target=wasm32-wasi-musl: unsupported linker arg: --import-undefined HOT 2
- translate-c macro `parseCCondExpr` doesn't handle condition being an int
- WASM LLVM crash on std.math.atan2(0, 1) HOT 2
- introduce `@branchWeight` builtin HOT 11
- Document Effects of Endianness on Packed Structs HOT 1
- translate-c build step causing crash in build system HOT 2
- translate-c build step lacks a way to link system libraries HOT 1
- InternPool unreachable when coercing extern function (`// use getExternFunc() instead`) HOT 4
- additional tooling for ABI compatibility verification HOT 3
- some projects use .s extension for preprocessed assembly source files, incompatible with zig's extension-based detection HOT 7
- Struggles building on mac m1 & trying to change & test std lib. HOT 1
- std.posix.recvmsg() missing
- Erroneous `local variable is never mutated` error when using inferred many-item pointer HOT 6
- Remove `usingnamespace` HOT 49
- Compiling Zig compiler to `wasm32-wasi` target HOT 2
- Comptime error return trace
- File duplicated when imports twice with differing case HOT 1
- avoid file system watches on read-only mounts HOT 2
- file system watching on linux fails to avoid placing marks from different mounts into the same fanotify descriptor
- Unable to use `callconv(.Interrupt)` for riscv targets HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zig.