Skip to content

Commit cf93d99

Browse files
authored
Backport "Do not use a constructed method symbol in a BoundMethodDefIndex" to release/dev17.14 (#79236)
* WIP: candidate fix for 78640 * Add reproducer * add IL baseline * Skip verification * Address some feedback * Regenerate bound nodes * Remove sealed * Address feedback
1 parent 3626840 commit cf93d99

File tree

9 files changed

+308
-3
lines changed

9 files changed

+308
-3
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System.Diagnostics;
6+
7+
namespace Microsoft.CodeAnalysis.CSharp
8+
{
9+
internal partial class BoundMethodDefIndex
10+
{
11+
private partial void Validate()
12+
{
13+
Debug.Assert(Method.IsDefinition);
14+
}
15+
}
16+
}

src/Compilers/CSharp/Portable/BoundTree/BoundNodes.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@
730730

731731
<!-- Represents the raw metadata RowId value for a method definition.
732732
Used by dynamic instrumentation to index into tables or arrays of per-method information. -->
733-
<Node Name="BoundMethodDefIndex" Base="BoundExpression">
733+
<Node Name="BoundMethodDefIndex" Base="BoundExpression" HasValidate="true">
734734
<!-- Non-null type is required for this node kind -->
735735
<Field Name="Type" Type="TypeSymbol" Override="true" Null="disallow"/>
736736
<Field Name="Method" Type="MethodSymbol"/>

src/Compilers/CSharp/Portable/Generated/BoundNodes.xml.Generated.cs

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/CSharp/Portable/Lowering/BoundTreeToDifferentEnclosingContextRewriter.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,13 @@ protected BoundBlock VisitBlock(BoundBlock node, bool removeInstrumentation)
139139
VisitType(node.Type));
140140
}
141141

142+
public override BoundNode? VisitMethodDefIndex(BoundMethodDefIndex node)
143+
{
144+
// Cannot replace a MethodDefIndex's Method/Type with a substituted symbol.
145+
Debug.Assert(node.Type.Equals(VisitType(node.Type), TypeCompareKind.ConsiderEverything));
146+
return node;
147+
}
148+
142149
[return: NotNullIfNotNull(nameof(method))]
143150
public override MethodSymbol? VisitMethodSymbol(MethodSymbol? method)
144151
{

src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncIteratorTests.cs

Lines changed: 254 additions & 0 deletions
Large diffs are not rendered by default.

src/Compilers/CSharp/Test/Emit/Emit/DynamicAnalysis/DynamicAnalysisResourceTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace Microsoft.CodeAnalysis.CSharp.DynamicAnalysis.UnitTests
2020
{
2121
public class DynamicAnalysisResourceTests : CSharpTestBase
2222
{
23-
const string InstrumentationHelperSource = @"
23+
public const string InstrumentationHelperSource = @"
2424
namespace Microsoft.CodeAnalysis.Runtime
2525
{
2626
public static class Instrumentation
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
' Licensed to the .NET Foundation under one or more agreements.
2+
' The .NET Foundation licenses this file to you under the MIT license.
3+
' See the LICENSE file in the project root for more information.
4+
5+
Imports Microsoft.CodeAnalysis.Text
6+
Imports Microsoft.CodeAnalysis.VisualBasic.Symbols
7+
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
8+
9+
Namespace Microsoft.CodeAnalysis.VisualBasic
10+
Partial Friend Class BoundMethodDefIndex
11+
#If DEBUG Then
12+
Private Sub Validate()
13+
Debug.Assert(Method.IsDefinition)
14+
End Sub
15+
#End If
16+
End Class
17+
End Namespace

src/Compilers/VisualBasic/Portable/BoundTree/BoundNodes.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@
256256

257257
<!-- Represents the raw metadata token index value for a method definition.
258258
Used by dynamic instrumentation to index into tables or arrays of per-method information. -->
259-
<Node Name="BoundMethodDefIndex" Base="BoundExpression">
259+
<Node Name="BoundMethodDefIndex" Base="BoundExpression" HasValidate="true">
260260
<!-- Non-null type is required for this node kind -->
261261
<Field Name="Type" Type="TypeSymbol" Override="true" Null="disallow"/>
262262
<Field Name="Method" Type="MethodSymbol"/>

src/Compilers/VisualBasic/Portable/Generated/BoundNodes.xml.Generated.vb

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)