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

all: promote value type function arguments to heap if necessary #10528

Merged
merged 12 commits into from
Jun 20, 2021

Conversation

UweKrueger
Copy link
Member

@UweKrueger UweKrueger commented Jun 20, 2021

This is a further follow-up to #9873 (and #10033). It makes the following possible:

  • Value arguments of functions is moved to heap if referenced:
fn get_ref(s St) &St {
    return &s
}
  • The above point always applies to structs declared as [heap] that are passed as value to a function
  • automatic heap promotion now also works for other data types (not only structs) – so the following works:
fn get_heap_ref() &int {
    n := 13
    return &n
}

fn promote_to_heap(x f64) &f64 {
    return &x
}

UweKrueger added a commit to UweKrueger/v that referenced this pull request Jun 20, 2021
@medvednikov medvednikov merged commit f32a76b into vlang:master Jun 20, 2021
@UweKrueger UweKrueger deleted the auto_heap_2 branch June 23, 2021 10:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants