-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement type name resolution for ILLink analyzer (#106209)
Adds support for parsing type names passed to Type.GetType. Fixes #95118
- Loading branch information
Showing
22 changed files
with
393 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 23 additions & 8 deletions
31
.../illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/RequireDynamicallyAccessedMembersAction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,55 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using System.Diagnostics; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Reflection.Metadata; | ||
using Microsoft.CodeAnalysis; | ||
using ILLink.RoslynAnalyzer.TrimAnalysis; | ||
using ILLink.Shared.TypeSystemProxy; | ||
using System.Collections.Immutable; | ||
|
||
namespace ILLink.Shared.TrimAnalysis | ||
{ | ||
internal partial struct RequireDynamicallyAccessedMembersAction | ||
{ | ||
readonly Location _location; | ||
readonly Action<Diagnostic>? _reportDiagnostic; | ||
readonly ReflectionAccessAnalyzer _reflectionAccessAnalyzer; | ||
readonly TypeNameResolver _typeNameResolver; | ||
#pragma warning disable CA1822 // Mark members as static - the other partial implementations might need to be instance methods | ||
#pragma warning disable IDE0060 // Unused parameters - should be removed once methods are actually implemented | ||
|
||
public RequireDynamicallyAccessedMembersAction ( | ||
DiagnosticContext diagnosticContext, | ||
TypeNameResolver typeNameResolver, | ||
Location location, | ||
Action<Diagnostic>? reportDiagnostic, | ||
ReflectionAccessAnalyzer reflectionAccessAnalyzer) | ||
{ | ||
_diagnosticContext = diagnosticContext; | ||
_typeNameResolver = typeNameResolver; | ||
_location = location; | ||
_reportDiagnostic = reportDiagnostic; | ||
_reflectionAccessAnalyzer = reflectionAccessAnalyzer; | ||
_diagnosticContext = new (location, reportDiagnostic); | ||
} | ||
|
||
public partial bool TryResolveTypeNameAndMark (string typeName, bool needsAssemblyName, out TypeProxy type) | ||
{ | ||
// TODO: Implement type name resolution to type symbol | ||
// https://github.com/dotnet/runtime/issues/95118 | ||
var diagnosticContext = new DiagnosticContext (_location, _reportDiagnostic); | ||
if (_reflectionAccessAnalyzer.TryResolveTypeNameAndMark (typeName, diagnosticContext, needsAssemblyName, out ITypeSymbol? foundType)) { | ||
if (foundType is INamedTypeSymbol namedType && namedType.IsGenericType) | ||
GenericArgumentDataFlow.ProcessGenericArgumentDataFlow (_typeNameResolver, _location, namedType, _reportDiagnostic); | ||
|
||
// Important corner cases: | ||
// IL2105 (see it's occurences in the tests) - non-assembly qualified type name which doesn't resolve warns | ||
// - will need to figure out what analyzer should do around this. | ||
type = new TypeProxy (foundType); | ||
return true; | ||
} | ||
|
||
type = default; | ||
return false; | ||
} | ||
|
||
private partial void MarkTypeForDynamicallyAccessedMembers (in TypeProxy type, DynamicallyAccessedMemberTypes dynamicallyAccessedMemberTypes) => | ||
_reflectionAccessAnalyzer.GetReflectionAccessDiagnostics (_diagnosticContext.Location, type.Type, dynamicallyAccessedMemberTypes); | ||
_reflectionAccessAnalyzer.GetReflectionAccessDiagnostics (_location, type.Type, dynamicallyAccessedMemberTypes); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.