Re: Is the following well defined and allowed?

2018-03-01 Thread Nathan S. via Digitalmars-d
On Thursday, 1 March 2018 at 21:01:08 UTC, Steven Schveighoffer 
wrote:

Yeah, it seems like -noboundscheck should never be used.


How good is DMD at omitting redundant bounds checks? I assume not 
much engineering effort has been put towards that due to 
"-boundscheck=off" being available.


Re: Opt-in non-null class references?

2018-03-01 Thread Jacob Carlborg via Digitalmars-d
On Wednesday, 28 February 2018 at 23:58:44 UTC, Jonathan M Davis 
wrote:
he's stated that dmd's optimizer uses code-flow analysis for 
some stuff, but for anything that involves putting it in the 
frontend where the behavior would have to be encoded in the 
spec, he's been against it.


The compiler can actually detect simple cases of null 
dereferences if optimizations are turned on, "-O", due to the 
optimizer using flow analysis.


--
/Jacob Carlborg


Re: I have a patch to let lldb demangle D symbols ; help welcome to improve it

2018-03-01 Thread Jacob Carlborg via Digitalmars-d

On Tuesday, 27 February 2018 at 05:28:41 UTC, Timothee Cour wrote:

https://github.com/llvm-mirror/lldb/pull/3
+
https://github.com/timotheecour/dtools/blob/master/dtools/lldbdplugin.d


on OSX, it works great except when encountering large symbols 
which

cause segfault when GC does a collection (triggered inside
core.demangle.demangle);
Help is welcome to improve that (or more generally to improve D
support in lldb, which I started in
https://github.com/llvm-mirror/lldb/pull/3)
NOTE: lldb doesn't accept github PR's but easier to work with 
PR's for

whoever wants to help on tha in the meantime


This is great work.

Keep in mind that DMD does not support dynamic libraries on macOS.

--
/Jacob Carlborg


Re: Thinktank: CI's, compiler lists, and project automation

2018-03-01 Thread Jacob Carlborg via Digitalmars-d
On Friday, 2 March 2018 at 06:07:25 UTC, Nick Sabalausky 
(Abscissa) wrote:
(I'm posting this here instead of D.learn because it isn't 
really a "How to do XYZ in D?", but rather to invite discussion 
on high-level solutions to a problem.)


Here's a common problem:

1. A project (ex, some library) uses travis-ci (and/or other) 
to ensure compatibility with a range of compiler versions. The 
travis configuration file includes a manually-curated list of 
compiler versions.


2. CI tests are triggered by new commits/merges/PRs in the 
project.


3. New compiler versions are released.

4. Compiler updates may or may not trigger new tests with the 
new compiler, depending on the project.


5. Project maintainer must manually update the list of 
compilers. (And this isn't one task, but rather O(n), where 
n=number of projects the given person is maintaining).


The challenge: What is the best way to automate this? (ie, #4 
and #5)


Travis CI allows you to specify a D compiler in the following 
ways:


*  - the latest version of the specified compiler
* -beta - the latest beta
* -nightly - the nightly build
* - - a specific version of the compiler

Where  is "dmd", "ldc" or "gdc".

Combine the above with a scheduled build that builds once every 
day you're pretty well covered. For an example, see the Travis CI 
configuration for DStep [1]. I'm building the latest version of 
DMD and LDC on Linux and macOS, but the betas and nightly are 
only built on Linux, due the the limited resources of macOS 
builds on Travis CI.


[1] 
https://github.com/jacob-carlborg/dstep/blob/master/.travis.yml


--
/Jacob Carlborg


Thinktank: CI's, compiler lists, and project automation

2018-03-01 Thread Nick Sabalausky (Abscissa) via Digitalmars-d
(I'm posting this here instead of D.learn because it isn't really a "How 
to do XYZ in D?", but rather to invite discussion on high-level 
solutions to a problem.)


Here's a common problem:

1. A project (ex, some library) uses travis-ci (and/or other) to ensure 
compatibility with a range of compiler versions. The travis 
configuration file includes a manually-curated list of compiler versions.


2. CI tests are triggered by new commits/merges/PRs in the project.

3. New compiler versions are released.

4. Compiler updates may or may not trigger new tests with the new 
compiler, depending on the project.


5. Project maintainer must manually update the list of compilers. (And 
this isn't one task, but rather O(n), where n=number of projects the 
given person is maintaining).


The challenge: What is the best way to automate this? (ie, #4 and #5)

We do already have certain approaches to at least certain facets of the 
problem (ex: some third party libs are included in DMD's CI testing), 
but there are still limitations and downsides (ex: D tester has limited 
resources, and it doesn't address manually updating the travis config's 
list of compilers or notifying authors their project's compiler list 
needs updated.)


Another sample point of discussion: One possible approach is to have a 
bot generate PRs to update project's compiler lists. But that leads to 
other questions: How/when is the bot triggered? On what machine does it 
run? Is there an existing jumping-off point for creating such a bot? How 
does it approach the task of modifying `.travis.yml` (how smart/dumb 
does it need to be)? Any security concerns to be mindful of? Etc.


Re: I have a patch to let lldb demangle D symbols ; help welcome to improve it

2018-03-01 Thread Timothee Cour via Digitalmars-d
yes, I've fixed the issue with crashes on large symbols using a
patched `demangle` ; will update code soon; but feel free to take a
look at lldb side of things




On Thu, Mar 1, 2018 at 12:23 PM, Luís Marques via Digitalmars-d
 wrote:
> On Tuesday, 27 February 2018 at 11:23:02 UTC, timotheecour wrote:
>>
>> On Tuesday, 27 February 2018 at 05:28:41 UTC, Timothee Cour wrote:
>>>
>>> https://github.com/llvm-mirror/lldb/pull/3
>>> +
>>> https://github.com/timotheecour/dtools/blob/master/dtools/lldbdplugin.d
>>>
>>>
>>> on OSX, it works great except when encountering large symbols which
>>> cause segfault when GC does a collection (triggered inside
>>> core.demangle.demangle);
>>> Help is welcome to improve that (or more generally to improve D
>>> support in lldb, which I started in
>>> https://github.com/llvm-mirror/lldb/pull/3)
>>> NOTE: lldb doesn't accept github PR's but easier to work with PR's for
>>> whoever wants to help on tha in the meantime
>>
>>
>> Specifically, the issue I'm facing is:
>> https://github.com/timotheecour/dtools/issues/2 (a crash occurs when
>> _d_arraysetlengthiT is called)
>>
>> any help would be greatly appreciated
>
>
> Thanks for working on this. I'll try to look into this in the next few days.
> (If you have further progress on this please provide an update here).



Re: How to stringify a template instantiation expression?

2018-03-01 Thread aliak via Digitalmars-d

On Thursday, 1 March 2018 at 16:46:30 UTC, Yuxuan Shui wrote:

Did you actually try that? With dmd 2.079-rc1, this:

template A(T...) {}
struct B {}
struct D {}
struct E {}
template C(T...) {}
pragma(msg, (A!(B, C!(D, E))).stringof);

Prints:

A!(B, __T1CTS2ax1DTSQh1EZ)

When compiled


Yep, though not all possible combinations of course:

struct X(T...) {}

void main() {
writeln(X!(int, X!(X!(int), float), char).stringof);
}

Seems like if you throw in template templates then things get a 
little more ... complicated.


Re: Opt-in non-null class references?

2018-03-01 Thread aliak via Digitalmars-d

On Thursday, 1 March 2018 at 19:10:29 UTC, Jonathan M Davis wrote:
DIP 1000 operates based on the type. As I understand it, it 
looks at the fact that something is scope or not and then 
determines whether a particular operation is valid or not based 
on whether the operation could result in a reference to the 
data escaping. An operation is then valid or not regardless of 
what other lines in the code are doing. As such, if I 
understand correctly, code-flow analysis isn't really 
necessary, just like code-flow analysis isn't necessary to 
determine what's valid or not when const is involved.


- Jonathan M Davis


Ah right, makes sense yep. Thanky!


Re: Is the following well defined and allowed?

2018-03-01 Thread ag0aep6g via Digitalmars-d
On Thursday, 1 March 2018 at 21:01:08 UTC, Steven Schveighoffer 
wrote:

Yeah, it seems like -noboundscheck should never be used.


Agreed.

It's undefined behavior if the check is disabled. How you get 
the check disabled may be affected by @safe, but whether it's 
UB or not has nothing to do with @safe. It has to do with "I 
turned off the checks". Basically, in D, if your program *would 
have* thrown an Error, but didn't because you turned it off, 
the compiler is free to assume UB.


You're looking at the behavior of the compiled executable. Then 
it makes sense to say that a program compiled with the checks has 
defined behavior (throwing Errors) and a program without the 
checks does something undefined (because the compiler manual 
doesn't say that anything in particular is supposed to happen).


That's not how I understand/use "undefined behavior". To me, it's 
the D source code that can have "undefined behavior". When it 
does, the program (as given in source code) is invalid and the 
compiler can do whatever it wants with it. It may:


1) reject the program statically, or it may
2) generate code that throws an Error at run time, or it may
3) generate code that does something arbitrary.

With that meaning of UB, out-of-bounds accesses and overlapping 
copies have undefined behavior in @system code, but they have 
defined behavior in @safe code.


For @system code, DMD chooses option #2 or option #3 depending on 
whether you give -release or not. DMD is free to do this, because 
the source code has UB.


For @safe code, DMD goes with option #2 either way, because the 
spec demands it.


If it were capable, DMD could also go with option #1 for both 
@system and @safe code. The spec allows/encourages that.


In this interpetation, -noboundscheck switches DMD to a different 
dialect of D. In that dialect, out-of-bounds accesses (and 
overlapping copies, apparently) always have UB, in both @system 
and @safe code. That defeats the purpose of @safe. Which is why I 
don't really care for that dialect.


Re: Is the following well defined and allowed?

2018-03-01 Thread Jonathan M Davis via Digitalmars-d
On Thursday, March 01, 2018 16:01:08 Steven Schveighoffer via Digitalmars-d 
wrote:
> On 3/1/18 3:24 PM, ag0aep6g wrote:
> > On Thursday, 1 March 2018 at 20:14:07 UTC, Steven Schveighoffer wrote:
> >> dmd -version=dosafe -noboundscheck -run testarrayoverlap.d => no
> >> error, undefined behavior
> >> dmd -run testarrayoverlap.d => error
> >>
> >> @safe has nothing to do with it.
> >
> > @safe has everything to do with. @safe guarantees that there's no
> > undefined behavior. If you can trigger UB in @safe code, that's a bug.
> > The guarantee must hold whether asserts are enabled or not.
> > -noboundscheck does not just disable asserts, it undermines @safe,
> > rendering it meaningless.
>
> Yeah, it seems like -noboundscheck should never be used.

IMHO, it was a mistake to ever add it.

> > For just disabling asserts (without affecting @safe), there's -release.
> > With your same code, `dmd -release` => UB, but `dmd -release
> > -version=dosafe` => Error.
>
> I was unaware that it would work this way. I thought it would be the
> same whether you used @safe or not with -release.

That depends on the feature. It's true for array bounds checking, but it's
not true for stuff like final switch statements - or apparently, this
situation. I don't know if that should be changed or not. Probably.

- Jonathan M Davis



Re: Is the following well defined and allowed?

2018-03-01 Thread Steven Schveighoffer via Digitalmars-d

On 3/1/18 3:24 PM, ag0aep6g wrote:

On Thursday, 1 March 2018 at 20:14:07 UTC, Steven Schveighoffer wrote:
dmd -version=dosafe -noboundscheck -run testarrayoverlap.d => no 
error, undefined behavior

dmd -run testarrayoverlap.d => error

@safe has nothing to do with it.


@safe has everything to do with. @safe guarantees that there's no 
undefined behavior. If you can trigger UB in @safe code, that's a bug. 
The guarantee must hold whether asserts are enabled or not. 
-noboundscheck does not just disable asserts, it undermines @safe, 
rendering it meaningless.


Yeah, it seems like -noboundscheck should never be used.

It's undefined behavior if the check is disabled. How you get the check 
disabled may be affected by @safe, but whether it's UB or not has 
nothing to do with @safe. It has to do with "I turned off the checks". 
Basically, in D, if your program *would have* thrown an Error, but 
didn't because you turned it off, the compiler is free to assume UB.




For just disabling asserts (without affecting @safe), there's -release. 
With your same code, `dmd -release` => UB, but `dmd -release 
-version=dosafe` => Error.


I was unaware that it would work this way. I thought it would be the 
same whether you used @safe or not with -release.


-Steve


Re: Is the following well defined and allowed?

2018-03-01 Thread ag0aep6g via Digitalmars-d
On Thursday, 1 March 2018 at 20:14:07 UTC, Steven Schveighoffer 
wrote:
dmd -version=dosafe -noboundscheck -run testarrayoverlap.d => 
no error, undefined behavior

dmd -run testarrayoverlap.d => error

@safe has nothing to do with it.


@safe has everything to do with. @safe guarantees that there's no 
undefined behavior. If you can trigger UB in @safe code, that's a 
bug. The guarantee must hold whether asserts are enabled or not. 
-noboundscheck does not just disable asserts, it undermines 
@safe, rendering it meaningless.


For just disabling asserts (without affecting @safe), there's 
-release. With your same code, `dmd -release` => UB, but `dmd 
-release -version=dosafe` => Error.


Re: I have a patch to let lldb demangle D symbols ; help welcome to improve it

2018-03-01 Thread Luís Marques via Digitalmars-d

On Tuesday, 27 February 2018 at 11:23:02 UTC, timotheecour wrote:
On Tuesday, 27 February 2018 at 05:28:41 UTC, Timothee Cour 
wrote:

https://github.com/llvm-mirror/lldb/pull/3
+
https://github.com/timotheecour/dtools/blob/master/dtools/lldbdplugin.d


on OSX, it works great except when encountering large symbols 
which

cause segfault when GC does a collection (triggered inside
core.demangle.demangle);
Help is welcome to improve that (or more generally to improve D
support in lldb, which I started in
https://github.com/llvm-mirror/lldb/pull/3)
NOTE: lldb doesn't accept github PR's but easier to work with 
PR's for

whoever wants to help on tha in the meantime


Specifically, the issue I'm facing is: 
https://github.com/timotheecour/dtools/issues/2 (a crash occurs 
when _d_arraysetlengthiT is called)


any help would be greatly appreciated


Thanks for working on this. I'll try to look into this in the 
next few days. (If you have further progress on this please 
provide an update here).


Re: Is the following well defined and allowed?

2018-03-01 Thread Steven Schveighoffer via Digitalmars-d

On 3/1/18 3:06 PM, ag0aep6g wrote:

On Thursday, 1 March 2018 at 19:05:26 UTC, Steven Schveighoffer wrote:
Yes it behaves just like array bounds. No it's not well-defined if you 
disable asserts.


Right. So it's defined to throw an Error in @safe code, and it has 
undefined behavior in @system code. The spec should say this.


No.


version(dosafe)
{
void main() @safe
{
int[4] arr;
arr[0 .. 3] = arr[1 .. 4];
}
}
else
{
void main()
{
int[4] arr;
arr[0 .. 3] = arr[1 .. 4];
}
}
---

dmd -version=dosafe -noboundscheck -run testarrayoverlap.d => no error, 
undefined behavior

dmd -run testarrayoverlap.d => error

@safe has nothing to do with it.

-Steve


Re: Is the following well defined and allowed?

2018-03-01 Thread ag0aep6g via Digitalmars-d
On Thursday, 1 March 2018 at 19:05:26 UTC, Steven Schveighoffer 
wrote:
Yes it behaves just like array bounds. No it's not well-defined 
if you disable asserts.


Right. So it's defined to throw an Error in @safe code, and it 
has undefined behavior in @system code. The spec should say this.


Re: D for microservices

2018-03-01 Thread Jacob Carlborg via Digitalmars-d

On 2018-02-25 17:51, yawniek wrote:


Q: what would be needed to build a single binary (a la golang) that
works in a FROM SCRATCH docker container?


Build a completely statically linked binary by compiling using LDC and 
add the "-static" flag.


--
/Jacob Carlborg


Re: Opt-in non-null class references?

2018-03-01 Thread Jonathan M Davis via Digitalmars-d
On Thursday, March 01, 2018 14:59:38 aliak via Digitalmars-d wrote:
> On Wednesday, 28 February 2018 at 23:58:44 UTC, Jonathan M Davis
>
> wrote:
> > On Wednesday, February 28, 2018 19:43:07 Kagamin via
> >
> > Digitalmars-d wrote:
> >> On Wednesday, 28 February 2018 at 14:05:19 UTC, Jonathan M
> >> Davis
> >>
> >> wrote:
> >> > [...]
> >>
> >> Doesn't difficulty depend on what exactly to get right? It's
> >> not a spherical problem in vacuum.
> >
> > Feel free to discuss any code-flow analysis issues with Walter,
> > but he's consistently been against using it for much of
> > anything whenever I've seen him discuss it. Not even stuff like
> > VRP covers multiple lines of code, because doing so would
> > require code-flow analysis. And he's specifically said that
> > he's against using it for detecting when a null pointer is
> > dereferenced. IIRC, he's stated that dmd's optimizer uses
> > code-flow analysis for some stuff, but for anything that
> > involves putting it in the frontend where the behavior would
> > have to be encoded in the spec, he's been against it.
> >
> > - Jonathan M Davis
>
> Isn't DIP1000 [1] basically code flow analysis and implemented
> (kinda?) in dmd with -dip1000 now?
>
> [1] https://github.com/dlang/DIPs/blob/master/DIPs/DIP1000.md

DIP 1000 operates based on the type. As I understand it, it looks at the
fact that something is scope or not and then determines whether a particular
operation is valid or not based on whether the operation could result in a
reference to the data escaping. An operation is then valid or not regardless
of what other lines in the code are doing. As such, if I understand
correctly, code-flow analysis isn't really necessary, just like code-flow
analysis isn't necessary to determine what's valid or not when const is
involved.

- Jonathan M Davis



Re: Is the following well defined and allowed?

2018-03-01 Thread Steven Schveighoffer via Digitalmars-d

On 3/1/18 12:31 PM, ag0aep6g wrote:

On Thursday, 1 March 2018 at 17:06:48 UTC, Steven Schveighoffer wrote:

On 3/1/18 11:48 AM, ag0aep6g wrote:

[...]
Does that mean it has undefined behavior and should not be allowed in 
@safe code?


No, it means it's a runtime error.


But then it's well-defined, like going beyond array bounds, no?


Yes it behaves just like array bounds. No it's not well-defined if you 
disable asserts.


-Steve


Re: How to stringify a template instantiation expression?

2018-03-01 Thread Simen Kjærås via Digitalmars-d

On Thursday, 1 March 2018 at 16:46:30 UTC, Yuxuan Shui wrote:

On Wednesday, 28 February 2018 at 15:49:25 UTC, aliak wrote:
On Wednesday, 28 February 2018 at 15:09:56 UTC, Yuxuan Shui 
wrote:
For a template instantiation expression like A!(B, C!(D, E)), 
I want to get a string "A!(B, C!(D, E))", better if A, B, C, 
D, E is replaced by fully qualified name.


Is this possible?


A!(B, C!(D, E)).stringof I guess. Will print the former.

There's a Learn forum as well btw :)

Cheers


Did you actually try that? With dmd 2.079-rc1, this:

template A(T...) {}
struct B {}
struct D {}
struct E {}
template C(T...) {}
pragma(msg, (A!(B, C!(D, E))).stringof);

Prints:

A!(B, __T1CTS2ax1DTSQh1EZ)

When compiled


string TemplateStringOf(T...)()
if (T.length == 1)
{
import std.traits : TemplateOf, TemplateArgsOf;
import std.meta : AliasSeq, staticMap;
import std.string : indexOf;
import std.conv : text;
static if (is(typeof({ alias a = TemplateOf!T; })))
{
alias Tmp = TemplateOf!T;
alias Args = TemplateArgsOf!T;

enum tmpFullName = Tmp.stringof;
enum tmpName = tmpFullName[0..tmpFullName.indexOf('(')];

alias AddCommas(T...) = AliasSeq!(T, ", ");
alias ArgNames = staticMap!(.TemplateStringOf, Args);
alias SeparatedArgNames = staticMap!(AddCommas, 
ArgNames)[0..$-1];


return text(tmpName, "!(", SeparatedArgNames, ")");
}
else
{
return T[0].stringof;
}
}

unittest {
template A(T...) {}
struct B {}
struct D {}
struct E {}
template C(T...) {}

assert(TemplateStringOf!(A!(B, C!(D, E))) == "A!(B, C!(D, 
E))");

}

unittest {
template A(T) { template A(T) {} }

assert(TemplateStringOf!(A!int) == "A!(int)");
}

Probably still some corner cases I haven't thought of, but it 
seems to cover what you're asking for.


One thing I didn't bother with is disambiguation - if B exists in 
modules foo and bar, the above will not specify which foo it's 
referring to. This is left as an exercise for the reader.


--
  Simen


Re: Is the following well defined and allowed?

2018-03-01 Thread ag0aep6g via Digitalmars-d
On Thursday, 1 March 2018 at 17:06:48 UTC, Steven Schveighoffer 
wrote:

On 3/1/18 11:48 AM, ag0aep6g wrote:

[...]
Does that mean it has undefined behavior and should not be 
allowed in @safe code?


No, it means it's a runtime error.


But then it's well-defined, like going beyond array bounds, no?


Just a few thoughts on traits

2018-03-01 Thread Luís Marques via Digitalmars-d
Not very important, but I was reminded of a few things yesterday 
while filling out the survey.


1) I remember reading somewhere a long time ago that __traits had 
that ugly name because it wasn't supposed to be used directly; 
you'd instead generally use something nicer like std.traits (or 
maybe I'm misremembering the argument for naming __gshared). But 
many of things that you can do with __traits still aren't in 
std.traits. Is this intentional, or is there a will to make 
std.traits the go to place for all things traity? BTW, one 
advantage of using std.traits instead of equivalent __traits is 
that you can use UFCS.


2) I also remember when I first used __traits allMembers that I 
was surprised it returned strings instead of references to the 
members. First of all, it's not named allMembersStrings. Second, 
it seemed like if you wanted a string you could use .stringof or 
something similar, and getting the member itself was the normal 
case, so what you'd optimize for. In any case, even if the 
__trait itself is never changed, that's probably a case where we 
could add a higher-level wrapper in std.traits that returns the 
references. Related to that, I saw this code mentioned in the 
d-idioms:


BuildSettings dup() const
{
BuildSettings ret;

foreach (m; __traits(allMembers, BuildSettings))
{
static if (is(typeof(__traits(getMember, ret, m) = 
__traits(getMember, this, m).dup)))
__traits(getMember, ret, m) = __traits(getMember, 
this, m).dup;
else static if (is(typeof(__traits(getMember, ret, m) = 
__traits(getMember, this, m
__traits(getMember, ret, m) = __traits(getMember, 
this, m);

}
return ret;
}

This is pretty intimidating code (and ugly IMO) for someone who 
isn't very familiar with the more advanced D features. I think 
what makes this harder to read for the uninitiated is that it's 
directly written in terms of lower-level features, instead of 
using nicer wrappers like hasSomeProperty!X. The wrapper has the 
advantage of both documenting the intent and making it easier to 
study how SomeProperty is detected using __traits, since you 
aren't simultaneously trying to understand *what* the code is 
testing and *how*. Documenting the intent in terms of a wrapper 
also makes it easier to catch bugs in code review, without having 
having to add actual code comments.




Re: How do you get comfortable with Dlang.org's Forum?

2018-03-01 Thread 0xFFFFFFFF via Digitalmars-d

On Friday, 23 February 2018 at 13:47:16 UTC, biocyberman wrote:

Want to learn something from you guys.

forum.dlang.org is by far the biggest gathering point for Dlang 
users. So, even though I wanted to get away with using 
stackoverflow.com, I have to come back here. However, to me it 
easier for me, I would like to know how you guys get 
comfortable with using the forum?


[...]


As for me, I would like more activity on Reddit.



Re: Is the following well defined and allowed?

2018-03-01 Thread Steven Schveighoffer via Digitalmars-d

On 3/1/18 11:48 AM, ag0aep6g wrote:

On 03/01/2018 04:34 PM, David Nadlinger wrote:

On Thursday, 1 March 2018 at 14:54:41 UTC, Shachar Shemesh wrote:

I.e. - is it well defined to copy between overlapping slices?


No: https://dlang.org/spec/arrays.html#overlapping-copying


Does that mean it has undefined behavior and should not be allowed in 
@safe code?


No, it means it's a runtime error.

https://run.dlang.io/is/xdiKxx

-Steve


Re: How to stringify a template instantiation expression?

2018-03-01 Thread Yuxuan Shui via Digitalmars-d

On Thursday, 1 March 2018 at 16:46:30 UTC, Yuxuan Shui wrote:

On Wednesday, 28 February 2018 at 15:49:25 UTC, aliak wrote:
On Wednesday, 28 February 2018 at 15:09:56 UTC, Yuxuan Shui 
wrote:
For a template instantiation expression like A!(B, C!(D, E)), 
I want to get a string "A!(B, C!(D, E))", better if A, B, C, 
D, E is replaced by fully qualified name.


Is this possible?


A!(B, C!(D, E)).stringof I guess. Will print the former.

There's a Learn forum as well btw :)

Cheers


Did you actually try that? With dmd 2.079-rc1, this:

template A(T...) {}
struct B {}
struct D {}
struct E {}
template C(T...) {}
pragma(msg, (A!(B, C!(D, E))).stringof);

Prints:

A!(B, __T1CTS2ax1DTSQh1EZ)

When compiled


Even worse, if the template instantiation yields another 
template, e.g:


template A(T) { template A(T) {} }

A!int.stringof returns "A(T)", which is not useful at all.


Re: How to stringify a template instantiation expression?

2018-03-01 Thread Yuxuan Shui via Digitalmars-d

On Wednesday, 28 February 2018 at 15:49:25 UTC, aliak wrote:
On Wednesday, 28 February 2018 at 15:09:56 UTC, Yuxuan Shui 
wrote:
For a template instantiation expression like A!(B, C!(D, E)), 
I want to get a string "A!(B, C!(D, E))", better if A, B, C, 
D, E is replaced by fully qualified name.


Is this possible?


A!(B, C!(D, E)).stringof I guess. Will print the former.

There's a Learn forum as well btw :)

Cheers


Did you actually try that? With dmd 2.079-rc1, this:

template A(T...) {}
struct B {}
struct D {}
struct E {}
template C(T...) {}
pragma(msg, (A!(B, C!(D, E))).stringof);

Prints:

A!(B, __T1CTS2ax1DTSQh1EZ)

When compiled


Re: Is the following well defined and allowed?

2018-03-01 Thread ag0aep6g via Digitalmars-d

On 03/01/2018 04:34 PM, David Nadlinger wrote:

On Thursday, 1 March 2018 at 14:54:41 UTC, Shachar Shemesh wrote:

I.e. - is it well defined to copy between overlapping slices?


No: https://dlang.org/spec/arrays.html#overlapping-copying


Does that mean it has undefined behavior and should not be allowed in 
@safe code?


Re: Opt-in non-null class references?

2018-03-01 Thread aliak via Digitalmars-d

On Wednesday, 28 February 2018 at 15:25:40 UTC, SimonN wrote:
My gripe is that the necessarily-nullable class reference 
doesn't express the intent.
Either a codebase must rely on silent conventions or every 
function with asserts.


I've put up a little experiment that you may be interested in for 
this part of the problem at least, also a little bit of compile 
time help because D treats dot on pointers and non pointers the 
same, it makes for some nice syntax:


class C {
int i = 3;
}

auto a = no!C;

if (auto c = a.unwrap) {
writeln("not here: ", c.i);
}
a.dispatch.i; // not ideal, but is at least safe no op.

a = some(new C());

if (auto c = a.unwrap) {
writeln("here: ", c.i);
}

If you're interested: https://github.com/aliak00/optional

Syntax allowing:
Optional!C = null;

is not there yet, but I think is doable because typeof(null) is 
distinguishable. So with an optional type this can be well 
defined as "none" internally as well


Not ideal I know, but maybe a start to see where it can go?

It's merely sad to see D, with all its powerful static 
inspection, rely on runtime tests for nulls while other 
languages (Kotlin, Zig, and 2017 C#) rule null out at 
compile-time, as if it's the most natural thing in the world.


Yeah, I whole heartedly agree with this. Maybe is an exposure 
thing? I remember seeing a talk (by I think the kickstarter 
people) that said after migrating to swift (from objective-c) 
their crash reports because dropped significantly (my brain for 
some reason remembers this to be zero, but I'm not sure and I 
can't figure out which talk this was).


Cheers,
- Ali



Re: C++ launched its community survey, too

2018-03-01 Thread German Diago via Digitalmars-d

On Tuesday, 27 February 2018 at 17:33:52 UTC, 12345swordy wrote:
On Tuesday, 27 February 2018 at 15:52:15 UTC, Andrei 
Alexandrescu wrote:

https://isocpp.org/blog/2018/02/new-cpp-foundation-developer-survey-lite-2018-02

Andrei


I have submitted, already. My major complaints boils down to 
the fact that they refuse to deprecated features due to 
religious like devotions to backwards compatibility support.


Well, not religious but... they are removing things too slow. 
There is a paper about stability and velocity of C++ that 
proposes to widen things to move forward faster and... btw I 
complained about exactly that as well. Things are getting bigger 
and bigger, just discard things. I also complained about the 
following:


1.- everyone is saying stop the preprocessor... modules support 
no preprocessor after import... ok, then, why feature test 
macros? They should be enums or constexpr but never a 
preprocessor macro.
2.- the single thing that bothers me the most... initialization 
is a mess, especially after adding {} vs (). With good intention, 
but the cognitive overhead and room for surprises is too big.
3.- if constexpr cannot simply compete with static if. I 
suggested adding: if constexpr that does not require a template 
function, and some alternative if constexpr mechanism (I do not 
care about the name or if it is a separate feature) that can 
conditionally compile structs or block scopes a la version() in 
D. This feature is needed to kill the preprocessor if they really 
want to take that seriously, especially with modules on its way.


BTW, I have been trying a bit of D lately and I like how flexible 
things such as opDispatch and static if are. I love modules as 
well. I like a lot also the fact that you do not need to be 
prefixing all things all the time because of potential hijacking. 
The static reflection has also been useful for me. I was just 
coding a SNES ROM parser but that was enough already to show some 
of the advantages.





Re: Is the following well defined and allowed?

2018-03-01 Thread David Nadlinger via Digitalmars-d

On Thursday, 1 March 2018 at 14:54:41 UTC, Shachar Shemesh wrote:

I.e. - is it well defined to copy between overlapping slices?


No: https://dlang.org/spec/arrays.html#overlapping-copying

 —David


Re: How do you get comfortable with Dlang.org's Forum?

2018-03-01 Thread Basile B. via Digitalmars-d
On Tuesday, 27 February 2018 at 20:09:22 UTC, Patrick Schluter 
wrote:

On Tuesday, 27 February 2018 at 07:33:05 UTC, Basile B. wrote:
On Saturday, 24 February 2018 at 19:30:52 UTC, Patrick 
Schluter wrote:
On Saturday, 24 February 2018 at 18:46:50 UTC, Steven 
Schveighoffer wrote:

On 2/24/18 7:00 AM, Patrick Schluter wrote:

[...]


Wow, that's insane. I would be interested in seeing it.

It's in the history of my work PC, may be I will find it on 
monday.


I'm french, i'm interested to know what the hell you talked 
about. Google search gave nothing. Do you referred to the 
journalist who was harassed by people on a gamer forum ?


No, it was not the Nadia Daam thing, she is probably too 
incompetent to pull that trick off.
As for the link, I checked but haven't found it. It was part of 
a longer youtube video but I don't remember which. Sorry.


Patrick, you should keep these kind of things out of there.
Right now you look like a guy who

1. either has been influebced by bullshits from the extreme right 
wing: read-believe-propagate.

2. or is a direct source of bullshits.

For the record: 
https://forum.dlang.org/post/upiiglzypphvaprll...@forum.dlang.org


That's not nice.




Re: How do you get comfortable with Dlang.org's Forum?

2018-03-01 Thread rikki cattermole via Digitalmars-d

On 02/03/2018 3:08 AM, Nick Sabalausky (Abscissa) wrote:

On 02/28/2018 12:48 PM, Vang Le wrote:
I don't mean to go into the good vs bad direction. What I was saying 
is that it is hard to get comfortable and use the forum the most 
effective/convenient ways. The forum should not be a technical barrier 
for members to communicate conveniently.


With that said, I am glad that I put up the questions and got a bunch 
of useful tips to use the forums. FYI, the most useful one is to 
install a NNTP client and use the 'forum' the way it is, a NNTP server 
with a web interface.


Speaking of which, and I apologize if this is inappropriate context, but 
has anyone found a good Android NNTP reader for this? I wasn't really 
able to find much when I looked, so I just use DFeed when I'm on the go, 
which is great (fantastic, really!) as far as web interfaces go, but a 
proper native reader would be really nice if anyone has any good tips!


I've used[0] in the past to read, but not for writing.

[0] https://play.google.com/store/apps/details?id=net.piaohong.newsgroup


Re: Opt-in non-null class references?

2018-03-01 Thread aliak via Digitalmars-d
On Wednesday, 28 February 2018 at 23:58:44 UTC, Jonathan M Davis 
wrote:
On Wednesday, February 28, 2018 19:43:07 Kagamin via 
Digitalmars-d wrote:
On Wednesday, 28 February 2018 at 14:05:19 UTC, Jonathan M 
Davis


wrote:
> [...]

Doesn't difficulty depend on what exactly to get right? It's 
not a spherical problem in vacuum.


Feel free to discuss any code-flow analysis issues with Walter, 
but he's consistently been against using it for much of 
anything whenever I've seen him discuss it. Not even stuff like 
VRP covers multiple lines of code, because doing so would 
require code-flow analysis. And he's specifically said that 
he's against using it for detecting when a null pointer is 
dereferenced. IIRC, he's stated that dmd's optimizer uses 
code-flow analysis for some stuff, but for anything that 
involves putting it in the frontend where the behavior would 
have to be encoded in the spec, he's been against it.


- Jonathan M Davis


Isn't DIP1000 [1] basically code flow analysis and implemented 
(kinda?) in dmd with -dip1000 now?


[1] https://github.com/dlang/DIPs/blob/master/DIPs/DIP1000.md


Is the following well defined and allowed?

2018-03-01 Thread Shachar Shemesh via Digitalmars-d

a[0..10][] = a[5..15][];

I.e. - is it well defined to copy between overlapping slices? Does it 
matter if, in the copy, the source is overlapping the end or the 
beginning of the destination?


Re: How do you get comfortable with Dlang.org's Forum?

2018-03-01 Thread Nick Sabalausky (Abscissa) via Digitalmars-d

On 02/28/2018 12:48 PM, Vang Le wrote:
I don't mean to go into the good vs bad direction. What I was saying is 
that it is hard to get comfortable and use the forum the most 
effective/convenient ways. The forum should not be a technical barrier 
for members to communicate conveniently.


With that said, I am glad that I put up the questions and got a bunch of 
useful tips to use the forums. FYI, the most useful one is to install a 
NNTP client and use the 'forum' the way it is, a NNTP server with a web 
interface.


Speaking of which, and I apologize if this is inappropriate context, but 
has anyone found a good Android NNTP reader for this? I wasn't really 
able to find much when I looked, so I just use DFeed when I'm on the go, 
which is great (fantastic, really!) as far as web interfaces go, but a 
proper native reader would be really nice if anyone has any good tips!


Re: Opt-in non-null class references?

2018-03-01 Thread Kagamin via Digitalmars-d
On Wednesday, 28 February 2018 at 23:58:44 UTC, Jonathan M Davis 
wrote:
Feel free to discuss any code-flow analysis issues with Walter, 
but he's consistently been against using it for much of 
anything whenever I've seen him discuss it.


I'd say massive breakage is what precludes it. Well, I like the 
way default initialization works in D.


Not even stuff like VRP covers multiple lines of code, because 
doing so would require code-flow analysis.


It feels like handling VRP for linear code can be simple enough, 
tracking VRP across branching is more of an overkill.