-
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.
Implements Requires*Attribute on class behavior for NativeAOT (#83417)
Implements most of the missing pieces to get Requires on class working correctly in NativeAOT. Major changes: * Detect Requires mismatch between derived and base class * Warn on field access if the owning class has Requires * Changes to reflection marking to warn on more cases (instance methods on Requires classes for example) Supportive changes: * The helpers to detect Requires attributes now return the found attribute view out parameter Fixes #81158 Still two missing pieces - tracked by #82447: * Requires on attributes - NativeAOT doesn't handle this at all yet, part of it is Requires on the attribute class * Avoid warning when DAM marking an override method which has Requires (or its class has) - this avoids lot of noise, NativeAOT currently generates these warnings in full
- Loading branch information
1 parent
2d82829
commit 5bdc36e
Showing
13 changed files
with
340 additions
and
113 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
38 changes: 38 additions & 0 deletions
38
...coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/TrimAnalysisFieldAccessPattern.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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using ILCompiler.Logging; | ||
using ILLink.Shared.TrimAnalysis; | ||
using Internal.TypeSystem; | ||
|
||
namespace ILCompiler.Dataflow | ||
{ | ||
public readonly record struct TrimAnalysisFieldAccessPattern | ||
{ | ||
public FieldDesc Field { init; get; } | ||
public MessageOrigin Origin { init; get; } | ||
|
||
public TrimAnalysisFieldAccessPattern(FieldDesc field, MessageOrigin origin) | ||
{ | ||
Field = field; | ||
Origin = origin; | ||
} | ||
|
||
// No Merge - there's nothing to merge since this pattern is uniquely identified by both the origin and the entity | ||
// and there's only one way to "access" a field. | ||
|
||
public void MarkAndProduceDiagnostics(ReflectionMarker reflectionMarker, Logger logger) | ||
{ | ||
var diagnosticContext = new DiagnosticContext( | ||
Origin, | ||
logger.ShouldSuppressAnalysisWarningsForRequires(Origin.MemberDefinition, DiagnosticUtilities.RequiresUnreferencedCodeAttribute), | ||
logger.ShouldSuppressAnalysisWarningsForRequires(Origin.MemberDefinition, DiagnosticUtilities.RequiresDynamicCodeAttribute), | ||
logger.ShouldSuppressAnalysisWarningsForRequires(Origin.MemberDefinition, DiagnosticUtilities.RequiresAssemblyFilesAttribute), | ||
logger); | ||
|
||
ReflectionMethodBodyScanner.CheckAndReportRequires(diagnosticContext, Field, DiagnosticUtilities.RequiresUnreferencedCodeAttribute); | ||
ReflectionMethodBodyScanner.CheckAndReportRequires(diagnosticContext, Field, DiagnosticUtilities.RequiresDynamicCodeAttribute); | ||
ReflectionMethodBodyScanner.CheckAndReportRequires(diagnosticContext, Field, DiagnosticUtilities.RequiresAssemblyFilesAttribute); | ||
} | ||
} | ||
} |
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.