Skip to content

Commit

Permalink
Do not instrument types nested in nested instrumentation type.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmat committed Feb 11, 2023
1 parent 7d8cb8e commit 92ac7e5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public static bool TryCreate(
}

var instrumentationType = factory.Compilation.GetWellKnownType(WellKnownType.Microsoft_CodeAnalysis_Runtime_LocalStoreTracker);
if (method.ContainingType.Equals(instrumentationType))
if (IsInstrumentationOrNestedType(method.ContainingType, instrumentationType))
{
return false;
}
Expand All @@ -178,6 +178,24 @@ public static bool TryCreate(
return true;
}

private static bool IsInstrumentationOrNestedType(NamedTypeSymbol type, NamedTypeSymbol instrumentationType)
{
while (true)
{
if (type.Equals(instrumentationType))
{
return true;
}

if (type.ContainingType is null)
{
return false;
}

type = type.ContainingType;
}
}

private MethodSymbol? GetLocalOrParameterStoreLogger(TypeSymbol variableType, Symbol targetSymbol, bool? refAssignmentSourceIsLocal, SyntaxNode syntax)
{
var enumDelta = (targetSymbol.Kind == SymbolKind.Parameter) ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class LocalStateTracingTests : CSharpTestBase
// TODO: https://github.com/dotnet/roslyn/issues/66809
// arrays (stloc, stelem),
// collections, anonymous types, tuples
// LogLocalStoreUnmanaged with local/parameter typed to a generic parameter

private static readonly EmitOptions s_emitOptions = EmitOptions.Default
.WithInstrumentationKinds(ImmutableArray.Create(InstrumentationKind.LocalStateTracing));
Expand All @@ -38,7 +39,7 @@ namespace Microsoft.CodeAnalysis.Runtime
using static System.Console;
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public unsafe readonly ref struct LocalStoreTracker
public unsafe readonly ref partial struct LocalStoreTracker
{
private static int s_stateMachineId;
Expand Down Expand Up @@ -460,7 +461,23 @@ .maxstack 3
[Fact]
public void HelpersNotInstrumented()
{
var source = WithHelpers("");
var source = WithHelpers(@"
namespace Microsoft.CodeAnalysis.Runtime
{
partial struct LocalStoreTracker
{
public class NestedHelpers
{
void F(int a) => a = 1;
public class SuperNestedHelpers
{
void F(int a) => a = 1;
}
}
}
}
");
var verifier = CompileAndVerify(source);
foreach (var entry in verifier.TestData.Methods)
{
Expand Down

0 comments on commit 92ac7e5

Please sign in to comment.