Initialising Context Pointer during Semantic Analysis
Johan
j at j.nl
Sat Nov 26 11:17:45 UTC 2022
On Friday, 25 November 2022 at 16:10:36 UTC, Teodor Dutu wrote:
> Hi,
>
> For SAoC 2022, I want to translate DRuntime hooks to templates.
> I am working on `_d_newitem{U,T,iT}`. The compiler uses them to
> lower `new S(args)` expressions, where `S` is a `struct`.
>
> To instantiate the new template hooks, the lowering has to be
> moved from the glue layer to the semantic analysis. However,
> when the constructed `struct` is nested, the lowering logic
> also needs to copy the `struct`'s context pointer(s). This is
> currently [handled by the glue layer in
> `e2ir.d`](https://github.com/dlang/dmd/blob/6bf60ea0eb174631ede0074a77d3898d943e0b30/compiler/src/dmd/e2ir.d#L1191-L1209). Now the same logic needs to be replicated in the semantic analysis, where there is no machinery to find the right frame pointer, such as [`getEthis()` in `toir.d`](https://github.com/dlang/dmd/blob/6bf60ea0eb174631ede0074a77d3898d943e0b30/compiler/src/dmd/toir.d#L212).
>
> After discussing with my mentors, we have come up with 2
> possible approaches:
>
> 1. Add a new AST node for copying context pointers to
> `expression.d`: `ContextPointerExp`. The new lowering of `new
> S(args)` in the semantic phase will insert a
> `ContextPointerExp` node and then the glue layer will visit it
> and copy the correct context pointer to the newly created
> `struct`. This approach is efficient from a runtime
> perspective, as it doesn't add any unnecessary computation, but
> has the disadvantage of requiring changes beyond the frontend.
> Thus it won't be transparent for LDC and GDC, who will have to
> handle `ContextPointerExp` in their own glue layers.
This is not a deal breaker, as long as it is clearly
communicated. So add a special section to the release notes for
frontend-dependent projects what has changed / what was added.
Adding AST nodes impacts more than just GDC and LDC.
Why not extend the information attached to a NewExpression node?
AST rewriting makes it much harder (or impossible) to generate
good user diagnostics and debug information.
-Johan
More information about the Digitalmars-d
mailing list