Result Location Semantics

Result Location semantics added to the Language Reference, authored by @mlugg
This explains “the primary mechanism of type inference in the language”.


Note that RLS has never been called or referred to as “r-value semantics”, and if you’re referring to the concept of lvalue and rvalue as in C, those concepts don’t quite map neatly to Zig (or at least, their definitions become more subtle), and aren’t really related to RLS in any case. I think the term “r-value” in this post could be a bit confusing!


Yes, I was referring to the Lvalue (but wrote rvalue) concept of CPL (ancestor of BCPL,B,C).
I removed it from the post. Yes, it was confusing, and the rvalue was wrong.

I’ve read through the linked section. The part about location semantics makes sense, but the table I find confusing/mystifying. 1. What does it mean that “x has no result location”? Is that just a meaning that the expression doesn’t “move” x? 2. What does it mean that the Parent Expression is Ptr? I get that a lot of those deal with pointers (or arrays, etc.) but not all of the do, or at least not obviously to me.

I ask not to be critical, but to understand better. I read any RLS occasionally here on the threads, but want to understand what’s the big deal.

The compiler must allocate a location to store the result (cannot optimize it using an existing location).

Cannot find it anywhere. Parent Result Type is used in the first table and you can replace it with Result Type; there is no special meaning for parent.

1 Like

This video explains them all:

  • parameter reference optimization
  • result location semantics

and their current problems.

Sorry I meant Result Location in the second table.

In the second table, column Result Location, there two values: - and ptr.

  • -” means nothing (e.g. in var val: T = x => result location of x is &val)
  • ptr” is just a name for the 1st column expression (e.g. in ptr = .{ .a = x } => result location of x is &ptr.a)
1 Like

I read it and I have to admit, that example went past my bat until I looked at it more than once. It’s hard to express the idea being presented, though. I don’t have a better way of saying what it’s trying to communicate.