-
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
List patterns: Add initial support for enumerables #66553
Draft
alrz
wants to merge
4
commits into
dotnet:main
Choose a base branch
from
alrz:elp/initial
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains 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
ghost
added
the
Community
The pull request was submitted by a contributor who is not a Microsoft employee.
label
Jan 26, 2023
alrz
commented
Jan 26, 2023
src/Compilers/CSharp/Test/Emit2/Semantics/PatternMatchingTests_ListPatterns.cs
Outdated
Show resolved
Hide resolved
Thanks for contributing this as always @alrz 😄 At the moment we are a bit overbooked for work. I think the earliest we'll be able to book this for review is this summer. It is on our list of potentials though. Sorry, this cycle has been a bit more resource constrained than anticipated. |
Curious about the state of this, as it's been a couple years, and this issue is referenced in the regex group. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Area-Compilers
Community
The pull request was submitted by a contributor who is not a Microsoft employee.
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.
This deviates from the draft spec in a few ways, in particular:
Splitting
TryGetElement
into a pair ofHasElementAt
andGetElementFrom{Start,End}
methods: To facilitate subsumption checking, a new test node is added to track the count. It narrows down a virtual temp bycount > index
at each element access. This also correctly eliminates forthcoming element tests where the result is known:HasElementAt(i)
impliesHasElementAt(j)
wherei >= j
!HasElementAt(i)
implies!HasElementAt(j)
wherei <= j
The "relation condition" is inserted as a constant value test just like indexables, because
count > 1 && !(count > 2)
produced by a fixed-length pattern (see below) leads to a single remaining value. This test won’t reach codegen.It’s still possible to lower a sequence of (element test, element evaluation) as
TryGetElement
for a slightly smaller code size.Removal of
Last()
: To test the end of the sequence, a negated test for the next element is used instead:!HasElementAt(N)
Removal of
Count()
: Trailing patterns are prefixed byHasElementAt(N-2)
to ensure there’s sufficient elements before callingGetElementFromEnd
for each subpattern after the slice.Note: this only covers
IEnumerable<T>
at the moment.