nothrow/@nogc inference troubles with emplace/move?
Dennis
dkorpel at gmail.com
Wed Aug 28 10:05:37 UTC 2024
On Wednesday, 28 August 2024 at 08:59:49 UTC, Manu wrote:
> Oh wow... that's bad. Is there any plan to fix this?
I want to, but with dmd's current architecture, I don't know how.
The tricky case is:
```D
// example of @safe inference, but the same applies to pure
nothrow and @nogc
void systemFunc() @system;
void fun1()()
{
fun2();
systemFunc();
}
void fun2()()
{
fun1();
}
void main0() @system
{
fun1();
}
void main1() @safe
{
fun2(); // should error
}
```
fun1 gets analyzed first, which gets interrupted when it sees the
call to fun2.
Then fun2 gets analyzed, but that sees a call to fun1, which at
that point is still in the process of inferring attributes. The
current implementation gives up here and infers fun2 as `@system`.
So I tried replacing that pessimistic assumption with an
optimistic assumption, but in this case, `fun1` will turn out to
be `@system` because of the `systemFunc()` call. But at the time
`fun2` ends its analysis, this is completely unknown. Until
`fun1` ends its analysis, the needed information isn't there.
I could start by inferring `fun2` as `@safe` and then retract
that once `fun1` finishes analysis, but currently, the compiler
assumes a function type to be final after its body was analyzed,
so mutating the type later is going to mess up things.
So without re-architecturing dmd's semantic analysis, I don't see
a way out.
More information about the Digitalmars-d
mailing list