-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Closed
Labels
Milestone
Description
First, I will start with a simple feature description. This is not meant to be a specification, just an English-language description of the feature and the intent.
The feature is to add a new well-known attribute to the compiler, System.Runtime.CompilerServices.SkipLocalsInit that causes method bodies nested "inside" the scope of the attribute to elide the ".locals init" CIL directive that causes the CLR to zero-init local variables and space reserved using the "localloc" instruction. "Nested inside the scope of the attribute" is a concept defined as follows:
- When the attribute is applied to a module, all emitted methods inside that module, including generated methods, will skip local initialization.
- When the attribute is applied to a type (including interfaces), all methods inside that type, including generated methods, will skip local initialization.
- When the attribute is applied to a method, the method and all methods generated by the compiler which contain user-influenced code inside that method (e.g., local functions, lambdas, async methods) will skip local initialization.
Given that definition, the test plan follows.
- Specification checked in to
csharplangand/orroslyn. - Trivial case: method with SkipLocalsInit and >0 locals lists locals but no .locals init flag on emit
- Method with SkipLocalsInit and no locals, but stackalloc doesn't have .locals init flag
- SkipLocalsInit attribute can be mixed with other attributes
- Nested functions inside method with SkipLocalsInit inherit setting
- Lambdas
- Local functions
- Async state machines
- Iterator state machines
- Local functions + async & iterator
- Versions of the previous nested inside one-another
- SkipLocalsInit doesn't apply to constructor of DisplayClass for closures
- SkipLocalsInit on module applies to generated anonymous type
- Other members
- Attribute on declaration part of partial method, but not implementation part
- Same with types
- Properties
- Indexers
- Constructors
- Field initializers that declare locals, e.g. through out var
- Finalizers
- Static versions of previous
- Property-like event handlers
- Attribute on declaration part of partial method, but not implementation part
- SkipLocalsInit on type also applies to all previous members and nested functions/generated members
- Abstract classes/inheritance
- Also inherited to generated types
- Nested types
- SkipLocalsInit on modules
- Applies to nested versions of all previous
- Works with netmodule emit
- If assembly references module with attribute, SkipLocalsInit is not automatically applied to other modules
- Applies to default interface implementations
- What to emit for EnC?
-
Scripting?? - Add supporting type Added CompilerServices.SkipLocalsInitAttribute coreclr#20093
- Update Test Plan doc to mention SkipLocalsInit for future testing
Productivity
- The diagnostic for missing
unsafeswitch should trigger appropriate fixer to fix the project
Reactions are currently unavailable