-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Handle IForToLoopOperation over numeric types in control flow graph #26734
Conversation
|
||
namespace Microsoft.CodeAnalysis.Operations | ||
{ | ||
internal class ForToLoopOperationUserDefinedInfo |
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.
Any reason this can't just be a struct? #Resolved
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.
Any reason this can't just be a struct?
It is not common to need this information. The intent is to save some memory for the common case.
In reply to: 187115823 [](ancestors = 187115823)
public ForToLoopStatement(ImmutableArray<ILocalSymbol> locals, ILabelSymbol continueLabel, ILabelSymbol exitLabel, IOperation loopControlVariable, IOperation initialValue, IOperation limitValue, IOperation stepValue, IOperation body, ImmutableArray<IOperation> nextVariables, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, Optional<object> constantValue, bool isImplicit) : | ||
base(locals, continueLabel, exitLabel, semanticModel, syntax, type, constantValue, isImplicit) | ||
public ForToLoopStatement(ImmutableArray<ILocalSymbol> locals, bool isChecked, | ||
(ILocalSymbol LoopObject, ForToLoopOperationUserDefinedInfo UserDefinedInfo) info, |
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.
[](start = 116, length = 1)
Lots of trailing whitespace. #WontFix
} | ||
} | ||
|
||
public static int VBForToShiftBits(this SpecialType specialType) |
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.
Can we add a comment on the intent of this method or update the name. Unsure exactly what this is for at a glance. #Resolved
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.
Can we add a comment on the intent of this method or update the name. Unsure exactly what this is for at a glance.
Will do
In reply to: 187118574 [](ancestors = 187118574)
@@ -2364,11 +2364,21 @@ internal sealed partial class LazyForLoopStatement : BaseForLoopStatement, IForL | |||
/// </summary> | |||
internal abstract partial class BaseForToLoopStatement : LoopStatement, IForToLoopOperation |
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.
BaseForToLoopStatement [](start = 36, length = 22)
Which change is causing this generated file to get updated? Was expecting to see a change to on of our XML files or generators but not seeing that. #Resolved
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.
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.
Ah okay. Thanks for the explanation.
As for renaming. I'm ambivalent. I don't want to create unnecessary work here if there is an issue tracking it.
In reply to: 187120137 [](ancestors = 187120137)
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'm planning on addressing the issue during the hackathon.
In reply to: 187121166 [](ancestors = 187121166,187120137)
_ = userDefinedInfo.Subtraction.Value; | ||
_ = userDefinedInfo.LessThanOrEqual.Value; | ||
_ = userDefinedInfo.GreaterThanOrEqual.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.
Consider adding a method to ForToLoopOperationUserDefinedInfo to force the evaluation of the lazies instances rather than enumerating the fields here. This would be more robust in the face of adding additional fields in the future. #Resolved
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.
Consider adding a method to ForToLoopOperationUserDefinedInfo to force the evaluation of the lazies instances rather than enumerating the fields here. This would be more robust in the face of adding additional fields in the future.
I do not expect us to add anything else to that class in the future. I also think this method would look strange in the class because it is only useful as a test.
In reply to: 187120366 [](ancestors = 187120366)
|
||
Visit(operation.LoopControlVariable, "LoopControlVariable"); | ||
Visit(operation.InitialValue, "InitialValue"); | ||
Visit(operation.LimitValue, "LimitValue"); | ||
Visit(operation.StepValue, "StepValue"); | ||
Visit(operation.Body, "Body"); | ||
VisitArray(operation.NextVariables, "NextVariables", logElementCount: true); | ||
|
||
(ILocalSymbol loopObject, ForToLoopOperationUserDefinedInfo userDefinedInfo) = ((BaseForToLoopStatement)operation).Info; |
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.
loopObject [](start = 26, length = 10)
The loopObject
element could be a discard. #WontFix
@@ -255,6 +260,16 @@ public override void VisitForToLoop(IForToLoopOperation operation) | |||
{ | |||
VisitLoop(operation); | |||
Assert.Equal(LoopKind.ForTo, operation.LoopKind); | |||
_ = operation.IsChecked; | |||
(ILocalSymbol loopObject, ForToLoopOperationUserDefinedInfo userDefinedInfo) = ((BaseForToLoopStatement)operation).Info; |
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 loopObject
element can be a discard. #WontFix
@@ -255,6 +260,16 @@ public override void VisitForToLoop(IForToLoopOperation operation) | |||
{ | |||
VisitLoop(operation); | |||
Assert.Equal(LoopKind.ForTo, operation.LoopKind); | |||
_ = operation.IsChecked; |
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 line looks suspicious. It implies there is a property here which is side effecting that needs to be executed. #Resolved
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 line looks suspicious. It implies there is a property here which is side effecting that needs to be executed.
The purpose of this line is to evaluate the property to make sure it doesn't crash. This is a test code.
In reply to: 187121790 [](ancestors = 187121790)
{ | ||
return new InvalidOperation(ImmutableArray.Create<IOperation>(child1, child2), | ||
semanticModel: null, syntax, type, | ||
constantValue: default, isImplicit: true); |
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.
Why are invalid operations implicit? #Resolved
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.
Why are invalid operations implicit?
Usually, implicit operations are those that are synthesized. Like this one, for example. It is not a clone of a node present in the original tree.
In reply to: 187123049 [](ancestors = 187123049)
} | ||
else | ||
{ | ||
IOperation controlVariableReferenceforCondition = getLoopControlVariableRefernce(forceImplicit: true); // Yes we are going to reevaluate it again |
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.
getLoopControlVariableRefernce [](start = 70, length = 30)
typo: getLoopControlVariableRefernce -> getLoopControlVariableReference #Resolved
//RemovePlaceholderReplacement(forStatement.OperatorsOpt.LeftOperandPlaceholder) | ||
//RemovePlaceholderReplacement(forStatement.OperatorsOpt.RightOperandPlaceholder) | ||
} | ||
else if (!operation.StepValue.ConstantValue.HasValue && |
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.
Can StepValue
be null? If not, we probably want to update the doc comment. #Resolved
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.
Can StepValue be null? If not, we probably want to update the doc comment.
I don't think it can ever be null. I'll update the doc comment. I will also adjust VisitForToLoop in TestOperationVisitor accordingly.
In reply to: 187130267 [](ancestors = 187130267)
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.
Probably also want to replace the null check with an assert in TestOperationVisitor #Resolved
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.
Probably also want to replace the null check with an assert in TestOperationVisitor
Yes, the null check should be removed there
In reply to: 187132438 [](ancestors = 187132438)
Tests look good. |
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.
Comments are OK to be addressed in a follow up PR.
@333fred, @mavasani, @jaredpar In my responses I identified the issues I am going to address in the next PR. These are:
Please let me know if you consider this issues, or any other issues, blocking for this PR. Otherwise, could you please sign-off so that I can resolve merge conflicts and merge the PR, it is going to conflict with any other builder change merged into the branch. |
@cston, @dotnet/roslyn-compiler Please review, need a second review |
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.
No description provided.