-
Notifications
You must be signed in to change notification settings - Fork 797
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
Eliminate tuple allocations in branching let binding rhs #11407
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e6c8a2d
Eliminate tuple allocations in branching let binding rhs
kerams 16bac85
Add more tuple elimination tests
kerams b532523
Address issues
kerams 0c37bbe
Refactor
kerams 3ea5579
Refactor
kerams af36a78
Fix condition
kerams File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
the
not a && not b
is irking me, does inverting the conditionals / branch looks better?Also wondering about repeated calls to v.IsCompilerGenerated that now occurs (one is introduced, unless mistaken).
As you are stress testing the inliner and bool expression optimizer, maybe you should also stress test the final reviewer by rewriting the whole condition from scratch to make it more readable 🙂.
Suggestion, since both current branches are very small expressions that could be copied:
In the comment, it says
this would be one simple if condition, then it says
This would be another one, the final case is just returning the default case.
Sorry if bikeshedding.
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.
not (a || b)
? Hm, I don't feel strongly either way.I know, but it needs to be a part of
IsMutableStructuralBindingForTupleElement
, otherwise If the caller does not also checkIsCompilerGenerated
, then it could lead to bugs.So what you're suggesting at the end is this?
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.
@kerams, thanks a lot for the feedback.
if that's the end result, the best (to me) would be
if a || b then
and inverting the branches expressions then (I don't like "not" for complex conditions, the same way I don't likeisNull
, I'd preferisNotNull
and not using "not" 🙂).Understood, it fits well with when I was proposing to extract a function, and it makes sense to have the redundant check to properly encapsulate the assumption.
It may also surface as a comment if you can expand on the deeper reason, to avoid someone trying to remove duplicate check to do it hastily.
for the unsuspecting next maintainer dealing with this part (which seems sensitive for tuple elision, but it, hmm, escapes me how it actually works), I feel your proposed edit, with maybe a re-interleaving of the keywords (such as "outArg values", "temp mutable for tuples that can be elided") from the larger text above, would do a great job at improving the very expansive conditional in the code, and shouldn't add runtime cost, just a duplicate branch with
info
.So I see potential small wins for the clarity of the code, if this is not bikeshedding and you feel it makes it easier for next person following your journey, I wish to understand better the flow of
Val
objects and do the work you do.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.
enters
TryRewriteBranchingTupleBinding
in the form ofand exits as
As you can see, there's still a let binding with a tuple (I copied that part from
ExpandStructuralBindingRaw
, the 4 lines in theelse
branch). It's only further on inOptimizeExprOpReductionsAfter
andTryOptimizeTupleFieldGet
that this tuple is eliminated. If you step through the code, you'll realize it's only possible when the equivalence ofpatternInput_0_tupleElem
andpatternInput.Item1
is established based on the former'sExprValueInfo
. Had I not changedAddValEqualityInfo
to account for this mutabletupleElem
, there'd be no equality information (because normally you can't, for obvious reasons, equate a mutable variable with another one) and the result would look like:If, on the other hand, I'd used a regular local in
MakeMutableStructuralBindingForTupleElement
instead ofmkMutableCompGenLocal
,patternInput_0_tupleElem
would be equated with that initialnull
(0) forever, and the whole function would through a series of inlining and eliminations be reduced to this: