-
Notifications
You must be signed in to change notification settings - Fork 52
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
Introduce constant-folding preprocessor #2149
Comments
Thanks for writing this up! I would generally like to frame this as a language built on top of Calyx, i.e., similar to the python eDSL, it's okay to make opinionated choices about how the parameterization should work and what kinds of things it should allow. A crucial implication of this distinction is that the Calyx compiler and language are not familiar with the effects of the parameterization on the optimization of the programs. I would also consider how far the effect of parameterization goes: do you want to extend the control language to support use of parameterized values? Should you be able to generate new groups based on parameterization (i.e. compile-time meta-programming), etc. |
I was emphatically not considering this to be a language* on top of calyx or to support parametrization -- if you think that this is a good idea, namely, a preprocessing layer geared toward parametrization, that would send the preprocessor down another direction. I feel as though parametrization should be handled in higher-level DSLs (e.g., Filament). I'm also worried about enabling stuff like meta-programming, which I feel might be too powerful (given that the main focus on language extensions should be geared toward generators). I think my idea with this preprocessor is just to get rid of magic numbers via a superset of calyx that doesn't affect anything existing. These are just my thoughts, though; I'll go ahead with whatever you feel is the best direction. *not in the sense that it is valid calyx, but in the sense that it provides more/different functionality than calyx. |
Looks awesome! Just fyi, error locations are working better in this PR: #1950. I'll get around to finishing this up soon. |
If people like this idea, I'll rewrite my mockup with actually good code. |
If this is not the case, then I'd rather just use |
Sure. I'm hesitant because I don't see a use for any features beside constants and constant folding, especially since calyx isn't designed as a frontend. |
I don't think what I want is a preprocessor. I think I found and implemented what I actually wanted. I'll close this if no one has any objections (and as Rachit pointed out, there are plenty of existing preprocessor in addition to EDIT: See #2157 |
As an IL, calyx is intended as a generation target. Still, there are instances in which we write calyx code directly, and due to a lack of constant and constant-folding support, we have to resort to magic numbers. These come with all the classic magic number issues about readability and maintainability. If you have
16
everywhere in your code to represent the number of bits an entry takes up, adding a single bit tag to one of these yields a random17
in the code, which is an entirely different magic number. Why not$define ENTRY_BITS 16
and then use$(ENTRY_BITS + 1)
?I propose to solve this with a very light constant-folding preprocessor. I've mocked up a working demo on the
preproc
branch (undertools/preprocessor
). Icargo run
on the initial file to produce the preprocessed file. Notice how line numbers are preserved (so that the LSP will still display correctly-positioned errors (it doesn't, but that's a separate bug)). It simply reads line-by-line fromstdin
and writes tostdout
, which I think is the kind of simplicity that suffices for this task.I find this useful in writing a cache (a highly parametrized construction), but I'd like to know if this is useful to anyone else.
Some further thoughts:
Workspace
too hard). Moving the imports to the preprocessor would also allow customization in terms of defining macros for the import. I've said this quite verbosely but imagine$import<WIDTH 32, INIT 0> "ram.futil"
or dim.fn process(&mut self, line: String) -> ContextResult<String>
), so it's not especially suited for direct input to tree-sitter, I believe. I tried to modify the LSP to capture thestdin
and wrap it in a new reader that applies the preprocessor to every line, but I wasn't able to get it working and ended up not committing it to the branch.The text was updated successfully, but these errors were encountered: