Skip to content
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

Closed
wants to merge 13 commits into from
Closed

Added documentation for Result Location Semantics #5035

wants to merge 13 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Apr 14, 2020

Closes #2809. New to Zig, probably rough around the edges. I'm doing my best.

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
Copy link
Contributor

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.

Copy link
Author

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?

Copy link
Contributor

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. 🤔

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?

Copy link
Contributor

@Tetralux Tetralux Apr 14, 2020

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.

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.

Copy link
Author

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also subscribed to #2761 and #2765 so I can fix those points when it's relevant (haven't yet gotten the hang of inline testing).

@ghost
Copy link
Author

ghost commented Apr 15, 2020

Ok, now it should build. Sorry, not good with docgen syntax. We really need to document that.

return Large { ... }
return Large {
// ...
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a semicolon

@ghost
Copy link
Author

ghost commented Apr 15, 2020

Never mind. Discarding changes and waiting until docgen is documented.

@ghost ghost closed this Apr 15, 2020
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add documentation for Result Location Semantics
9 participants