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

Implement implicit returns #6

Closed
pzipper opened this issue Jun 2, 2023 · 0 comments
Closed

Implement implicit returns #6

pzipper opened this issue Jun 2, 2023 · 0 comments
Assignees
Labels
A-backend-clif Area: the Cranelift backend C-bug-report Category: bug report C-feature-tracking Category: tracking a planned feature which is not yet implemented M-compiler-panic Dealing with a compiler panic/crash P-high Priority: should ship in the earliest possible release
Milestone

Comments

@pzipper
Copy link
Member

pzipper commented Jun 2, 2023

Currently, if a function doesn't return, the compiler panics due to Cranelift's verification pass.

Instead, the compiler should implicitly return from each function. If the function should return a value, it should return uninitialized memory instead.

For basic types such as integers, 0 shall be returned as a default, similar to C.

This will eventually be replaced with a check that doesn't allow a function to return implicitly if it returns a value, and a function would have to explicitly return uninit instead:

const Main = func main(): i32 {
    // ...
    
    return uninit;
}

Equivalent to the following C code:

int main() {
    // implicit return
}
@pzipper pzipper added A-backend-clif Area: the Cranelift backend C-bug-report Category: bug report C-feature-tracking Category: tracking a planned feature which is not yet implemented P-high Priority: should ship in the earliest possible release M-compiler-panic Dealing with a compiler panic/crash labels Jun 2, 2023
@pzipper pzipper added this to the 0.5.0-alpha milestone Jun 2, 2023
@pzipper pzipper self-assigned this Jun 2, 2023
@pzipper pzipper closed this as completed Jun 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-backend-clif Area: the Cranelift backend C-bug-report Category: bug report C-feature-tracking Category: tracking a planned feature which is not yet implemented M-compiler-panic Dealing with a compiler panic/crash P-high Priority: should ship in the earliest possible release
Projects
None yet
Development

No branches or pull requests

1 participant