-
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
Collection expressions: IOperation support #70650
Conversation
ce50d29
to
f5c7696
Compare
d1f454a
to
86b01ce
Compare
35b30f3
to
ad8cdd6
Compare
ad8cdd6
to
398b930
Compare
8871fda
to
65a4ae9
Compare
65a4ae9
to
5f2379c
Compare
2c1626f
to
f3bb8d1
Compare
@@ -2343,7 +2343,7 @@ public async Task ChangeNamespace_DoesNotThrowInDuplicateProgramDeclaration() | |||
|
|||
// No change namespace action because the folder name is not valid identifier | |||
var (topLevelProgramFolder, topLevelProgramFilePath) = CreateDocumentFilePath(["3B", "C"], "Program.cs"); | |||
var (duplicateProgramFolder, duplicateProgramFilePath) = CreateDocumentFilePath([], "Program.cs"); | |||
var (duplicateProgramFolder, _) = CreateDocumentFilePath([], "Program.cs"); |
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.
Is this change related to the PR? #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.
Yes, with this change, an analyzer reports a diagnostic here for an unnecessary assignment.
Are we testing control flow graph with control flow constructs within a collection expression? |
|
@dotnet/roslyn-compiler, please review, thanks. |
Looking |
</Comments> | ||
</Property> | ||
</Node> | ||
<Node Name="ISpreadOperation" Base="IOperation" HasType="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.
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.
Good catch, thanks.
operation.Type, | ||
IsImplicit(operation)); | ||
|
||
static IOperation unwrapElement(IOperation element) |
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.
public override IOperation? VisitCollectionExpression(ICollectionExpressionOperation operation, int? argument) | ||
{ | ||
EvalStackFrame frame = PushStackFrame(); | ||
var elements = VisitArray(operation.Elements, unwrapElement, wrapElement); |
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.
Changed both local functions to lambda expressions.
@@ -6368,6 +6368,46 @@ IArrayInitializerOperation popAndAssembleArrayInitializerValues(IArrayInitialize | |||
} | |||
} | |||
|
|||
public override IOperation? VisitCollectionExpression(ICollectionExpressionOperation operation, int? argument) |
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.
Looking at VisitInterpolatedStringHandlerCreation
below, I would have expected the CFG for collection expression to surface the nitty-gritty details of the collection evaluation. It sounds like this was discussed/approved in API review, but I'm not clear on whether this is the level of abstraction for CFG that we want moving forward? #Closed
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.
Resolved offline. This is the result of a case-by-case discussion in API review considering the needs of the CFG customer. Thanks
} | ||
} | ||
|
||
private IOperation CreateBoundCollectionExpressionSpreadElement(BoundCollectionExpressionSpreadElement boundSpreadExpression) | ||
private IOperation CreateBoundCollectionExpressionSpreadElement(BoundCollectionExpressionSpreadElement element, BoundExpression? iteratorItem) |
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.
} | ||
} | ||
|
||
private IOperation CreateBoundCollectionExpressionSpreadElement(BoundCollectionExpressionSpreadElement boundSpreadExpression) | ||
private IOperation CreateBoundCollectionExpressionSpreadElement(BoundCollectionExpressionSpreadElement element, BoundExpression? iteratorItem) |
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 doc for iteratorItem
#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.
Removed parameter.
} | ||
return Create(getUnderlyingExpression((BoundExpression)element)); | ||
|
||
[return: NotNullIfNotNull("element")] static BoundExpression? getUnderlyingExpression(BoundExpression? element) |
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.
nit: consider adding a test that shows more interesting element conversions than identity or reference conversions. For instance, a collection with different Add methods where each element gets its own conversion. #Resolved Refers to: src/Compilers/CSharp/Test/Emit2/Semantics/CollectionExpressionTests.cs:21265 in 7320176. [](commit_id = 7320176, deletion_comment = False) |
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 Thanks (iteration 9) with some nits to consider
Added In reply to: 1832759003 Refers to: src/Compilers/CSharp/Test/Emit2/Semantics/CollectionExpressionTests.cs:21265 in 7320176. [](commit_id = 7320176, deletion_comment = False) |
See API proposal #70631.
Relates to test plan #66418