-
-
Notifications
You must be signed in to change notification settings - Fork 47
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
[Refactor] Add a lower-level IR for C++ code generation #1233
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only got about halfway through Cpp.ml today, but so far I like what I see! Mostly seeing a few places it would be nice to have more verbose names / names that more closely align with C++ verbage. But the overall scheme seems very nice so far
Codecov Report
@@ Coverage Diff @@
## master #1233 +/- ##
==========================================
- Coverage 88.49% 87.20% -1.29%
==========================================
Files 63 64 +1
Lines 9262 9687 +425
==========================================
+ Hits 8196 8448 +252
- Misses 1066 1239 +173
|
@nhuurre - I talked to @SteveBronder and he doesn't have the bandwidth to review this soon. Do you feel comfortable reviewing a PR in this area, and would you mind? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You say that this closes #354 but that issue is about MIR dump format, something this PR does not touch at all.
With the exception of a few things like functor generation and tracking map-rect calls, there are no side effects in the code gen.
I didn't see functor generation side effects; it's forward declarations that have side effects but those are fully contained in Lower_functions.ml
so I wouldn't worry too much.
More annoying is the map_rect
tracking and registration.
Do you think it would be reasonable to separate map_rect
id assignment from code lowering?
For example, Locations.prepare_prog
walks the whole program and collects and relabels all the location metadata. Maybe it could also transform map_rect
calls
map_rect(fn, args...) -> map_rect(id, fn, args...)
and return a list of the id
s.
My bad, I thought that was about the (nearly identical) issue we currently have in the C++ code gen for printing a lot of empty cuts.
Giving that suggestion a try now |
@nhuurre I quite like the result of moving map_rect into a pre-processing phase. The end result is that we shouldn't have any global state left in the code gen, it should all be within the scope of one function/module |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of nitpicky comments but those are optional so I'll approve now.
Thanks for the thorough review @nhuurre! @SteveBronder - I believe merging will still be blocked so long as you have 'requested changes'. Do you mind clearing that? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
Closes #850, #354.
This PR introduces a relatively simple1 C++ representation for the code generation backend.
Rather than code generating by creating strings directly, we first lower the MIR to this representation and then print it out.
Benefits:
(MethodCall (Parens (StreamInsertion (Constructor (row_vector Double, [Literal "3"]), [Literal "1"; Var "a"; Literal "3"]), "finished", [], [])
, which moves all the least-important information to the front of the code).There is a lot of potential to add further processing of this generated C++ before it is stringified and output, but that is not part of this PR.
The code generated by this PR is intended to be semantically identical; whitespace, the ordering of some functions, and other superficial changes are common however. I recommend viewing the diffs with whitespace changes hidden. I have eyeballed all of them, but this PR is the first time some of it will actually be compiled to executable.
Submission Checklist
Release notes
Refactored how C++ is code-generated in the compiler.
Copyright and Licensing
By submitting this pull request, the copyright holder is agreeing to
license the submitted work under the BSD 3-clause license (https://opensource.org/licenses/BSD-3-Clause)
Footnotes
"Relatively simple" in that it 1) does not try to capture all of C++, just the portion of C++ we currently generate and 2) is a basic recursive data type, no two-level-type reasoning is needed at this level ↩