-
Notifications
You must be signed in to change notification settings - Fork 161
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
Extension of IL verification rules to address readonly references #21
Conversation
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.
Spec looks right and doable. We'll schedule work to prototype it on mono.
proposed/verifiable-ref-readonly.md
Outdated
## Merging stack states ## | ||
*(add to III.1.8.1.3 Merging stack states)* | ||
|
||
Merging a readonly managed pointer with an managed pointer of an ordinary or controlled mutability kind results in a managed pointer of that kind. |
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.
I believe this contradicts what's stated here about C# rules: https://github.com/dotnet/designs/pull/21/files#diff-f24baba7454a8bd449c0bce2f4e46336R15
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.
You are right. I adopted the part of this rule from the "returnable ref" proposal, but in this case the readonly
should win over since it is the most constrained.
Will fix. Thanks!!
After a review of the rules around implementing/overriding with @davidwrighton it has become clear that it is not always possible to guarantee that methods match in terms of Hence the change in that part of the proposal. We no longer rely on verification to match While so far the primary purpose of the |
@davidwrighton - please take a look |
Would it make sense to try to align this with how C++/CLI handles public value class A
{
public:
const A% GetA(const A% a) { return a; }
}; Gets represented as this in the metadata:
Things of note:
|
Merging this, since this has been opened for a long time, and informally approved by interested parties. NOTE: The proposal does not have direct impact on the language, but has effect on the compiler. |
@VSadov Were there reasons why we needed to reinvent the metadata encoding for this? (See how C++/CLI represents this above.) (I've been labeled the owner of the metadata stack in the CLR for a while so I would say I'm an "interested party"). |
IsConst was the first thing we tried here. It turned out not possible - specifically because it is already in use for various purposes. And in particular because C++ knows about it and in many cases simply ignores it. The conclusion was - if we want something with defined semantics it must be something new or we run into issues where it already means something different from what we need. I.E. ironically - if we had chosen IsConst we would close the door to interop with C++ as our use would conflict with theirs. |
The proposal here is to rationalize rules how the metadata that C# already emits (with some additions around locals) could be used in verification. It is still a proposal, but not a “proposal for a proposal” :) |
@MichalStrehovsky - please take a look at #31 After thinking a bit about whether |
A proposal for extension of IL verification rules that would allow operating with readonly references without defensive copying in verifiable code.
In the nutshell the rules would allow type-safe scenarios like fetching a reference to a readonly field and passing that to an “in” parameter be formally verifiable.
The proposal explains how “readonliness” demands and guarantees can be propagated and validated by the IL verification algorithm.