Skip to content

Consider dropping support for <field initialize="true" /> #107379

@MichalStrehovsky

Description

@MichalStrehovsky

https://github.com/dotnet/linker/blob/main/docs/data-formats.md#override-static-field-value-with-a-constant

The implementation of this is to delete any stsfld in the cctor and inject a ststfld before the last ret in the method body but:

  • There's no law the last ret of the method body needs to be executed at all (there could be an if/else in the cctor that just terminates early, never executing the injected code, or an EH block, or anything else).
  • There's no law that the only way to initialize a static is through a stsfld in the cctor. It could be initialized from a method the cctor calls, it could be initialized through ldsflda/stind, etc.

I don't know what use case motivated initialize, but given the real complexity of implementing it properly is much higher than the simple thing IL Linker has, it should be put under scrutiny whether we need it in the first place. If we need it, the above are bugs.

Metadata

Metadata

Assignees

Labels

area-Tools-ILLink.NET linker development as well as trimming analyzersin-prThere is an active PR which will close this issue when it is merged

Type

No type

Projects

Status

No status

Relationships

None yet

Development

No branches or pull requests

Issue actions