-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
enhancementSolving this issue will likely involve adding new logic or components to the codebase.Solving this issue will likely involve adding new logic or components to the codebase.
Milestone
Description
(see below comment for up to date details of this issue)
struct Foo {
x: i32,
y: i32,
}
fn make_foo(x: i32, y: i32) -> Foo {
var f: Foo = undefined;
foo.x = x;
foo.y = y;
return f;
}
fn f() {
var foo = make_foo(1234, 5678);
}When make_foo is generated, we should notice that f is always returned, which means instead of allocating stack space for f, we use the secret first argument pointer value and directly put the values there.
Also, in the code generated for function f, we notice the simple assignment, and instead of doing a memcpy, simply allocate the stack variable for foo, and then call make_foo passing the stack variable address as the secret first parameter.
Once these two optimizations are implemented, idiomatic zig code for initializing structs can be an assignment.
Metadata
Metadata
Assignees
Labels
enhancementSolving this issue will likely involve adding new logic or components to the codebase.Solving this issue will likely involve adding new logic or components to the codebase.