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

Builder: rehome builder_util #1665

Merged
merged 27 commits into from
Aug 18, 2023
Merged

Builder: rehome builder_util #1665

merged 27 commits into from
Aug 18, 2023

Conversation

anshumanmohan
Copy link
Contributor

@anshumanmohan anshumanmohan commented Aug 15, 2023

In #1637, we proposed finding a new home for many of the utilities that currently live in builder_util.py.

In this PR have done that, experimentally, for one such helper: insert_eq. It now lives under ComponentBuilder and is called eq_use. I have piped the changes through to all the Python files, though you may want to look specifically at fifo.py since it benefits from the cleanup of #1664.

Note that I'm calling this utility eq_use to differentiate it from the existing method eq that is also declared on ComponentBuilder. The helper eq just returns a StdEq cell, while this new eq_use variant creates a cell, wires up its ports, and then returns the group and the cell that do all this.

Say we have:

prog = cb.Builder()
fifo: cb.ComponentBuilder = prog.component("fifo")

we used to use the utility via:

util.insert_eq(fifo, cmd, 0, 2) 
# `cmd == 0`, where `cmd` is 2 bits wide.

and now we can do it more directly via:

fifo.eq_use(cmd, 0, 2)

Please let me know what you think, and I'll propagate these changes all over, for all the other utilities.

@anshumanmohan anshumanmohan linked an issue Aug 15, 2023 that may be closed by this pull request
Copy link
Contributor

@rachitnigam rachitnigam left a comment

Choose a reason for hiding this comment

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

Looks good! I'm really missing Rust-style traits here which can just add methods on structs without having to define them in the same file. I wonder if there is some sort of idiomatic way to do this in Python but if not, keeping these methods in the ComponentBuilder makes sense to me.

@anshumanmohan
Copy link
Contributor Author

Thanks for taking a look. I've gone ahead and made this change all over, and as a result, the entire builder_util.py file has gone under the ComponentBuilder class. All the changes have been piped everywhere and the eDSL code is lighter as a result. Ready for another review and then a merge!

@rachitnigam
Copy link
Contributor

Looks like we have some failing tests!

Copy link
Contributor

@sampsyo sampsyo left a comment

Choose a reason for hiding this comment

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

Awesome. I definitely think this is headed in the right direction, i.e., adding higher- and higher-level stuff to the builder to make it easier to express the common case.

On @rachitnigam's question:

I'm really missing Rust-style traits here which can just add methods on structs without having to define them in the same file. I wonder if there is some sort of idiomatic way to do this in Python but if not, keeping these methods in the ComponentBuilder makes sense to me.

The way to do this in Python is with mixins. It would look like:

class ComponentBuilderBase:
    # all the basic stuff

class ComponentExtra:
    # high-level fancy stuff like `mem_write_seq_d1_to_reg`

class ComponentBuilder(ComponentBuilderBase, ComponentExtra):
    pass

Multiple inheritance combines the two sets of members together in one exported class. Not sure it's worth it in this case, but we could consider it.

calyx-py/calyx/builder.py Outdated Show resolved Hide resolved
calyx-py/calyx/builder.py Outdated Show resolved Hide resolved
Base automatically changed from builder-gensym to master August 18, 2023 14:20
@anshumanmohan
Copy link
Contributor Author

I'll keep this in mind and return to it in a separate PR! I just don't want to gunk up the works and create more merge conflicts than I can handle

@anshumanmohan anshumanmohan enabled auto-merge (squash) August 18, 2023 14:55
@anshumanmohan anshumanmohan merged commit 1008ba7 into master Aug 18, 2023
5 checks passed
@anshumanmohan anshumanmohan deleted the builder-util-rehome branch August 18, 2023 15:18
rachitnigam pushed a commit that referenced this pull request Feb 16, 2024
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.

Move builder_util into builder itself
3 participants