-
-
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
Remove for loop trick for inlining functions w/o multiple returns + optims #1097
Remove for loop trick for inlining functions w/o multiple returns + optims #1097
Conversation
…ions if there are multiple return statements
…turn checking and which is for the returned value
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 few comments questions. The test output on this looks a lot cleaner than the existing stuff!
…when inlining non-multi return functions
Also fyi before we merge this I think I should turn it on for all of the tests that get compiled and run it once through Jenkins to help ensure there are no weird edge cases we are missing |
Do you want this in before the RC? If it can wait we have tons of time to do that |
It can absolutely wait. Yeah thinking it over that would be good to do. Though I may need some help as that sort of schema is a little over what I'm used to doing |
dedf6bc
to
ec69d87
Compare
… internally created objects erroneously
… of a unsizedtype
Is there a reason to update Core? We can, but I’ll need to do another windows port and our CI will need updates |
No we don't as long as you can tell me how to downgrade the stuff on my laptop after running |
You should be able to do |
This reverts commit d47a1bf.
This reverts commit aa1fe0c.
|
We could, though I think in general there is no reason to run |
Signed-off-by: Brian Ward <[email protected]>
Signed-off-by: Brian Ward <[email protected]>
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 few style/organization comments. I think that the logic here is sound in general, but I'd appreciate some clarifying comments in the code, especially around the sized 0 sizedtypes created.
…type to sized type function into Mir_utiles
Ty for looking this over! lmk if you have more Qs or suggestions |
How would you feel about doing some git squashing to remove some of the early commits in this PR (things like the opam switch that you reverted)? Definitely optional but it's a fair number of commits which don't really meaningfully contribute to the history IMO |
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.
This looks good to me. I propose squashing and merging rather than just a normal merge, but I leave that up to you @SteveBronder
Sounds good! I'll merge on Monday |
Summary
This PR removes for loops surrounding inlined functions if the inlined function does not have more than one return statement while also allow C++ to perform move semantics from the inlined functions inner return to it's outer return object.
After @WardBrian posted #1096 I thought it was odd that inlined functions are always wrapped in a for loop with breaks at the bottom. So this PR looks at a function as we are inlining it and if the function only has one return statement then the inlined function's code is placed into a
Block
(curly braces) instead of a for loop. For instance the following code is wrapped inside of a for loop that just runs once.But we can see that there are not multiple returns here and so instead of having a for loop we can just have a block
After cleaning that up, I noticed that the inlining code did a pattern where an variable is declared outside of the block scope, than another variable is declared at the inlined functions scope, and at the end of the inlined functions scope the inner variable is assigned to the outer variable. The below is pseudocode showing what I mean here.
This is the exact kind of place where we want to do move semantics, where at the end of the scope instead of copying
A_inner
toA_outer
we can just handA_outer
the memory ofA_inner
. This is safe and good becauseA_inner
will be deleted at the end of the inlined functions block scope. To let the C++ know an expression can be moved I made an internalfun_kind
calledFnMove
where if an expression is wrapped in aFnMove
the C++ code generator can then callstd::move(expr)
such as the below.While I was reading this PR I was having a hard time following which
inline_sym{number}__
was doing what and where. So now when we generate code for inline functions the local inlined variables have the patterninline_{function}_{orig_name}_sym{number}__
. The outer return mentioned above now has the nameinline_{func_name}_return_sym{number}__
. The iterator for the for loop trick when we have multiple returns now has the patterninline_{func_name}_{iterator}_sym{number}__
.Submission Checklist
Release notes
Replace this text with a short note on what will change if this pull request is merged. This will be included in the release notes.
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)