digitalmars.D.learn - Details on how aggregates are constructed with `new` and later
- Per =?UTF-8?B?Tm9yZGzDtnc=?= (12/12) Oct 08 2018 I want to understand how calls to `new` for classes and structs
- Nicholas Wilson (8/20) Oct 08 2018 Memory is allocated, .init (for classes this comes from
- Stanislav Blinov (9/13) Oct 08 2018 There's no such trait as far as I'm aware. If there were, it'd
I want to understand how calls to `new` for classes and structs are lowered by the compiler and druntime to a GC-allocation (specifically how the `ba`-argument bits are determined) followed by an initialization using default constructor or via a user-defined constructor called using arguments to `new`. And how this is related to the trait `hasElaborateConstructor` for both `classes` and `structs`. I also want to understand how manually defined constructors and destructors affect the setting of the GC finalizer for a given aggregate type. And how this is related to the trait `hasElaborateDestructor` for both `classes` and `structs`. Where's the dmd and druntime code that handles these steps?
Oct 08 2018
On Monday, 8 October 2018 at 11:19:40 UTC, Per Nordlöw wrote:I want to understand how calls to `new` for classessee _d_newclassand structs are lowered by the compiler and druntime to a GC-allocation (specifically how the `ba`-argument bits are determined) followed by an initialization using default constructor or via a user-defined constructor called using arguments to `new`. And how this is related to the trait `hasElaborateConstructor` for both `classes` and `structs`.Memory is allocated, .init (for classes this comes from typeid(T).initializer) is copied over the memory and then the constructor is run.I also want to understand how manually defined constructors and destructors affect the setting of the GC finalizer for a given aggregate type. And how this is related to the trait `hasElaborateDestructor` for both `classes` and `structs`For classes the typeid(T).destructor is called on the class, for structs I'm not sure.Where's the dmd and druntime code that handles these steps?should be src/rt/lifetime.d IIRC
Oct 08 2018
On Monday, 8 October 2018 at 11:19:40 UTC, Per Nordlöw wrote:And how this is related to the trait `hasElaborateConstructor` for both `classes` and `structs`.There's no such trait as far as I'm aware. If there were, it'd likely be checking for the presence of a '__ctor' member. Thing is, it can't be generic because ctors may be templates, the best that can be done is checking if `T` is constructible with some arguments `Args`.And how this is related to the trait `hasElaborateDestructor` for both `classes` and `structs`.It isn't. The trait literally just checks if the compiler has generated a '__dtor' member, and it doesn't do so for classes at all.
Oct 08 2018