-
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
Avoid binding lambdas unnecessarily in some error scenarios #59733
base: main
Are you sure you want to change the base?
Conversation
8f56558
to
72b4a11
Compare
72b4a11
to
f2ab18e
Compare
var data = new LambdaBindingData(); | ||
comp.TestOnlyCompilationData = data; | ||
var diagnostics = comp.GetDiagnostics(); | ||
Assert.Equal((84, 126), (data.LambdaBindingCount, data.UnboundLambdaStateCount)); |
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.
@@ -1663,14 +1668,17 @@ private ImmutableArray<BoundExpression> BuildArgumentsForErrorRecovery(AnalyzedA | |||
{ | |||
// bind the argument against each applicable parameter | |||
var unboundArgument = (UnboundLambda)argument; | |||
foreach (var parameterList in parameterListList) | |||
if (!unboundArgument.HasBoundForErrorRecovery) |
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.
var data = new LambdaBindingData(); | ||
comp.TestOnlyCompilationData = data; | ||
var diagnostics = comp.GetDiagnostics(); | ||
Assert.Equal((84, 126), (data.LambdaBindingCount, data.UnboundLambdaStateCount)); |
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.
Done review pass
@@ -987,5 +987,231 @@ static void M(object o) | |||
var containingTypes = exprs.SelectAsArray(e => model.GetSymbolInfo(e).Symbol.ContainingSymbol).ToTestDisplayStrings(); | |||
Assert.Equal(new[] { "A", "B", "B", "A", "B", "B" }, containingTypes); | |||
} | |||
|
|||
[Fact] | |||
public void NestedLambdasAndOverloads_NoTypes_NoErrors() |
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.
I think we should verify the IOperation trees for these tests to make sure that we know what semantic information will be availble to the IDE in these cases.
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 5)
@@ -1756,14 +1772,18 @@ private ImmutableArray<BoundExpression> BuildArgumentsForErrorRecovery(AnalyzedA | |||
{ | |||
// bind the argument against each applicable parameter | |||
var unboundArgument = (UnboundLambda)argument; | |||
foreach (var parameterList in parameterListList) | |||
if (NestedLambdaExpressionDepth(unboundArgument.Syntax) <= MaxLambdaExpressionDepthForErrorRecovery && |
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.
NestedLambdaExpressionDepth(unboundArgument.Syntax) <= MaxLambdaExpressionDepthForErrorRecovery
This condition looks questionable to me. Perhaps, the lambda is in the third level of nesting. Why is that important on its own? We might not be rebinding any of the enclosing lambdas for error recovery, doing simple plain body binding, and recovering in this case will not cause any noticeable overhead.
The issue says: "Reduce the overhead of binding lambdas when there are nested lambda expressions with multiple overloads. Specifically, consider avoiding binding nested lambdas unnecessarily for overloads that do not match." It doesn't look like any of the conditions, except the nesting, are checked.
Done with review pass (commit 5) |
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 6)
Inspired by dotnet#59733.
* Bind fully-typed lambda only once for error recovery * Assert number of lambda bindings Inspired by #59733. * Test only with one lambda and one statement * Copy a comment
@cston What is the status on this PR please? |
Fixes #63896.