Jump to page: 1 2
Thread overview
[Issue 10506] New: Purity should not be checked in a mixin statement
Jun 29, 2013
Andrej Mitrovic
Jun 30, 2013
Kenji Hara
Jun 30, 2013
Andrej Mitrovic
Jul 01, 2013
yebblies
Jul 01, 2013
Andrej Mitrovic
Jul 01, 2013
yebblies
Jul 01, 2013
Andrej Mitrovic
Jul 01, 2013
Kenji Hara
Jul 05, 2013
Walter Bright
June 29, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10506

           Summary: Purity should not be checked in a mixin statement
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: andrej.mitrovich@gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-06-29 12:59:23 PDT ---
-----
import std.string;

void test() pure
{
     mixin(["foo", "bar"].join());
}

void main() {}
-----

> test.d(5): Error: pure function 'test.test' cannot call impure function 'std.array.join!(string[]).join'
> test.d(5): Error: found 'EOF' when expecting ';' following statement
> test.d(5): Error: undefined identifier foobar

I think the above should be allowed. I can't think of a case where the code which *produces* the string to be mixed in can somehow affect the purity of the function the mixin statement is in.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 30, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10506


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
          Component|DMD                         |Phobos
         Resolution|                            |FIXED


--- Comment #1 from Kenji Hara <k.hara.pg@gmail.com> 2013-06-30 03:04:01 PDT ---
Currently (from 2.063) compiler disables purity check in CTFE context.

void foobar() pure {}

string gen()    // impure
{ return "foobar;"; }

void test() pure
{
     mixin(gen());   // succeed to compile
}

That was the std.array.join issue. It uses std.array.Appender, but Appender had impure operation until very recent days.

https://github.com/D-Programming-Language/phobos/commit/4da1639c98cb73d07858b17c2d225063889e4700#L0L2287

(static member function "Appender.newCapacity" was impure)

Right now Appender operation is potentially pure, and in the OP case has been also changed to pure.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 30, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10506



--- Comment #2 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-06-30 05:25:04 PDT ---
(In reply to comment #1)
> That was the std.array.join issue. It uses std.array.Appender, but Appender had impure operation until very recent days.

Here's the thing though, aren't all functions when CTFE evaluated pure?

You can't save any state or read global state while in CTFE, so I'm thinking that during a chain of CTFE calls (e.g. join -> appender -> newCapacity), it isn't necessary to check for purity?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 01, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10506


yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies@gmail.com
          Component|Phobos                      |DMD
         Resolution|FIXED                       |DUPLICATE


--- Comment #3 from yebblies <yebblies@gmail.com> 2013-07-01 15:34:45 EST ---
This is issue 6169, which was fixed a while ago.  I don't know what compiler version you were using but I double-checked the source and it calls ctfeSemantic like it should.

*** This issue has been marked as a duplicate of issue 6169 ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 01, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10506



--- Comment #4 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-07-01 05:29:06 PDT ---
(In reply to comment #3)
> This is issue 6169, which was fixed a while ago.  I don't know what compiler version you were using but I double-checked the source and it calls ctfeSemantic like it should.
> 
> *** This issue has been marked as a duplicate of issue 6169 ***

Let's try this:

-----
import std.string;

void test() pure
{
     mixin(["int ", "x;"].join());
}

void main() {}
-----

2.061: ok
2.062: Error: pure function 'test' cannot call impure function 'join'
2.063: Error: pure function 'test' cannot call impure function 'join'
2.064: ok (but I think this is because join has become pure?)

Note that the test-case in Issue 6169 works in all of these compilers, but not the sample I gave.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 01, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10506


monarchdodra@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |monarchdodra@gmail.com


--- Comment #5 from monarchdodra@gmail.com 2013-07-01 06:00:47 PDT ---
(In reply to comment #4)
> (In reply to comment #3)
> > This is issue 6169, which was fixed a while ago.  I don't know what compiler version you were using but I double-checked the source and it calls ctfeSemantic like it should.
> > 
> > *** This issue has been marked as a duplicate of issue 6169 ***
> 
> Let's try this:
> 
> -----
> import std.string;
> 
> void test() pure
> {
>      mixin(["int ", "x;"].join());
> }
> 
> void main() {}
> -----
> 
> 2.061: ok
> 2.062: Error: pure function 'test' cannot call impure function 'join'
> 2.063: Error: pure function 'test' cannot call impure function 'join'
> 2.064: ok (but I think this is because join has become pure?)
> 
> Note that the test-case in Issue 6169 works in all of these compilers, but not the sample I gave.

I have reopened 6169 with this usecase:
--------
string bar(string op = "+") @property
{
    return "a" ~ op ~ "b";
}

void foo()()
{
    int a, b;
    int c = mixin(bar);
}

@safe void main()
{
    foo!()();
}
--------
main.d(14): Error: safe function 'D main' cannot call system function
'main.foo!().foo'
--------
Observations:
1) The problem is only with @safe, not pure.
2) Calling "min(bar("+"))" also makes the problem go away.
--------

Not sure if this is strictly 6169 or if I should have posted here and un-resolved as duplicate. But in any case, this is (I think) a simpler use case.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 01, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10506



--- Comment #6 from yebblies <yebblies@gmail.com> 2013-07-01 23:03:13 EST ---
(In reply to comment #4)
> 
> Let's try this:
> 
> -----
> import std.string;
> 
> void test() pure
> {
>      mixin(["int ", "x;"].join());
> }
> 
> void main() {}
> -----
> 
> 2.061: ok
> 2.062: Error: pure function 'test' cannot call impure function 'join'
> 2.063: Error: pure function 'test' cannot call impure function 'join'
> 2.064: ok (but I think this is because join has become pure?)
> 
> Note that the test-case in Issue 6169 works in all of these compilers, but not the sample I gave.

Ah, I think I know what's going on.  Does it possibly work in 2.063 when not using ufcs?  I think it's only getting the direct calls to semantic, but some others are being missed (eg resolveProperties)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 01, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10506



--- Comment #7 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-07-01 06:10:13 PDT ---
(In reply to comment #6)
> Does it possibly work in 2.063 when not using ufcs?

No, I get the same results.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 01, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10506


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull
             Status|RESOLVED                    |REOPENED
         Resolution|DUPLICATE                   |


--- Comment #8 from Kenji Hara <k.hara.pg@gmail.com> 2013-07-01 07:47:23 PDT ---
https://github.com/D-Programming-Language/dmd/pull/2289

Essentially this issue has been caused by the incomplete fix for bug 6169. But the actual issue is very small, so I'd like to keep this independent from that.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 05, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10506



--- Comment #9 from github-bugzilla@puremagic.com 2013-07-05 11:22:14 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/075f1ec31be42d13be4ca44fb861dd71216701c3 fix Issue 10506 - Purity should not be checked in a mixin statement

https://github.com/D-Programming-Language/dmd/commit/d16ce295dddda97d00cd3d2aabeb862e85437e02 Merge pull request #2289 from 9rnsr/fix10506

Issue 10506 - Purity should not be checked in a mixin statement

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
« First   ‹ Prev
1 2