Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Clean up code for converting collection expressions in the binder. #80740

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

Open
CyrusNajmabadi wants to merge 35 commits into dotnet:features/collection-expression-arguments
base: features/collection-expression-arguments
Choose a base branch
Loading
from CyrusNajmabadi:withElementCleanup2

Conversation

Copy link
Member

@CyrusNajmabadi CyrusNajmabadi commented Oct 15, 2025
edited
Loading

This PR should be reviewed commit by commit. Each commit make a small and easily verifiable change. The net result is that all the code for collection expression conversions is extract and isolated into its own component. And within that component the flow of cases is much clearer and easier to reason about.

Overall changes:

  1. encapsulated all code specific to collection expression conversion into its own type.
  2. pulled immutable state into fields to make it easy to know what can always be accessed, vs what is specific to a method.
  3. pulled ccommon code and common error handling pattern up to the top.
  4. broke the main cases in the spec out into individual helpers (IEnumerable, Array, Spans, and CollectionBuilders).
  5. In those case, any helpers are located only there so as to not leak into anything else.

Each case is also responsible for creating the right final bound node, instead of having a big mass of mutable state that they all change which comes together into the one construction call. This makes examining and understanding each case as they only share what is acutally possible, and otherwise have independent logic for each case.

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner October 15, 2025 21:19
return converter.Do();
}

private readonly struct CollectionExpressionConverter(
Copy link
Member Author

@CyrusNajmabadi CyrusNajmabadi Oct 15, 2025

Choose a reason for hiding this comment

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

note: i would like to pull this into its own file as well. but i wante dto check how you felt about that @RikkiGibson

Copy link
Member

@RikkiGibson RikkiGibson Oct 15, 2025

Choose a reason for hiding this comment

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

I have no objection to that, except that if any of the diffs in this file are useful, we might want to delay extracting until we're ready to merge.

Copy link
Member Author

@CyrusNajmabadi CyrusNajmabadi Oct 16, 2025

Choose a reason for hiding this comment

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

Sure. I'd also be fine doing it in a subsequent PR if that makes the history cleaner.

{
base.IsParamsArrayOrCollection = value;
}
get => base.IsParamsArrayOrCollection;
Copy link
Contributor

@AlekseyTs AlekseyTs Oct 15, 2025
edited
Loading

Choose a reason for hiding this comment

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

get => b

Is this a style only change? Please revert if so #Closed

Copy link
Member Author

@CyrusNajmabadi CyrusNajmabadi Oct 16, 2025

Choose a reason for hiding this comment

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

It was not style-only. I'm changing from init to setter here.

Copy link
Member Author

@CyrusNajmabadi CyrusNajmabadi Oct 16, 2025

Choose a reason for hiding this comment

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

Note: i'd prefer to keep this, as it ensures all codepaths set in CollectionExpressinConverter set these values (instead of potentially forgetting them). If it is still preferable to keep this 'init', then i can revert and set in the 5 different locations (and assert in the topmost function). But i find this cleaner and easier to reason about.

Copy link
Contributor

@AlekseyTs AlekseyTs Oct 16, 2025

Choose a reason for hiding this comment

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

The use of init was intentional. The intent was to prevent changes to this property post construction. Please revert.

var element = elements[i];
var elementConversion = elementConversions[i];
builder.Add(element is BoundCollectionExpressionSpreadElement spreadElement
? BindSpreadElement(
Copy link
Contributor

@AlekseyTs AlekseyTs Oct 15, 2025
edited
Loading

Choose a reason for hiding this comment

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

? BindSpreadElement(

This looks like a style-only change, please revert #Closed

Copy link
Member Author

@CyrusNajmabadi CyrusNajmabadi Oct 16, 2025

Choose a reason for hiding this comment

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

Changed what is being called and what is being referenced. Intentionally updated the code when doing that.

Copy link
Contributor

@AlekseyTs AlekseyTs Oct 16, 2025

Choose a reason for hiding this comment

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

Changed what is being called and what is being referenced. Intentionally updated the code when doing that.

I am referring to changes around punctuation placement.

Copy link
Contributor

@AlekseyTs AlekseyTs Oct 16, 2025

Choose a reason for hiding this comment

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

Since you moved code around a lot, in order to get correct placement of the comments, I suggest you using CodeFlow and looking at the view corresponding to the comment. For example, according to CodeFlow, this comment belongs to Iteration 6

Copy link
Member Author

@CyrusNajmabadi CyrusNajmabadi Oct 16, 2025

Choose a reason for hiding this comment

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

Yes. i was changing this code and would prefer to have be in this form. I find it much easier to reason about as it is clear what the branching structure is at the start of the line, which is something i wanted to improve as part of this effort.

Copy link
Contributor

@AlekseyTs AlekseyTs Oct 16, 2025

Choose a reason for hiding this comment

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

To clarify, this comment is about moving position of ?.

Copy link
Contributor

@AlekseyTs AlekseyTs Oct 16, 2025

Choose a reason for hiding this comment

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

Yes. i was changing this code and would prefer to have be in this form. I find it much easier to reason about as it is clear what the branching structure is at the start of the line, which is something i wanted to improve as part of this effort.

This constitutes a stylistic change based on a personal preference. We do not welcome changes like that. Different people have different preferences, what is considered "easier to reason about" by one is considered "very hard to reason about" by someone else. Touching other parts of the statement doesn't give a free pass. Please respect the original style and revert the change.

spreadElement,
elementType,
elementConversion)
: _binder.CreateConversion(
Copy link
Contributor

@AlekseyTs AlekseyTs Oct 15, 2025
edited
Loading

Choose a reason for hiding this comment

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

: _binder.CreateConversion(

This looks like a style-only change, please revert #Closed

Copy link
Contributor

@AlekseyTs AlekseyTs Oct 16, 2025

Choose a reason for hiding this comment

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

To clarify, this comment is about moving position of :.

Copy link
Contributor

AlekseyTs commented Oct 16, 2025
edited
Loading

Removal of a prototype comment doesn't belong in a pure refactoring PR. Consider reverting

NOte: this was an accidental comment left in in the prior PR. I had already made the change it refers to in that PR. I just forgot to remove the comment.

Could you point to that PR and the relevant comment? #Closed

Copy link
Member Author

Could you point to that PR and the relevant comment?

The comment was added in #80568. but reflected the logic at a prior time, when we weren't doing the filtering of these methods. The filtering was added in that same PR and happens here:

image

I would linkk to the line in that PR, but github linking isn't working for me. Since we added the filtering option (which we'd mentioned in the prototype comment) the comment should have been deleted when i also removed teh checking for this in that location. But i only changed the code and left the comment. rectifying that in this PR.

Copy link
Contributor

AlekseyTs commented Oct 16, 2025
edited
Loading

Done with review pass (commit 31) #Closed

Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

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

LGTM (commit 32)

Copy link
Contributor

This PR modifies public API files. Please follow the instructions at https://github.com/dotnet/roslyn/blob/main/docs/contributing/API%20Review%20Process.md for ensuring all public APIs are reviewed before merging.

Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

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

LGTM (commit 34)

Copy link
Member

Taking a look this afternoon.

Copy link
Member

@RikkiGibson RikkiGibson left a comment

Choose a reason for hiding this comment

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

LGTM. None of my comments are blocking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@RikkiGibson RikkiGibson RikkiGibson approved these changes

@AlekseyTs AlekseyTs AlekseyTs approved these changes

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /