Improve types for variables generated from stack slots - #4071
Merged
Merged
Conversation
…e `object` This was due to StackType.O doing double-duty as `object` and `other`. While ExpressionBuilder would often improve the type of such locals, the `object` nevertheless ended up used in a couple of places, e.g. via the `typeHint`. This could result in value types being boxed even though the original IL didn't contain any `box` instruction. This is an attempt to use better types for stack slot variables created by ILReader. The idea is: there aren't many IL instructions that produce "other" value types, and `InferType()` already handles pretty much all of them, so we can use that to assign types to our stack slots. It's a bit more tricky if the stack is pushed to on multiple branches that join together before the value is used: here the variable type must be suitable for both assignments. In this case, we go back to the previously-used stacktype.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Stack slots holding value types previously nevertheless often had type
objectThis was due to StackType.O doing double-duty as
objectandother. While ExpressionBuilder would often improve the type of such locals, theobjectnevertheless ended up used in a couple of places, e.g. via thetypeHint. This could result in value types being boxed even though the original IL didn't contain anyboxinstruction.This is an attempt to use better types for stack slot variables created by ILReader. The idea is: there aren't many IL instructions that produce "other" value types, and
InferType()already handles pretty much all of them, so we can use that to assign types to our stack slots.It's a bit more tricky if the stack is pushed to on multiple branches that join together before the value is used: here the variable type must be suitable for both assignments. In this case, we go back to the previously-used stacktype.
Fixes #4068 (comment) -- the issue there was that the stack slot holding the
(int, bool)had typeobjectand was passing this as a TypeHint to the switch-expression translation. That caused switch-expression translation to box -- but the uses of the variable didn't unbox, so this was a correctness bug.