DIP Proposal: @manualScoped to prevent automatic field destruction
aliak
something at something.com
Fri Jul 27 11:44:10 UTC 2018
On Friday, 27 July 2018 at 09:30:00 UTC, FeepingCreature wrote:
> A new UDA is introduced: @manualScoped. It is valid for fields
> in structs and classes, as well as variables and parameters.
> Fields marked with @manualScoped are not automatically
> destructed on scope end.
>
> For instance, a function taking a struct as a @manualScoped
> value will lead to a copy constructor call, but no destructor
> call. It is assumed the passed value will be moved into another
> field via move() or moveEmplace().
>
> In @safe, only @manualScoped fields may be initialized with
> .init. This is to indicate that init represents a hole in the
> typesystem, and using it forces you to engage in manual
> lifecycle management.
>
> The goal of this DIP is to make the union hack unnecessary and
> resolve the value/variable problem with .init initialized
> struct destruction, where { S s = S.init; } led to a destructor
> call but no corresponding constructor call.
>
> Opinions?
A) I'd suggest "@nodestruct" instead, since it sounds like that
what it's supposed to do?
B) is this basically for the case of invariants being run before
destructors where T.init are not valid runtime instances of T?
C) If it is, then this seems to me that this is something that
should just work without a programmer needing to know about how
T.init and invariants are implemented, so an implementation that
doesn't call invariants before a destructor only if an instance
was never constructed at runtime is maybe the way to go? Though I
have no idea how possible that is.
Cheers,
- Ali
maybe your PR where invariants is not called before a destructor
if an instance is a T.init is maybe the way to go? [0]
More information about the Digitalmars-d
mailing list