Implements Requires*Attribute on class behavior for NativeAOT (#83417)
authorVitek Karas <10670590+vitek-karas@users.noreply.github.com>
Thu, 16 Mar 2023 13:49:47 +0000 (06:49 -0700)
committerGitHub <noreply@github.com>
Thu, 16 Mar 2023 13:49:47 +0000 (06:49 -0700)
commit5bdc36e1d956fc39cd768b6cf59ac4b4bf5f56a5
treede1210fa831a3b420a36f61fd2b95174981ae56a
parent2d8282993ca76f164e820eb2ee9b97aa23e0160c
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 https://github.com/dotnet/runtime/issues/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
13 files changed:
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/DiagnosticUtilities.cs
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReflectionMarker.cs
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReflectionMethodBodyScanner.cs
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/TrimAnalysisAssignmentPattern.cs
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/TrimAnalysisFieldAccessPattern.cs [new file with mode: 0644]
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/TrimAnalysisPatternStore.cs
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/DataflowAnalyzedTypeDefinitionNode.cs
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Logger.cs
src/coreclr/tools/aot/ILCompiler.Compiler/ILCompiler.Compiler.csproj
src/tools/illink/src/linker/Linker.Steps/MarkStep.cs
src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/GenericParameterDataFlow.cs
src/tools/illink/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresInCompilerGeneratedCode.cs
src/tools/illink/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresOnClass.cs