Skip to content

multiple expression return values, error type redesign, introduction of copyable property of types #83

Closed
@andrewrk

Description

@andrewrk

(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

No one assigned

    Labels

    enhancementSolving this issue will likely involve adding new logic or components to the codebase.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions