On Sunday, 15 August 2021 at 16:49:22 UTC, Paul Backus wrote:
On Sunday, 15 August 2021 at 07:10:17 UTC, JG wrote:

Hi,

This is exactly the behaviour I was trying to obtain.

It however comes with a fair amount of overhead, as can be seen in the following llvm ir:

[...]

I'm not really familiar with llvm ir, but looking at it on godbolt, it seems like the main difference is that taking the address of `s.x` forces the compiler to place `s` in memory, rather than keeping it entirely in registers:

https://d.godbolt.org/z/1afbsM6fv

The function `std.stdio.writeln!(example.Ref!(int))` is not trivial. I doubt there is a reasonable optimization/transformation path from a call to `std.stdio.writeln!(example.Ref!(int))` to a call to `std.stdio.writeln!(int).writeln(int)`. Without being able to simplify it to that call, `s` has to be put in memory. It's the opaqueness of `std.stdio.writeln!(example.Ref!(int))` and that it (must) takes the address of `s.x` as parameter.

-Johan

Reply via email to