Skip to content
This repository was archived by the owner on Nov 1, 2020. It is now read-only.

Allow preinitializing delegates and reading initonly statics#8204

Merged
MichalStrehovsky merged 3 commits into
dotnet:masterfrom
MichalStrehovsky:preinitDelegate
Jun 23, 2020
Merged

Allow preinitializing delegates and reading initonly statics#8204
MichalStrehovsky merged 3 commits into
dotnet:masterfrom
MichalStrehovsky:preinitDelegate

Conversation

@MichalStrehovsky

Copy link
Copy Markdown
Member

This extends the static constructor interpreter with support for preinitializing delegates and support for reading readonly static fields declared by other types.

The readonly static fields can be accessed after interpreting the static constructor of the containing type. This opens us up to recursive dependencies - the interpreter will bail if recursive dependency is hit (we already have a test).

This significantly improves the interpreter's ability to run static constructors at compile time:

Eligible types Preinitialized before Preinitialized after
WinForms 1520 702 967
WebApi 2005 746 1278

About 60% of types now have their static constructor executed at compile time.

This extends the static constructor interpreter with support for preinitializing delegates and support for reading readonly static fields declared by other types.

The readonly static fields can be accessed after interpreting the static constructor of the containing type. This opens us up to recursive dependencies. The interpreter will bail if recursive dependency is hit (we already have a test).

This significantly improves the interpreter's ability to run static constructors at compile time:

|          | Eligible types | Preinitialized before | Preinitialized after |
| -------- | -------------- | --------------------- | -------------------- |
| WinForms | 1520           | 702                   | 967                  |
| WebApi   | 2005           | 746                   | 1278                 |

About 60% of types now have their static constructor executed at compile time.

@jkotas jkotas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thanks

Comment thread src/ILCompiler.Compiler/src/Compiler/TypePreinit.cs Outdated
Comment thread src/ILCompiler.Compiler/src/Compiler/TypePreinit.cs
Comment thread src/ILCompiler.Compiler/src/Compiler/TypePreinit.cs
Comment thread src/ILCompiler.Compiler/src/Compiler/TypePreinit.cs Outdated
@MichalStrehovsky MichalStrehovsky merged commit fa19492 into dotnet:master Jun 23, 2020
@MichalStrehovsky MichalStrehovsky deleted the preinitDelegate branch June 23, 2020 06:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants