www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9980] New: [CTFE] Allow interpreting function with variable arguments when their values aren't used

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9980

           Summary: [CTFE] Allow interpreting function with variable
                    arguments when their values aren't used
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: verylonglogin.reg gmail.com



13:56:57 MSD ---
---
int f(int)
{
    return 1;
}

int g(bool first, int a, int b)
{
    return first ? a : b;
}

void main()
{
    int i;
    static assert(f(i) == 1);
    static assert(g(true, 2, i) == 2);
    static assert(g(false, i, 3) == 3);
}
---

Currently code fails with "variable i cannot be read at compile time" errors.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 23 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9980




13:59:21 MSD ---
E.g. this will allow such `isLvalue` library implementation:
---
bool isLvalue(T)(auto ref T t)
{ return __traits(isRef, t); }


void main()
{
    int i;
    static assert( isLvalue(i));
    static assert(!isLvalue(i + 1));
}
---

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 23 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9980


timon.gehr gmx.ch changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |timon.gehr gmx.ch



I think fixing the following issue should already allow the implementation of
an isLvalue function:

http://d.puremagic.com/issues/show_bug.cgi?id=9981

The enhancement is still valid.
Are there other use cases you have in mind?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 23 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9980




The values _are_ used, though. Function arguments are evaluated when the
function is called, unless it's a 'lazy' argument.

Would you want this to also happen with:

static assert(g(true, 2, i + 1) == 2);

?
since 'i + 1' is used exactly as much as 'i' is in the original example.

So what this request is, is quite difficult to describe. It's kind of "delay
evaluation of function arguments in CTFE until the point at which they are used
in the function, if the argument has no side-effects".

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 12 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9980





 ...
 
 So what this request is, is quite difficult to describe. It's kind of "delay
 evaluation of function arguments in CTFE until the point at which they are used
 in the function, if the argument has no side-effects".
It should be sufficient to delay error reporting. (But I see no use case.) -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 12 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9980


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |WONTFIX





 ...
 
 So what this request is, is quite difficult to describe. It's kind of "delay
 evaluation of function arguments in CTFE until the point at which they are used
 in the function, if the argument has no side-effects".
It should be sufficient to delay error reporting. (But I see no use case.)
Yeah. But it's more complicated than the example suggests, since the 'unused variable' may be passed to another CTFE function... And this is actually extremely common. Very many functions only use their arguments by passing them to functions. I doubt you'd actually want this, since it would be hard to track down where the unused variable actually came from. A backtrace is not an answer, you only want the error messages to be exactly the same as they are now. It's also not clear in this proposal what constitutes "using" a value. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 14 2013