SE-0519: Borrow and Inout types for safe, first-class references

It's an unfortunate mismatch. The behavior of Borrow's layout is driven by the existing calling convention ABI, which passes values smaller than four Ints in registers. Since Borrow uses the value representation in exactly the situations where its target type is passed in registers across function calls, this ensures that a function can receive a parameter and return a Borrow referencing that parameter without needing to allocate a local temporary, since that temporary allocation would then artificially limit the Borrow's lifetime.

The proposal does mention this possibility, or at least the possibility of an always-pointer Ref type. Any alternative type that doesn't follow the calling convention will however have problems with temporary lifetimes in some situations.

We chose this name in an attempt to align the API shape with UniqueBox, which is also currently undergoing review. I agree that it's not the greatest name, though I do think there is some value in keeping a common shape to these wrapper-like types that primarily represent a single value (particularly if we do pursue a Deref-like feature in the future, as Alex noted above).

2 Likes