www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 23890] New: "Warning: cannot inline function" in core.lifetime

https://issues.dlang.org/show_bug.cgi?id=23890

          Issue ID: 23890
           Summary: "Warning: cannot inline function" in core.lifetime
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: regression
          Priority: P1
         Component: druntime
          Assignee: nobody puremagic.com
          Reporter: dlang-bugzilla thecybershadow.net

This code produces a warning inside Druntime, that the user cannot do much
about:

/////////////////////////// test.d ///////////////////////////
import core.lifetime;

auto fctr(alias fun, State...)(State state)
{
    struct Pred
    {
        State state;

        static if (state.length)
            private this(State state)
            {
                static foreach (i; 0 .. state.length)
                    moveEmplace(state[i], this.state[i]);
            }

        auto opCall(this This, Args...)(auto ref Args args)
        {
            return fun(state, args);
        }
    }

    static if (state.length)
        return Pred(forward!state);
    else
        return Pred.init;
}

unittest
{
    struct NC
    {
         disable this();
         disable this(this);
        int i;
        this(int i) { this.i = i; }
    }

    auto f = fctr!((ref a, ref b) => a.i + b.i)(NC(2), NC(3));
    assert(f() == 5);
}
//////////////////////////////////////////////////////////////

Command: dmd -o- -unittest -wi test.d

Output:
.../druntime/core/lifetime.d(1558): Warning: cannot inline function
`test.__unittest_L30_C1.fctr!((ref a, ref b) => a.i + b.i, NC,
NC).fctr.fwd!(_param_0).fwd`
.../druntime/core/lifetime.d(1558): Warning: cannot inline function
`test.__unittest_L30_C1.fctr!((ref a, ref b) => a.i + b.i, NC,
NC).fctr.fwd!(_param_1).fwd`
.../druntime/core/lifetime.d(2582): Warning: cannot inline function
`core.lifetime.wipe!(NC).wipe`

Most likely introduced in https://github.com/dlang/druntime/pull/3653.

--
May 05 2023