Closed iK4tsu closed 1 year ago
I need to finish something I promised but end up getting at the bottom of my task list.
For context, this is it: https://github.com/PhilippeSigaud/Pegged/pull/314#issuecomment-1315512690.
To be fair, that change is likely necessary only when dmd#14236 gets merged, and that PR has currently stalled (@dkorpel). So we could decide to tag Pegged now if we remember to make the change before a new DMD release makes that necessary.
It seems a rather trivial change, though, so @iK4tsu if you want to have a go at it, maybe @ljmf00-wekaio can review it and we can release without pending TODO's.
Yes, if you can @iK4tsu, I appreciate. It's basically implement something like:
/**
* Assume non scope variable
*
* This function casts away scope attribute from the given parameter.
*
* Params:
* arg = The scope variable to cast scope away
*
* Returns: the variable `arg` as is, but without scope attribute.
*
* Note: This breaks the language type system.
*/
@nogc
auto ref assumeNonScope(T)(auto ref scope T arg)
{
return *cast(T*)cast(void*)&arg;
}
And use in the dip1000 hacks I added.
Also, worth mentioning @dkorpel that the hack with size_t
doesn't work with all types, hence I use void*
.
* Note: This breaks the language type system.
Could you help me understand why it is necessary to break the language type system? Is it because the compiler gets it wrong (https://github.com/PhilippeSigaud/Pegged/pull/314#issuecomment-1255311759)?
Yes, cast(void*)
is pretty much breaking the type system, in terms of changing type qualifiers or lifetime attributes. This shouldn't be required if the compiler could construct a DAG of the lifetimes and do these checks properly, but you can read more about the issue in the referenced bugzilla tickets on the PR you just mentioned.
Yes, if you can @iK4tsu, I appreciate. It's basically implement something like:
/** * Assume non scope variable * * This function casts away scope attribute from the given parameter. * * Params: * arg = The scope variable to cast scope away * * Returns: the variable `arg` as is, but without scope attribute. * * Note: This breaks the language type system. */ @nogc auto ref assumeNonScope(T)(auto ref scope T arg) { return *cast(T*)cast(void*)&arg; }
And use in the dip1000 hacks I added. Also, worth mentioning @dkorpel that the hack with
size_t
doesn't work with all types, hence I usevoid*
.
casting to void*
does not cast away scope
@ljmf00-wekaio fixed dip1000 issues a while ago but this isn't tagged yet; could you release a new version with these fixes?