-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove ILLink support for field init substitutions #107380
base: main
Are you sure you want to change the base?
Conversation
[Kept] | ||
[ExpectedInstructionSequence (new[] { | ||
"ldc.i4.1", | ||
"ret", | ||
})] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are these methods removed now / why weren't they before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without the static ctor, the type is now BeforeFieldInit, which lets UnreachableBlocksOptimizer treat the method calls as side-effect free and inline them.
|
||
string init = GetAttribute (fieldNav, "initialize"); | ||
if (init?.ToLowerInvariant () == "true") { | ||
_substitutionInfo.SetFieldInit (field); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is effectively a silent break - I would prefer we report a warning.
Pros - we don't need to "Educate" anyone on this really - the tooling will do the education for us
Cons - code to keep around and delete a release or two later (and the test)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we throw on this code path like native AOT?
runtime/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/BodySubstitutionParser.cs
Lines 145 to 153 in 66e45ef
if (string.Equals(GetAttribute(fieldNav, "initialize"), "true", StringComparison.InvariantCultureIgnoreCase)) | |
{ | |
// We would need to also mess with the cctor of the type to set the field to this value: | |
// | |
// * ILLink will remove all stsfld instructions referencing this field from the cctor | |
// * It will place an explicit stsfld in front of the last "ret" instruction in the cctor | |
// | |
// This approach... has issues. | |
throw new NotSupportedException(); |
That avoids having to keep around the machinery and tests for the new warning, which seems a bit much for a feature that is barely used and not really considered supported in the first place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That works - warning is a bit more "pleasant" (can be ignored), hard crash means that the code MUST be fixed, so if this comes from a NuGet I'm screwed. But given the rarity of this, it may be fine.
@tannergooding what would it take to remove the use of this in your repos? Looks like you're the only user of this on Github. If I remember correctly, this is a for a feature that wasn't even needed in the end (with terrafx/terrafx.interop.windows#343, one shouldn't need to set feature switches to get size savings). |
@MichalStrehovsky sorry I missed the ping here. Are you specifically referring to removing the If so, I think I'd really just want some definitive code pattern for dealing with While the use of |
Yep. We don't really substitute fields elsewhere, we substitute properties. ILLinker has support for the hacky |
I can switch it to a property fairly easily. The main reason it wasn't is because such calls used to be
For sure. Just wondering though, is this perhaps something that would be fine to leave as undefined behavior? That is, just state that using the substituted fields with reflection is unsupported. The places I'm using it aren't using (and have no desire to use) reflection with such fields, as it kind-of defeats their purpose 😄. If we could still support this and just leave reflecting over substituted fields as UB, then it mostly avoids the issue and doesn't force a lot of extra calls to exist for the JIT scenario that then have to be handled by the inliner and its budget. -- Definitely understand if this still isn't desired, just thought I'd ask since it would keep a nice feature still efficient for that scenario. |
Oh so this PR only removes the support for the |
Gotcha, so this just requires removal of That's all good with me and I can get the repo's updated to drop that. I likely only added |
Yes, that's the idea. |
Fixes #107379.
Uses of this were very limited: https://github.com/search?q=path%3AILLink.Substitutions.xml%20initialize%3D%22true%22&type=code.
Would this need a breaking change doc?