Re: Destructors can't be @nogc?

2021-07-24 Thread vit via Digitalmars-d-learn
On Friday, 23 July 2021 at 20:24:02 UTC, Jim wrote: Hello, I've been playing with D and trying to understand how to work with @nogc. I must be doing something wrong, because even though I tagged the destructor for my class `@nogc`, I'm getting the following error: `.\min.d(27): Error: "@nogc"

byKeyValue is not available at compilation-time right ?

2021-07-24 Thread someone via Digitalmars-d-learn
As you can see in the following code I cannot avoid to type the IDs twice in the structureExchanges enum: ```d public struct structureExchange { /// solely‐intended to help build code at compilation‐time; for client‐code classExchanges should be used instead public typeLocation location;

Re: Destructors can't be @nogc?

2021-07-24 Thread Mike Parker via Digitalmars-d-learn
On Sunday, 25 July 2021 at 00:15:30 UTC, Jim wrote: But I think `destroy()` not being @nogc even though the destructor is tagged @nogc is a bug, and it should be fixed. Because it is problematic behaviour even if we limit the usage of @nogc. It's not a bug. The destructor being tagged has

Re: Performance issue with fiber

2021-07-24 Thread jfondren via Digitalmars-d-learn
On Saturday, 24 July 2021 at 09:17:47 UTC, Stefan Koch wrote: On Wednesday, 21 July 2021 at 22:51:38 UTC, hanabi1224 wrote: Hi, I'm new to D lang and encounter some performance issues with fiber, not sure if there's something obviously wrong with my code. There is your problem. auto sc

Re: Build time

2021-07-24 Thread russhy via Digitalmars-d-learn
One thing to add: With LDC you can add this flag ``-linkonce-templates`` to get faster link time when using templates a lot

Re: Build time

2021-07-24 Thread russhy via Digitalmars-d-learn
On Saturday, 24 July 2021 at 09:12:15 UTC, JG wrote: On Saturday, 24 July 2021 at 08:26:39 UTC, JG wrote: On Friday, 23 July 2021 at 20:03:22 UTC, Dennis wrote: On Friday, 23 July 2021 at 18:53:06 UTC, JG wrote: [...] You can try profiling it with LDC 1.25 or later. Add this to dub.sdl: [

Re: Destructors can't be @nogc?

2021-07-24 Thread user1234 via Digitalmars-d-learn
On Friday, 23 July 2021 at 20:24:02 UTC, Jim wrote: Hello, I've been playing with D and trying to understand how to work with @nogc. I must be doing something wrong, because even though I tagged the destructor for my class `@nogc`, I'm getting the following error: `.\min.d(27): Error: "@nogc"

Re: Destructors can't be @nogc?

2021-07-24 Thread user1234 via Digitalmars-d-learn
On Sunday, 25 July 2021 at 01:17:06 UTC, user1234 wrote: That bypasses the runtime mechanism for classes construction and destruction. But `new` and `destroy` must not be called anymore, you must get stick with your own system. and of course `cast(Object)` should be prohibited (maybe `opCast`

Re: Destructors can't be @nogc?

2021-07-24 Thread Jim via Digitalmars-d-learn
On Saturday, 24 July 2021 at 10:15:50 UTC, Mike Parker wrote: Personally, I think `@nogc` on main is a bad idea. `@nogc` should be used as far down the call stack as you can put it. The higher it is, the more difficulty you're going to run into. I recommend you apply it only on functions that

Re: How to check if variable of some type can be of null value?

2021-07-24 Thread JG via Digitalmars-d-learn
On Saturday, 24 July 2021 at 20:10:37 UTC, JG wrote: On Saturday, 24 July 2021 at 19:39:02 UTC, Alexey wrote: [...] There are probably better ways. However, this seems to work: ```d import std; enum canBeSetToNull(T) = __traits(compiles,(T.init is null)); interface I1 { } class C1 : I1 { }

Re: How to check if variable of some type can be of null value?

2021-07-24 Thread JG via Digitalmars-d-learn
On Saturday, 24 July 2021 at 19:39:02 UTC, Alexey wrote: On Saturday, 24 July 2021 at 18:10:07 UTC, Alexey wrote: I've tried to use ```typeof(t) is cast(t)null```, but compiler exits with error and so this can't be used for checking this issue. The goal I with to achieve by this check - is to

Re: How to check if variable of some type can be of null value?

2021-07-24 Thread Alexey via Digitalmars-d-learn
On Saturday, 24 July 2021 at 18:10:07 UTC, Alexey wrote: I've tried to use ```typeof(t) is cast(t)null```, but compiler exits with error and so this can't be used for checking this issue. The goal I with to achieve by this check - is to use template and to assign value to variable basing on i

How to check if variable of some type can be of null value?

2021-07-24 Thread Alexey via Digitalmars-d-learn
I've tried to use ```typeof(t) is cast(t)null```, but compiler exits with error and so this can't be used for checking this issue. The goal I with to achieve by this check - is to use template and to assign value to variable basing on it's ability to accept null as a value. some testing cod

Re: Build time

2021-07-24 Thread Adam D Ruppe via Digitalmars-d-learn
On Saturday, 24 July 2021 at 09:12:15 UTC, JG wrote: the slowest parts are in library code This is really common. A lot of libraries do really weird things... if you want to keep quick builds it is best to use the language directly.

Re: Destructors can't be @nogc?

2021-07-24 Thread Mike Parker via Digitalmars-d-learn
On Saturday, 24 July 2021 at 09:45:01 UTC, Jim wrote: In that case, what should we use to check functions called from `main` are not using the garbage collector? When compiling, you can pass -vgc to dmd and it will tell you where GC allocations are possible. Because it seems like we can

Re: Destructors can't be @nogc?

2021-07-24 Thread Guillaume via Digitalmars-d-learn
On Saturday, 24 July 2021 at 02:48:51 UTC, Paul Backus wrote: Which raises the question, *why* is `destroy` not `@nogc` when the destructor is `@nogc`? And it turns out the answer is that [it calls `rt_finalize`][1], which [takes its argument as a `void*`][2] and therefore has to assume that an

Re: Destructors can't be @nogc?

2021-07-24 Thread Jim via Digitalmars-d-learn
On Saturday, 24 July 2021 at 02:02:00 UTC, Mike Parker wrote: The problem is that you've marked main as `@nogc`, and `destroy` is not `@nogc`. Remove the annotation from main and it will compile. In that case, what should we use to check functions called from `main` are not using the garbage

Re: Build time

2021-07-24 Thread JG via Digitalmars-d-learn
On Saturday, 24 July 2021 at 09:12:15 UTC, JG wrote: On Saturday, 24 July 2021 at 08:26:39 UTC, JG wrote: On Friday, 23 July 2021 at 20:03:22 UTC, Dennis wrote: [...] Thanks for this suggestion. Unfortunately this makes the compile use too much memory for my system and so it gets killed bef

Re: Performance issue with fiber

2021-07-24 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 21 July 2021 at 22:51:38 UTC, hanabi1224 wrote: Hi, I'm new to D lang and encounter some performance issues with fiber, not sure if there's something obviously wrong with my code. There is your problem. auto scheduler = new FiberScheduler; The Fiber scheduler will spawn

Re: Build time

2021-07-24 Thread JG via Digitalmars-d-learn
On Saturday, 24 July 2021 at 08:26:39 UTC, JG wrote: On Friday, 23 July 2021 at 20:03:22 UTC, Dennis wrote: On Friday, 23 July 2021 at 18:53:06 UTC, JG wrote: [...] You can try profiling it with LDC 1.25 or later. Add this to dub.sdl: [...] Thanks for this suggestion. Unfortunately this

Traceinfo gone

2021-07-24 Thread frame via Digitalmars-d-learn
I recently discovered that my exceptions do not show a trace anymore. How can this happen? ```d int main() { try { throw new Exception("test"); } catch(Throwable e) { writefln("trace: %s", e.info); } // ... } ``` I'm expecting something like this: ``` trace: 0x00402326 0x0040E337

Re: Build time

2021-07-24 Thread JG via Digitalmars-d-learn
On Friday, 23 July 2021 at 20:03:22 UTC, Dennis wrote: On Friday, 23 July 2021 at 18:53:06 UTC, JG wrote: [...] You can try profiling it with LDC 1.25 or later. Add this to dub.sdl: [...] Thanks for this suggestion. Unfortunately this makes the compile use too much memory for my system a