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

Hydroflow syntax type-inference fails for some simple cases #980

Open
shadaj opened this issue Dec 14, 2023 · 2 comments
Open

Hydroflow syntax type-inference fails for some simple cases #980

shadaj opened this issue Dec 14, 2023 · 2 comments
Assignees
Labels
bug Something isn't working hydroflow syntax Hydroflow's custom surface syntax

Comments

@shadaj
Copy link
Member

shadaj commented Dec 14, 2023

when going directly from a source_stream to a for_each

For reasons that are not clear to me, v fails to type-infer in the first example but the second example has no problem compiling.

#[multiplatform_test]
pub fn test_basic_4_fails() {
    let send_recv =
        hydroflow::util::unbounded_channel::<Result<(), ()>>();

    let mut df = hydroflow_syntax! {
        source_stream(send_recv.1)
            -> for_each(|v| {
                dbg!(v.unwrap());
            });
    };
}

#[multiplatform_test]
pub fn test_basic_4_compiles() {
    let send_recv =
        hydroflow::util::unbounded_channel::<Result<(), ()>>();

    let mut df = hydroflow_syntax! {
        source_stream(send_recv.1)
            -> map(|v| v.unwrap())
            -> for_each(|v| {
                dbg!(v);
            });
    };
}

tee to a pivot (formerly #1149)

#[multiplatform_test]
pub fn test_fold_zip() {
    let mut df = hydroflow::hydroflow_syntax! {
        stream1 = source_iter(1..=10);
        stream2 = source_iter_delta(3..=5) -> map(Max::new);
        sum_of_stream2 = stream2 -> lattice_reduce() -> tee();

        filtered_stream1 = stream1
            -> [0]filtered_stream2;
        sum_of_stream2 -> identity::<Max<_>>() -> [1]filtered_stream2;

        filtered_stream2 = zip()
            -> filter(|(value, sum_of_stream2)| {
                // This is not monotonic.
                value <= sum_of_stream2.as_reveal_ref()
            })
            -> map(|(x, _max)| (context.current_tick(), x))
            -> assert_eq([(0, 1), (0, 2), (0, 3), (0, 4), (0, 5)]);

        // Optional:
        sum_of_stream2
            -> map(|x| (context.current_tick(), x.into_reveal()))
            -> assert_eq([(0, 3), (0, 4), (0, 5), (0, 6), (0, 7)]);
    };

    assert_graphvis_snapshots!(df);

    df.run_available(); // Should return quickly and not hang
}

A few initial attempts to rearrange codegen to fix the type inference proved fruitless

(This example can work by making the final map |x: Max<_>| ...)

@MingweiSamuel

@shadaj shadaj added the bug Something isn't working label Dec 14, 2023
@shadaj
Copy link
Member Author

shadaj commented Dec 14, 2023

Tentatively tagged @MingweiSamuel cause I have no clue what's going on here.

@MingweiSamuel
Copy link
Member

May be (hopefully) improved by #1500 codegen optimizations

@MingweiSamuel MingweiSamuel changed the title Type-inference fails when going directly from a source_stream to a for_each Hydroflow syntax type-inference fails for some simple cases Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working hydroflow syntax Hydroflow's custom surface syntax
Projects
None yet
Development

No branches or pull requests

2 participants