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 support for extern_spec for enum #586

Merged
merged 16 commits into from
Dec 28, 2023
Merged

Add support for extern_spec for enum #586

merged 16 commits into from
Dec 28, 2023

Conversation

ranjitjhala
Copy link
Contributor

The following now works

#[extern_spec]
#[flux::refined_by(b:bool)]
enum Option<T> {
    #[flux::variant(Option<T>[false])]
    None,
    #[flux::variant({T} -> Option<T>[true])]
    Some(T),
}

#[flux::sig(fn(x:Option<T>[true]) -> T)]
pub fn my_unwrap<T>(x: Option<T>) -> T {
    match x {
        Option::Some(v) => v,
        Option::None => never(0),
    }
}

pub fn test3() {
    let x = Option::Some(42);
    let y = my_unwrap(x);
    assert(y == 42);
}

Copy link
Member

@nilehmann nilehmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One major comment, but overall it looks good.

I don't mind the hack (I considered myself). I was settling into something more sophisticated and expanding the macro to:

#[flux::extern(enum)]
mod _extern_option {
    type Option<T> = core::option::Option<T>;
    
    enum FakeOption<T> {
        #[flux::variant(Option<T>[false])]
        None,
        #[flux::variant((T) -> Option<T>[true])
        Some(T)
    }
}

but that requires a bit more thought and in the end it's equally hacky.

crates/flux-refineck/src/checker.rs Outdated Show resolved Hide resolved
crates/flux-fhir-analysis/src/annot_check.rs Outdated Show resolved Hide resolved
crates/flux-fhir-analysis/src/annot_check.rs Outdated Show resolved Hide resolved
crates/flux-fhir-analysis/src/annot_check.rs Outdated Show resolved Hide resolved
Copy link
Member

@nilehmann nilehmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

crates/flux-fhir-analysis/src/annot_check.rs Outdated Show resolved Hide resolved
@ranjitjhala ranjitjhala merged commit 5652293 into main Dec 28, 2023
4 checks passed
@ranjitjhala ranjitjhala deleted the option branch December 28, 2023 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants