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

Merge main branch into list-patterns branch #57425

Merged
merged 80 commits into from
Oct 29, 2021

Conversation

alrz
Copy link
Member

@alrz alrz commented Oct 27, 2021

Relates to test plan #51289

jonfortescue and others added 30 commits September 3, 2021 15:00
Use Roslyn.sln, not Compilers.sln, to build more projects during
source-build. Update ExcludeFromSourceBuild properties to include more
projects and exclude a few projects that shouldn't be in source-build.

The newly included projects are used by downstream repos.
This makes source-build stop producing the Microsoft.CodeAnalysis.Collections package. Downstream repos (MSBuild) can't safely use a source-built version.
By default, the projects reference Microsoft.Build 16.5.0, which has netcoreapp2.1 and net472 support. The new 17.0.0-...
version built during source-build only has net6.0. This causes Microsoft.CodeAnalysis.Workspaces.MSBuild.csproj to fail.
Adding 16.5.0 to SBRP and dodging the override by renaming each package version property is the safe way to fix it.
@AlekseyTs
Copy link
Contributor

Checks that do not depend on Source should be performed before we look at sources.

@alrz
Copy link
Member Author

alrz commented Oct 28, 2021

We're doing just that.

  • For the indexer case, we have to first find the top-level input (in case of nested slices)
  • For the rest we do that in the when clause after the null check.

There's no earlier place that we could check those at the same time.

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Oct 28, 2021

                case (BoundDagIndexerEvaluation s1, BoundDagIndexerEvaluation s2):

When we enter this case, where do we check that s1Input.Index == s2Input.Index? #Closed


Refers to: src/Compilers/CSharp/Portable/Binder/DecisionDagBuilder.cs:1376 in 362472f. [](commit_id = 362472f, deletion_comment = False)

@alrz
Copy link
Member Author

alrz commented Oct 28, 2021

Line 1384 (notice we're depending on the Source)

(s1Input, BoundDagTemp s1LengthTemp, int s1Index) = GetCanonicalInput(s1);
(s2Input, BoundDagTemp s2LengthTemp, int s2Index) = GetCanonicalInput(s2);
Debug.Assert(s1LengthTemp.Syntax is ListPatternSyntax);
Debug.Assert(s2LengthTemp.Syntax is ListPatternSyntax);
// Ignore input source as it will be matched in the subsequent iterations.
if (s1Input.IsEquivalentTo(s2Input) &&

@AlekseyTs
Copy link
Contributor

Line 1384 (notice we're depending on the Source)

This line checks different inputs, note that lines 1379 and 1380 overwrite values in s1Input and s2Input. If you are saying that it would be harmful to require s1Input.Index == s2Input.Index before entering the switch. I would like to hear an explanation. I believe this requirement should be met regardless of values in s1Input.Source and s2Input.Source.

@alrz
Copy link
Member Author

alrz commented Oct 28, 2021

I think you mean we put the entire switch in if (s1Input.IsEquivalentTo(s2Input)) which is fine. Nevertheless, if GetCanonicalInput returns a different temp, we'd expect Index to be always zero because those are only contained within list patterns. I'll also add a couple of assertions to that effect.

@alrz
Copy link
Member Author

alrz commented Oct 28, 2021

That would change the behavior though which is against well-behaved assumption from spec. If Slice on the outer list returns a different type from Slice on the inner list, we no longer consider those related with this check.

@AlekseyTs
Copy link
Contributor

I think you mean we put the entire switch in if (s1Input.IsEquivalentTo(s2Input)) which is fine.

I think the type check will be inappropriate here as well.

Nevertheless, if GetCanonicalInput returns a different temp, we'd expect Index to be always zero because those are only contained within list patterns. I'll also add a couple of assertions to that effect.

I prefer us to not rely on assumptions like that, even if they are valid assumptions today. An approach like that is not robust in the long term should BoundDagTemp evolve. The "equivalence" of inputs that doesn't depend on their sources, should be checked before we do anything with sources.

@AlekseyTs
Copy link
Contributor

Note, that the change that you are merging is sayin that "equivalence" of inputs doesn't require equality of types by default. Equality of types is required when types are indeed important. The merge doesn't preserve this principle and I think it should be preserved.

@alrz
Copy link
Member Author

alrz commented Oct 28, 2021

I think the type check will be inappropriate here as well.

That would work (different Slice return types will be ignored) but I'm not sure what does that entail for the rest of usages of IsEquivalentTo. It's possible we will need another helper for those.

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Oct 28, 2021

That would work (different Slice return types will be ignored) but I'm not sure what does that entail for the rest of usages of IsEquivalentTo. It's possible we will need another helper for those.

I do not believe I suggested to simply make changes to IsEquivalentTo, or call it in some place, I simply made comments about specific call sites that I find problematic.


In reply to: 954040600

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Oct 29, 2021

        while (!s1Input.Equals(s2Input)); // if we have found two identical input fragments, there's no point to continue.

Is there an advantage to do this check, which potentially does a very deep check on every iteration) instead of simply letting the loop to descend one step at a time and handle reaching null source on either or both sides? #Closed


Refers to: src/Compilers/CSharp/Portable/Binder/DecisionDagBuilder.cs:1442 in e6d7842. [](commit_id = e6d7842, deletion_comment = False)

/// <summary>
/// Determine if two <see cref="BoundDagTemp"/>s represent the same value for the purpose of a pattern evaluation.
/// </summary>
public bool IsSameValue(BoundDagTemp other)
Copy link
Contributor

Choose a reason for hiding this comment

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

IsSameValue

I think the name no longer accurately reflrects what this function is doing. And the doc comment as well. Consider renaming to something like "IsEquivalentIgnoringType" and adjusting the comment accordingly.

@AlekseyTs
Copy link
Contributor

Done with review pass (commit 84), it looks like there are legitimate test failures.

@alrz alrz requested review from jcouv and AlekseyTs October 29, 2021 09:27
@alrz alrz force-pushed the epilogue branch 2 times, most recently from ec65c8d to 5e4d260 Compare October 29, 2021 11:26
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 86)

@AlekseyTs
Copy link
Contributor

I also only reviewed commits passed 79. Consider squashing commits 80 and up into a single commit before merging.

@jcouv
Copy link
Member

jcouv commented Oct 29, 2021

Taking another look to understand the difference and what I'd missed. Go ahead and squash the non-merge portion of the PR, then we'll merge. Thanks

case var (s1, s2) when s1 == s2:
if (conditions != null)
{
relationCondition = Tests.AndSequence.Create(conditions);
Copy link
Member

Choose a reason for hiding this comment

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

Not related to this PR: would be clearer if we renamed this overload to CreateAndFree

@@ -4984,34 +4979,33 @@ void Test(int[][] a)
Diagnostic(ErrorCode.ERR_SwitchCaseSubsumed, "[[42]]").WithLocation(9, 18));

VerifyDecisionDagDump<SwitchStatementSyntax>(comp,
@"[0]: t0 != null ? [1] : [27]
@"[0]: t0 != null ? [1] : [26]
Copy link
Member

Choose a reason for hiding this comment

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

Consider adding a test like Subsumption_15 or Subsumption_16 (which involve multiple preconditions to match temps) where the subsumption results from types (one is I and Base and the other is Derived) rather than remaining values.

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 86) with a test suggestion

@jcouv jcouv enabled auto-merge October 29, 2021 18:38
@jcouv jcouv merged commit 67a9216 into dotnet:features/list-patterns Oct 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Area-Infrastructure Community The pull request was submitted by a contributor who is not a Microsoft employee. Feature - List Patterns
Projects
None yet
Development

Successfully merging this pull request may close these issues.