Inline resource strings in the compiler (#80896)
authorMichal Strehovský <MichalStrehovsky@users.noreply.github.com>
Mon, 30 Jan 2023 23:53:42 +0000 (08:53 +0900)
committerGitHub <noreply@github.com>
Mon, 30 Jan 2023 23:53:42 +0000 (08:53 +0900)
commit759fecb5ef5ca893d289da7b885cf7f8dd50cb84
tree8f4c9c2439929569ec5a627d178110e528b1f63b
parentb6935d3791cbcb0a680512a1dab3eeaefdbd328d
Inline resource strings in the compiler (#80896)

On a high level:
* When we're looking at IL to do substitutions, we additionally look for calls to `SR.SomeResourceName`. These are generated properties (generated by a piece of code in Arcade) that basically just do `GetResourceString(nameof(SomeResourceName))`. We look up what the resource string is (in the manifest resource) and replace the call with the looked up string literal.
* We also keep track of calls to `SR.GetResourceString`. Seeing this in the graph means that the optimization was defeated - someone bypassed the generated accessors. If we see one, we add dependency graph node to the graph that represent the manifest resource that has the string.
* When generating managed resources we skip over the one that has the strings unless the above dependency node is in the graph. This allows optimizing away the resource blobs if all accesses were inlined.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/StackFrame.NativeAot.cs
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/InlineableStringsResourceNode.cs [new file with mode: 0644]
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NodeFactory.cs
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ResourceDataNode.cs
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/FeatureSwitchManager.cs
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/MetadataManager.cs
src/coreclr/tools/aot/ILCompiler.Compiler/ILCompiler.Compiler.csproj
src/libraries/Common/src/System/SR.cs
src/libraries/System.Private.CoreLib/src/System/Text/EncodingData.cs
src/libraries/System.Private.CoreLib/src/System/Text/EncodingTable.cs
src/tests/nativeaot/SmokeTests/FrameworkStrings/Program.cs