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

[Idea] Syntactic sugar for channel data converter/adapter #1973

Open
mikex-oss opened this issue Mar 4, 2025 · 0 comments
Open

[Idea] Syntactic sugar for channel data converter/adapter #1973

mikex-oss opened this issue Mar 4, 2025 · 0 comments
Labels
dslx DSLX (domain specific language) implementation / front-end enhancement New feature or request

Comments

@mikex-oss
Copy link
Collaborator

mikex-oss commented Mar 4, 2025

What's hard to do? (limit 100 words)

When the channel data type (and semantics) match up exactly, it's convenient to just take the two channel ends and pass them along to child procs for "direct" connectivity inside proc config. You don't need to worry about introducing ordering complexity into proc next.

However, suppose you have two IPs (procs) to integrate where the output of one proc feeds the input of the other proc. The catch is that their types are only nominally compatible, e.g. (1) they may be structurally equivalent but not identical, or (2) be the same bits type but one is binary encoded and the other is Gray encoded.

Without touching either sub-proc, you now need to write another "adapter" proc to do an explicit conversion. Then the child proc 1 output channel feeds into the adapter proc, and the output of the adapter proc can feed into child proc 2.

Writing and integrating another child proc to spawn is cumbersome with not much interesting going on besides the actual data conversion logic.

Current best alternative workaround (limit 100 words)

You can write an adapter proc like:

proc FooBarAdapter {
  foo: chan<Foo> in;
  bar: chan<Bar> out;

config(foo: chan<Foo> in, bar: chan<Bar> out) {
  (foo, bar)
}

next(state: ()) {
  // recv on foo
  // convert foo to bar
  // send on bar
}

and pass the corresponding channel ends to this adapter proc:

proc Parent {

  config() {
        let (foo_s, foo_r) = chan<Foo>("foo");
        let (bar_s, bar_r) = chan<Bar>("bar");
        spawn Child1(foo_s);
        spawn FooBarAdapter(foo_r, bar_s);
        spawn Child2(bar_r);
  }
}

Your view of the "best case XLS enhancement" (limit 100 words)

It would be nice to have some built-in that allows you to write a conversion function and connect up different typed channel ends.

A couple brainstormed ideas:

fn foo_to_bar(x: Foo) -> Bar { ... }

proc Parent {

  config() {
        let (foo_s, bar_r) =
            chan_adapter<Foo, Bar>("foobar", foo_to_bar);
        spawn Child1(foo_s);
        spawn Child2(bar_r);
  }
}

or @grebe's more incremental version:

proc Parent {

  config() {
        let (foo_s, foo_r) = chan<Foo>("foo");
        let (bar_s, bar_r) = chan<Bar>("bar");
        spawn Child1(foo_s);
        spawn Child2(bar_r);
        connect(foo_r, bar_s, foo_to_bar);
  }
}
@mikex-oss mikex-oss added dslx DSLX (domain specific language) implementation / front-end enhancement New feature or request labels Mar 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dslx DSLX (domain specific language) implementation / front-end enhancement New feature or request
Projects
Status: No status
Development

No branches or pull requests

1 participant