On Wednesday, 9 June 2021 at 21:44:20 UTC, Walter Bright wrote:
> On 6/9/2021 7:01 AM, Steven Schveighoffer wrote:
> I'm 99% sure we could have a nogc stack trace for InvalidMemoryOperationError if we had a nogc demangler. Everything else seems already nogc, just not fully marked.
I don't believe it would be hard to make a nogc demangler, even if it used malloc.
Even better, provide a "sink" parameter for the result, and have the demangler defer its final allocation needs to the caller, and free its temporary data itself.
Yep, the sink approach seems the most practical one, from my experience.
We use it a lot (for toString
, serialization, hashing...) but it has one major drawback: It is restricted to the attributes that are set by the sink / function.
I talked about this when I mentioned my proposal for ADA at last DConf and I have a PR for a DIP I need to finish.
But for the demangler, we could just manually provide all possible overloads and call it a day.
Regarding the bigger point, I've been wanting to have more structured stack traces for a very long time, and that would also enable @nogc
stack traces. Currently, object.Throwable.TraceInfo, the interface exposed by the runtime, is the other blocker, since any change would be a breaking change, its toString
doesn't take a sink, and its opApply
provides a formatted string, which forces allocation in opApply
.
Currently, this is worked around by having a limited buffer (https://github.com/dlang/druntime/blob/751f5665a31ea0f150d71b22a9852abacc2f61ec/src/core/internal/backtrace/dwarf.d#L197-L239) but it just means we have a length limit for stack traces.
I really hope we can expose a struct like this to TraceInfo
so that users can iterate on the stack trace themselves.