Minutes of my talk at Riverbed

2011-05-07 Thread Andrei Alexandrescu
Ali Cehreli, engineer at Riverbed (http://www.riverbed.com), facilitated 
a talk at the company. Thanks!


http://blog.riverbed.com/2011/05/d-programming-language-showcased-at-riverbed.html


Andrei


Re: Patterns of Human Error - my presentation at the DC ACM

2011-05-07 Thread Florian Weimer
* Nick Sabalausky:

 Is there anything reddit doesn't auto-flag as junk?

Perhaps content that is actually viewable and accessible?


Re: Beta List

2011-05-07 Thread Sean Cavanaugh

On 5/7/2011 12:24 AM, Andrej Mitrovic wrote:

Here's a quick weblink:
http://news.gmane.org/gmane.comp.lang.d.dmd.beta/cutoff=624


It works on my machine :-D




Re: Beta List

2011-05-07 Thread bearophile
Jonathan M Davis:

 Just a reminder in case you didn't know, but there is a beta list (dmd-beta) 
 for posting and discussing beta releases of dmd prior to actual releases.

I am not yet a subscriber there. Here are some notes on 2.053beta.

This little program:

int foo(int x, int y) {
return x / y;
}
void main() {
foo(1, 0);
}


Produces the stack trace:

object.Error: Integer Divide by Zero

...\test.d(5): _Dmain



While this similar Python2 program:

def foo(x, y):
return x / y
def main():
foo(1, 0)
main()


Gives the stacktrace (feel fee to ignore the first global call to main()):

Traceback (most recent call last):
  File ...\temp.py, line 5, in module
main()
  File ...\temp.py, line 4, in main
foo(1, 0)
  File ...\temp.py, line 2, in foo
return x / y
ZeroDivisionError: integer division or modulo by zero


On Python the stacktrace is reversed compared to the D one, maybe this is 
better.

And as first line it prints this, that's useful for D too:
Traceback (most recent call last):

And the Python stacktrace shows the line/function where the division by zero 
happens too, instead of just all the frames of the functions up to the one that 
has called the function that has generated the division by zero. I'd like to 
see foo() too in the D stacktrace.

--

Bugzilla 1330 is fixed, I have done a little CTFE benchmark:


import std.c.stdio;

size_t counter(size_t v) {
size_t c;
for (c = 0; v; c++)
v = v - 1; // clear the least significant bit set
return c;
}

int[] tabler(int n) {
int[] result = new int[n];
foreach (i, ref x; result)
x = counter(i);
return result;
}

const int N = 4000;
const int[] t = tabler(N);

void main() {
for (size_t i = N - 5; i  N; i++)
printf(%u %u\n, i, t[i]);
}


Results:
2.052: 0.78 seconds, about  70 MB committed.
2.053beta: 1.56 seconds, about 140 MB committed.

--

The traits.html docs don't seem to contain the new parent.

--

This little program:


import std.stdio, std.container;
void main() {
auto t = redBlackTree(0, 7, 5, 2);
writeln(t);
writeln(t[]);
}


Prints:
std.container.RedBlackTree!(int).RedBlackTree
[0, 2, 5, 7]


But I'd like one of the two (the first, if possible) to print instead:
redBlackTree(0, 2, 5, 7)

--

This line is present two times in the changelog:

Added parent to __traits for QtD support

--

Regarding this bug:
http://d.puremagic.com/issues/show_bug.cgi?id=4298


This little program:

enum int[] arr = [1, 2, 3];
void main() {
assert(arr.ptr == arr.ptr);
}


Generates this asm:


__Dmain comdat
L0: pushEAX
mov EAX,offset FLAT:_D11TypeInfo_Ai6__initZ
pushEBX
pushESI
push3
push2
push1
push3
pushEAX
callnear ptr __d_arrayliteralT
add ESP,014h
mov ECX,EAX
pushECX
sub ESP,4
mov EDX,offset FLAT:_D11TypeInfo_Ai6__initZ
push3
mov EBX,3
push2
push1
push3
pushEDX
callnear ptr __d_arrayliteralT
mov ECX,EAX
add ESP,014h
add ESP,4
mov ESI,ECX
mov EAX,3
pop ECX
cmp ECX,ESI
je  L55
mov EAX,3
callnear ptr _D4test8__assertFiZv
L55:xor EAX,EAX
pop ESI
pop EBX
pop ECX
ret

--

Bye,
bearophile


Re: C++ static analysis

2011-05-07 Thread Timon Gehr
 Timon Gehr:

 I think it might be a
 good idea though. However, having this feature means requiring one AST 
 compare for
 every boolean operator.

 You are worried about compilation time. I think the feature we're talking 
 about
just tests the equivalence of the then/else clauses.

 Clang has a --analyze switch that runs the (potentially slow) static analyser,
otherwise it performs a normal amount of static test on the code. This gives you
choice between a faster compilation and a slower analysis able to find some 
other
bugs.

 Bye,
 bearophile

I think Walter does not like introducing new switches, because it doubles the
number of compilers to test and maintain.

Timon


Re: Beta List

2011-05-07 Thread KennyTM~

On May 7, 11 18:54, bearophile wrote:

Jonathan M Davis:


Just a reminder in case you didn't know, but there is a beta list (dmd-beta)
for posting and discussing beta releases of dmd prior to actual releases.


I am not yet a subscriber there. Here are some notes on 2.053beta.

This little program:

int foo(int x, int y) {
 return x / y;
}
void main() {
 foo(1, 0);
}


Produces the stack trace:

object.Error: Integer Divide by Zero

...\test.d(5): _Dmain




Oh, what flags have you passed to DMD? I can only get a Floating point 
exception on OS X, which is, well, expected as it's the CPU that 
catches the integer-divide-by-zero error, not the language. The stack 
trace can be read by the debugger.


#0  0x1e61 in D1y3fooFiiZi ()
#1  0x1e4a in _Dmain ()
#2  0x00012357 in D2rt6dmain24mainUiPPaZi7runMainMFZv ()
#3  0x00011f01 in D2rt6dmain24mainUiPPaZi7tryExecMFMDFZvZv ()
#4  0x0001239f in D2rt6dmain24mainUiPPaZi6runAllMFZv ()
#5  0x00011f01 in D2rt6dmain24mainUiPPaZi7tryExecMFMDFZvZv ()
#6  0x00011e9b in main ()

Throwing an exception manually does produce a stack trace up to 'foo', 
just like Python (which traps divide-by-zero in the language).




Re: Beta List

2011-05-07 Thread bearophile
KennyTM~:

 Oh, what flags have you passed to DMD?

-w -g, Windows Vista.


 I can only get a Floating point 
 exception on OS X, which is, well, expected as it's the CPU that 
 catches the integer-divide-by-zero error, not the language.

Right, I am sorry.

Bye,
bearophile


Re: dmd2 on Ubuntu

2011-05-07 Thread Brian Myers
So I removed the executables from /usr/local/bin and rather than adding them to 
my path, I sym linked them to the dmd2/linux/bin directory in
my home directory. I did this because I'd like to have the compiler and tools 
available system wide. I then moved the dmd.conf file from /etc to
the linux/bin directory where dmd resides.

When I do this I get different messages from dmd, but it still can't make ld 
find -lphobos2. The two messages I get, however, are:

/usr/bin/ld: skipping incompatible /usr/lib/libphobos2.a when searching for 
-lphobos2

The other message is also about libphobos2.a, it's just finding it relative to 
the gcc library path.

I even extracted all the object files from libphobos2.a and verified that they 
were 64 bit ELF format. Is it really that libphobos2.a is messed up, or
is this message a red herring?

Thanx again

Brian


Re: dmd2 on Ubuntu

2011-05-07 Thread Walter Bright

On 5/7/2011 12:03 PM, Brian Myers wrote:

So I removed the executables from /usr/local/bin and rather than adding them
to my path, I sym linked them to the dmd2/linux/bin directory in my home
directory. I did this because I'd like to have the compiler and tools
available system wide. I then moved the dmd.conf file from /etc to the
linux/bin directory where dmd resides.

When I do this I get different messages from dmd, but it still can't make ld
find -lphobos2. The two messages I get, however, are:

/usr/bin/ld: skipping incompatible /usr/lib/libphobos2.a when searching for
-lphobos2

The other message is also about libphobos2.a, it's just finding it relative
to the gcc library path.

I even extracted all the object files from libphobos2.a and verified that
they were 64 bit ELF format. Is it really that libphobos2.a is messed up, or
is this message a red herring?


There is a libphobos2.a that is 32 bit, and one that is 64 bit. Make sure that 
you're using one that is compatible with the -m32 or -m64 settings you're using 
with the compiler.


Also, please use dmd.conf, which contains a switch to shut off undesired warning 
messages from ld.


I strongly suggest trying the default install, making sure that works, before 
modifying it for your own needs.


Re: Implementing std.log

2011-05-07 Thread Jose Armando Garcia
Hey folks,

For the past couple of days I took the liberty of partially
implementing a logging module for D. I say partially because all the
features that I want to implement are not currently implement. You
should really look at the implementation more as a proof of concept
even thought most of the code will be used in the final
implementation.

That been said I am really interested in getting some feedback on the
API. That includes high-level design (e.g. using a thread to perform
logging. On that note I am planning to also have a shared memory
implementation), interfaces and the documentation.

When making comment be aware that the design goals of the module are:
1) Provide a logging mechanism that is easy to use in the common case.
2) The module should allow for as much configuration as possible at
compile time and execution time without breaking design goal 1.
3) It should be possible to extend or replace the backend without
breaking the semantic exposed by the API.

I am fairly new to the D language so any comment on how I can take
advantage of D idiom or D features in the API or implementation would
be greatly appreciated.

My intent, and hopefully we will get there with your help, is to
include this in Phobos for D2.

Thanks,
-Jose

On Mon, Apr 25, 2011 at 12:03 AM, Andrei Alexandrescu
seewebsiteforem...@erdani.org wrote:
 On 04/24/2011 02:23 PM, Sean Cavanaugh wrote:

 On 4/20/2011 11:09 AM, Robert Clipsham wrote:

 Hey folks,

 I've just finished porting my web framework from D1/Tango to D2/Phobos,
 and in the transition lost logging functionality. As I'll be writing a
 logging library anyway, I wondered if there'd be interest in a std.log?
 If so, is there a current logging library we would like it to be based
 on, or should we design from scratch?

 I know there has been discussion about Google's
 http://google-glog.googlecode.com/svn/trunk/doc/glog.html and another
 candidate may be http://logging.apache.org/log4j/ . Do we want a
 comprehensive logging library, or just the basics? (Possibly with some
 method for extension if needed).



 I just wanted to mention Pantheios as a C++ logging system to take look
 at as well, I didn't see it mentioned in this thread and it seems to
 have all the major requirements for frontend/backend chaining and
 whatnot that people have brought up. The code is on sourceforge to boot.

 I think Pantheios is an example of library design gone bad. It is
 fascinatingly overengineered.

 Andrei


Title: std.logging

std.logging

Implements application level logging mechanism.

This module defines a set of functions useful for many common logging tasks.  The module must be initialized (ideally in single threaded mode) by calling initializeLogging. Messages of different severity level are logged by calling the template functions log and logf. Verbose messages can be logged by calling the template functions  vlog and vlogf.


Examples:
import std.logging;

int main(string[] args)
{
   initializeLogging(ActorLogger.getCreator(args[0]));

   // ...
   logf(Level.info, "Log message from %s", args[0]);
}



Note:
Logging can be disable at compile time by defining the LOGGING_DISABLED version.



enum Level;

Defines the severity levels supported by the logging library.

Logging messages of severity level Level.fatal will also cause the program to halt. Messages of a given severity will be written in the log file of that severity and the log files of lower severity.

fatalerrorwarninginfo




void initializeLogging(shared(Logger) delegate() logCreator, LogConfig logConfig = LogConfig(null,cast(Level)1,null,null));

Initializes the logging infrastructure.

This function must be called ounce before calling any of the logging functions.


Params:
shared(Logger) delegate() logCreator
Delegate which creates the Logger used by the module.
LogConfig logConfig
Module configuration object.

See Also:
LogConfig


void logf(string file = __FILE__, int line = __LINE__, T...)(Level level, lazy T args);

Logs a formatted message.

Logs a formatted message if level is of higher or equal severity as that specified in the LogConfig object passed to initializeLogging.


The first parameter in args will be used as the format string. See std.format.formattedWrite for a description of the format string.


void log(string file = __FILE__, int line = __LINE__, T...)(Level level, lazy T args);

Logs a message

Logs a message if level is of higher or equal severity as that specified in the LogConfig object passed to initializeLogging.


void vlogf(string file = __FILE__, int line = __LINE__, T...)(uint level, lazy T args);

Logs a formatted verbose message

Logs a formatted verbose message if the file and level matches one of the entries specified in the vLogConfigs property of the LogConfig object passed to initializeLogging.


The first parameter in args will be used as the format string. See 

Re: Implementing std.log

2011-05-07 Thread Jose Armando Garcia
Hey folks,

For the past couple of days I took the liberty of partially
implementing a logging module for D. I say partially because all the
features that I want to implement are not currently implement. You
should really look at the implementation more as a proof of concept
even thought most of the code will be used in the final
implementation.

That been said I am really interested in getting some feedback on the
API. That includes high-level design (e.g. using a thread to perform
logging. On that note I am planning to also have a shared memory
implementation), interfaces and the documentation.

When making comment be aware that the design goals of the module are:
1) Provide a logging mechanism that is easy to use in the common case.
2) The module should allow for as much configuration as possible at
compile time and execution time without breaking design goal 1.
3) It should be possible to extend or replace the backend without
breaking the semantic exposed by the API.

I am fairly new to the D language so any comment on how I can take
advantage of D idiom or D features in the API or implementation would
be greatly appreciated.

My intent, and hopefully we will get there with your help, is to
include this in Phobos for D2.

logging.d - http://ubuntuone.com/p/rfL/
logging.html - http://ubuntuone.com/p/rfM/

Thanks,
-Jose

On Mon, Apr 25, 2011 at 12:03 AM, Andrei Alexandrescu
seewebsiteforem...@erdani.org wrote:
 On 04/24/2011 02:23 PM, Sean Cavanaugh wrote:

 On 4/20/2011 11:09 AM, Robert Clipsham wrote:

 Hey folks,

 I've just finished porting my web framework from D1/Tango to D2/Phobos,
 and in the transition lost logging functionality. As I'll be writing a
 logging library anyway, I wondered if there'd be interest in a std.log?
 If so, is there a current logging library we would like it to be based
 on, or should we design from scratch?

 I know there has been discussion about Google's
 http://google-glog.googlecode.com/svn/trunk/doc/glog.html and another
 candidate may be http://logging.apache.org/log4j/ . Do we want a
 comprehensive logging library, or just the basics? (Possibly with some
 method for extension if needed).



 I just wanted to mention Pantheios as a C++ logging system to take look
 at as well, I didn't see it mentioned in this thread and it seems to
 have all the major requirements for frontend/backend chaining and
 whatnot that people have brought up. The code is on sourceforge to boot.

 I think Pantheios is an example of library design gone bad. It is
 fascinatingly overengineered.

 Andrei




Re: Implementing std.log

2011-05-07 Thread Andrew Wiley
On Sat, May 7, 2011 at 4:17 PM, Jose Armando Garcia jsan...@gmail.comwrote:

 Hey folks,

 For the past couple of days I took the liberty of partially
 implementing a logging module for D. I say partially because all the
 features that I want to implement are not currently implement. You
 should really look at the implementation more as a proof of concept
 even thought most of the code will be used in the final
 implementation.

 That been said I am really interested in getting some feedback on the
 API. That includes high-level design (e.g. using a thread to perform
 logging. On that note I am planning to also have a shared memory
 implementation), interfaces and the documentation.

 When making comment be aware that the design goals of the module are:
 1) Provide a logging mechanism that is easy to use in the common case.
 2) The module should allow for as much configuration as possible at
 compile time and execution time without breaking design goal 1.
 3) It should be possible to extend or replace the backend without
 breaking the semantic exposed by the API.

 I am fairly new to the D language so any comment on how I can take
 advantage of D idiom or D features in the API or implementation would
 be greatly appreciated.

 My intent, and hopefully we will get there with your help, is to
 include this in Phobos for D2.

 logging.d - http://ubuntuone.com/p/rfL/
 logging.html - http://ubuntuone.com/p/rfM/

 Thanks,
 -Jose



I'll be sure to try it out in the next few days. Passing messages to a
separate logging thread seems like it might be a overkill, but it could
work. I do like that you can get the file and line included with messages.
One thing I'll miss from Log4J and its siblings is that typing
log.info(message)
is a lot more intuitive than log(LogLevel.info, message). I don't think
that's a major gripe though.


Re: D auto-tester

2011-05-07 Thread Nick Sabalausky
Robert Clipsham rob...@octarineparrot.com wrote in message 
news:ipv3tv$1eg0$1...@digitalmars.com...

   * What is Linux 32/64 vs. 64/32?

 32 bit dmd creating 64 bit binaries, 64 bit dmd creating 32 bit binaries. 
 I believe you get a description if you hover over them.


Probably a stupid question, but 32-bit DMD can't create 64-bit binaries when 
running on a 32-bit system, can it? I assume 32-bit DMD can only create 
64-bit binaries when running on a 64-bit system, right?




Re: D auto-tester

2011-05-07 Thread Robert Clipsham

On 07/05/2011 23:15, Nick Sabalausky wrote:

Robert Clipshamrob...@octarineparrot.com  wrote in message
news:ipv3tv$1eg0$1...@digitalmars.com...



   * What is Linux 32/64 vs. 64/32?


32 bit dmd creating 64 bit binaries, 64 bit dmd creating 32 bit binaries.
I believe you get a description if you hover over them.



Probably a stupid question, but 32-bit DMD can't create 64-bit binaries when
running on a 32-bit system, can it? I assume 32-bit DMD can only create
64-bit binaries when running on a 64-bit system, right?


It should be able to if you have a multilib gcc installed, along with 
the relevant 64bit libraries (that makes it sound so simple, I know from 
experience that anything to do with gcc almost 100% isn't that simple). 
You won't be able to run the resulting binary of course.


--
Robert
http://octarineparrot.com/


Re: Implementing std.log

2011-05-07 Thread dsimcha

On 5/7/2011 5:55 PM, Andrew Wiley wrote:

I'll be sure to try it out in the next few days. Passing messages to a
separate logging thread seems like it might be a overkill, but it could
work.


Can you explain why you did this?  I admittedly don't know much about 
logging but my gut instinct is that it's overengineering.  Unless 
there's a good reason that I didn't foresee, I'd much rather just keep 
things like logging simple and stupid.


Re: D auto-tester

2011-05-07 Thread Nick Sabalausky
Robert Clipsham rob...@octarineparrot.com wrote in message 
news:iq4gpa$tq0$2...@digitalmars.com...
 On 07/05/2011 23:15, Nick Sabalausky wrote:
 Robert Clipshamrob...@octarineparrot.com  wrote in message
 news:ipv3tv$1eg0$1...@digitalmars.com...

* What is Linux 32/64 vs. 64/32?

 32 bit dmd creating 64 bit binaries, 64 bit dmd creating 32 bit 
 binaries.
 I believe you get a description if you hover over them.


 Probably a stupid question, but 32-bit DMD can't create 64-bit binaries 
 when
 running on a 32-bit system, can it? I assume 32-bit DMD can only create
 64-bit binaries when running on a 64-bit system, right?

 It should be able to if you have a multilib gcc installed, along with the 
 relevant 64bit libraries

Oh, cool :)

 (that makes it sound so simple, I know from experience that anything to do 
 with gcc almost 100% isn't that simple).

Definitely. I think I've managed to develop a strong allergy to gcc due to 
such issues in the past.

 You won't be able to run the resulting binary of course.


Aww, shucks ;) There go my plans of a software-based CPU upgrade!





Re: D auto-tester

2011-05-07 Thread Robert Clipsham

On 08/05/2011 01:05, Nick Sabalausky wrote:

You won't be able to run the resulting binary of course.


Aww, shucks ;) There go my plans of a software-based CPU upgrade!


Check out QEMU, it will let you run a virtualized 64 bit operating 
system on 32 bit hardware, same for arm and a number of other cpu 
architectures. It's been a while since I used it, could do what you want 
though. I believe there's an extras package for it if you're on Ubuntu 
which adds a load of architectures if it's not available by default. 
Also make sure to get the kvm package if your hardware supports it, 
it'll give a significant speed boost.


--
Robert
http://octarineparrot.com/


Re: D auto-tester

2011-05-07 Thread Daniel Gibson
Am 08.05.2011 02:33, schrieb Robert Clipsham:
 On 08/05/2011 01:05, Nick Sabalausky wrote:
 You won't be able to run the resulting binary of course.

 Aww, shucks ;) There go my plans of a software-based CPU upgrade!
 
 Check out QEMU, it will let you run a virtualized 64 bit operating
 system on 32 bit hardware, same for arm and a number of other cpu
 architectures. It's been a while since I used it, could do what you want
 though. I believe there's an extras package for it if you're on Ubuntu
 which adds a load of architectures if it's not available by default.
 Also make sure to get the kvm package if your hardware supports it,
 it'll give a significant speed boost.
 

If his hardware supports KVM, it has 64bit support anyway (at least for
x86/amd64) ;)


Re: Implementing std.log

2011-05-07 Thread Jose Armando Garcia
Eat your own dog food. D goes to great extend to discourage memory
sharing and instead favor message passing. So I figure we should eat
our own dog food and use message passing in Phobos.

I know that is not a technical argument so let me do the following:
implement log buffering, implement a shared memory backend and do a
performance comparison of the two approaches on my crappy netbook
(which will be unfair but I don't currently have access to a
multi-core multi-process machine).

Thanks!
-Jose

On Sat, May 7, 2011 at 8:25 PM, dsimcha dsim...@yahoo.com wrote:
 On 5/7/2011 5:55 PM, Andrew Wiley wrote:

 I'll be sure to try it out in the next few days. Passing messages to a
 separate logging thread seems like it might be a overkill, but it could
 work.

 Can you explain why you did this?  I admittedly don't know much about
 logging but my gut instinct is that it's overengineering.  Unless there's a
 good reason that I didn't foresee, I'd much rather just keep things like
 logging simple and stupid.



Re: D auto-tester

2011-05-07 Thread Nick Sabalausky
Robert Clipsham rob...@octarineparrot.com wrote in message 
news:iq4ojp$1ate$1...@digitalmars.com...
 On 08/05/2011 01:05, Nick Sabalausky wrote:
 You won't be able to run the resulting binary of course.

 Aww, shucks ;) There go my plans of a software-based CPU upgrade!

 Check out QEMU, it will let you run a virtualized 64 bit operating system 
 on 32 bit hardware, same for arm and a number of other cpu architectures. 
 It's been a while since I used it, could do what you want though. I 
 believe there's an extras package for it if you're on Ubuntu which adds a 
 load of architectures if it's not available by default. Also make sure to 
 get the kvm package if your hardware supports it, it'll give a significant 
 speed boost.


Wow, I'm genuinely surprised anyone's even bothered to make anything that 
can emulate 64-bit on 32-bit hardware.




Re: Implementing std.log

2011-05-07 Thread dsimcha
Ok, there's clearly been some misunderstanding here.  My real point was, 
why do you need this threading at all?


On 5/7/2011 9:01 PM, Jose Armando Garcia wrote:

Eat your own dog food. D goes to great extend to discourage memory
sharing and instead favor message passing. So I figure we should eat
our own dog food and use message passing in Phobos.

I know that is not a technical argument so let me do the following:
implement log buffering, implement a shared memory backend and do a
performance comparison of the two approaches on my crappy netbook
(which will be unfair but I don't currently have access to a
multi-core multi-process machine).

Thanks!
-Jose

On Sat, May 7, 2011 at 8:25 PM, dsimchadsim...@yahoo.com  wrote:

On 5/7/2011 5:55 PM, Andrew Wiley wrote:


I'll be sure to try it out in the next few days. Passing messages to a
separate logging thread seems like it might be a overkill, but it could
work.


Can you explain why you did this?  I admittedly don't know much about
logging but my gut instinct is that it's overengineering.  Unless there's a
good reason that I didn't foresee, I'd much rather just keep things like
logging simple and stupid.





int or size_t ?

2011-05-07 Thread %u
In Patterns of Human Error, the slide 31 point that you should replce int with
size_t
why that consider an error ?


Re: int or size_t ?

2011-05-07 Thread bearophile
%u:

 In Patterns of Human Error, the slide 31 point that you should replce int with
 size_t
 why that consider an error ?

If T is a byte and the array size is 5 billion items, on 64 bit systems...? In 
the little find() function you compare it with the length, that's a size_t. 
Someone else will give you better answers.

Bye,
bearophile


Re: int or size_t ?

2011-05-07 Thread Andrej Mitrovic
void main()
{
size_t val = int.max+1;
int val2 = val;
writeln(val2);
}

writes -2147483648

That should give you a hint.


Re: int or size_t ?

2011-05-07 Thread %u
size_t val1 = int.max+1;
int val2 = int.max+1;
writeln(val1); // 2147483648
writeln(val2); // -2147483648

very clear example

thanks you both


Re: int or size_t ?

2011-05-07 Thread Andrej Mitrovic
Actually my example was bad. What I wanted to say is that size_t will
be 64bit on 64bit platforms while int will stay 32bit. Another
difference is that size_t is unsigned. So it's bad to use int even if
you're sure you're only going to compile only on 32bit platforms.

Here's the relevant definitions in object_.d:

version(X86_64)
{
alias ulong size_t;
alias long  ptrdiff_t;
alias long  sizediff_t;
}
else
{
alias uint  size_t;
alias int   ptrdiff_t;
alias int   sizediff_t;
}

And an example:
void main()
{
size_t val = size_t.max;// maximum unsigned 32bit number on
32bit platforms

int val2 = val;
writeln(val2);  // -1 on 32bit platforms, due to
unsigned - signed conversion
}

Usually people type int because.. well it's used everywhere and it's
easy to type. I never liked the size_t name, but it has become a de
facto standard in other languages, so D uses that name as well. We've
already had a discussion on changing its name but nothing came out of
it.


Re: int or size_t ?

2011-05-07 Thread Andrej Mitrovic
Edit: I just saw you've already figured this out. :)


Re: Cannot interpret struct at compile time

2011-05-07 Thread Robert Clipsham

On 07/05/2011 23:36, Andrej Mitrovic wrote:

Not too sure, CTFE is a pain in the ass sometimes. What exactly are
you trying to do, print field names in a custom way?


No, I have a struct that I don't have access to in the scope I'm in, I 
do however have its type - by using the above, I can create a local 
clone of the type which acts the same (at least for my purposes), which 
I can then do things with. Except that it fails with that error message D;


--
Robert
http://octarineparrot.com/


Re: Cannot interpret struct at compile time

2011-05-07 Thread Andrej Mitrovic
One simplistic solution is to use alias this to simulate the same type:

struct Foo
{
int x, y;
}

string structClone(T)()
{
return struct  ~ T.stringof ~ _ { 
~ T.stringof ~  _inner;
alias _inner this;
this(T...)(T t) { _inner = typeof(_inner)(t);  } };;
}

void main()
{
mixin(structClone!Foo);
Foo_ foo = Foo_(1, 2);

assert(foo.x == 1);
assert(foo.y == 2);
}

Field initializations and ctors will work thanks to the templated ctor
that just forwards to the _inner struct.


Re: Cannot interpret struct at compile time

2011-05-07 Thread Robert Clipsham

On 08/05/2011 00:39, Andrej Mitrovic wrote:

One simplistic solution is to use alias this to simulate the same type:

struct Foo
{
 int x, y;
}

string structClone(T)()
{
 return struct  ~ T.stringof ~ _ { 
 ~ T.stringof ~  _inner;
 alias _inner this;
 this(T...)(T t) { _inner = typeof(_inner)(t);  } };;
}

void main()
{
 mixin(structClone!Foo);
 Foo_ foo = Foo_(1, 2);

 assert(foo.x == 1);
 assert(foo.y == 2);
}

Field initializations and ctors will work thanks to the templated ctor
that just forwards to the _inner struct.


Unfortunately this won't do what I need - I need to be able to iterate 
over the members of the resulting struct using .tupleof, which I can't 
do with alias this.


--
Robert
http://octarineparrot.com/


Shouldn't duplicate functions be caught by DMD?

2011-05-07 Thread Andrej Mitrovic
I'm not talking about function overloading, but functions with the same 
parameters inside the same class definition:

class Foo
{
int foo(int i)
{
return 1;
}

int foo(int i)
{
return 1;
}

void bar()
{
foo(1);
}
}

void main()
{
auto foo = new Foo();
}

Errors:
test.d(19): Error: function test.Foo.foo called with argument types:
((int))
matches both:
test.Foo.foo(int i)
and:
test.Foo.foo(int i)

If you comment out the call to foo(), and compile via -c -w -wi, no errors will 
be emitted. Only later when you try to use the object file you'll get a linker 
error:

fset 003C4H Record Type 00C3
 Error 1: Previous Definition Different : _D4test3Foo3fooMFiZi
--- errorlevel 1

I think the compiler should check catch these mistakes at compile-time.


Getting equivalent elements in a range/array

2011-05-07 Thread Andrej M.
I want to turn this:
auto arr = [1, 1, 2, 3, 4, 4];

into this:
auto arr2 = [[1, 1], [2], [3], [4, 4]];

I want an array of arrays of the same elements. Lazy or not, I don't care.

I thought I could get away with this inside some while loop:
auto equals = array(filter!a == b(arr));
arr = arr[equals.length-1..$];

Nope.

I need this for some buffered output, where the requirement is the elements of 
the buffer all need to have the same properties so a function can output a 
buffer of elements in one call instead of calling the function for each element 
(the function call is expensive).


[Issue 5939] Cannot copy std.algorithm.map

2011-05-07 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5939


kenn...@gmail.com changed:

   What|Removed |Added

 CC||kenn...@gmail.com


--- Comment #1 from kenn...@gmail.com 2011-05-06 23:15:51 PDT ---
The problem isn't copying a map, but initializing the type using 'T xSaved'. If
you use 'T xSaved = x;' it compiles. A reduced example:

-
import std.algorithm;
void main() {
typeof(map!a([0])) a;
}
-
x.d(3): Error: function std.algorithm.map!(a).map!(int[]).map is a nested
function and cannot be accessed from main
-

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


[Issue 5940] Cannot create arrays of std.algorithm.map

2011-05-07 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5940


kenn...@gmail.com changed:

   What|Removed |Added

 CC||kenn...@gmail.com


--- Comment #1 from kenn...@gmail.com 2011-05-06 23:29:24 PDT ---
See as issue 4274.

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


[Issue 5930] cas doesn't work when used in code compiled with -D

2011-05-07 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5930


Rainer Schuetze r.sagita...@gmx.de changed:

   What|Removed |Added

 CC||r.sagita...@gmx.de


--- Comment #2 from Rainer Schuetze r.sagita...@gmx.de 2011-05-06 23:31:50 
PDT ---
phobos now uses version StdDdoc instead of D_Ddoc to fix similar issues.

Grep tells me core.atomic is the only module in druntime that uses
version(D_ddoc).

What needs to be done is:
- add -version=DruntimeDdoc or similar to DOCFMT in the makefiles
- use version(DruntimeDdoc) instead of version(D_Ddoc)

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


[Issue 3581] private attribute breaks override

2011-05-07 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=3581



--- Comment #15 from Rainer Schuetze r.sagita...@gmx.de 2011-05-06 23:37:50 
PDT ---
(In reply to comment #13)
 See proposed patch and problems with patch:
 
 https://github.com/donc/dmd/commit/9f7b2f8cfe5d7482f2de7f9678c176d54abe237f#commitcomment-321724

Copying my comment on github for better visibility:

As I happen to have the patch installed, I stumbled over this problem today
when running the unittests. The problem is that the override sets the
attribute for the complete mixin, including auto-implemented constructors.

Here's a patch that moves the override attribute to each generated function if
it is not a constructor:

diff --git a/std/typecons.d b/std/typecons.d
index e0868b0..979b1d1 100644
--- a/std/typecons.d
+++ b/std/typecons.d
@@ -1593,7 +1593,7 @@ class AutoImplement(Base, alias how, alias what =
isAbstractFunction) : Base
 private alias AutoImplement_Helper!(
 autoImplement_helper_, Base, Base, how, what )
  autoImplement_helper_;
-override mixin(autoImplement_helper_.code);
+mixin(autoImplement_helper_.code);
 }

 /*
@@ -2081,6 +2081,8 @@ private static:
 enum storageClass = make_storageClass();

 //
+if(isAbstractFunction!func)
+code ~= override ;
 code ~= Format!(extern(%s) %s %s(%s) %s %s\n,
 functionLinkage!(func),
 returnType,

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


[Issue 5939] Cannot copy std.algorithm.map

2011-05-07 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5939



--- Comment #2 from kenn...@gmail.com 2011-05-06 23:52:03 PDT ---
The bug is introduced in commit 1083bd4e
(https://github.com/D-Programming-Language/phobos/commit/1083bd4e7b4ef0475084d7eab2e67c65e511c3d4#L1L160),
where the return type of map changes from an external private struct to an
inner struct.

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


[Issue 5941] New: Using inner struct which references nested function in a no-attribute or auto-return member function causes nested function cannot be accessed error

2011-05-07 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5941

   Summary: Using inner struct which references nested function in
a no-attribute or auto-return member function causes
nested function cannot be accessed error
   Product: D
   Version: D2
  Platform: All
OS/Version: All
Status: NEW
  Severity: normal
  Priority: P2
 Component: DMD
AssignedTo: nob...@puremagic.com
ReportedBy: kenn...@gmail.com


--- Comment #0 from kenn...@gmail.com 2011-05-07 00:11:05 PDT ---
May or may not be the same as issue 5939. Happens at least since 2.042.

Test case:
-
auto f() {
static int h(int x) pure nothrow @safe { return x*x*x-x*x; }
struct S {
int get() {
return h(8);
}
}
return S.init;
}
void main() {
typeof(f()) z;
assert(z.get == 448);
assert(z.get == 448);
}
-
x.d(11): Error: function x.f is a nested function and cannot be accessed from
main
-

The bug will appear only when the 'get' function
 - is an auto-return function (e.g. '@property auto get()')
 - or has no attributes at all (e.g. 'int get()')

The bug is gone when you supply at least one attribute to 'get', e.g. '@safe
int get()'.

I don't know if it is a reject-valid or accept-invalid.

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


[Issue 5941] Using inner struct which references nested function in a no-attribute or auto-return member function causes nested function cannot be accessed error

2011-05-07 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5941



--- Comment #1 from kenn...@gmail.com 2011-05-07 00:27:39 PDT ---
A slight variant is when 'f' is a template function taking a delegate literal
as input, it will generate an ICE:

-
auto f(alias T)() {
static void h(){}
struct S {
void get() {
h();
}
}
return S();
}
void main() {
typeof(f!((){})()) z;
}
-
Internal error: backend/cgcs.c 363
-

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


[Issue 5942] New: Bitfields are overwritten erroneously

2011-05-07 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5942

   Summary: Bitfields are overwritten erroneously
   Product: D
   Version: D2
  Platform: Other
OS/Version: Linux
Status: NEW
  Severity: normal
  Priority: P2
 Component: DMD
AssignedTo: nob...@puremagic.com
ReportedBy: samu...@voliacable.com


--- Comment #0 from Max Samukha samu...@voliacable.com 2011-05-07 04:03:20 
PDT ---
struct S
{
mixin(bitfields!(
int, a , 32,
int, b , 32
));
}

void main()
{
S data;
data.b = 42;
data.a = 1;
assert(data.b == 42); // fail
}

Looks like assigning fields at offsets  32 bit clears fields at offsets = 32
bit.

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


[Issue 5943] New: Power expression optimisation: 2^^unsigned == 1unsigned

2011-05-07 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5943

   Summary: Power expression optimisation: 2^^unsigned ==
1unsigned
   Product: D
   Version: D2
  Platform: All
OS/Version: Windows
Status: NEW
  Keywords: performance
  Severity: enhancement
  Priority: P2
 Component: DMD
AssignedTo: nob...@puremagic.com
ReportedBy: bearophile_h...@eml.cc


--- Comment #0 from bearophile_h...@eml.cc 2011-05-07 05:27:50 PDT ---
Related to bug 5812
I think it's good to have an optimization of 2^^x == 1x when x is an
unsigned integral or where the compiler can infer x to be a not negative
integral:


import std.math; // currently std.math is needed here
int main(string[] args) {
return 2 ^^ args.length;
}


Currently it generates:

__Dmaincomdat
L0:pushEAX
push2
movEAX,0Ch[ESP]
callnear ptr _D3std4math12__T3powTiTkZ3powFNaNbNeikZk
popECX
ret

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


[Issue 5944] New: Five ideas for the stacktrace

2011-05-07 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5944

   Summary: Five ideas for the stacktrace
   Product: D
   Version: D2
  Platform: All
OS/Version: All
Status: NEW
  Keywords: diagnostic
  Severity: enhancement
  Priority: P2
 Component: druntime
AssignedTo: nob...@puremagic.com
ReportedBy: bearophile_h...@eml.cc


--- Comment #0 from bearophile_h...@eml.cc 2011-05-07 06:06:11 PDT ---
This little program:


int foo(int x, int y) {
return x / y;
}
void main() {
foo(1, 0);
}


Produces the stack trace (dmd 2.053beta):

object.Error: Integer Divide by Zero

...\test.d(5): _Dmain



While this similar Python2 program:

def foo(x, y):
return x / y
def main():
foo(1, 0)
main()


Gives the stacktrace (feel fee to ignore the first global call to main()):

Traceback (most recent call last):
  File ...\temp.py, line 5, in module
main()
  File ...\temp.py, line 4, in main
foo(1, 0)
  File ...\temp.py, line 2, in foo
return x / y
ZeroDivisionError: integer division or modulo by zero


[Idea1] On Python the stacktrace is reversed compared to the D one, maybe this
is better.

[Idea2] And as first line it prints this, that's useful for D too:
Traceback (most recent call last):

[Idea3] And the Python stacktrace shows the line/function where the division by
zero happens too, instead of just all the frames of the functions up to the one
that has called the function that has generated the division by zero. I'd like
to see foo() too in the D stacktrace.



This program:


int foo(int x) {
if (x  0)
return bar(x - 1);
else
return 10 / x;
}
int bar(int x) {
if (x  0)
return foo(x - 1);
else
return 10 / x;
}
void main() {
foo(10);
}

dmd 2.053beta (witout -g switch) gives:

object.Error: Integer Divide by Zero

40CCF4
40CB6B
402041
402021
402041
402021
402041
402021
402041
402021
402041
402021
40205A
4025FB
4021F7
411FDD


[Idea4] When the -g switch is not used I suggest to add a note about missing
debug info, useful for not expert programmers/newbies:

object.Error: Integer Divide by Zero

Traceback, no symbolic debug info (most recent call last):
40CCF4
40CB6B
402041
402021
402041
402021
402041
402021
402041
402021
402041
402021
40205A
4025FB
4021F7
411FDD


Instead of just:


object.Error: Integer Divide by Zero

Traceback (most recent call last):
40CCF4
40CB6B
402041
402021
402041
402021
402041
402021
402041
402021
402041
402021
40205A
4025FB
4021F7
411FDD




This little program:


int foo(int x) {
if (x  0)
return foo(x - 1);
else
return 10 / x;
}
void main() {
foo(10);
}


dmd 2.053beta gives just (here DMD has performed tail-call optimization, so
there are no stack frames to show for the recursive calls to foo()):

object.Error: Integer Divide by Zero

...



A bigger similar example:

import core.stdc.stdio: printf;
nothrow pure int str2int(const char *str, in int n=0) {
if (str == null || *str == '\0') {
int x = 10 / cast(size_t)*str; // A bug
return n;
} else
return str2int(str+1, n*10 + *str-'0');
}
void main() {
printf(%d\n, str2int(12345678.ptr));
}


The asm shows that DMD performs the tail-call optimization on str2int():

_D5test37str2intFNaNbxPaxiZicomdat
pushEBX
mov EBX,8[ESP]
testEBX,EBX
pushESI
mov ESI,EAX
pushEDI
je  L12
cmp byte ptr [EBX],0
jne L1A
L12:pop EDI
mov EAX,ESI
pop ESI
pop EBX
ret 4
L1A:lea EDX,1[EBX]
movzx   ECX,byte ptr [EBX]
lea EDI,[ESI*4][ESI]
lea EDI,-030h[EDI*2][ECX]
mov ESI,EDI
mov EBX,EDX
testEDX,EDX
je  L12
cmp byte ptr [EDX],0
je  L12
jmp short   L1A


object.Error: Integer Divide by Zero

...



[Idea5] In this case the stacktrace may add a note:

object.Error: Integer Divide by Zero

...\test.d(4): int test.str2int(const char*, const int) [Tail-Call Optimized]


--

This little program just crashes at runtime (dmd 2.053beta):


int foo() {
return foo();
}
void main() {
foo();
}


With DMD 2.052 it gives:
object.Error: Stack Overflow



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


[Issue 5945] New: redBlackTree printing

2011-05-07 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5945

   Summary: redBlackTree printing
   Product: D
   Version: D2
  Platform: All
OS/Version: All
Status: NEW
  Severity: enhancement
  Priority: P2
 Component: Phobos
AssignedTo: nob...@puremagic.com
ReportedBy: bearophile_h...@eml.cc


--- Comment #0 from bearophile_h...@eml.cc 2011-05-07 06:13:17 PDT ---
This little program:


import std.stdio, std.container;
void main() {
auto t = redBlackTree(0, 7, 5, 2);
writeln(t);
writeln(t[]);
}


Prints (DMD 2.053 beta):
std.container.RedBlackTree!(int).RedBlackTree
[0, 2, 5, 7]


But often I'd like collections to print something that's able to generate the
data structure again, as in Python:

 s = set([1, 2, 3])
 s
set([1, 2, 3])
 l = [1, 2, 3]
 l
[1, 2, 3]
 d = {1:1, 2:2, 3:3}
 d
{1: 1, 2: 2, 3: 3}

This is very useful for debugging, logging, for quick scripts, etc.

So I'd like one of the two (the first one?) to print something more like this
instead:

redBlackTree(0, 2, 5, 7)

This too is acceptable:

std.container.redBlackTree(0, 2, 5, 7)

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


[Issue 693] 'this' can't be used as an alias parameter for a mixin

2011-05-07 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=693


Kenji Hara k.hara...@gmail.com changed:

   What|Removed |Added

 CC||zan77...@nifty.com


--- Comment #4 from Kenji Hara k.hara...@gmail.com 2011-05-07 06:20:37 PDT ---
*** Issue 4799 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: ---


[Issue 5944] Five ideas for the stacktrace

2011-05-07 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5944



--- Comment #1 from bearophile_h...@eml.cc 2011-05-07 06:21:51 PDT ---
KennyTM~ reminds me that the [idea 3] is bugus, because divisions by zero are
not DMD exceptions. So please ignore it.

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


[Issue 5946] New: failing lookup 'this' from function in template

2011-05-07 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5946

   Summary: failing lookup 'this' from function in template
   Product: D
   Version: unspecified
  Platform: All
OS/Version: All
Status: NEW
  Keywords: rejects-valid
  Severity: normal
  Priority: P2
 Component: DMD
AssignedTo: nob...@puremagic.com
ReportedBy: k.hara...@gmail.com


--- Comment #0 from Kenji Hara k.hara...@gmail.com 2011-05-07 06:58:08 PDT ---
Following code compile fails with
https://github.com/D-Programming-Language/dmd/commit/3fcc2344681ab9d31d1897188f36051c9beb247f

template TTest1()
{
  int call(){ return this.g(); }
}
class CTest1
{
  int f() { mixin TTest1!(); return call(); }
  int g() { return 10; }
}
void main()
{
  assert((new CTest1()).f() == 10);
}

test.d(3): Error: 'this' is only defined in non-static member functions, not
call
test.d(7): Error: mixin test.CTest1.f.TTest1!() error instantiating


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


[Issue 5947] New: Classes derived from templated interfaces do not check for method implementation

2011-05-07 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5947

   Summary: Classes derived from templated interfaces do not check
for method implementation
   Product: D
   Version: D2
  Platform: Other
OS/Version: Mac OS X
Status: NEW
  Severity: normal
  Priority: P2
 Component: DMD
AssignedTo: nob...@puremagic.com
ReportedBy: rob...@octarineparrot.com


--- Comment #0 from Robert Clipsham rob...@octarineparrot.com 2011-05-07 
21:24:55 BST ---
The following code:

interface I(T)
{
T foo();
void bar();
}

class C : I!int
{
}

Compiles without error, it should complain that foo and bar are not
implemented.

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


[Issue 5947] Classes derived from interfaces do not check for method implementation with -o-

2011-05-07 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5947


Robert Clipsham rob...@octarineparrot.com changed:

   What|Removed |Added

Summary|Classes derived from|Classes derived from
   |templated interfaces do not |interfaces do not check for
   |check for method|method implementation with
   |implementation  |-o-


--- Comment #1 from Robert Clipsham rob...@octarineparrot.com 2011-05-07 
21:38:51 BST ---
It seems this is only happening when the -o- switch is being used, and happens
regardless of whether the interface is templated.

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


[Issue 5948] New: Different error messages for int array

2011-05-07 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5948

   Summary: Different error messages for int array
   Product: D
   Version: unspecified
  Platform: x86
OS/Version: Windows
Status: NEW
  Keywords: diagnostic
  Severity: minor
  Priority: P2
 Component: DMD
AssignedTo: nob...@puremagic.com
ReportedBy: bearophile_h...@eml.cc


--- Comment #0 from bearophile_h...@eml.cc 2011-05-07 16:07:43 PDT ---
A wrong D2 program:


void main() {
 int[] arr1 = [[1]];
enum int[] arr2 = [[1]];
}


DMD 2.053beta gives:
test.d(2): Error: cannot implicitly convert expression ([[1]]) of type int[][]
to int[]
test.d(3): Error: cannot use array to initialize int

In this case I expect to receive two times the first error message.

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


[Issue 5949] New: Mutable enum matrix rows

2011-05-07 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5949

   Summary: Mutable enum matrix rows
   Product: D
   Version: unspecified
  Platform: x86
OS/Version: Windows
Status: NEW
  Keywords: accepts-invalid
  Severity: normal
  Priority: P2
 Component: DMD
AssignedTo: nob...@puremagic.com
ReportedBy: bearophile_h...@eml.cc


--- Comment #0 from bearophile_h...@eml.cc 2011-05-07 16:08:46 PDT ---
This D2 code compiles and runs with no errors (DMD 2.053beta), but it's wrong:


void main() {
enum int[][] data = [[1]];
foreach (a; data)
a[0]++;
assert(data[0][0] == 1);
foreach (ref a; data)
a[0]++;
assert(data[0][0] == 1);
}

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


[Issue 5950] New: Linker problem with AA.get()

2011-05-07 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5950

   Summary: Linker problem with AA.get()
   Product: D
   Version: unspecified
  Platform: x86
OS/Version: Windows
Status: NEW
  Keywords: rejects-valid
  Severity: normal
  Priority: P2
 Component: druntime
AssignedTo: nob...@puremagic.com
ReportedBy: bearophile_h...@eml.cc


--- Comment #0 from bearophile_h...@eml.cc 2011-05-07 16:12:45 PDT ---
This D2 code:


import std.stdio;
void main() {
string[char] tab = ['e': red, 'b': blue];
string r;
foreach (c; aba) {
// if (c in tab) r ~= tab[c]; // OK
r ~= tab.get(c, ); // ERR
}
writeln(r);
}


Gives me a linker error (DMD 2.053beta):

test.obj(test) 
Error 42: Symbol Undefined
_D6object28__T16AssociativeArrayTaTAyaZ16AssociativeArray3getMFaLAyaZAya

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


[Issue 5951] New: writeln(AAbyValue()) doesn't show the values

2011-05-07 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5951

   Summary: writeln(AAbyValue()) doesn't show the values
   Product: D
   Version: unspecified
  Platform: x86
OS/Version: Windows
Status: NEW
  Keywords: wrong-code
  Severity: normal
  Priority: P2
 Component: druntime
AssignedTo: nob...@puremagic.com
ReportedBy: bearophile_h...@eml.cc


--- Comment #0 from bearophile_h...@eml.cc 2011-05-07 16:24:13 PDT ---
import std.stdio;
void main() {
int[int] hash = [1:2, 3:4];
auto vals = hash.byValue();
writeln(vals);
}


With DMD 2.053beta at runtime the writeln prints:
int delegate(int delegate(ref int))

Expected: the sequence of the items, something like:
[2; 4]


See also bug 3813

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


[Issue 5952] New: map(AA.byValue()) problem

2011-05-07 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5952

   Summary: map(AA.byValue()) problem
   Product: D
   Version: unspecified
  Platform: x86
OS/Version: Windows
Status: NEW
  Keywords: rejects-valid
  Severity: normal
  Priority: P2
 Component: Phobos
AssignedTo: nob...@puremagic.com
ReportedBy: bearophile_h...@eml.cc


--- Comment #0 from bearophile_h...@eml.cc 2011-05-07 16:27:16 PDT ---
import std.algorithm;
void main() {
int[int] hash = [1:2, 3:4];
auto vals = hash.byValue();
map!q{a}(vals); // error
}


The line of code with map causes this (DMD 2.053beta):

test.d(5): Error: template std.algorithm.map!(a).map(Range) if
(isInputRange!(Unqual!(Range))) does not match any function template
declaration
test.d(5): Error: template std.algorithm.map!(a).map(Range) if
(isInputRange!(Unqual!(Range))) cannot deduce template function from argument
types !()(int delegate(int delegate(ref int) dg))

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


[Issue 5953] New: Too many trailing commas are accepted

2011-05-07 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5953

   Summary: Too many trailing commas are accepted
   Product: D
   Version: D2
  Platform: x86
OS/Version: Windows
Status: NEW
  Keywords: accepts-invalid
  Severity: minor
  Priority: P2
 Component: DMD
AssignedTo: nob...@puremagic.com
ReportedBy: bearophile_h...@eml.cc


--- Comment #0 from bearophile_h...@eml.cc 2011-05-07 16:28:09 PDT ---
Accepting an extra trailing comma is acceptable, but this looks excessive (this
compiles and runs with no errors, DMD 2.053 beta):


void main() {
auto a = [,];
assert(a.length == 0);
}


As in Python I suggest to accept only one extra trailing comma:

 a = [1]
 a = [1,]
 a = [1,,]
  File stdin, line 1
a = [1,,]
   ^
SyntaxError: invalid syntax

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


[Issue 5954] New: enum structs with ctor

2011-05-07 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5954

   Summary: enum structs with ctor
   Product: D
   Version: D2
  Platform: Other
OS/Version: Windows
Status: NEW
  Keywords: rejects-valid
  Severity: enhancement
  Priority: P2
 Component: DMD
AssignedTo: nob...@puremagic.com
ReportedBy: bearophile_h...@eml.cc


--- Comment #0 from bearophile_h...@eml.cc 2011-05-07 16:31:20 PDT ---
D2 code:


struct Foo {
int x;
this(int xx) {
this.x = xx;
}
}
void main() {
enum f = Foo(10);
}


DMD 2.053beta is not able to compile it, and shows the errors:

test.d(8): Error: variable __ctmp3 cannot be read at compile time
test.d(8): Error: cannot evaluate __ctmp3.this(10) at compile time

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