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

Add safety check for await inside nosuspend blocks #8001

Open
mguaypaq opened this issue Feb 12, 2021 · 0 comments
Open

Add safety check for await inside nosuspend blocks #8001

mguaypaq opened this issue Feb 12, 2021 · 0 comments
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase.
Milestone

Comments

@mguaypaq
Copy link
Contributor

As discussed in #7972 (specifically, this comment by @SpexGuy), the zig compiler currently (version 0.7.1) doesn't put in a safety check when, inside a nosuspend block, we await an async function which has not yet completed. Instead, a garbage value is silently used as the function's return value.

The compiler should put in a safety check to check whether the awaited function has completed.

pub fn main() void {
    var f = async not_done_yet();

    // This is undefined behavior and should be safety-checked.
    var i = nosuspend await f;

    @import("std").debug.print("garbage: {}\n", .{i});
}

fn not_done_yet() u8 {
    suspend;
    suspend;
    return 2;
}
@Vexu Vexu added the enhancement Solving this issue will likely involve adding new logic or components to the codebase. label Feb 12, 2021
@Vexu Vexu added this to the 0.9.0 milestone Feb 12, 2021
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 May 19, 2021
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.
Projects
None yet
Development

No branches or pull requests

3 participants