-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Allow initonly field during ldflda and stfld import #57385
Conversation
Tagging subscribers to this area: @JulieLeeMSFT Issue DetailsFixes #55033 An immediate fix for this issue could be: --- a/src/coreclr/tools/ILVerification/ILImporter.Verify.cs
+++ b/src/coreclr/tools/ILVerification/ILImporter.Verify.cs
@@ -2108,7 +2108,7 @@ void ImportAddressOfField(int token, bool isStatic)
instance = actualThis.Type;
if (field.IsInitOnly)
- Check(_method.IsConstructor && field.OwningType == _method.OwningType && actualThis.IsThisPtr, VerifierError.InitOnly);
+ Check(_method.IsVirtual || (_method.IsConstructor && field.OwningType == _method.OwningType && actualThis.IsThisPtr), VerifierError.InitOnly);
}
Check(_method.OwningType.CanAccess(field, instance), VerifierError.FieldAccess); in case of ToString, GetHashCode examples, we are:
However, reading the conversation in related thread dotnet/roslyn#22485, this check seems too conservative and does not take modern ECMA rules into account. This PR removes the check and adds +/- test cases where it should or shouldn't be allowed.
|
@jkotas, PTAL. I was able to reproduce it in tests using |
8383faf
to
3fe6a7b
Compare
It would be better to add the verification rules for readonly references proposed in dotnet/designs#21 instead of just deleting this check. Have you thought about what it would take? If it is not something you would like to spend time on right now, we should open a new issue on adding the verification rules for readonly references and comment out this check instead of deleting it, with the link to the new issue. |
The same check for instance fields in ImportStoreField has this problem as well. It should get the same treatment. It will fail on C# program like this:
|
I have updated stfld and stsfld checks such that:
|
Thanks for sharing this link. From the perspective of ldflda and ldsflda, the spec seem to have relaxed the rules for initonly fields. I have kept the checks commented for now. |
dd37909
to
a63b014
Compare
a63b014
to
0d23e53
Compare
// * `get_Property` -> [ 'get_Property' ] | ||
// * `CheckSomething_Valid` -> [ 'CheckSomething', 'Valid' ] | ||
// * 'WrongMethod_Invalid_BranchOutOfTry' -> [ 'WrongMethod', 'Invalid', 'BranchOutOfTry' ] | ||
// * 'MoreWrongMethod_Invalid_TypeAccess.InitOnly' -> [ 'MoreWrongMethod', 'Invalid', 'TypeAccess', 'InitOnly' ] |
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.
TypeAccess.InitOnly
Should this be TypeAccess_InitOnly
? I do not see where we are recognizing .
as the separator.
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.
We have 25 cases using period as a error code separator when there is more than one error:
$ git grep '_Invalid_.*\..*\(.*\)' ':/src/tests/ilverify/ILTests'
It is documented here https://github.com/dotnet/runtime/tree/main/src/coreclr/tools/ILVerify#methods-with-special-names. I agree it is quite complicated; imo, we should use xml or json list for this rather than complex naming convention parsing.
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.
we should use xml or json list
Then you have a problem with the IL and json being out-of-sync all the time. I actually like the convention based scheme we have here.
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.
Then you have a problem with the IL and json being out-of-sync all the time.
Current approach is equally fragile. The test discovery does not give any indication whether or not it has skipped the test during parsing (which is spread across three separate methods of TestDataLoader.cs). We have to remember total count before and after the new additions.
@@ -95,19 +95,8 @@ | |||
ret | |||
} | |||
|
|||
.method public hidebysig instance void 'special.StoreInitonlyFieldOtherInstance..ctor_Invalid_InitOnly'(class FieldTestsType c) cil managed { ret } | |||
.method public hidebysig specialname rtspecialname instance void .ctor(class FieldTestsType c) cil managed |
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.
body is actually not doing what method name suggests.
As far as I can tell, StoreInitonlyFieldOtherInstance described well what the body was doing. Am I missing something?
a74beaa
to
fc831d8
Compare
src/coreclr/tools/aot/ILCompiler.TypeSystem.ReadyToRun.Tests/SignatureTests.cs
Show resolved
Hide resolved
75039cb
to
e66f149
Compare
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.
LGTM. Thank you!
Thanks! |
Fixes #55033
An immediate fix for this issue could be:
in case of ToString, GetHashCode examples, we are:
this
is not a thisptrHowever, reading the conversation in related thread dotnet/roslyn#22485, this check seems too conservative and does not take modern ECMA rules into account. This PR removes the check and adds +/- test cases where it should or shouldn't be allowed.