-
Notifications
You must be signed in to change notification settings - Fork 146
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
Pretty-printing bug involving let
and letseq
#529
Comments
This is a workaround for B-Lang-org/bsc#529.
I'd be happy to submit a fix for this issue, but I'm not sure of the best way to add a test case. One way would be to add a test that calls An alternative approach would be to invoke the |
Another hiccup: the existing |
I take back my comment in #529 (comment). It's not that the output is being written to a temporary file, but rather that the test case wasn't running at all, since I wasn't setting the Along the way, I noticed a couple of things:
|
This is cargo-culted from the existing `run_bsc2bsv` command. This will be used in a subsequent commit which adds a test case requiring `bsv2bsc` (see B-Lang-org#529).
The pretty-printer for `letseq` and `letrec` was not adding braces around the variables being bound, resulting in malformed pretty-printed output such as `letseq hw = "Hello, World!";; ...`. After adding braces, this now becomes `letseq { hw = "Hello, World!"; };`, which is valid Bluespec code. Fixes B-Lang-org#529.
Hi Ryan, thank you for reporting this and for all the work on the issue! I need to take time time to look at the PR, but I should be able to accept it soon. Thank you! I can give some context first, though. In 2003/2004, Bluespec Inc was created to take the BSC technology (that existed previously at Sandburst Corp) and make it into a commercially available tool. The only syntax accepted by BSC was BH, and it was decided that this was too foreign for hardware engineers, so a new syntax was needed. At the same time, SystemVerilog was being developed and heralded, so it was decided to embed rules in that language. A first step towards that was just to create a parser for a SV-like syntax, BSV. Ultimately, no further step was taken. Anyway, at that time (2004), everything was written in BH and it was necessary to start converting examples into BSV. So a quick tool was cobbled together ( The tool was never released to the public (it wasn't in the BSC release tar-files) and it was mostly never used after 2004. The reverse program, So it was never expected to work fully, has hardly been used, and was never released. So it's no surprise that it has issues. These tools were included in the open BSC repo, in case they were useful. Because they're not tested and potentially buggy, they aren't put into the installation files by default and aren't in the releases that we build. We could change that decision though, and reclassify it from "internal tools" to first-class tools, and have it tested properly in the testsuite and included in builds and releases. We probably also would want to rename them to be Pretty-printing is of course also used by BSC, in error messages. So "bugs" in the pretty printer output are worth fixing even if we don't care about Anyway, your suggestions all seem fine and I should be able to accept the PR. Thank you! One comment would be, if we care about making the pretty-print output readable/friendly, is that it might be better to print using indentation rather than braces. (I'm not suggesting that you need to do that!) However, there are benefits to using braces, in developer dumps etc, so I wouldn't want to print that way everywhere. Just something to note. |
Thanks for the additional context! For what it's worth, my actual motivation is that I am developing a Haskell library for representing Bluespec ASTs, and I am using the code in |
Ah, very cool! Feel free to submit more fixes or libraries. There is a way to dump the pretty-printed parsing, using BSC's flags for dumping after each stage:
If you run BSC with It turns out there there is already a testsuite a directory, Anyway, sorry to reward your effort with more work. If it's too much, I can do it, but I'd certainly appreciate your help to do it. |
Also, FYI, we have a long-term goal of making BSC (and its codebase) more modular. For example, making the CSyntax and its utilities into their own library, and the parsers into their own libraries, etc. And then BSC is just a top-level project that imports these libraries. So that people can use their them in their own projects, and so that people can experiment with implementing their own parts of the flow (new parsers, new backends, new features in between existing stages, etc). If that fits with your use -- for example, having the CSyntax be a Cabal library that projects can import -- then feel free to propose or submit changes in that direction. |
Ooh, this is exactly what I wanted earlier, but failed to find in the
Perfect, that sounds much more direct than the
No problem! I'm happy to start over if the end result becomes nicer. |
Ah, good to know! Indeed, I am more-or-less copy-pasting
I might be interested in working on that, although I'd need to figure out how to make a |
The pretty-printer for `letseq` and `letrec` was not adding braces around the variables being bound, resulting in malformed pretty-printed output such as `letseq hw = "Hello, World!";; ...`. After adding braces, this now becomes `letseq { hw = "Hello, World!"; };`, which is valid Bluespec code. Fixes B-Lang-org#529.
The pretty-printer for `letseq` and `letrec` was not adding braces around the variables being bound, resulting in malformed pretty-printed output such as `letseq hw = "Hello, World!";; ...`. After adding braces, this now becomes `letseq { hw = "Hello, World!"; };`, which is valid Bluespec code. Fixes #529.
If you run
I don't see one specifically for that. Issue #22 maybe -- it's about splitting up the codebase to allow parallel compilation for improved compile time, but it does mention Cabal as an option for that. PR #166 was a draft of support, but BSC has changed since then, so it would need to be updated. Issue #187 and PR #267 are similar, but for Stack instead of Cabal. (In a comment on that PR, I explained my thinking on how both Cabal and Stack building could be supported in the BSC makefile, as alternatives to the default compilation. My opinions might have changed since then; I'd have to stop and think about it.) Issue 37 is just generally about defining the supported OS/toolchains. |
I recently noticed a bug in the way
bsc
pretty-printslet
andletseq
statements. The easiest way to observe the bug is by calling thebsv2bsc
utility on this program:Running
bsv2bsc
on this program will generate:The
letseq hw = "Hello, World!";;
bit is not valid Bluespec Haskell. If you try compiling this, it will fail with:Why are there two semicolons after the
letseq
statement? ThePPrint CExpr
instance separates each statement in a module with a semicolon (see here), and thePPrint CDefl
instance also separates each clause in in aletseq
statement with a semicolon (see here).One way to fix the issue is the add intervening braces, like so:
With this patch applied,
bsv2bsc
generates this code instead:This time,
letseq { hw = "Hello, World!"; };
is valid BH.There is a similar bug involving
let
/letseq
expressions (as opposed tolet
/letseq
statements). It can be fixed in a similar manner:The text was updated successfully, but these errors were encountered: