GithubHelp home page GithubHelp logo

Comments (4)

andrewrk avatar andrewrk commented on August 11, 2024

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.

andrewrk avatar andrewrk commented on August 11, 2024

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.

andrewrk avatar andrewrk commented on August 11, 2024

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.

BarabasGitHub avatar BarabasGitHub commented on August 11, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.