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

caching of comptime function calls #7669

Closed
andrewrk opened this issue Jan 3, 2021 · 1 comment
Closed

caching of comptime function calls #7669

andrewrk opened this issue Jan 3, 2021 · 1 comment
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@andrewrk
Copy link
Member

andrewrk commented Jan 3, 2021

export fn _start() noreturn {
    assert(List(i32) == List(i32));
    exit(0);
}

fn List(T: type) type {
    return struct {
        items: []T,
        capacity: usize,
    };
}

fn assert(ok: bool) {
    if (!ok) @panic("test fail");
}

fn exit(code: usize) noreturn {
    asm volatile ("syscall"
        :
        : [number] "{rax}" (231),
          [arg1] "{rdi}" (code)
        : "rcx", "r11", "memory"
    );
    unreachable;
}
@andrewrk andrewrk added enhancement Solving this issue will likely involve adding new logic or components to the codebase. frontend Tokenization, parsing, AstGen, Sema, and Liveness. labels Jan 3, 2021
@andrewrk andrewrk added this to the 0.8.0 milestone Jan 3, 2021
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 Jun 4, 2021
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 Nov 22, 2021
@andrewrk
Copy link
Member Author

Covered by this behavior test:

zig/test/behavior/eval.zig

Lines 161 to 172 in a7c05c0

test "comptime function with the same args is memoized" {
comptime {
try expect(MakeType(i32) == MakeType(i32));
try expect(MakeType(i32) != MakeType(f64));
}
}
fn MakeType(comptime T: type) type {
return struct {
field: T,
};
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Projects
None yet
Development

No branches or pull requests

1 participant