Skip to content
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

Merged
merged 10 commits into from
Nov 30, 2023

Conversation

cston
Copy link
Member

@cston cston commented Nov 1, 2023

See API proposal #70631.

Relates to test plan #66418

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Nov 1, 2023
@cston cston force-pushed the collections-ioperation branch 2 times, most recently from d1f454a to 86b01ce Compare November 2, 2023 17:38
@cston cston force-pushed the collections-ioperation branch 3 times, most recently from 35b30f3 to ad8cdd6 Compare November 2, 2023 21:08
@cston cston force-pushed the collections-ioperation branch 9 times, most recently from 8871fda to 65a4ae9 Compare November 15, 2023 06:28
@cston cston force-pushed the collections-ioperation branch 3 times, most recently from 2c1626f to f3bb8d1 Compare November 19, 2023 20:08
@@ -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");
Copy link
Member

@333fred 333fred Nov 20, 2023

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

Copy link
Member Author

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.

@cston cston requested a review from a team November 20, 2023 21:45
@AlekseyTs
Copy link
Contributor

Are we testing control flow graph with control flow constructs within a collection expression?

@cston
Copy link
Member Author

cston commented Nov 22, 2023

Are we testing control flow graph with control flow constructs within a collection expression?

CollectionExpressionTests.IOperation_01 and _02.

@cston
Copy link
Member Author

cston commented Nov 29, 2023

@dotnet/roslyn-compiler, please review, thanks.

@jcouv
Copy link
Member

jcouv commented Nov 29, 2023

Looking

@jcouv jcouv self-assigned this Nov 29, 2023
</Comments>
</Property>
</Node>
<Node Name="ISpreadOperation" Base="IOperation" HasType="true">
Copy link
Member

@jcouv jcouv Nov 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HasType="true"

That seems unexpected. What's the type of a spread? #Resolved

Copy link
Member Author

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)
Copy link
Member

@jcouv jcouv Nov 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unwrapElement

static? #Closed

public override IOperation? VisitCollectionExpression(ICollectionExpressionOperation operation, int? argument)
{
EvalStackFrame frame = PushStackFrame();
var elements = VisitArray(operation.Elements, unwrapElement, wrapElement);
Copy link
Member

@jcouv jcouv Nov 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrapElement

nit: it seems wrapElement can't be made static (it uses instance method IsImplicit). Consider using a lambda around it to cache the allocated delegate. #Resolved

Copy link
Member Author

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)
Copy link
Member

@jcouv jcouv Nov 29, 2023

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

Copy link
Member

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)
Copy link
Member

@jcouv jcouv Nov 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IOperation

nit: consider declaring a more specific return type #Resolved

}
}

private IOperation CreateBoundCollectionExpressionSpreadElement(BoundCollectionExpressionSpreadElement boundSpreadExpression)
private IOperation CreateBoundCollectionExpressionSpreadElement(BoundCollectionExpressionSpreadElement element, BoundExpression? iteratorItem)
Copy link
Member

@jcouv jcouv Nov 29, 2023

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

Copy link
Member Author

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)
Copy link
Member

@jcouv jcouv Nov 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"element"

nameof(element)? #Resolved

@jcouv
Copy link
Member

jcouv commented Nov 29, 2023

    }

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)

Copy link
Member

@jcouv jcouv left a 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

@cston
Copy link
Member Author

cston commented Nov 29, 2023

    }

Added CollectionInitializerType_20 with multiple Add methods and nullable and boxing conversions.


In reply to: 1832759003


Refers to: src/Compilers/CSharp/Test/Emit2/Semantics/CollectionExpressionTests.cs:21265 in 7320176. [](commit_id = 7320176, deletion_comment = False)

@cston cston merged commit 772aefd into dotnet:main Nov 30, 2023
26 of 27 checks passed
@cston cston deleted the collections-ioperation branch November 30, 2023 00:03
@ghost ghost added this to the Next milestone Nov 30, 2023
@Cosifne Cosifne modified the milestones: Next, 17.9 P3 Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers New Feature - Collection Expressions untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants