forked from B-Lang-org/bsc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BSV: Pretty-print module return types when possible
The BSV pretty-printer would print a function like this: ``` module [Module] helloWorld#(Module#(Empty) m)(Empty); let e <- m; endmodule ``` Without the `[Module]` bit, resulting in a function declaration that wouldn't typecheck. This patch makes a best-effort attempt to pretty-print this bit whenever possible. More specifically: * We check if the return type of a function is equal to `M ty`, where `M` is a type constructor like `Module`. If so, pretty-print `[M]`. * Otherwise, check if the return type is equal to `m ty`, where `m` is a type variable with a corresponding `IsModule#(m, c)` constraint. If so, pretty-print `[m]`. The `findModId` function is responsible for finding type variables like `m`. While investigating this issue, I noticed a bug in which `findModId` would drop the `IsModule#(m, c)` constraint in which `m` appears, which would cause the constraint not to be pretty-printed. I've fixed this bug as part of this patch. Fixes B-Lang-org#663.
- Loading branch information
1 parent
e4361d9
commit 54028fa
Showing
4 changed files
with
38 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
testsuite/bsc.syntax/bsv05_parse_pretty/ModuleArgument.bsv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package ModuleArgument; | ||
|
||
module [Module] helloWorld#(Module#(Empty) mod)(Empty); | ||
let e <- mod; | ||
endmodule | ||
|
||
module [m] fooBar#(m#(Empty) mod)(Empty) | ||
provisos (IsModule#(m, c)); | ||
let e <- mod; | ||
endmodule | ||
|
||
endpackage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters