Re: alias and __VERSION__ condition doesn't play well
On Wednesday, 19 January 2022 at 04:15:54 UTC, Steven Schveighoffer wrote: On 1/18/22 7:19 AM, vit wrote: On Tuesday, 18 January 2022 at 12:05:38 UTC, Paul Backus wrote: On Tuesday, 18 January 2022 at 04:42:45 UTC, frame wrote: At the very top of my module I have this declaration: ```d static if (__VERSION__ >= 2098) { alias Foo = TypeA; } else { alias Foo = TypeB; } ``` No problem inside the module itself but this doesn't work when imported from another module: Error: undefined identifier `Foo` Works for me: https://run.dlang.io/is/XZlvQ8 It works until you have cyclic dependencies: https://run.dlang.io/is/wDDcK5 Has nothing to do with `__VERSION__`: https://run.dlang.io/is/pa8lDy That does seem like a bug. And it's LDC specific, dmd seems to work fine. -Steve In dmd is order of module compilation different. Same problem: https://run.dlang.io/is/NkySAw This is not only problem with imports: ```d class Foo{ Bar.B b; static if(true) alias F = int; } class Bar{ Foo.F f; //Error: no property `F` for type `onlineapp.Foo` static if(true) alias B = int; } void main(){} ```
Re: alias and __VERSION__ condition doesn't play well
On 1/18/22 7:19 AM, vit wrote: On Tuesday, 18 January 2022 at 12:05:38 UTC, Paul Backus wrote: On Tuesday, 18 January 2022 at 04:42:45 UTC, frame wrote: At the very top of my module I have this declaration: ```d static if (__VERSION__ >= 2098) { alias Foo = TypeA; } else { alias Foo = TypeB; } ``` No problem inside the module itself but this doesn't work when imported from another module: Error: undefined identifier `Foo` Works for me: https://run.dlang.io/is/XZlvQ8 It works until you have cyclic dependencies: https://run.dlang.io/is/wDDcK5 Has nothing to do with `__VERSION__`: https://run.dlang.io/is/pa8lDy That does seem like a bug. And it's LDC specific, dmd seems to work fine. -Steve
Re: number ranges
On Wednesday, 19 January 2022 at 03:00:49 UTC, Tejas wrote: On Tuesday, 18 January 2022 at 20:43:08 UTC, forkit wrote: On Tuesday, 18 January 2022 at 16:02:42 UTC, Tejas wrote: Newer languages nowadays use `start..intent, think it's something we should follow? I've decided to avoid using number ranges 'directly', and instead use a wrapper function... auto range(T:T)(T a, T b) { import std.range : iota; return iota(a, (b+1)); } Aww, come on; it ain't that bad... Well that depends on entirely on what the code is doing ;-) The key is to *always* *remember* the stop index is not included. I sure hope they 'remembered' this in the code running on that telescope floating out into open space...
Re: number ranges
On Tuesday, 18 January 2022 at 20:43:08 UTC, forkit wrote: On Tuesday, 18 January 2022 at 16:02:42 UTC, Tejas wrote: Newer languages nowadays use `start..intent, think it's something we should follow? I've decided to avoid using number ranges 'directly', and instead use a wrapper function... auto range(T:T)(T a, T b) { import std.range : iota; return iota(a, (b+1)); } Aww, come on; it ain't that bad...
Re: number ranges
On Tuesday, 18 January 2022 at 17:58:54 UTC, H. S. Teoh wrote: On Tue, Jan 18, 2022 at 04:02:42PM +, Tejas via Digitalmars-d-learn wrote: [...] Newer languages nowadays use `start..intent, think it's something we should follow? I've never seen that before. Which languages use that? T In Nim for example: ``` for n in 5 .. 9: #Both 5 and 9 are included echo n echo "" for n in 5 ..< 9: #5 is included but 9 is excluded echo n ``` In Odin also: ``` for i in 0..<10 { fmt.println(i) } // or for i in 0..9 { fmt.println(i) } ```
Re: number ranges
On Monday, 17 January 2022 at 22:28:10 UTC, H. S. Teoh wrote: This will immediately make whoever reads the code (i.e., myself after 2 months :D) wonder, "why +1?" And the answer will become clear and enlightenment ensues. ;-) In those cases i find myself rewriting said code. Generally to say **for(int i=1; i<=5; i++)** or something, where it includes the last one but doesn't add oddities that doesn't explain the magic numbers or odd +1. Then again the big issue *probably* comes from people coming from BASIC of some description where the **FOR A=1 TO 5**, where index starts at 1 and includes the number listed; And you aren't given other conditions to test against. It really does take a little getting used to. Maybe we don't use Qbasic or 8bit MSBASIC much anymore, but Visual Basic and legacy code grandfathers those in, and maybe a few other interpreted languages too.
Debug symbols from libs not being linked on windows
I have separated my project in a bunch of modules to be compiled separated. But it seems I have lost my debugging power since then. I would like to know if there is any workaround beside not using it as a lib. I'm using it from dub and it is has the debug options on them: ``` "buildOptions": [ "debugMode", "debugInfo", "debugInfoC" ], ``` And on every lib too.
Re: ldc2 failed with exit code -1073741819.
On Tuesday, 18 January 2022 at 16:25:45 UTC, Anonymouse wrote: What can I *reasonably* do here? Do I *have* to compile LDC from source, to get debug symbols? How else can I reduce it when it doesn't say what goes wrong? [-1073741819 == 0xc005 => access violation] Some options: 1. This might be 'caught' by an existing assertion. You can use a CI build (https://github.com/ldc-developers/ldc/releases/tag/CI) with enabled assertions to check. 2. In case the segfault does NOT happen in the frontend, enabling verbose codegen via `-vv` can be of great help to see what the glue layer was doing right before the crash (at the end of the potentially huge log). My manual reductions usually start there for glue layer crashes.
Re: number ranges
On 1/18/22 14:08, forkit wrote: > never use number ranges.. not ever! ;-) > > (except in combination with iota) Indeed, the following is an elegant but slow (tested with dmd) implementation with Phobos: auto range(T)(T a, T b) in (a <= b) { import std.range : chain, iota, only; return chain(iota(a, b), only(b)); } But I like the following one better because it is fast and I think it works correctly. However, I am reminded of one of the reasons why exclusive ranges are better: It is not possible to represent an empty range with the same syntax. For example, range(42, 42) includes 42. Hmmm. Should range(42, 41) mean empty? Looks weird. struct InclusiveRange(T) { T front; T last; bool empty; this(U)(in U front, in U last) in (front <= last) { this.front = front; this.last = last; this.empty = false; } void popFront() { if (front == last) { empty = true; } else { ++front; } } } auto inclusiveRange(T)(T first, T last) { return InclusiveRange!T(first, last); } unittest { // Impossible to be empty import std.algorithm : equal; auto r = inclusiveRange(42, 42); assert(!r.empty); assert(r.equal([42])); } unittest { // Can represent all values of a type import std.range : ElementType; import std.algorithm : sum; auto r = inclusiveRange(ubyte.min, ubyte.max); static assert(is(ElementType!(typeof(r)) == ubyte)); assert(r.sum == (ubyte.max * (ubyte.max + 1)) / 2); } unittest { // Really inclusive import std.algorithm : sum; assert(inclusiveRange(1, 10).sum == 55); } unittest { // Works with negative values import std.algorithm : equal; assert(inclusiveRange(-3, 3).equal([-3, -2, -1, 0, 1, 2, 3])); assert(inclusiveRange(-30, -27).equal([-30, -29, -28, -27])); } import std.stdio; void main() { } Ali
Re: shared defaultlib with dmd
On Tuesday, 18 January 2022 at 22:35:08 UTC, H. S. Teoh wrote: On Tue, Jan 18, 2022 at 10:04:15PM +, forkit via Digitalmars-d-learn wrote: so I use this compile command (on Windows, using ldc) -link-defaultlib-shared=true Then (in simple example) the size of my compiled .exe: From 806KB down to 18KB Oh. That's so much nicer on my SSD ;-) (yes, I understand the implictions here of dynamic sharing, but I test/compile/debug so much, that I'd like to limit the impact on my SSD drive. [...] Uhm... are you SURE this is actually nicer on your SSD? For all you know, it could be writing the 806KB first and then optimizing that in-place to reduce it to 18KB... Just because the final file size is small doesn't mean there aren't any large intermediate files. T no. there are no intermediary files. just this, and only this: (bytes) 145 EZ_Compiler_tmpfile.d 15,360 EZ_Compiler_tmpfile.exe 18,384 EZ_Compiler_tmpfile.obj
Re: shared defaultlib with dmd
On Tue, Jan 18, 2022 at 10:04:15PM +, forkit via Digitalmars-d-learn wrote: > so I use this compile command (on Windows, using ldc) > > -link-defaultlib-shared=true > > Then (in simple example) the size of my compiled .exe: > > From 806KB down to 18KB > > Oh. That's so much nicer on my SSD ;-) > > (yes, I understand the implictions here of dynamic sharing, but I > test/compile/debug so much, that I'd like to limit the impact on my > SSD drive. [...] Uhm... are you SURE this is actually nicer on your SSD? For all you know, it could be writing the 806KB first and then optimizing that in-place to reduce it to 18KB... Just because the final file size is small doesn't mean there aren't any large intermediate files. T -- Never ascribe to malice that which is adequately explained by incompetence. -- Napoleon Bonaparte
Re: shared defaultlib with dmd
On Tuesday, 18 January 2022 at 22:09:18 UTC, Adam D Ruppe wrote: On Tuesday, 18 January 2022 at 22:04:15 UTC, forkit wrote: so I use this compile command (on Windows, using ldc) On Linux dmd can do `-defaultlib=libphobos2.so` for the same thing. On Windows, dmd cannot handle a shared druntime. yes. but why? - is it technically too difficult? (ldc seems to have overcome that, if that's true)
Re: number ranges
On Tuesday, 18 January 2022 at 20:50:06 UTC, Ali Çehreli wrote: Needs a little more work to be correct. The following produces and empty range. ;) range(uint.min, uint.max) Also, is it important for the result to be the same as T? For example, even if T is ubyte, because b+1 is 'int', the range will produce ints. Ali a change of mind... never use number ranges.. not ever! ;-) (except in combination with iota)
Re: shared defaultlib with dmd
On Tuesday, 18 January 2022 at 22:04:15 UTC, forkit wrote: so I use this compile command (on Windows, using ldc) On Linux dmd can do `-defaultlib=libphobos2.so` for the same thing. On Windows, dmd cannot handle a shared druntime.
shared defaultlib with dmd
so I use this compile command (on Windows, using ldc) -link-defaultlib-shared=true Then (in simple example) the size of my compiled .exe: From 806KB down to 18KB Oh. That's so much nicer on my SSD ;-) (yes, I understand the implictions here of dynamic sharing, but I test/compile/debug so much, that I'd like to limit the impact on my SSD drive. But I can't do this with dmd ?? it has not such option ??
Re: number ranges
On 1/18/22 12:43, forkit wrote: > wrapper function... > > > auto range(T:T)(T a, T b) > { > import std.range : iota; > return iota(a, (b+1)); > } Needs a little more work to be correct. The following produces and empty range. ;) range(uint.min, uint.max) Also, is it important for the result to be the same as T? For example, even if T is ubyte, because b+1 is 'int', the range will produce ints. Ali
Re: number ranges
On Tuesday, 18 January 2022 at 16:02:42 UTC, Tejas wrote: Newer languages nowadays use `start..intent, think it's something we should follow? I've decided to avoid using number ranges 'directly', and instead use a wrapper function... auto range(T:T)(T a, T b) { import std.range : iota; return iota(a, (b+1)); }
Re: ldc2 failed with exit code -1073741819.
Compiling the project without: version "Colours" works So the problem lies here in this struct: https://github.com/zorael/kameloso/blob/9ccff29ead6ca2e80e2db0f06085c751326ed578/source/kameloso/constants.d#L320
Re: number ranges
On Tue, Jan 18, 2022 at 04:02:42PM +, Tejas via Digitalmars-d-learn wrote: [...] > Newer languages nowadays use `start.. it's something we should follow? I've never seen that before. Which languages use that? T -- "If you're arguing, you're losing." -- Mike Thomas
Re: ldc2 failed with exit code -1073741819.
On Tue, Jan 18, 2022 at 05:41:34PM +, Anonymouse via Digitalmars-d-learn wrote: > On Tuesday, 18 January 2022 at 17:37:27 UTC, H. S. Teoh wrote: > > > Bypassing dub and calling the raw ldc command gives no output. > > > What else can I do? > > > > What does `echo $?` print immediately after you run the raw ldc > > command? [...] > It exits with 5. I could look for that, certainly. Yeah, that's probably the more reliable way to reduce this case. T -- Help a man when he is in trouble and he will remember you when he is in trouble again.
Re: ldc2 failed with exit code -1073741819.
On Tuesday, 18 January 2022 at 17:37:27 UTC, H. S. Teoh wrote: Bypassing dub and calling the raw ldc command gives no output. What else can I do? What does `echo $?` print immediately after you run the raw ldc command? T It exits with 5. I could look for that, certainly.
Re: ldc2 failed with exit code -1073741819.
On Tue, Jan 18, 2022 at 05:20:04PM +, Anonymouse via Digitalmars-d-learn wrote: > On Tuesday, 18 January 2022 at 16:43:52 UTC, H. S. Teoh wrote: > > What's the dustmite command you used? In such cases, it's useful to > > check for this specific error message in your dustmite command, so > > that it doesn't reduce it past the actual problem case. [...] > Yes, but the only thing I have to go on is dub reporting `-1073741819`, so I > just made a script that grepped for that. > > ``` > #!/bin/sh > dub.exe build --compiler=ldc2 2>&1 | grep "ldc2 failed with exit code > -1073741819" > ``` > > It was not unique enough an error and I ended up with some empty files > that didn't import each other correctly. [...] > Bypassing dub and calling the raw ldc command gives no output. What > else can I do? What does `echo $?` print immediately after you run the raw ldc command? T -- INTEL = Only half of "intelligence".
Re: ldc2 failed with exit code -1073741819.
On Tuesday, 18 January 2022 at 16:43:52 UTC, H. S. Teoh wrote: What's the dustmite command you used? In such cases, it's useful to check for this specific error message in your dustmite command, so that it doesn't reduce it past the actual problem case. T Yes, but the only thing I have to go on is dub reporting `-1073741819`, so I just made a script that grepped for that. ``` #!/bin/sh dub.exe build --compiler=ldc2 2>&1 | grep "ldc2 failed with exit code -1073741819" ``` It was not unique enough an error and I ended up with some empty files that didn't import each other correctly. ``` source\kameloso\plugins\twitchbot\keygen.d(1,8): Error: module `kameloso.plugins.twitchbot` from file source\kameloso\plugins\twitchbot\base.d must be imported with 'import kameloso.plugins.twitchbot;' [...] ldc2 failed with exit code -1073741819. ``` Bypassing dub and calling the raw ldc command gives no output. What else can I do?
Re: How to alias
On Friday, 14 January 2022 at 18:04:35 UTC, kyle wrote: Thanks Adam. We need a repository of articles about stuff that doesn't do what people expect. I put this as a tip of the week in my late post: http://dpldocs.info/this-week-in-d/Blog.Posted_2022_01_10.html#tip-of-the-week My blog sometimes gets these if you do a ctrl+f search on the index sometimes something will come up.
Re: ldc2 failed with exit code -1073741819.
On Tue, Jan 18, 2022 at 04:25:45PM +, Anonymouse via Digitalmars-d-learn wrote: > I did a big sweep through my project and changed all `writefln`s and > `format`s and the such to take their format patterns as compile-time > parameters, and now ldc can no longer build it on Windows. It works on > linux, and dmd has no problems with it. > > There is no error message beyond "failed with exit code -1073741819", > which is not unique enough to be able to dustmite on. (It reduced it > to a practically empty set with a different error.) [...] What's the dustmite command you used? In such cases, it's useful to check for this specific error message in your dustmite command, so that it doesn't reduce it past the actual problem case. T -- An elephant: A mouse built to government specifications. -- Robert Heinlein
ldc2 failed with exit code -1073741819.
I did a big sweep through my project and changed all `writefln`s and `format`s and the such to take their format patterns as compile-time parameters, and now ldc can no longer build it on Windows. It works on linux, and dmd has no problems with it. There is no error message beyond "failed with exit code -1073741819", which is not unique enough to be able to dustmite on. (It reduced it to a practically empty set with a different error.) Manually running the command listed by `dub build -v` fails with no output at all and simply returns a shell exit code of 5. ``` git clone https://github.com/zorael/kameloso.git -b ctpatterns cd kameloso dub build --compiler=ldc2 ``` What can I *reasonably* do here? Do I *have* to compile LDC from source, to get debug symbols? How else can I reduce it when it doesn't say what goes wrong?
Re: number ranges
On Monday, 17 January 2022 at 22:48:17 UTC, H. S. Teoh wrote: On Mon, Jan 17, 2022 at 10:35:30PM +, forkit via Digitalmars-d-learn wrote: On Monday, 17 January 2022 at 22:28:10 UTC, H. S. Teoh wrote: > [...] [...] If I were able to write a compiler, my compiler would warn you: "This is ill-advised and you should know better! Please rewrite this." :-D If *I* were to write a compiler, it'd come with a GC built-in. It'd throw up 90% of programs you feed it with the error "this program is garbage, please throw it away and write something better". :-D T Newer languages nowadays use `start..think it's something we should follow?
Re: alias and __VERSION__ condition doesn't play well
On Tuesday, 18 January 2022 at 12:05:38 UTC, Paul Backus wrote: On Tuesday, 18 January 2022 at 04:42:45 UTC, frame wrote: At the very top of my module I have this declaration: ```d static if (__VERSION__ >= 2098) { alias Foo = TypeA; } else { alias Foo = TypeB; } ``` No problem inside the module itself but this doesn't work when imported from another module: Error: undefined identifier `Foo` Works for me: https://run.dlang.io/is/XZlvQ8 It works until you have cyclic dependencies: https://run.dlang.io/is/wDDcK5
Re: alias and __VERSION__ condition doesn't play well
On Tuesday, 18 January 2022 at 04:42:45 UTC, frame wrote: At the very top of my module I have this declaration: ```d static if (__VERSION__ >= 2098) { alias Foo = TypeA; } else { alias Foo = TypeB; } ``` No problem inside the module itself but this doesn't work when imported from another module: Error: undefined identifier `Foo` Works for me: https://run.dlang.io/is/XZlvQ8