-
Notifications
You must be signed in to change notification settings - Fork 53
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
ir::Builder
should provide mutable access to LibrarySignatures
#1583
Comments
Thanks for the thoughtful write-up Ben! I agree that there is room for improvement here. I think the immutable by default nature of libraries comes from the original use-case: program compilation. It was not obvious that program compilation should create new primitives. However, you're exactly right about #419 needing this capability. For example, if we have a program, that during compilation wants to expose the requirement that it needs |
Indeed; thanks for the discussion! I too like the "forward declaration" idea. This seems like a good reflection of the needs of frontends that need to bring in their own custom primitives, and it doesn't seem like too radical of a change either. |
@bcarlet can you summarize the outcomes from the synchronous meeting we had about this? IIRC, the top-level points were:
If any of these are actionable, we should open issues for those |
From my notes, the issues that we agreed were immediately actionable were:
The right approach for encoding the standard primitives was more of an open issue, but we considered adding the calyx-numbers |
I think with #1596, we can consider adding all the "truly stable" primitives in the |
#1609 adds those methods to |
ir::Builder
ir::Builder
should provide mutable access to LibrarySignatures
There are currently several limitations in the Rust builder library that make working with primitives inconvenient.
Currently, to instantiate an
ir::Builder
you must first construct anir::LibrarySignatures
containing all the primitive definitions you will need when building the component. Any subsequent calls toadd_primitive
will panic if you attempt to add a primitive not in the library, and there is no way to modify the library once it is created.This makes it awkward to use inlined primitives, which are supposed to enable the generation of Calyx and Verilog code simultaneously. It also makes it less convenient to use the standard library, since you must import all the files you will ever need up front. For comparison, the Python builder library transparently accumulates any required imports as new primitives are instantiated.
The simple solution to this is to expose an interface to mutate the
ir::LibrarySignatures
. Their::Builder
would need to expose a mutable reference to the library, and their::LibrarySignatures
would need to expose a function to add new primitives.It might also make sense to allow forward declarations of primitives in the
ir::Builder
(i.e., make a version ofadd_primitive
that behaves more likeadd_component
). That would offer more flexibility as to when the primitives get created, and something like this might also be a prerequisite for more ambitious proposals such as #419 (at least in the setting where it's not easy to tell ahead of time which instantiations you'll need).The text was updated successfully, but these errors were encountered: