-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added documentation for Result Location Semantics #5035
Conversation
that memory, to avoid making multiple allocations and copying between them:</p> | ||
{#code_begin#} | ||
pub fn main() void { | ||
// foo() allocates its result directly in x -- only one allocation is made |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Allocation" is usually considered dynamic allocation, but that's not what's happening here.
Here we're talking about more general allocation of registers or stack space for variables.
For field2
below, not even that - the allocation of space was already done by var y
so we're just referring to that space instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, what would the appropriate term for that be then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure. I guess you could just clarify it; that the term refers to allocation of variables, which is either on the stack or in a register, rather than a dynamic allocation. 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about just qualify the allocation as a stack allocation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it may not (and probably won't) always be a stack allocation, and you might care---Zig being a systems language---about that fact.
OTOH, you could argue that putting it in a register is an optimization, and that it's easier to think about if you just talk about the stack -- even though it's an optimization that always happens.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, then 'non-heap' allocation, if you want to factor in compiler optimization potentials.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, cleared up and rebased. Now it should be ready for merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…st "integer type" (#5028) * error message of ir_analyze_bit_shift now more accurate/specific * fixed compile error test to match bit shift error message
Ok, now it should build. Sorry, not good with docgen syntax. We really need to document that. |
doc/langref.html.in
Outdated
return Large { ... } | ||
return Large { | ||
// ... | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a semicolon
Never mind. Discarding changes and waiting until docgen is documented. |
Closes #2809. New to Zig, probably rough around the edges. I'm doing my best.