www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8651] New: Slice op Slice throws exceptions (not errors), and nothrow

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

           Summary: Slice op Slice throws exceptions (not errors), and
                    nothrow
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: monarchdodra gmail.com



2 related problems:

First
--------
import std.stdio;
void main()
{
  try
  {
    int[] b = new int[](10);
    b[] = 5;
    b[0..6] = b[4..10];
  }
  catch(Exception e)
  {
    writeln(e);
  }
  writeln("finish");
}
--------
The built-in range assign will throw an Exception when it fails. This should be
an Error.

Second
--------
nothrow void foo(int[] a)
{
  a[] = a[];
}

nothrow void bar(int[] a)
{
  a[] += a[];
}
--------
_arraySliceSliceAddass_i is not nothrow
function main.bar 'bar' is nothrow yet may throw
--------
This is doubly problematic:
First, these methods should throw Errors, so the code should compile.
Two, ironically, []+=[] currently doesn't throw anything, and []=[] throws an
exception, yet it is the []+=[] version that doesn't compile.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 13 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8651




Also, simple SlicoOp operations should be nothrow:

nothrow void foo(int[] a)
{
  a[] += 5;
}
Error: _arrayExpSliceAddass_i is not nothrow
Error: function main.foo 'foo' is nothrow yet may throw


nothrow void foo(int[] a)
{
  a[] &= 5;
}
Error: _arrayExpSliceAddass_i is not nothrow
Error: function main.foo 'foo' is nothrow yet may throw

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 15 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8651




Commits pushed to master at https://github.com/D-Programming-Language/druntime

https://github.com/D-Programming-Language/druntime/commit/92f92aa87c30370a2c7641499977dd0e53982540


https://github.com/D-Programming-Language/druntime/commit/92f92aa87c30370a2c7641499977dd0e53982540


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 25 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8651


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc



And someday even [1,2].dup will be nothrow.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 25 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8651





 And someday even [1,2].dup will be nothrow.
Doesn't dup allocate? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 25 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8651





 2 related problems:
 
 First
 --------
 import std.stdio;
 void main()
 {
   try
   {
     int[] b = new int[](10);
     b[] = 5;
     b[0..6] = b[4..10];
   }
   catch(Exception e)
   {
     writeln(e);
   }
   writeln("finish");
 }
 --------
 The built-in range assign will throw an Exception when it fails. This should be
 an Error.
Confirmed fixed.
 Second
 --------
 nothrow void foo(int[] a)
 {
   a[] = a[];
 }
 
 nothrow void bar(int[] a)
 {
   a[] += a[];
 }
 --------
 _arraySliceSliceAddass_i is not nothrow
 function main.bar 'bar' is nothrow yet may throw
 --------
 This is doubly problematic:
 First, these methods should throw Errors, so the code should compile.
 Two, ironically, []+=[] currently doesn't throw anything, and []=[] throws an
 exception, yet it is the []+=[] version that doesn't compile.
!!!!!!!! This is NOT FIXED. !!!!!!!! This is very strange, because arraySliceSliceAddass_i *is* marked as nothrow. However, when calling "a[] += a[]", I still get: ---- Error: _arraySliceSliceAddass_l is not nothrow ---- I'm not sure what to make about this? Maybe the "nothrow" info is lost in the "extern C" ? If I place the code as a unittest *inside* "src/rt/arrayint.d", then it passes. But outside of that source, then... It doesn't compile. We'd need one of the compiler guys (or just people that understand C and linking better than I do) to investigate. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Dec 17 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8651


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies gmail.com




 
 !!!!!!!!
 This is NOT FIXED.
 !!!!!!!!
 
 This is very strange, because arraySliceSliceAddass_i *is* marked as nothrow.
 However, when calling "a[] += a[]", I still get:
 ----
 Error: _arraySliceSliceAddass_l is not nothrow
 ----
 
 I'm not sure what to make about this? Maybe the "nothrow" info is lost in the
 "extern C" ?
 
 If I place the code as a unittest *inside* "src/rt/arrayint.d", then it passes.
 But outside of that source, then... It doesn't compile.
 
 We'd need one of the compiler guys (or just people that understand C and
 linking better than I do) to investigate.
Being C functions, the nothrowness is not part of the mangled name, otherwise that change would have caused lots of link failures. Inside the compiler (arrayop.c) a dummy function declaration is created with the correct name, and a call is inserted in place of the array op. This function declaration needs to be changed for the compiler to pick it up as nothrow, and it will need to be manually verified that the nothrowness matches at both ends for each function. A lot of druntime functions should probably have D linkage to prevent mistakes like this. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 01 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8651


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |simendsjo gmail.com



*** Issue 6311 has been marked as a duplicate of this issue. ***


*** Issue 9933 has been marked as a duplicate of this issue. ***

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


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |simendsjo gmail.com



*** Issue 6311 has been marked as a duplicate of this issue. ***


*** Issue 9933 has been marked as a duplicate of this issue. ***

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


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull
            Version|unspecified                 |D2



A while ago, built-in array-op implementations has been changed to  trusted
nothrow by the druntime fix:

https://github.com/D-Programming-Language/druntime/pull/306



I opened a new pull request for the compiler fix.

https://github.com/D-Programming-Language/dmd/pull/2141




 A lot of druntime functions should probably have D linkage to prevent mistakes
 like this.
From 2.063, we can use pragma(mangle). Using it could add D linkages to the druntime functions with hiding internal module packages. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 06 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8651




Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/0b560e6ae873a2f519406faadf1806d404937b51
fix Issue 8651 - Slice op Slice throws exceptions (not errors), and nothrow

Array ops should work in  safe pure nothrow code

https://github.com/D-Programming-Language/dmd/commit/99c0531136b342afc35bafed23d293ec4be7f316


Issue 8651 - Slice op Slice throws exceptions (not errors), and nothrow

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


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 07 2013