-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Extensions: address instrumentation follow-ups #79557
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2305,14 +2305,6 @@ private void DeclareVariables(ImmutableArray<LocalSymbol> locals) | |
| } | ||
| } | ||
|
|
||
| private void DeclareVariables(OneOrMany<LocalSymbol> locals) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Correct |
||
| { | ||
| foreach (var symbol in locals) | ||
| { | ||
| DeclareVariable(symbol); | ||
| } | ||
| } | ||
|
|
||
| private void DeclareVariable(LocalSymbol symbol) | ||
| { | ||
| var initiallyAssigned = | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,8 +17,6 @@ namespace Microsoft.CodeAnalysis.CSharp | |
| /// </summary> | ||
| internal sealed class ExtensionMethodBodyRewriter : BoundTreeToDifferentEnclosingContextRewriter | ||
| { | ||
| private readonly SourceExtensionImplementationMethodSymbol _implementationMethod; | ||
|
|
||
| /// <summary> | ||
| /// Maps parameters and local functions from original enclosing context to corresponding rewritten symbols for rewritten context. | ||
| /// </summary> | ||
|
|
@@ -37,7 +35,6 @@ public ExtensionMethodBodyRewriter(MethodSymbol sourceMethod, SourceExtensionImp | |
| Debug.Assert(implementationMethod is not null); | ||
| Debug.Assert(sourceMethod == (object)implementationMethod.UnderlyingMethod); | ||
|
|
||
| _implementationMethod = implementationMethod; | ||
| _symbolMap = ImmutableDictionary<Symbol, Symbol>.Empty.WithComparers(ReferenceEqualityComparer.Instance, ReferenceEqualityComparer.Instance); | ||
|
|
||
| bool haveExtraParameter = sourceMethod.ParameterCount != implementationMethod.ParameterCount; | ||
|
|
@@ -97,6 +94,10 @@ public override ParameterSymbol VisitParameterSymbol(ParameterSymbol symbol) | |
| var rewritten = new RewrittenLambdaOrLocalFunctionSymbol(node.Symbol, _rewrittenContainingMethod); | ||
|
|
||
| var savedState = EnterMethod(node.Symbol, rewritten); | ||
|
|
||
| // BoundMethodDefIndex in instrumentation will refer to the lambda method symbol, so we need to map it. | ||
| _symbolMap = _symbolMap.Add(node.Symbol, rewritten); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| BoundBlock body = (BoundBlock)this.Visit(node.Body); | ||
| (_rewrittenContainingMethod, _symbolMap) = savedState; | ||
|
|
||
|
|
@@ -150,7 +151,7 @@ protected override ImmutableArray<MethodSymbol> VisitDeclaredLocalFunctions(Immu | |
| switch (symbol?.MethodKind) | ||
| { | ||
| case MethodKind.LambdaMethod: | ||
| throw ExceptionUtilities.Unreachable(); | ||
| return (MethodSymbol)_symbolMap[symbol]; | ||
|
|
||
| case MethodKind.LocalFunction: | ||
| if (symbol.IsDefinition) | ||
|
|
@@ -208,5 +209,10 @@ public override BoundNode VisitUnaryOperator(BoundUnaryOperator node) | |
| { | ||
| return ExtensionMethodReferenceRewriter.VisitBinaryOperatorData(this, node); | ||
| } | ||
|
|
||
| public override BoundNode? VisitMethodDefIndex(BoundMethodDefIndex node) | ||
| { | ||
| return ExtensionMethodReferenceRewriter.VisitMethodDefIndex(this, node); | ||
| } | ||
| } | ||
| } | ||
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.
📝 The purpose of this change is to get the locals rewritten (see
VisitLocalsinVisitBlockInstrumentation). Otherwise, we end up with non-rewritten locals in the emit stage (ie. not found in LocalSlotManager)